@aztec/pxe 0.0.1-commit.db765a8 → 0.0.1-commit.df81a97b5

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.
Files changed (91) hide show
  1. package/dest/config/index.d.ts +2 -2
  2. package/dest/config/index.d.ts.map +1 -1
  3. package/dest/config/index.js +1 -1
  4. package/dest/contract_function_simulator/contract_function_simulator.d.ts +9 -3
  5. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  6. package/dest/contract_function_simulator/contract_function_simulator.js +25 -3
  7. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
  8. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  9. package/dest/contract_function_simulator/execution_tagging_index_cache.js +17 -9
  10. package/dest/contract_function_simulator/index.d.ts +2 -1
  11. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  12. package/dest/contract_function_simulator/index.js +1 -0
  13. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -3
  14. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  15. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +5 -4
  16. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  17. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  18. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
  19. package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts +16 -0
  20. package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts.map +1 -0
  21. package/dest/contract_function_simulator/noir-structs/message_tx_context.js +57 -0
  22. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -4
  23. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  24. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +3 -5
  25. package/dest/contract_function_simulator/oracle/interfaces.d.ts +14 -9
  26. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  28. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  29. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +42 -0
  30. package/dest/contract_function_simulator/oracle/oracle.d.ts +8 -7
  31. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/oracle/oracle.js +44 -18
  33. package/dest/contract_function_simulator/oracle/private_execution.js +4 -2
  34. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +8 -33
  35. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +7 -39
  37. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +27 -7
  38. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +71 -7
  40. package/dest/contract_sync/contract_sync_service.d.ts +5 -3
  41. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  42. package/dest/contract_sync/contract_sync_service.js +47 -30
  43. package/dest/messages/message_context_service.d.ts +17 -0
  44. package/dest/messages/message_context_service.d.ts.map +1 -0
  45. package/dest/messages/message_context_service.js +36 -0
  46. package/dest/oracle_version.d.ts +2 -2
  47. package/dest/oracle_version.js +2 -2
  48. package/dest/pxe.d.ts +6 -3
  49. package/dest/pxe.d.ts.map +1 -1
  50. package/dest/pxe.js +33 -19
  51. package/dest/storage/metadata.d.ts +1 -1
  52. package/dest/storage/metadata.js +1 -1
  53. package/dest/storage/tagging_store/sender_tagging_store.d.ts +26 -25
  54. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  55. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  56. package/dest/tagging/index.d.ts +2 -2
  57. package/dest/tagging/index.d.ts.map +1 -1
  58. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +1 -1
  59. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  60. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +10 -1
  61. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  62. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  63. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  64. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +2 -1
  65. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  66. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +24 -11
  67. package/package.json +16 -16
  68. package/src/config/index.ts +1 -1
  69. package/src/contract_function_simulator/contract_function_simulator.ts +36 -4
  70. package/src/contract_function_simulator/execution_tagging_index_cache.ts +16 -11
  71. package/src/contract_function_simulator/index.ts +1 -0
  72. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -5
  73. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
  74. package/src/contract_function_simulator/noir-structs/message_tx_context.ts +55 -0
  75. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -6
  76. package/src/contract_function_simulator/oracle/interfaces.ts +17 -17
  77. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +135 -0
  78. package/src/contract_function_simulator/oracle/oracle.ts +53 -43
  79. package/src/contract_function_simulator/oracle/private_execution.ts +3 -3
  80. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +9 -57
  81. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +105 -9
  82. package/src/contract_sync/contract_sync_service.ts +67 -38
  83. package/src/messages/message_context_service.ts +45 -0
  84. package/src/oracle_version.ts +2 -2
  85. package/src/pxe.ts +51 -18
  86. package/src/storage/metadata.ts +1 -1
  87. package/src/storage/tagging_store/sender_tagging_store.ts +182 -135
  88. package/src/tagging/index.ts +1 -1
  89. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +19 -1
  90. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  91. 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
- return oracleNames.reduce((acc, name) => {
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 aztec_prv_notifyEnqueuedPublicFunctionCall(
465
- [contractAddress]: ACVMField[],
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 aztec_prv_notifySetMinRevertibleSideEffectCounter([minRevertibleSideEffectCounter]: ACVMField[]): Promise<
497
- ACVMField[]
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 aztec_prv_isSideEffectCounterRevertible([sideEffectCounter]: ACVMField[]): Promise<ACVMField[]> {
507
- const isRevertible = await this.handlerAsPrivate().isSideEffectCounterRevertible(
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[],
@@ -616,7 +605,7 @@ export class Oracle {
616
605
  }
617
606
 
618
607
  // eslint-disable-next-line camelcase
619
- async aztec_utl_aes128Decrypt(
608
+ async aztec_utl_tryAes128Decrypt(
620
609
  ciphertextBVecStorage: ACVMField[],
621
610
  [ciphertextLength]: ACVMField[],
622
611
  iv: ACVMField[],
@@ -626,8 +615,15 @@ export class Oracle {
626
615
  const ivBuffer = fromUintArray(iv, 8);
627
616
  const symKeyBuffer = fromUintArray(symKey, 8);
628
617
 
629
- const plaintext = await this.handlerAsUtility().aes128Decrypt(ciphertext, ivBuffer, symKeyBuffer);
630
- return bufferToBoundedVec(plaintext, ciphertextBVecStorage.length);
618
+ // Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
619
+ try {
620
+ const plaintext = await this.handlerAsUtility().aes128Decrypt(ciphertext, ivBuffer, symKeyBuffer);
621
+ const [storage, length] = bufferToBoundedVec(plaintext, ciphertextBVecStorage.length);
622
+ return [toACVMField(1), storage, length];
623
+ } catch {
624
+ const zeroStorage = Array(ciphertextBVecStorage.length).fill(toACVMField(0));
625
+ return [toACVMField(0), zeroStorage, toACVMField(0)];
626
+ }
631
627
  }
632
628
 
633
629
  // eslint-disable-next-line camelcase
@@ -644,9 +640,23 @@ export class Oracle {
644
640
  return secret.toFields().map(toACVMField);
645
641
  }
646
642
 
643
+ // eslint-disable-next-line camelcase
644
+ aztec_utl_invalidateContractSyncCache(
645
+ [contractAddress]: ACVMField[],
646
+ scopes: ACVMField[],
647
+ [scopeCount]: ACVMField[],
648
+ ): Promise<ACVMField[]> {
649
+ const scopeAddresses = scopes.slice(0, +scopeCount).map(s => AztecAddress.fromField(Fr.fromString(s)));
650
+ this.handlerAsUtility().invalidateContractSyncCache(
651
+ AztecAddress.fromField(Fr.fromString(contractAddress)),
652
+ scopeAddresses,
653
+ );
654
+ return Promise.resolve([]);
655
+ }
656
+
647
657
  // eslint-disable-next-line camelcase
648
658
  async aztec_utl_emitOffchainEffect(data: ACVMField[]) {
649
- await this.handlerAsPrivate().emitOffchainEffect(data.map(Fr.fromString));
659
+ await this.handlerAsUtility().emitOffchainEffect(data.map(Fr.fromString));
650
660
  return [];
651
661
  }
652
662
 
@@ -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 preTags = privateExecutionOracle.getUsedPreTags();
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
- preTags,
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 PreTag } from '@aztec/stdlib/logs';
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 {
@@ -26,7 +26,6 @@ import {
26
26
  } from '@aztec/stdlib/tx';
27
27
 
28
28
  import type { AccessScopes } from '../../access_scopes.js';
29
- import type { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
30
29
  import { NoteService } from '../../notes/note_service.js';
31
30
  import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
32
31
  import { syncSenderTaggingIndexes } from '../../tagging/index.js';
@@ -49,7 +48,6 @@ export type PrivateExecutionOracleArgs = Omit<UtilityExecutionOracleArgs, 'contr
49
48
  noteCache: ExecutionNoteCache;
50
49
  taggingIndexCache: ExecutionTaggingIndexCache;
51
50
  senderTaggingStore: SenderTaggingStore;
52
- contractSyncService: ContractSyncService;
53
51
  totalPublicCalldataCount?: number;
54
52
  sideEffectCounter?: number;
55
53
  senderForTags?: AztecAddress;
@@ -73,7 +71,6 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
73
71
  private newNotes: NoteAndSlot[] = [];
74
72
  private noteHashNullifierCounterMap: Map<number, number> = new Map();
75
73
  private contractClassLogs: CountedContractClassLog[] = [];
76
- private offchainEffects: { data: Fr[] }[] = [];
77
74
  private nestedExecutionResults: PrivateCallExecutionResult[] = [];
78
75
 
79
76
  private readonly argsHash: Fr;
@@ -84,7 +81,6 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
84
81
  private readonly noteCache: ExecutionNoteCache;
85
82
  private readonly taggingIndexCache: ExecutionTaggingIndexCache;
86
83
  private readonly senderTaggingStore: SenderTaggingStore;
87
- private readonly contractSyncService: ContractSyncService;
88
84
  private totalPublicCalldataCount: number;
89
85
  protected sideEffectCounter: number;
90
86
  private senderForTags?: AztecAddress;
@@ -104,7 +100,6 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
104
100
  this.noteCache = args.noteCache;
105
101
  this.taggingIndexCache = args.taggingIndexCache;
106
102
  this.senderTaggingStore = args.senderTaggingStore;
107
- this.contractSyncService = args.contractSyncService;
108
103
  this.totalPublicCalldataCount = args.totalPublicCalldataCount ?? 0;
109
104
  this.sideEffectCounter = args.sideEffectCounter ?? 0;
110
105
  this.senderForTags = args.senderForTags;
@@ -159,17 +154,10 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
159
154
  }
160
155
 
161
156
  /**
162
- * Return the offchain effects emitted during this execution.
157
+ * Returns the tagging index ranges that were used in this execution (and that need to be stored in the db).
163
158
  */
164
- public getOffchainEffects() {
165
- return this.offchainEffects;
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();
159
+ public getUsedTaggingIndexRanges(): TaggingIndexRange[] {
160
+ return this.taggingIndexCache.getUsedTaggingIndexRanges();
173
161
  }
174
162
 
175
163
  /**
@@ -569,6 +557,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
569
557
  senderAddressBookStore: this.senderAddressBookStore,
570
558
  capsuleStore: this.capsuleStore,
571
559
  privateEventStore: this.privateEventStore,
560
+ messageContextService: this.messageContextService,
572
561
  contractSyncService: this.contractSyncService,
573
562
  jobId: this.jobId,
574
563
  totalPublicCalldataCount: this.totalPublicCalldataCount,
@@ -608,7 +597,8 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
608
597
  };
609
598
  }
610
599
 
611
- #onNewPublicFunctionCall(calldataHash: Fr) {
600
+ /** Validates the calldata preimage exists in the cache and checks cumulative calldata size is within limits. */
601
+ public validatePublicCalldata(calldataHash: Fr) {
612
602
  const calldata = this.executionCache.getPreimage(calldataHash);
613
603
  if (!calldata) {
614
604
  throw new Error('Calldata for public call not found in cache');
@@ -618,47 +608,14 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
618
608
  if (this.totalPublicCalldataCount > MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS) {
619
609
  throw new Error(`Too many total args to all enqueued public calls! (> ${MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS})`);
620
610
  }
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
611
  return Promise.resolve();
638
612
  }
639
613
 
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> {
614
+ public notifyRevertiblePhaseStart(minRevertibleSideEffectCounter: number): Promise<void> {
658
615
  return this.noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
659
616
  }
660
617
 
661
- public isSideEffectCounterRevertible(sideEffectCounter: number): Promise<boolean> {
618
+ public inRevertiblePhase(sideEffectCounter: number): Promise<boolean> {
662
619
  return Promise.resolve(this.noteCache.isSideEffectCounterRevertible(sideEffectCounter));
663
620
  }
664
621
 
@@ -685,9 +642,4 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
685
642
  public getDebugFunctionName() {
686
643
  return this.contractStore.getDebugFunctionName(this.contractAddress, this.callContext.functionSelector);
687
644
  }
688
-
689
- public emitOffchainEffect(data: Fr[]): Promise<void> {
690
- this.offchainEffects.push({ data });
691
- return Promise.resolve();
692
- }
693
645
  }
@@ -6,24 +6,27 @@ 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';
26
+ import type { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
25
27
  import { EventService } from '../../events/event_service.js';
26
28
  import { LogService } from '../../logs/log_service.js';
29
+ import { MessageContextService } from '../../messages/message_context_service.js';
27
30
  import { NoteService } from '../../notes/note_service.js';
28
31
  import { ORACLE_VERSION } from '../../oracle_version.js';
29
32
  import type { AddressStore } from '../../storage/address_store/address_store.js';
@@ -36,6 +39,7 @@ import type { SenderAddressBookStore } from '../../storage/tagging_store/sender_
36
39
  import { EventValidationRequest } from '../noir-structs/event_validation_request.js';
37
40
  import { LogRetrievalRequest } from '../noir-structs/log_retrieval_request.js';
38
41
  import { LogRetrievalResponse } from '../noir-structs/log_retrieval_response.js';
42
+ import { MessageTxContext } from '../noir-structs/message_tx_context.js';
39
43
  import { NoteValidationRequest } from '../noir-structs/note_validation_request.js';
40
44
  import { UtilityContext } from '../noir-structs/utility_context.js';
41
45
  import { pickNotes } from '../pick_notes.js';
@@ -58,6 +62,8 @@ export type UtilityExecutionOracleArgs = {
58
62
  senderAddressBookStore: SenderAddressBookStore;
59
63
  capsuleStore: CapsuleStore;
60
64
  privateEventStore: PrivateEventStore;
65
+ messageContextService: MessageContextService;
66
+ contractSyncService: ContractSyncService;
61
67
  jobId: string;
62
68
  log?: ReturnType<typeof createLogger>;
63
69
  scopes: AccessScopes;
@@ -71,6 +77,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
71
77
  isUtility = true as const;
72
78
 
73
79
  private contractLogger: Logger | undefined;
80
+ private offchainEffects: OffchainEffect[] = [];
74
81
 
75
82
  protected readonly contractAddress: AztecAddress;
76
83
  protected readonly authWitnesses: AuthWitness[];
@@ -85,6 +92,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
85
92
  protected readonly senderAddressBookStore: SenderAddressBookStore;
86
93
  protected readonly capsuleStore: CapsuleStore;
87
94
  protected readonly privateEventStore: PrivateEventStore;
95
+ protected readonly messageContextService: MessageContextService;
96
+ protected readonly contractSyncService: ContractSyncService;
88
97
  protected readonly jobId: string;
89
98
  protected logger: ReturnType<typeof createLogger>;
90
99
  protected readonly scopes: AccessScopes;
@@ -103,12 +112,29 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
103
112
  this.senderAddressBookStore = args.senderAddressBookStore;
104
113
  this.capsuleStore = args.capsuleStore;
105
114
  this.privateEventStore = args.privateEventStore;
115
+ this.messageContextService = args.messageContextService;
116
+ this.contractSyncService = args.contractSyncService;
106
117
  this.jobId = args.jobId;
107
118
  this.logger = args.log ?? createLogger('simulator:client_view_context');
108
119
  this.scopes = args.scopes;
109
120
  }
110
121
 
111
122
  public assertCompatibleOracleVersion(version: number): void {
123
+ // TODO(F-416): Remove this hack on v5 when protocol contracts are redeployed.
124
+ // Protocol contracts/canonical contracts shipped with committed bytecode that cannot be changed. Assert they use
125
+ // the expected pinned version or the current one. We want to allow for both the pinned and the current versions
126
+ // because we want this code to work with both the pinned and unpinned version since some branches do not have the
127
+ // pinned contracts (like e.g. next)
128
+ const LEGACY_ORACLE_VERSION = 12;
129
+ if (isProtocolContract(this.contractAddress)) {
130
+ if (version !== LEGACY_ORACLE_VERSION && version !== ORACLE_VERSION) {
131
+ throw new Error(
132
+ `Expected legacy oracle version ${LEGACY_ORACLE_VERSION} or current oracle version ${ORACLE_VERSION} for alpha payload contract at ${this.contractAddress}, got ${version}.`,
133
+ );
134
+ }
135
+ return;
136
+ }
137
+
112
138
  if (version !== ORACLE_VERSION) {
113
139
  throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
114
140
  }
@@ -232,12 +258,18 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
232
258
  }
233
259
 
234
260
  /**
235
- * Retrieve the complete address associated to a given address.
261
+ * Retrieve the public keys and partial address associated to a given address.
236
262
  * @param account - The account address.
237
- * @returns A complete address associated with the input address, or `undefined` if not registered.
263
+ * @returns The public keys and partial address, or `undefined` if the account is not registered.
238
264
  */
239
- public tryGetPublicKeysAndPartialAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
240
- return this.addressStore.getCompleteAddress(account);
265
+ public async tryGetPublicKeysAndPartialAddress(
266
+ account: AztecAddress,
267
+ ): Promise<{ publicKeys: PublicKeys; partialAddress: PartialAddress } | undefined> {
268
+ const completeAddress = await this.addressStore.getCompleteAddress(account);
269
+ if (!completeAddress) {
270
+ return undefined;
271
+ }
272
+ return { publicKeys: completeAddress.publicKeys, partialAddress: completeAddress.partialAddress };
241
273
  }
242
274
 
243
275
  protected async getCompleteAddressOrFail(account: AztecAddress): Promise<CompleteAddress> {
@@ -448,6 +480,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
448
480
  contractAddress: AztecAddress,
449
481
  noteValidationRequestsArrayBaseSlot: Fr,
450
482
  eventValidationRequestsArrayBaseSlot: Fr,
483
+ maxNotePackedLen: number,
484
+ maxEventSerializedLen: number,
451
485
  ) {
452
486
  // TODO(#10727): allow other contracts to store notes
453
487
  if (!this.contractAddress.equals(contractAddress)) {
@@ -458,11 +492,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
458
492
  // faster as we don't need to wait for the network round-trip.
459
493
  const noteValidationRequests = (
460
494
  await this.capsuleStore.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, this.jobId)
461
- ).map(NoteValidationRequest.fromFields);
495
+ ).map(fields => NoteValidationRequest.fromFields(fields, maxNotePackedLen));
462
496
 
463
497
  const eventValidationRequests = (
464
498
  await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId)
465
- ).map(EventValidationRequest.fromFields);
499
+ ).map(fields => EventValidationRequest.fromFields(fields, maxEventSerializedLen));
466
500
 
467
501
  const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
468
502
  const noteStorePromises = noteValidationRequests.map(request =>
@@ -542,6 +576,47 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
542
576
  );
543
577
  }
544
578
 
579
+ public async utilityResolveMessageContexts(
580
+ contractAddress: AztecAddress,
581
+ messageContextRequestsArrayBaseSlot: Fr,
582
+ messageContextResponsesArrayBaseSlot: Fr,
583
+ ) {
584
+ try {
585
+ if (!this.contractAddress.equals(contractAddress)) {
586
+ throw new Error(`Got a message context request from ${contractAddress}, expected ${this.contractAddress}`);
587
+ }
588
+ const requestCapsules = await this.capsuleStore.readCapsuleArray(
589
+ contractAddress,
590
+ messageContextRequestsArrayBaseSlot,
591
+ this.jobId,
592
+ );
593
+
594
+ const txHashes = requestCapsules.map((fields, i) => {
595
+ if (fields.length !== 1) {
596
+ throw new Error(
597
+ `Malformed message context request at index ${i}: expected 1 field (tx hash), got ${fields.length}`,
598
+ );
599
+ }
600
+ return fields[0];
601
+ });
602
+
603
+ const maybeMessageContexts = await this.messageContextService.resolveMessageContexts(
604
+ txHashes,
605
+ this.anchorBlockHeader.getBlockNumber(),
606
+ );
607
+
608
+ // Leave response in response capsule array.
609
+ await this.capsuleStore.setCapsuleArray(
610
+ contractAddress,
611
+ messageContextResponsesArrayBaseSlot,
612
+ maybeMessageContexts.map(MessageTxContext.toSerializedOption),
613
+ this.jobId,
614
+ );
615
+ } finally {
616
+ await this.capsuleStore.setCapsuleArray(contractAddress, messageContextRequestsArrayBaseSlot, [], this.jobId);
617
+ }
618
+ }
619
+
545
620
  public storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
546
621
  if (!contractAddress.equals(this.contractAddress)) {
547
622
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
@@ -580,6 +655,17 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
580
655
  return this.capsuleStore.copyCapsule(this.contractAddress, srcSlot, dstSlot, numEntries, this.jobId);
581
656
  }
582
657
 
658
+ /**
659
+ * Clears cached sync state for a contract for a set of scopes, forcing re-sync on the next query so that newly
660
+ * stored notes or events are discovered.
661
+ */
662
+ public invalidateContractSyncCache(contractAddress: AztecAddress, scopes: AztecAddress[]): void {
663
+ if (!contractAddress.equals(this.contractAddress)) {
664
+ throw new Error(`Contract ${this.contractAddress} cannot invalidate sync cache of ${contractAddress}`);
665
+ }
666
+ this.contractSyncService.invalidateContractForScopes(contractAddress, scopes);
667
+ }
668
+
583
669
  // TODO(#11849): consider replacing this oracle with a pure Noir implementation of aes decryption.
584
670
  public aes128Decrypt(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer> {
585
671
  const aes128 = new Aes128();
@@ -601,4 +687,14 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
601
687
  const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
602
688
  return deriveEcdhSharedSecret(addressSecret, ephPk);
603
689
  }
690
+
691
+ public emitOffchainEffect(data: Fr[]): Promise<void> {
692
+ this.offchainEffects.push({ data, contractAddress: this.contractAddress });
693
+ return Promise.resolve();
694
+ }
695
+
696
+ /** Returns offchain effects collected during execution. */
697
+ public getOffchainEffects(): OffchainEffect[] {
698
+ return this.offchainEffects;
699
+ }
604
700
  }