@aztec/pxe 0.0.1-commit.3895657bc → 0.0.1-commit.3e3d0c9cd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +9 -3
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +17 -3
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +17 -9
- package/dest/contract_function_simulator/index.d.ts +2 -1
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -3
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +5 -4
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
- package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts +16 -0
- package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/message_tx_context.js +57 -0
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +3 -5
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +13 -9
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +43 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +6 -6
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +21 -15
- package/dest/contract_function_simulator/oracle/private_execution.js +4 -2
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +8 -30
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +7 -37
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +19 -7
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +60 -7
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +36 -0
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/pxe.d.ts +6 -3
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +27 -17
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +26 -25
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
- package/dest/tagging/index.d.ts +2 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +10 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +2 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +24 -11
- package/package.json +16 -16
- package/src/contract_function_simulator/contract_function_simulator.ts +25 -3
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +16 -11
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -5
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
- package/src/contract_function_simulator/noir-structs/message_tx_context.ts +55 -0
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -6
- package/src/contract_function_simulator/oracle/interfaces.ts +16 -17
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +142 -0
- package/src/contract_function_simulator/oracle/oracle.ts +30 -40
- package/src/contract_function_simulator/oracle/private_execution.ts +3 -3
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +9 -53
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +90 -9
- package/src/messages/message_context_service.ts +45 -0
- package/src/oracle_version.ts +2 -2
- package/src/pxe.ts +45 -16
- package/src/storage/metadata.ts +1 -1
- package/src/storage/tagging_store/sender_tagging_store.ts +182 -135
- package/src/tagging/index.ts +1 -1
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +19 -1
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +19 -9
|
@@ -16,6 +16,7 @@ import { BlockHash } from '@aztec/stdlib/block';
|
|
|
16
16
|
import { ContractClassLog, ContractClassLogFields } from '@aztec/stdlib/logs';
|
|
17
17
|
|
|
18
18
|
import type { IMiscOracle, IPrivateExecutionOracle, IUtilityExecutionOracle } from './interfaces.js';
|
|
19
|
+
import { buildLegacyOracleCallbacks } from './legacy_oracle_mappings.js';
|
|
19
20
|
import { packAsHintedNote } from './note_packing_utils.js';
|
|
20
21
|
|
|
21
22
|
export class UnavailableOracleError extends Error {
|
|
@@ -85,11 +86,13 @@ export class Oracle {
|
|
|
85
86
|
});
|
|
86
87
|
|
|
87
88
|
// Build callback object and return it
|
|
88
|
-
|
|
89
|
+
const callback = oracleNames.reduce((acc, name) => {
|
|
89
90
|
const method = this[name as keyof Omit<Oracle, (typeof excludedProps)[number]>];
|
|
90
91
|
acc[name] = method.bind(this);
|
|
91
92
|
return acc;
|
|
92
93
|
}, {} as ACIRCallback);
|
|
94
|
+
|
|
95
|
+
return { ...callback, ...buildLegacyOracleCallbacks(this) };
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
// eslint-disable-next-line camelcase
|
|
@@ -461,52 +464,20 @@ export class Oracle {
|
|
|
461
464
|
}
|
|
462
465
|
|
|
463
466
|
// eslint-disable-next-line camelcase
|
|
464
|
-
async
|
|
465
|
-
|
|
466
|
-
[calldataHash]: ACVMField[],
|
|
467
|
-
[sideEffectCounter]: ACVMField[],
|
|
468
|
-
[isStaticCall]: ACVMField[],
|
|
469
|
-
): Promise<ACVMField[]> {
|
|
470
|
-
await this.handlerAsPrivate().notifyEnqueuedPublicFunctionCall(
|
|
471
|
-
AztecAddress.fromString(contractAddress),
|
|
472
|
-
Fr.fromString(calldataHash),
|
|
473
|
-
Fr.fromString(sideEffectCounter).toNumber(),
|
|
474
|
-
Fr.fromString(isStaticCall).toBool(),
|
|
475
|
-
);
|
|
476
|
-
return [];
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
// eslint-disable-next-line camelcase
|
|
480
|
-
async aztec_prv_notifySetPublicTeardownFunctionCall(
|
|
481
|
-
[contractAddress]: ACVMField[],
|
|
482
|
-
[calldataHash]: ACVMField[],
|
|
483
|
-
[sideEffectCounter]: ACVMField[],
|
|
484
|
-
[isStaticCall]: ACVMField[],
|
|
485
|
-
): Promise<ACVMField[]> {
|
|
486
|
-
await this.handlerAsPrivate().notifySetPublicTeardownFunctionCall(
|
|
487
|
-
AztecAddress.fromString(contractAddress),
|
|
488
|
-
Fr.fromString(calldataHash),
|
|
489
|
-
Fr.fromString(sideEffectCounter).toNumber(),
|
|
490
|
-
Fr.fromString(isStaticCall).toBool(),
|
|
491
|
-
);
|
|
467
|
+
async aztec_prv_validatePublicCalldata([calldataHash]: ACVMField[]): Promise<ACVMField[]> {
|
|
468
|
+
await this.handlerAsPrivate().validatePublicCalldata(Fr.fromString(calldataHash));
|
|
492
469
|
return [];
|
|
493
470
|
}
|
|
494
471
|
|
|
495
472
|
// eslint-disable-next-line camelcase
|
|
496
|
-
async
|
|
497
|
-
|
|
498
|
-
> {
|
|
499
|
-
await this.handlerAsPrivate().notifySetMinRevertibleSideEffectCounter(
|
|
500
|
-
Fr.fromString(minRevertibleSideEffectCounter).toNumber(),
|
|
501
|
-
);
|
|
473
|
+
async aztec_prv_notifyRevertiblePhaseStart([minRevertibleSideEffectCounter]: ACVMField[]): Promise<ACVMField[]> {
|
|
474
|
+
await this.handlerAsPrivate().notifyRevertiblePhaseStart(Fr.fromString(minRevertibleSideEffectCounter).toNumber());
|
|
502
475
|
return Promise.resolve([]);
|
|
503
476
|
}
|
|
504
477
|
|
|
505
478
|
// eslint-disable-next-line camelcase
|
|
506
|
-
async
|
|
507
|
-
const isRevertible = await this.handlerAsPrivate().
|
|
508
|
-
Fr.fromString(sideEffectCounter).toNumber(),
|
|
509
|
-
);
|
|
479
|
+
async aztec_prv_inRevertiblePhase([sideEffectCounter]: ACVMField[]): Promise<ACVMField[]> {
|
|
480
|
+
const isRevertible = await this.handlerAsPrivate().inRevertiblePhase(Fr.fromString(sideEffectCounter).toNumber());
|
|
510
481
|
return Promise.resolve([toACVMField(isRevertible)]);
|
|
511
482
|
}
|
|
512
483
|
|
|
@@ -530,11 +501,15 @@ export class Oracle {
|
|
|
530
501
|
[contractAddress]: ACVMField[],
|
|
531
502
|
[noteValidationRequestsArrayBaseSlot]: ACVMField[],
|
|
532
503
|
[eventValidationRequestsArrayBaseSlot]: ACVMField[],
|
|
504
|
+
[maxNotePackedLen]: ACVMField[],
|
|
505
|
+
[maxEventSerializedLen]: ACVMField[],
|
|
533
506
|
): Promise<ACVMField[]> {
|
|
534
507
|
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
|
|
535
508
|
AztecAddress.fromString(contractAddress),
|
|
536
509
|
Fr.fromString(noteValidationRequestsArrayBaseSlot),
|
|
537
510
|
Fr.fromString(eventValidationRequestsArrayBaseSlot),
|
|
511
|
+
Fr.fromString(maxNotePackedLen).toNumber(),
|
|
512
|
+
Fr.fromString(maxEventSerializedLen).toNumber(),
|
|
538
513
|
);
|
|
539
514
|
|
|
540
515
|
return [];
|
|
@@ -554,6 +529,20 @@ export class Oracle {
|
|
|
554
529
|
return [];
|
|
555
530
|
}
|
|
556
531
|
|
|
532
|
+
// eslint-disable-next-line camelcase
|
|
533
|
+
async aztec_utl_utilityResolveMessageContexts(
|
|
534
|
+
[contractAddress]: ACVMField[],
|
|
535
|
+
[messageContextRequestsArrayBaseSlot]: ACVMField[],
|
|
536
|
+
[messageContextResponsesArrayBaseSlot]: ACVMField[],
|
|
537
|
+
): Promise<ACVMField[]> {
|
|
538
|
+
await this.handlerAsUtility().utilityResolveMessageContexts(
|
|
539
|
+
AztecAddress.fromString(contractAddress),
|
|
540
|
+
Fr.fromString(messageContextRequestsArrayBaseSlot),
|
|
541
|
+
Fr.fromString(messageContextResponsesArrayBaseSlot),
|
|
542
|
+
);
|
|
543
|
+
return [];
|
|
544
|
+
}
|
|
545
|
+
|
|
557
546
|
// eslint-disable-next-line camelcase
|
|
558
547
|
async aztec_utl_storeCapsule(
|
|
559
548
|
[contractAddress]: ACVMField[],
|
|
@@ -615,6 +604,7 @@ export class Oracle {
|
|
|
615
604
|
return [];
|
|
616
605
|
}
|
|
617
606
|
|
|
607
|
+
// TODO(F-452): Return Option and wrap in try/catch so BB exceptions don't crash PXE.
|
|
618
608
|
// eslint-disable-next-line camelcase
|
|
619
609
|
async aztec_utl_aes128Decrypt(
|
|
620
610
|
ciphertextBVecStorage: ACVMField[],
|
|
@@ -646,7 +636,7 @@ export class Oracle {
|
|
|
646
636
|
|
|
647
637
|
// eslint-disable-next-line camelcase
|
|
648
638
|
async aztec_utl_emitOffchainEffect(data: ACVMField[]) {
|
|
649
|
-
await this.
|
|
639
|
+
await this.handlerAsUtility().emitOffchainEffect(data.map(Fr.fromString));
|
|
650
640
|
return [];
|
|
651
641
|
}
|
|
652
642
|
|
|
@@ -81,7 +81,7 @@ export async function executePrivateFunction(
|
|
|
81
81
|
const newNotes = privateExecutionOracle.getNewNotes();
|
|
82
82
|
const noteHashNullifierCounterMap = privateExecutionOracle.getNoteHashNullifierCounterMap();
|
|
83
83
|
const offchainEffects = privateExecutionOracle.getOffchainEffects();
|
|
84
|
-
const
|
|
84
|
+
const taggingIndexRanges = privateExecutionOracle.getUsedTaggingIndexRanges();
|
|
85
85
|
const nestedExecutionResults = privateExecutionOracle.getNestedExecutionResults();
|
|
86
86
|
|
|
87
87
|
let timerSubtractionList = nestedExecutionResults;
|
|
@@ -103,8 +103,8 @@ export async function executePrivateFunction(
|
|
|
103
103
|
newNotes,
|
|
104
104
|
noteHashNullifierCounterMap,
|
|
105
105
|
rawReturnValues,
|
|
106
|
-
offchainEffects,
|
|
107
|
-
|
|
106
|
+
offchainEffects.map(e => ({ data: e.data })),
|
|
107
|
+
taggingIndexRanges,
|
|
108
108
|
nestedExecutionResults,
|
|
109
109
|
contractClassLogs,
|
|
110
110
|
{
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
15
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
16
16
|
import { PrivateContextInputs } from '@aztec/stdlib/kernel';
|
|
17
|
-
import { type ContractClassLog, ExtendedDirectionalAppTaggingSecret, type
|
|
17
|
+
import { type ContractClassLog, ExtendedDirectionalAppTaggingSecret, type TaggingIndexRange } from '@aztec/stdlib/logs';
|
|
18
18
|
import { Tag } from '@aztec/stdlib/logs';
|
|
19
19
|
import { Note, type NoteStatus } from '@aztec/stdlib/note';
|
|
20
20
|
import {
|
|
@@ -73,7 +73,6 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
73
73
|
private newNotes: NoteAndSlot[] = [];
|
|
74
74
|
private noteHashNullifierCounterMap: Map<number, number> = new Map();
|
|
75
75
|
private contractClassLogs: CountedContractClassLog[] = [];
|
|
76
|
-
private offchainEffects: { data: Fr[] }[] = [];
|
|
77
76
|
private nestedExecutionResults: PrivateCallExecutionResult[] = [];
|
|
78
77
|
|
|
79
78
|
private readonly argsHash: Fr;
|
|
@@ -159,17 +158,10 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
159
158
|
}
|
|
160
159
|
|
|
161
160
|
/**
|
|
162
|
-
*
|
|
161
|
+
* Returns the tagging index ranges that were used in this execution (and that need to be stored in the db).
|
|
163
162
|
*/
|
|
164
|
-
public
|
|
165
|
-
return this.
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Returns the pre-tags that were used in this execution (and that need to be stored in the db).
|
|
170
|
-
*/
|
|
171
|
-
public getUsedPreTags(): PreTag[] {
|
|
172
|
-
return this.taggingIndexCache.getUsedPreTags();
|
|
163
|
+
public getUsedTaggingIndexRanges(): TaggingIndexRange[] {
|
|
164
|
+
return this.taggingIndexCache.getUsedTaggingIndexRanges();
|
|
173
165
|
}
|
|
174
166
|
|
|
175
167
|
/**
|
|
@@ -569,6 +561,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
569
561
|
senderAddressBookStore: this.senderAddressBookStore,
|
|
570
562
|
capsuleStore: this.capsuleStore,
|
|
571
563
|
privateEventStore: this.privateEventStore,
|
|
564
|
+
messageContextService: this.messageContextService,
|
|
572
565
|
contractSyncService: this.contractSyncService,
|
|
573
566
|
jobId: this.jobId,
|
|
574
567
|
totalPublicCalldataCount: this.totalPublicCalldataCount,
|
|
@@ -608,7 +601,8 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
608
601
|
};
|
|
609
602
|
}
|
|
610
603
|
|
|
611
|
-
|
|
604
|
+
/** Validates the calldata preimage exists in the cache and checks cumulative calldata size is within limits. */
|
|
605
|
+
public validatePublicCalldata(calldataHash: Fr) {
|
|
612
606
|
const calldata = this.executionCache.getPreimage(calldataHash);
|
|
613
607
|
if (!calldata) {
|
|
614
608
|
throw new Error('Calldata for public call not found in cache');
|
|
@@ -618,47 +612,14 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
618
612
|
if (this.totalPublicCalldataCount > MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS) {
|
|
619
613
|
throw new Error(`Too many total args to all enqueued public calls! (> ${MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS})`);
|
|
620
614
|
}
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
/**
|
|
624
|
-
* Verify relevant information when a public function is enqueued.
|
|
625
|
-
* @param targetContractAddress - The address of the contract to call.
|
|
626
|
-
* @param calldataHash - The hash of the function selector and arguments.
|
|
627
|
-
* @param sideEffectCounter - The side effect counter at the start of the call.
|
|
628
|
-
* @param isStaticCall - Whether the call is a static call.
|
|
629
|
-
*/
|
|
630
|
-
public notifyEnqueuedPublicFunctionCall(
|
|
631
|
-
_targetContractAddress: AztecAddress,
|
|
632
|
-
calldataHash: Fr,
|
|
633
|
-
_sideEffectCounter: number,
|
|
634
|
-
_isStaticCall: boolean,
|
|
635
|
-
) {
|
|
636
|
-
this.#onNewPublicFunctionCall(calldataHash);
|
|
637
615
|
return Promise.resolve();
|
|
638
616
|
}
|
|
639
617
|
|
|
640
|
-
|
|
641
|
-
* Verify relevant information when a public teardown function is set.
|
|
642
|
-
* @param targetContractAddress - The address of the contract to call.
|
|
643
|
-
* @param argsHash - The arguments hash to pass to the function.
|
|
644
|
-
* @param sideEffectCounter - The side effect counter at the start of the call.
|
|
645
|
-
* @param isStaticCall - Whether the call is a static call.
|
|
646
|
-
*/
|
|
647
|
-
public notifySetPublicTeardownFunctionCall(
|
|
648
|
-
_targetContractAddress: AztecAddress,
|
|
649
|
-
calldataHash: Fr,
|
|
650
|
-
_sideEffectCounter: number,
|
|
651
|
-
_isStaticCall: boolean,
|
|
652
|
-
) {
|
|
653
|
-
this.#onNewPublicFunctionCall(calldataHash);
|
|
654
|
-
return Promise.resolve();
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
public notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number): Promise<void> {
|
|
618
|
+
public notifyRevertiblePhaseStart(minRevertibleSideEffectCounter: number): Promise<void> {
|
|
658
619
|
return this.noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
|
|
659
620
|
}
|
|
660
621
|
|
|
661
|
-
public
|
|
622
|
+
public inRevertiblePhase(sideEffectCounter: number): Promise<boolean> {
|
|
662
623
|
return Promise.resolve(this.noteCache.isSideEffectCounterRevertible(sideEffectCounter));
|
|
663
624
|
}
|
|
664
625
|
|
|
@@ -685,9 +646,4 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
685
646
|
public getDebugFunctionName() {
|
|
686
647
|
return this.contractStore.getDebugFunctionName(this.contractAddress, this.callContext.functionSelector);
|
|
687
648
|
}
|
|
688
|
-
|
|
689
|
-
public emitOffchainEffect(data: Fr[]): Promise<void> {
|
|
690
|
-
this.offchainEffects.push({ data });
|
|
691
|
-
return Promise.resolve();
|
|
692
|
-
}
|
|
693
649
|
}
|
|
@@ -6,24 +6,26 @@ import { Point } from '@aztec/foundation/curves/grumpkin';
|
|
|
6
6
|
import { LogLevels, type Logger, createLogger } from '@aztec/foundation/log';
|
|
7
7
|
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
8
8
|
import type { KeyStore } from '@aztec/key-store';
|
|
9
|
+
import { isProtocolContract } from '@aztec/protocol-contracts';
|
|
9
10
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
10
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
11
12
|
import { BlockHash } from '@aztec/stdlib/block';
|
|
12
|
-
import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
|
|
13
|
+
import type { CompleteAddress, ContractInstance, PartialAddress } from '@aztec/stdlib/contract';
|
|
13
14
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
14
15
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
15
16
|
import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
|
|
16
|
-
import { computeAddressSecret } from '@aztec/stdlib/keys';
|
|
17
|
+
import { type PublicKeys, computeAddressSecret } from '@aztec/stdlib/keys';
|
|
17
18
|
import { deriveEcdhSharedSecret } from '@aztec/stdlib/logs';
|
|
18
19
|
import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
19
20
|
import type { NoteStatus } from '@aztec/stdlib/note';
|
|
20
21
|
import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
21
|
-
import type { BlockHeader, Capsule } from '@aztec/stdlib/tx';
|
|
22
|
+
import type { BlockHeader, Capsule, OffchainEffect } from '@aztec/stdlib/tx';
|
|
22
23
|
|
|
23
24
|
import type { AccessScopes } from '../../access_scopes.js';
|
|
24
25
|
import { createContractLogger, logContractMessage } from '../../contract_logging.js';
|
|
25
26
|
import { EventService } from '../../events/event_service.js';
|
|
26
27
|
import { LogService } from '../../logs/log_service.js';
|
|
28
|
+
import { MessageContextService } from '../../messages/message_context_service.js';
|
|
27
29
|
import { NoteService } from '../../notes/note_service.js';
|
|
28
30
|
import { ORACLE_VERSION } from '../../oracle_version.js';
|
|
29
31
|
import type { AddressStore } from '../../storage/address_store/address_store.js';
|
|
@@ -36,6 +38,7 @@ import type { SenderAddressBookStore } from '../../storage/tagging_store/sender_
|
|
|
36
38
|
import { EventValidationRequest } from '../noir-structs/event_validation_request.js';
|
|
37
39
|
import { LogRetrievalRequest } from '../noir-structs/log_retrieval_request.js';
|
|
38
40
|
import { LogRetrievalResponse } from '../noir-structs/log_retrieval_response.js';
|
|
41
|
+
import { MessageTxContext } from '../noir-structs/message_tx_context.js';
|
|
39
42
|
import { NoteValidationRequest } from '../noir-structs/note_validation_request.js';
|
|
40
43
|
import { UtilityContext } from '../noir-structs/utility_context.js';
|
|
41
44
|
import { pickNotes } from '../pick_notes.js';
|
|
@@ -58,6 +61,7 @@ export type UtilityExecutionOracleArgs = {
|
|
|
58
61
|
senderAddressBookStore: SenderAddressBookStore;
|
|
59
62
|
capsuleStore: CapsuleStore;
|
|
60
63
|
privateEventStore: PrivateEventStore;
|
|
64
|
+
messageContextService: MessageContextService;
|
|
61
65
|
jobId: string;
|
|
62
66
|
log?: ReturnType<typeof createLogger>;
|
|
63
67
|
scopes: AccessScopes;
|
|
@@ -71,6 +75,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
71
75
|
isUtility = true as const;
|
|
72
76
|
|
|
73
77
|
private contractLogger: Logger | undefined;
|
|
78
|
+
private offchainEffects: OffchainEffect[] = [];
|
|
74
79
|
|
|
75
80
|
protected readonly contractAddress: AztecAddress;
|
|
76
81
|
protected readonly authWitnesses: AuthWitness[];
|
|
@@ -85,6 +90,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
85
90
|
protected readonly senderAddressBookStore: SenderAddressBookStore;
|
|
86
91
|
protected readonly capsuleStore: CapsuleStore;
|
|
87
92
|
protected readonly privateEventStore: PrivateEventStore;
|
|
93
|
+
protected readonly messageContextService: MessageContextService;
|
|
88
94
|
protected readonly jobId: string;
|
|
89
95
|
protected logger: ReturnType<typeof createLogger>;
|
|
90
96
|
protected readonly scopes: AccessScopes;
|
|
@@ -103,12 +109,28 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
103
109
|
this.senderAddressBookStore = args.senderAddressBookStore;
|
|
104
110
|
this.capsuleStore = args.capsuleStore;
|
|
105
111
|
this.privateEventStore = args.privateEventStore;
|
|
112
|
+
this.messageContextService = args.messageContextService;
|
|
106
113
|
this.jobId = args.jobId;
|
|
107
114
|
this.logger = args.log ?? createLogger('simulator:client_view_context');
|
|
108
115
|
this.scopes = args.scopes;
|
|
109
116
|
}
|
|
110
117
|
|
|
111
118
|
public assertCompatibleOracleVersion(version: number): void {
|
|
119
|
+
// TODO(F-416): Remove this hack on v5 when protocol contracts are redeployed.
|
|
120
|
+
// Protocol contracts/canonical contracts shipped with committed bytecode that cannot be changed. Assert they use
|
|
121
|
+
// the expected pinned version or the current one. We want to allow for both the pinned and the current versions
|
|
122
|
+
// because we want this code to work with both the pinned and unpinned version since some branches do not have the
|
|
123
|
+
// pinned contracts (like e.g. next)
|
|
124
|
+
const LEGACY_ORACLE_VERSION = 12;
|
|
125
|
+
if (isProtocolContract(this.contractAddress)) {
|
|
126
|
+
if (version !== LEGACY_ORACLE_VERSION && version !== ORACLE_VERSION) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
`Expected legacy oracle version ${LEGACY_ORACLE_VERSION} or current oracle version ${ORACLE_VERSION} for alpha payload contract at ${this.contractAddress}, got ${version}.`,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
112
134
|
if (version !== ORACLE_VERSION) {
|
|
113
135
|
throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
|
|
114
136
|
}
|
|
@@ -232,12 +254,18 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
232
254
|
}
|
|
233
255
|
|
|
234
256
|
/**
|
|
235
|
-
* Retrieve the
|
|
257
|
+
* Retrieve the public keys and partial address associated to a given address.
|
|
236
258
|
* @param account - The account address.
|
|
237
|
-
* @returns
|
|
259
|
+
* @returns The public keys and partial address, or `undefined` if the account is not registered.
|
|
238
260
|
*/
|
|
239
|
-
public tryGetPublicKeysAndPartialAddress(
|
|
240
|
-
|
|
261
|
+
public async tryGetPublicKeysAndPartialAddress(
|
|
262
|
+
account: AztecAddress,
|
|
263
|
+
): Promise<{ publicKeys: PublicKeys; partialAddress: PartialAddress } | undefined> {
|
|
264
|
+
const completeAddress = await this.addressStore.getCompleteAddress(account);
|
|
265
|
+
if (!completeAddress) {
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
return { publicKeys: completeAddress.publicKeys, partialAddress: completeAddress.partialAddress };
|
|
241
269
|
}
|
|
242
270
|
|
|
243
271
|
protected async getCompleteAddressOrFail(account: AztecAddress): Promise<CompleteAddress> {
|
|
@@ -448,6 +476,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
448
476
|
contractAddress: AztecAddress,
|
|
449
477
|
noteValidationRequestsArrayBaseSlot: Fr,
|
|
450
478
|
eventValidationRequestsArrayBaseSlot: Fr,
|
|
479
|
+
maxNotePackedLen: number,
|
|
480
|
+
maxEventSerializedLen: number,
|
|
451
481
|
) {
|
|
452
482
|
// TODO(#10727): allow other contracts to store notes
|
|
453
483
|
if (!this.contractAddress.equals(contractAddress)) {
|
|
@@ -458,11 +488,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
458
488
|
// faster as we don't need to wait for the network round-trip.
|
|
459
489
|
const noteValidationRequests = (
|
|
460
490
|
await this.capsuleStore.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, this.jobId)
|
|
461
|
-
).map(NoteValidationRequest.fromFields);
|
|
491
|
+
).map(fields => NoteValidationRequest.fromFields(fields, maxNotePackedLen));
|
|
462
492
|
|
|
463
493
|
const eventValidationRequests = (
|
|
464
494
|
await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId)
|
|
465
|
-
).map(EventValidationRequest.fromFields);
|
|
495
|
+
).map(fields => EventValidationRequest.fromFields(fields, maxEventSerializedLen));
|
|
466
496
|
|
|
467
497
|
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
|
|
468
498
|
const noteStorePromises = noteValidationRequests.map(request =>
|
|
@@ -542,6 +572,47 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
542
572
|
);
|
|
543
573
|
}
|
|
544
574
|
|
|
575
|
+
public async utilityResolveMessageContexts(
|
|
576
|
+
contractAddress: AztecAddress,
|
|
577
|
+
messageContextRequestsArrayBaseSlot: Fr,
|
|
578
|
+
messageContextResponsesArrayBaseSlot: Fr,
|
|
579
|
+
) {
|
|
580
|
+
try {
|
|
581
|
+
if (!this.contractAddress.equals(contractAddress)) {
|
|
582
|
+
throw new Error(`Got a message context request from ${contractAddress}, expected ${this.contractAddress}`);
|
|
583
|
+
}
|
|
584
|
+
const requestCapsules = await this.capsuleStore.readCapsuleArray(
|
|
585
|
+
contractAddress,
|
|
586
|
+
messageContextRequestsArrayBaseSlot,
|
|
587
|
+
this.jobId,
|
|
588
|
+
);
|
|
589
|
+
|
|
590
|
+
const txHashes = requestCapsules.map((fields, i) => {
|
|
591
|
+
if (fields.length !== 1) {
|
|
592
|
+
throw new Error(
|
|
593
|
+
`Malformed message context request at index ${i}: expected 1 field (tx hash), got ${fields.length}`,
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
return fields[0];
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
const maybeMessageContexts = await this.messageContextService.resolveMessageContexts(
|
|
600
|
+
txHashes,
|
|
601
|
+
this.anchorBlockHeader.getBlockNumber(),
|
|
602
|
+
);
|
|
603
|
+
|
|
604
|
+
// Leave response in response capsule array.
|
|
605
|
+
await this.capsuleStore.setCapsuleArray(
|
|
606
|
+
contractAddress,
|
|
607
|
+
messageContextResponsesArrayBaseSlot,
|
|
608
|
+
maybeMessageContexts.map(MessageTxContext.toSerializedOption),
|
|
609
|
+
this.jobId,
|
|
610
|
+
);
|
|
611
|
+
} finally {
|
|
612
|
+
await this.capsuleStore.setCapsuleArray(contractAddress, messageContextRequestsArrayBaseSlot, [], this.jobId);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
545
616
|
public storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
|
|
546
617
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
547
618
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
@@ -601,4 +672,14 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
601
672
|
const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
|
|
602
673
|
return deriveEcdhSharedSecret(addressSecret, ephPk);
|
|
603
674
|
}
|
|
675
|
+
|
|
676
|
+
public emitOffchainEffect(data: Fr[]): Promise<void> {
|
|
677
|
+
this.offchainEffects.push({ data, contractAddress: this.contractAddress });
|
|
678
|
+
return Promise.resolve();
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/** Returns offchain effects collected during execution. */
|
|
682
|
+
public getOffchainEffects(): OffchainEffect[] {
|
|
683
|
+
return this.offchainEffects;
|
|
684
|
+
}
|
|
604
685
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
3
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
4
|
+
|
|
5
|
+
import { MessageTxContext } from '../contract_function_simulator/noir-structs/message_tx_context.js';
|
|
6
|
+
|
|
7
|
+
/** Resolves transaction hashes into the context needed to process messages. */
|
|
8
|
+
export class MessageContextService {
|
|
9
|
+
constructor(private readonly aztecNode: AztecNode) {}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolves a list of tx hashes into their message contexts.
|
|
13
|
+
*
|
|
14
|
+
* For each tx hash, looks up the corresponding tx effect and extracts the note hashes and first nullifier needed to
|
|
15
|
+
* process messages that originated from that transaction. Returns `null` for tx hashes that are zero, not yet
|
|
16
|
+
* available, or in blocks beyond the anchor block.
|
|
17
|
+
*/
|
|
18
|
+
resolveMessageContexts(txHashes: Fr[], anchorBlockNumber: number): Promise<(MessageTxContext | null)[]> {
|
|
19
|
+
// TODO: optimize, we might be hitting the node to get the same txHash repeatedly
|
|
20
|
+
return Promise.all(
|
|
21
|
+
txHashes.map(async txHashField => {
|
|
22
|
+
// A zero tx hash indicates a tx-less offchain message (e.g. one not tied to any onchain transaction).
|
|
23
|
+
// These messages don't have a transaction context to resolve, so we return null.
|
|
24
|
+
if (txHashField.isZero()) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const txHash = TxHash.fromField(txHashField);
|
|
29
|
+
const txEffect = await this.aztecNode.getTxEffect(txHash);
|
|
30
|
+
if (!txEffect || txEffect.l2BlockNumber > anchorBlockNumber) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Every tx has at least one nullifier (the first nullifier derived from the tx hash). Hitting this condition
|
|
35
|
+
// would mean a buggy node, but since we need to access data.nullifiers[0], the defensive check does no harm.
|
|
36
|
+
const data = txEffect.data;
|
|
37
|
+
if (data.nullifiers.length === 0) {
|
|
38
|
+
throw new Error(`Tx effect for ${txHash} has no nullifiers`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return new MessageTxContext(data.txHash, data.noteHashes, data.nullifiers[0]);
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/oracle_version.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
///
|
|
5
5
|
/// @dev Whenever a contract function or Noir test is run, the `aztec_utl_assertCompatibleOracleVersion` oracle is called
|
|
6
6
|
/// and if the oracle version is incompatible an error is thrown.
|
|
7
|
-
export const ORACLE_VERSION =
|
|
7
|
+
export const ORACLE_VERSION = 16;
|
|
8
8
|
|
|
9
9
|
/// This hash is computed as by hashing the Oracle interface and it is used to detect when the Oracle interface changes,
|
|
10
10
|
/// which in turn implies that you need to update the ORACLE_VERSION constant in this file and in
|
|
11
11
|
/// `noir-projects/aztec-nr/aztec/src/oracle/version.nr`.
|
|
12
|
-
export const ORACLE_INTERFACE_HASH = '
|
|
12
|
+
export const ORACLE_INTERFACE_HASH = '73ccb2a24bc9fe7514108be9ff98d7ca8734bc316fb7c1ec4329d1d32f412a55';
|