@aztec/pxe 0.0.1-commit.cd76b27 → 0.0.1-commit.ce4f8c4f2

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 (139) 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 +33 -11
  7. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  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 +19 -11
  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 +50 -45
  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 +45 -44
  31. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/oracle/oracle.js +163 -94
  33. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  34. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +22 -47
  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 +40 -80
  37. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +57 -39
  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 +138 -63
  40. package/dest/contract_logging.d.ts +22 -0
  41. package/dest/contract_logging.d.ts.map +1 -0
  42. package/dest/contract_logging.js +23 -0
  43. package/dest/contract_sync/contract_sync_service.d.ts +5 -3
  44. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  45. package/dest/contract_sync/contract_sync_service.js +47 -30
  46. package/dest/entrypoints/client/bundle/index.d.ts +2 -1
  47. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  48. package/dest/entrypoints/client/bundle/index.js +1 -0
  49. package/dest/entrypoints/client/lazy/index.d.ts +2 -1
  50. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  51. package/dest/entrypoints/client/lazy/index.js +1 -0
  52. package/dest/logs/log_service.d.ts +1 -1
  53. package/dest/logs/log_service.d.ts.map +1 -1
  54. package/dest/logs/log_service.js +4 -4
  55. package/dest/messages/message_context_service.d.ts +17 -0
  56. package/dest/messages/message_context_service.d.ts.map +1 -0
  57. package/dest/messages/message_context_service.js +36 -0
  58. package/dest/oracle_version.d.ts +2 -2
  59. package/dest/oracle_version.js +3 -3
  60. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  61. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  62. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +125 -64
  63. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  64. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  65. package/dest/private_kernel/hints/test_utils.js +203 -0
  66. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  67. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  68. package/dest/private_kernel/private_kernel_execution_prover.js +13 -5
  69. package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
  70. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  71. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  72. package/dest/pxe.d.ts +8 -4
  73. package/dest/pxe.d.ts.map +1 -1
  74. package/dest/pxe.js +55 -33
  75. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  76. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  77. package/dest/storage/contract_store/contract_store.js +140 -64
  78. package/dest/storage/metadata.d.ts +1 -1
  79. package/dest/storage/metadata.js +1 -1
  80. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  81. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  82. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  83. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  84. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  85. package/dest/tagging/index.d.ts +3 -3
  86. package/dest/tagging/index.d.ts.map +1 -1
  87. package/dest/tagging/index.js +1 -1
  88. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  89. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  90. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +3 -3
  91. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  92. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  93. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  94. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  95. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  96. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  97. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  98. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  99. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  100. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
  101. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  102. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  103. package/package.json +16 -16
  104. package/src/config/index.ts +1 -1
  105. package/src/contract_function_simulator/contract_function_simulator.ts +51 -20
  106. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  107. package/src/contract_function_simulator/index.ts +1 -0
  108. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -5
  109. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
  110. package/src/contract_function_simulator/noir-structs/message_tx_context.ts +55 -0
  111. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -6
  112. package/src/contract_function_simulator/oracle/interfaces.ts +54 -54
  113. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +135 -0
  114. package/src/contract_function_simulator/oracle/oracle.ts +176 -138
  115. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  116. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +45 -99
  117. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +200 -80
  118. package/src/contract_logging.ts +39 -0
  119. package/src/contract_sync/contract_sync_service.ts +67 -38
  120. package/src/entrypoints/client/bundle/index.ts +1 -0
  121. package/src/entrypoints/client/lazy/index.ts +1 -0
  122. package/src/logs/log_service.ts +10 -5
  123. package/src/messages/message_context_service.ts +45 -0
  124. package/src/oracle_version.ts +3 -3
  125. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +157 -110
  126. package/src/private_kernel/hints/test_utils.ts +325 -0
  127. package/src/private_kernel/private_kernel_execution_prover.ts +13 -6
  128. package/src/private_kernel/private_kernel_oracle.ts +7 -7
  129. package/src/pxe.ts +74 -34
  130. package/src/storage/contract_store/contract_store.ts +170 -71
  131. package/src/storage/metadata.ts +1 -1
  132. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  133. package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
  134. package/src/tagging/index.ts +2 -2
  135. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +3 -6
  136. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  137. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
  138. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  139. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
@@ -3,26 +3,30 @@ import type { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { Aes128 } from '@aztec/foundation/crypto/aes128';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { Point } from '@aztec/foundation/curves/grumpkin';
6
- import { LogLevels, type Logger, applyStringFormatting, createLogger } from '@aztec/foundation/log';
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';
25
+ import { createContractLogger, logContractMessage } from '../../contract_logging.js';
26
+ import type { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
24
27
  import { EventService } from '../../events/event_service.js';
25
28
  import { LogService } from '../../logs/log_service.js';
29
+ import { MessageContextService } from '../../messages/message_context_service.js';
26
30
  import { NoteService } from '../../notes/note_service.js';
27
31
  import { ORACLE_VERSION } from '../../oracle_version.js';
28
32
  import type { AddressStore } from '../../storage/address_store/address_store.js';
@@ -35,6 +39,7 @@ import type { SenderAddressBookStore } from '../../storage/tagging_store/sender_
35
39
  import { EventValidationRequest } from '../noir-structs/event_validation_request.js';
36
40
  import { LogRetrievalRequest } from '../noir-structs/log_retrieval_request.js';
37
41
  import { LogRetrievalResponse } from '../noir-structs/log_retrieval_response.js';
42
+ import { MessageTxContext } from '../noir-structs/message_tx_context.js';
38
43
  import { NoteValidationRequest } from '../noir-structs/note_validation_request.js';
39
44
  import { UtilityContext } from '../noir-structs/utility_context.js';
40
45
  import { pickNotes } from '../pick_notes.js';
@@ -57,6 +62,8 @@ export type UtilityExecutionOracleArgs = {
57
62
  senderAddressBookStore: SenderAddressBookStore;
58
63
  capsuleStore: CapsuleStore;
59
64
  privateEventStore: PrivateEventStore;
65
+ messageContextService: MessageContextService;
66
+ contractSyncService: ContractSyncService;
60
67
  jobId: string;
61
68
  log?: ReturnType<typeof createLogger>;
62
69
  scopes: AccessScopes;
@@ -70,6 +77,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
70
77
  isUtility = true as const;
71
78
 
72
79
  private contractLogger: Logger | undefined;
80
+ private offchainEffects: OffchainEffect[] = [];
73
81
 
74
82
  protected readonly contractAddress: AztecAddress;
75
83
  protected readonly authWitnesses: AuthWitness[];
@@ -84,8 +92,10 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
84
92
  protected readonly senderAddressBookStore: SenderAddressBookStore;
85
93
  protected readonly capsuleStore: CapsuleStore;
86
94
  protected readonly privateEventStore: PrivateEventStore;
95
+ protected readonly messageContextService: MessageContextService;
96
+ protected readonly contractSyncService: ContractSyncService;
87
97
  protected readonly jobId: string;
88
- protected log: ReturnType<typeof createLogger>;
98
+ protected logger: ReturnType<typeof createLogger>;
89
99
  protected readonly scopes: AccessScopes;
90
100
 
91
101
  constructor(args: UtilityExecutionOracleArgs) {
@@ -102,22 +112,39 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
102
112
  this.senderAddressBookStore = args.senderAddressBookStore;
103
113
  this.capsuleStore = args.capsuleStore;
104
114
  this.privateEventStore = args.privateEventStore;
115
+ this.messageContextService = args.messageContextService;
116
+ this.contractSyncService = args.contractSyncService;
105
117
  this.jobId = args.jobId;
106
- this.log = args.log ?? createLogger('simulator:client_view_context');
118
+ this.logger = args.log ?? createLogger('simulator:client_view_context');
107
119
  this.scopes = args.scopes;
108
120
  }
109
121
 
110
- public utilityAssertCompatibleOracleVersion(version: number): void {
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
+
111
138
  if (version !== ORACLE_VERSION) {
112
139
  throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
113
140
  }
114
141
  }
115
142
 
116
- public utilityGetRandomField(): Fr {
143
+ public getRandomField(): Fr {
117
144
  return Fr.random();
118
145
  }
119
146
 
120
- public utilityGetUtilityContext(): UtilityContext {
147
+ public getUtilityContext(): UtilityContext {
121
148
  return new UtilityContext(this.anchorBlockHeader, this.contractAddress);
122
149
  }
123
150
 
@@ -128,7 +155,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
128
155
  * @throws If the keys are not registered in the key store.
129
156
  * @throws If scopes are defined and the account is not in the scopes.
130
157
  */
131
- public async utilityGetKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
158
+ public async getKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
132
159
  // If scopes are defined, check that the key belongs to an account in the scopes.
133
160
  if (this.scopes !== 'ALL_SCOPES' && this.scopes.length > 0) {
134
161
  let hasAccess = false;
@@ -146,16 +173,18 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
146
173
 
147
174
  /**
148
175
  * Fetches the index and sibling path of a leaf at a given block from the note hash tree.
149
- * @param anchorBlockHash - The hash of a block that contains the note hash tree root in which to find the membership
150
- * witness.
176
+ * @param blockHash - The hash of a block that contains the note hash tree root in which to find the
177
+ * membership witness.
151
178
  * @param noteHash - The note hash to find in the note hash tree.
152
179
  * @returns The membership witness containing the leaf index and sibling path
153
180
  */
154
- public utilityGetNoteHashMembershipWitness(
155
- anchorBlockHash: BlockHash,
181
+ public getNoteHashMembershipWitness(
182
+ blockHash: BlockHash,
156
183
  noteHash: Fr,
157
184
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
158
- return this.aztecNode.getNoteHashMembershipWitness(anchorBlockHash, noteHash);
185
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
186
+ this.aztecNode.getNoteHashMembershipWitness(blockHash, noteHash),
187
+ );
159
188
  }
160
189
 
161
190
  /**
@@ -164,16 +193,21 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
164
193
  * Block hashes are the leaves of the archive tree. Each time a new block is added to the chain,
165
194
  * its block hash is appended as a new leaf to the archive tree.
166
195
  *
167
- * @param anchorBlockHash - The hash of a block that contains the archive tree root in which to find the membership
196
+ * @param referenceBlockHash - The hash of a block that contains the archive tree root in which to find the membership
168
197
  * witness.
169
198
  * @param blockHash - The block hash to find in the archive tree.
170
199
  * @returns The membership witness containing the leaf index and sibling path
171
200
  */
172
- public utilityGetBlockHashMembershipWitness(
173
- anchorBlockHash: BlockHash,
201
+ public getBlockHashMembershipWitness(
202
+ referenceBlockHash: BlockHash,
174
203
  blockHash: BlockHash,
175
204
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
176
- return this.aztecNode.getBlockHashMembershipWitness(anchorBlockHash, blockHash);
205
+ // Note that we validate that the reference block hash is at or before the anchor block - we don't test the block
206
+ // hash at all. If the block hash did not exist by the reference block hash, then the node will not return the
207
+ // membership witness as there is none.
208
+ return this.#queryWithBlockHashNotAfterAnchor(referenceBlockHash, () =>
209
+ this.aztecNode.getBlockHashMembershipWitness(referenceBlockHash, blockHash),
210
+ );
177
211
  }
178
212
 
179
213
  /**
@@ -182,11 +216,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
182
216
  * @param nullifier - Nullifier we try to find witness for.
183
217
  * @returns The nullifier membership witness (if found).
184
218
  */
185
- public utilityGetNullifierMembershipWitness(
219
+ public getNullifierMembershipWitness(
186
220
  blockHash: BlockHash,
187
221
  nullifier: Fr,
188
222
  ): Promise<NullifierMembershipWitness | undefined> {
189
- return this.aztecNode.getNullifierMembershipWitness(blockHash, nullifier);
223
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
224
+ this.aztecNode.getNullifierMembershipWitness(blockHash, nullifier),
225
+ );
190
226
  }
191
227
 
192
228
  /**
@@ -198,11 +234,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
198
234
  * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
199
235
  * we are trying to prove non-inclusion for.
200
236
  */
201
- public utilityGetLowNullifierMembershipWitness(
237
+ public getLowNullifierMembershipWitness(
202
238
  blockHash: BlockHash,
203
239
  nullifier: Fr,
204
240
  ): Promise<NullifierMembershipWitness | undefined> {
205
- return this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier);
241
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
242
+ this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier),
243
+ );
206
244
  }
207
245
 
208
246
  /**
@@ -211,8 +249,10 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
211
249
  * @param leafSlot - The slot of the public data tree to get the witness for.
212
250
  * @returns - The witness
213
251
  */
214
- public utilityGetPublicDataWitness(blockHash: BlockHash, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
215
- return this.aztecNode.getPublicDataWitness(blockHash, leafSlot);
252
+ public getPublicDataWitness(blockHash: BlockHash, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
253
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
254
+ this.aztecNode.getPublicDataWitness(blockHash, leafSlot),
255
+ );
216
256
  }
217
257
 
218
258
  /**
@@ -220,7 +260,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
220
260
  * @param blockNumber - The number of a block of which to get the block header.
221
261
  * @returns Block extracted from a block with block number `blockNumber`.
222
262
  */
223
- public async utilityGetBlockHeader(blockNumber: BlockNumber): Promise<BlockHeader | undefined> {
263
+ public async getBlockHeader(blockNumber: BlockNumber): Promise<BlockHeader | undefined> {
224
264
  const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
225
265
  if (blockNumber > anchorBlockNumber) {
226
266
  throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
@@ -231,12 +271,18 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
231
271
  }
232
272
 
233
273
  /**
234
- * Retrieve the complete address associated to a given address.
274
+ * Retrieve the public keys and partial address associated to a given address.
235
275
  * @param account - The account address.
236
- * @returns A complete address associated with the input address, or `undefined` if not registered.
276
+ * @returns The public keys and partial address, or `undefined` if the account is not registered.
237
277
  */
238
- public utilityTryGetPublicKeysAndPartialAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
239
- return this.addressStore.getCompleteAddress(account);
278
+ public async tryGetPublicKeysAndPartialAddress(
279
+ account: AztecAddress,
280
+ ): Promise<{ publicKeys: PublicKeys; partialAddress: PartialAddress } | undefined> {
281
+ const completeAddress = await this.addressStore.getCompleteAddress(account);
282
+ if (!completeAddress) {
283
+ return undefined;
284
+ }
285
+ return { publicKeys: completeAddress.publicKeys, partialAddress: completeAddress.partialAddress };
240
286
  }
241
287
 
242
288
  protected async getCompleteAddressOrFail(account: AztecAddress): Promise<CompleteAddress> {
@@ -255,11 +301,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
255
301
  * @param address - Address.
256
302
  * @returns A contract instance.
257
303
  */
258
- public utilityGetContractInstance(address: AztecAddress): Promise<ContractInstance> {
259
- return this.getContractInstance(address);
260
- }
261
-
262
- protected async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
304
+ public async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
263
305
  const instance = await this.contractStore.getContractInstance(address);
264
306
  if (!instance) {
265
307
  throw new Error(`No contract instance found for address ${address.toString()}`);
@@ -273,7 +315,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
273
315
  * @param messageHash - Hash of the message to authenticate.
274
316
  * @returns Authentication witness for the requested message hash.
275
317
  */
276
- public utilityGetAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
318
+ public getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
277
319
  return Promise.resolve(this.authWitnesses.find(w => w.requestHash.equals(messageHash))?.witness);
278
320
  }
279
321
 
@@ -299,7 +341,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
299
341
  * @param status - The status of notes to fetch.
300
342
  * @returns Array of note data.
301
343
  */
302
- public async utilityGetNotes(
344
+ public async getNotes(
303
345
  owner: AztecAddress | undefined,
304
346
  storageSlot: Fr,
305
347
  numSelects: number,
@@ -339,7 +381,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
339
381
  * @param innerNullifier - The inner nullifier.
340
382
  * @returns A boolean indicating whether the nullifier exists in the tree or not.
341
383
  */
342
- public async utilityCheckNullifierExists(innerNullifier: Fr) {
384
+ public async checkNullifierExists(innerNullifier: Fr) {
343
385
  const [nullifier, anchorBlockHash] = await Promise.all([
344
386
  siloNullifier(this.contractAddress, innerNullifier!),
345
387
  this.anchorBlockHeader.hash(),
@@ -351,19 +393,20 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
351
393
  }
352
394
 
353
395
  /**
354
- * Fetches a message from the executionStore, given its key.
396
+ * Returns the membership witness of an un-nullified L1 to L2 message.
355
397
  * @param contractAddress - Address of a contract by which the message was emitted.
356
398
  * @param messageHash - Hash of the message.
357
399
  * @param secret - Secret used to compute a nullifier.
358
400
  * @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
359
401
  * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
360
402
  */
361
- public async utilityGetL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr) {
403
+ public async getL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr) {
362
404
  const [messageIndex, siblingPath] = await getNonNullifiedL1ToL2MessageWitness(
363
405
  this.aztecNode,
364
406
  contractAddress,
365
407
  messageHash,
366
408
  secret,
409
+ await this.anchorBlockHeader.hash(),
367
410
  );
368
411
 
369
412
  return new MessageLoadOracleInputs(messageIndex, siblingPath);
@@ -376,25 +419,27 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
376
419
  * @param startStorageSlot - The starting storage slot.
377
420
  * @param numberOfElements - Number of elements to read from the starting storage slot.
378
421
  */
379
- public async utilityStorageRead(
422
+ public storageRead(
380
423
  blockHash: BlockHash,
381
424
  contractAddress: AztecAddress,
382
425
  startStorageSlot: Fr,
383
426
  numberOfElements: number,
384
427
  ) {
385
- const slots = Array(numberOfElements)
386
- .fill(0)
387
- .map((_, i) => new Fr(startStorageSlot.value + BigInt(i)));
428
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, async () => {
429
+ const slots = Array(numberOfElements)
430
+ .fill(0)
431
+ .map((_, i) => new Fr(startStorageSlot.value + BigInt(i)));
388
432
 
389
- const values = await Promise.all(
390
- slots.map(storageSlot => this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot)),
391
- );
433
+ const values = await Promise.all(
434
+ slots.map(storageSlot => this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot)),
435
+ );
392
436
 
393
- this.log.debug(
394
- `Oracle storage read: slots=[${slots.map(slot => slot.toString()).join(', ')}] address=${contractAddress.toString()} values=[${values.join(', ')}]`,
395
- );
437
+ this.logger.debug(
438
+ `Oracle storage read: slots=[${slots.map(slot => slot.toString()).join(', ')}] address=${contractAddress.toString()} values=[${values.join(', ')}]`,
439
+ );
396
440
 
397
- return values;
441
+ return values;
442
+ });
398
443
  }
399
444
 
400
445
  /**
@@ -402,26 +447,26 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
402
447
  */
403
448
  async #getContractLogger(): Promise<Logger> {
404
449
  if (!this.contractLogger) {
405
- const addrAbbrev = this.contractAddress.toString().slice(0, 10);
406
- const name = await this.contractStore.getDebugContractName(this.contractAddress);
407
- const module = name ? `contract_log::${name}(${addrAbbrev})` : `contract_log::${addrAbbrev}`;
408
450
  // Purpose of instanceId is to distinguish logs from different instances of the same component. It makes sense
409
451
  // to re-use jobId as instanceId here as executions of different PXE jobs are isolated.
410
- this.contractLogger = createLogger(module, { instanceId: this.jobId });
452
+ this.contractLogger = await createContractLogger(
453
+ this.contractAddress,
454
+ addr => this.contractStore.getDebugContractName(addr),
455
+ { instanceId: this.jobId },
456
+ );
411
457
  }
412
458
  return this.contractLogger;
413
459
  }
414
460
 
415
- public async utilityLog(level: number, message: string, fields: Fr[]): Promise<void> {
461
+ public async log(level: number, message: string, fields: Fr[]): Promise<void> {
416
462
  if (!LogLevels[level]) {
417
463
  throw new Error(`Invalid log level: ${level}`);
418
464
  }
419
- const levelName = LogLevels[level];
420
465
  const logger = await this.#getContractLogger();
421
- logger[levelName](`${applyStringFormatting(message, fields)}`);
466
+ logContractMessage(logger, LogLevels[level], message, fields);
422
467
  }
423
468
 
424
- public async utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) {
469
+ public async fetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) {
425
470
  const logService = new LogService(
426
471
  this.aztecNode,
427
472
  this.anchorBlockHeader,
@@ -431,7 +476,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
431
476
  this.senderAddressBookStore,
432
477
  this.addressStore,
433
478
  this.jobId,
434
- this.log.getBindings(),
479
+ this.logger.getBindings(),
435
480
  );
436
481
 
437
482
  await logService.fetchTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
@@ -447,10 +492,12 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
447
492
  * @param noteValidationRequestsArrayBaseSlot - The base slot of capsule array containing note validation requests.
448
493
  * @param eventValidationRequestsArrayBaseSlot - The base slot of capsule array containing event validation requests.
449
494
  */
450
- public async utilityValidateAndStoreEnqueuedNotesAndEvents(
495
+ public async validateAndStoreEnqueuedNotesAndEvents(
451
496
  contractAddress: AztecAddress,
452
497
  noteValidationRequestsArrayBaseSlot: Fr,
453
498
  eventValidationRequestsArrayBaseSlot: Fr,
499
+ maxNotePackedLen: number,
500
+ maxEventSerializedLen: number,
454
501
  ) {
455
502
  // TODO(#10727): allow other contracts to store notes
456
503
  if (!this.contractAddress.equals(contractAddress)) {
@@ -461,11 +508,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
461
508
  // faster as we don't need to wait for the network round-trip.
462
509
  const noteValidationRequests = (
463
510
  await this.capsuleStore.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, this.jobId)
464
- ).map(NoteValidationRequest.fromFields);
511
+ ).map(fields => NoteValidationRequest.fromFields(fields, maxNotePackedLen));
465
512
 
466
513
  const eventValidationRequests = (
467
514
  await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId)
468
- ).map(EventValidationRequest.fromFields);
515
+ ).map(fields => EventValidationRequest.fromFields(fields, maxEventSerializedLen));
469
516
 
470
517
  const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
471
518
  const noteStorePromises = noteValidationRequests.map(request =>
@@ -503,7 +550,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
503
550
  await this.capsuleStore.setCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, [], this.jobId);
504
551
  }
505
552
 
506
- public async utilityBulkRetrieveLogs(
553
+ public async bulkRetrieveLogs(
507
554
  contractAddress: AztecAddress,
508
555
  logRetrievalRequestsArrayBaseSlot: Fr,
509
556
  logRetrievalResponsesArrayBaseSlot: Fr,
@@ -528,7 +575,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
528
575
  this.senderAddressBookStore,
529
576
  this.addressStore,
530
577
  this.jobId,
531
- this.log.getBindings(),
578
+ this.logger.getBindings(),
532
579
  );
533
580
 
534
581
  const maybeLogRetrievalResponses = await logService.bulkRetrieveLogs(logRetrievalRequests);
@@ -545,7 +592,48 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
545
592
  );
546
593
  }
547
594
 
548
- public utilityStoreCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
595
+ public async utilityResolveMessageContexts(
596
+ contractAddress: AztecAddress,
597
+ messageContextRequestsArrayBaseSlot: Fr,
598
+ messageContextResponsesArrayBaseSlot: Fr,
599
+ ) {
600
+ try {
601
+ if (!this.contractAddress.equals(contractAddress)) {
602
+ throw new Error(`Got a message context request from ${contractAddress}, expected ${this.contractAddress}`);
603
+ }
604
+ const requestCapsules = await this.capsuleStore.readCapsuleArray(
605
+ contractAddress,
606
+ messageContextRequestsArrayBaseSlot,
607
+ this.jobId,
608
+ );
609
+
610
+ const txHashes = requestCapsules.map((fields, i) => {
611
+ if (fields.length !== 1) {
612
+ throw new Error(
613
+ `Malformed message context request at index ${i}: expected 1 field (tx hash), got ${fields.length}`,
614
+ );
615
+ }
616
+ return fields[0];
617
+ });
618
+
619
+ const maybeMessageContexts = await this.messageContextService.resolveMessageContexts(
620
+ txHashes,
621
+ this.anchorBlockHeader.getBlockNumber(),
622
+ );
623
+
624
+ // Leave response in response capsule array.
625
+ await this.capsuleStore.setCapsuleArray(
626
+ contractAddress,
627
+ messageContextResponsesArrayBaseSlot,
628
+ maybeMessageContexts.map(MessageTxContext.toSerializedOption),
629
+ this.jobId,
630
+ );
631
+ } finally {
632
+ await this.capsuleStore.setCapsuleArray(contractAddress, messageContextRequestsArrayBaseSlot, [], this.jobId);
633
+ }
634
+ }
635
+
636
+ public storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
549
637
  if (!contractAddress.equals(this.contractAddress)) {
550
638
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
551
639
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
@@ -554,7 +642,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
554
642
  return Promise.resolve();
555
643
  }
556
644
 
557
- public async utilityLoadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
645
+ public async loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
558
646
  if (!contractAddress.equals(this.contractAddress)) {
559
647
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
560
648
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
@@ -566,7 +654,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
566
654
  );
567
655
  }
568
656
 
569
- public utilityDeleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void> {
657
+ public deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void> {
570
658
  if (!contractAddress.equals(this.contractAddress)) {
571
659
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
572
660
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
@@ -575,12 +663,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
575
663
  return Promise.resolve();
576
664
  }
577
665
 
578
- public utilityCopyCapsule(
579
- contractAddress: AztecAddress,
580
- srcSlot: Fr,
581
- dstSlot: Fr,
582
- numEntries: number,
583
- ): Promise<void> {
666
+ public copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void> {
584
667
  if (!contractAddress.equals(this.contractAddress)) {
585
668
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
586
669
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
@@ -588,8 +671,19 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
588
671
  return this.capsuleStore.copyCapsule(this.contractAddress, srcSlot, dstSlot, numEntries, this.jobId);
589
672
  }
590
673
 
674
+ /**
675
+ * Clears cached sync state for a contract for a set of scopes, forcing re-sync on the next query so that newly
676
+ * stored notes or events are discovered.
677
+ */
678
+ public invalidateContractSyncCache(contractAddress: AztecAddress, scopes: AztecAddress[]): void {
679
+ if (!contractAddress.equals(this.contractAddress)) {
680
+ throw new Error(`Contract ${this.contractAddress} cannot invalidate sync cache of ${contractAddress}`);
681
+ }
682
+ this.contractSyncService.invalidateContractForScopes(contractAddress, scopes);
683
+ }
684
+
591
685
  // TODO(#11849): consider replacing this oracle with a pure Noir implementation of aes decryption.
592
- public utilityAes128Decrypt(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer> {
686
+ public aes128Decrypt(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer> {
593
687
  const aes128 = new Aes128();
594
688
  return aes128.decryptBufferCBC(ciphertext, iv, symKey);
595
689
  }
@@ -600,11 +694,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
600
694
  * @param ephPk - The ephemeral public key to get the secret for.
601
695
  * @returns The secret for the given address.
602
696
  */
603
- public utilityGetSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
604
- return this.getSharedSecret(address, ephPk);
605
- }
606
-
607
- protected async getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
697
+ public async getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
608
698
  // TODO(#12656): return an app-siloed secret
609
699
  const recipientCompleteAddress = await this.getCompleteAddressOrFail(address);
610
700
  const ivskM = await this.keyStore.getMasterSecretKey(
@@ -613,4 +703,34 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
613
703
  const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
614
704
  return deriveEcdhSharedSecret(addressSecret, ephPk);
615
705
  }
706
+
707
+ public emitOffchainEffect(data: Fr[]): Promise<void> {
708
+ this.offchainEffects.push({ data, contractAddress: this.contractAddress });
709
+ return Promise.resolve();
710
+ }
711
+
712
+ /** Returns offchain effects collected during execution. */
713
+ public getOffchainEffects(): OffchainEffect[] {
714
+ return this.offchainEffects;
715
+ }
716
+
717
+ /** Runs a query concurrently with a validation that the block hash is not ahead of the anchor block. */
718
+ async #queryWithBlockHashNotAfterAnchor<T>(blockHash: BlockHash, query: () => Promise<T>): Promise<T> {
719
+ const [response] = await Promise.all([
720
+ query(),
721
+ (async () => {
722
+ const header = await this.aztecNode.getBlockHeader(blockHash);
723
+ if (!header) {
724
+ throw new Error(`Could not find block header for block hash ${blockHash}`);
725
+ }
726
+
727
+ if (header.getBlockNumber() > this.anchorBlockHeader.getBlockNumber()) {
728
+ throw new Error(
729
+ `Made a node query with a reference block hash ${blockHash} with block number ${header.getBlockNumber()}, which is ahead of the anchor block number ${this.anchorBlockHeader.getBlockNumber()} (from anchor block hash ${await this.anchorBlockHeader.hash()}).`,
730
+ );
731
+ }
732
+ })(),
733
+ ]);
734
+ return response;
735
+ }
616
736
  }
@@ -0,0 +1,39 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { type LogLevel, type Logger, applyStringFormatting, createLogger } from '@aztec/foundation/log';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { DebugLog } from '@aztec/stdlib/logs';
5
+
6
+ /** Resolves a contract address to a human-readable name, if available. */
7
+ export type ContractNameResolver = (address: AztecAddress) => Promise<string | undefined>;
8
+
9
+ /**
10
+ * Creates a logger whose output is prefixed with `contract_log::<name>(<addrAbbrev>)`.
11
+ */
12
+ export async function createContractLogger(
13
+ contractAddress: AztecAddress,
14
+ getContractName: ContractNameResolver,
15
+ options?: { instanceId?: string },
16
+ ): Promise<Logger> {
17
+ const addrAbbrev = contractAddress.toString().slice(0, 10);
18
+ const name = await getContractName(contractAddress);
19
+ const module = name ? `contract_log::${name}(${addrAbbrev})` : `contract_log::Unknown(${addrAbbrev})`;
20
+ return createLogger(module, options);
21
+ }
22
+
23
+ /**
24
+ * Formats and emits a single contract log message through the given logger.
25
+ */
26
+ export function logContractMessage(logger: Logger, level: LogLevel, message: string, fields: Fr[]): void {
27
+ logger[level](applyStringFormatting(message, fields));
28
+ }
29
+
30
+ /**
31
+ * Displays debug logs collected during public function simulation,
32
+ * using the `contract_log::` prefixed logger format.
33
+ */
34
+ export async function displayDebugLogs(debugLogs: DebugLog[], getContractName: ContractNameResolver): Promise<void> {
35
+ for (const log of debugLogs) {
36
+ const logger = await createContractLogger(log.contractAddress, getContractName);
37
+ logContractMessage(logger, log.level, log.message, log.fields);
38
+ }
39
+ }