@aztec/pxe 0.0.1-commit.d117d021b → 0.0.1-commit.d1da697d6

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 (161) hide show
  1. package/dest/block_synchronizer/block_synchronizer.d.ts +1 -1
  2. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  3. package/dest/block_synchronizer/block_synchronizer.js +6 -0
  4. package/dest/contract_function_simulator/contract_function_simulator.d.ts +10 -5
  5. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  6. package/dest/contract_function_simulator/contract_function_simulator.js +29 -6
  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 +2 -5
  16. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -3
  17. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  18. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +2 -5
  19. package/dest/contract_function_simulator/oracle/interfaces.d.ts +20 -18
  20. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  21. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  22. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  23. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +38 -0
  24. package/dest/contract_function_simulator/oracle/oracle.d.ts +38 -17
  25. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/oracle/oracle.js +89 -37
  27. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  28. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +10 -22
  29. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +20 -24
  31. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +45 -28
  32. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +164 -71
  34. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  35. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/pick_notes.js +9 -2
  37. package/dest/contract_logging.d.ts +9 -4
  38. package/dest/contract_logging.d.ts.map +1 -1
  39. package/dest/contract_logging.js +21 -6
  40. package/dest/contract_sync/contract_sync_service.d.ts +6 -5
  41. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  42. package/dest/contract_sync/contract_sync_service.js +44 -37
  43. package/dest/contract_sync/helpers.d.ts +2 -3
  44. package/dest/contract_sync/helpers.d.ts.map +1 -1
  45. package/dest/contract_sync/helpers.js +7 -2
  46. package/dest/debug/pxe_debug_utils.d.ts +3 -3
  47. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  48. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  49. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  50. package/dest/entrypoints/client/bundle/index.js +0 -1
  51. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  52. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  53. package/dest/entrypoints/client/bundle/utils.js +2 -2
  54. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  55. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  56. package/dest/entrypoints/client/lazy/index.js +0 -1
  57. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  58. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  59. package/dest/entrypoints/client/lazy/utils.js +2 -2
  60. package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
  61. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  62. package/dest/entrypoints/pxe_creation_options.js +3 -1
  63. package/dest/entrypoints/server/index.d.ts +1 -2
  64. package/dest/entrypoints/server/index.d.ts.map +1 -1
  65. package/dest/entrypoints/server/index.js +0 -1
  66. package/dest/entrypoints/server/utils.d.ts +2 -2
  67. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  68. package/dest/entrypoints/server/utils.js +2 -2
  69. package/dest/events/event_service.d.ts +3 -2
  70. package/dest/events/event_service.d.ts.map +1 -1
  71. package/dest/events/event_service.js +16 -4
  72. package/dest/logs/log_service.d.ts +6 -7
  73. package/dest/logs/log_service.d.ts.map +1 -1
  74. package/dest/logs/log_service.js +32 -30
  75. package/dest/messages/message_context_service.d.ts +17 -0
  76. package/dest/messages/message_context_service.d.ts.map +1 -0
  77. package/dest/messages/message_context_service.js +36 -0
  78. package/dest/notes/note_service.d.ts +4 -5
  79. package/dest/notes/note_service.d.ts.map +1 -1
  80. package/dest/notes/note_service.js +14 -5
  81. package/dest/notes_filter.d.ts +2 -3
  82. package/dest/notes_filter.d.ts.map +1 -1
  83. package/dest/oracle_version.d.ts +2 -2
  84. package/dest/oracle_version.js +2 -2
  85. package/dest/pxe.d.ts +9 -7
  86. package/dest/pxe.d.ts.map +1 -1
  87. package/dest/pxe.js +39 -23
  88. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  89. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  90. package/dest/storage/capsule_store/capsule_service.js +50 -0
  91. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  92. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  93. package/dest/storage/capsule_store/capsule_store.js +33 -28
  94. package/dest/storage/capsule_store/index.d.ts +2 -1
  95. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  96. package/dest/storage/capsule_store/index.js +1 -0
  97. package/dest/storage/metadata.d.ts +1 -1
  98. package/dest/storage/metadata.js +1 -1
  99. package/dest/storage/note_store/note_store.d.ts +1 -1
  100. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  101. package/dest/storage/note_store/note_store.js +2 -2
  102. package/dest/storage/tagging_store/sender_tagging_store.d.ts +26 -25
  103. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  104. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  105. package/dest/tagging/index.d.ts +2 -2
  106. package/dest/tagging/index.d.ts.map +1 -1
  107. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +1 -1
  108. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  109. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +10 -1
  110. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  111. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  112. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  113. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +2 -1
  114. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  115. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +24 -11
  116. package/package.json +16 -16
  117. package/src/block_synchronizer/block_synchronizer.ts +6 -0
  118. package/src/contract_function_simulator/contract_function_simulator.ts +42 -10
  119. package/src/contract_function_simulator/execution_tagging_index_cache.ts +16 -11
  120. package/src/contract_function_simulator/index.ts +1 -0
  121. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +0 -3
  122. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +0 -3
  123. package/src/contract_function_simulator/oracle/interfaces.ts +31 -16
  124. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +98 -0
  125. package/src/contract_function_simulator/oracle/oracle.ts +116 -32
  126. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  127. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +24 -31
  128. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +284 -83
  129. package/src/contract_function_simulator/pick_notes.ts +9 -2
  130. package/src/contract_logging.ts +18 -5
  131. package/src/contract_sync/contract_sync_service.ts +77 -59
  132. package/src/contract_sync/helpers.ts +4 -4
  133. package/src/debug/pxe_debug_utils.ts +3 -3
  134. package/src/entrypoints/client/bundle/index.ts +0 -1
  135. package/src/entrypoints/client/bundle/utils.ts +2 -3
  136. package/src/entrypoints/client/lazy/index.ts +0 -1
  137. package/src/entrypoints/client/lazy/utils.ts +2 -3
  138. package/src/entrypoints/pxe_creation_options.ts +7 -0
  139. package/src/entrypoints/server/index.ts +0 -1
  140. package/src/entrypoints/server/utils.ts +2 -3
  141. package/src/events/event_service.ts +17 -4
  142. package/src/logs/log_service.ts +63 -48
  143. package/src/messages/message_context_service.ts +44 -0
  144. package/src/notes/note_service.ts +18 -8
  145. package/src/notes_filter.ts +1 -3
  146. package/src/oracle_version.ts +2 -2
  147. package/src/pxe.ts +62 -28
  148. package/src/storage/capsule_store/capsule_service.ts +90 -0
  149. package/src/storage/capsule_store/capsule_store.ts +34 -26
  150. package/src/storage/capsule_store/index.ts +1 -0
  151. package/src/storage/metadata.ts +1 -1
  152. package/src/storage/note_store/note_store.ts +2 -5
  153. package/src/storage/tagging_store/sender_tagging_store.ts +182 -135
  154. package/src/tagging/index.ts +1 -1
  155. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +19 -1
  156. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  157. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +19 -9
  158. package/dest/access_scopes.d.ts +0 -9
  159. package/dest/access_scopes.d.ts.map +0 -1
  160. package/dest/access_scopes.js +0 -6
  161. package/src/access_scopes.ts +0 -9
@@ -6,6 +6,7 @@ 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';
@@ -14,20 +15,21 @@ 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
17
  import { type PublicKeys, computeAddressSecret } from '@aztec/stdlib/keys';
17
- import { deriveEcdhSharedSecret } from '@aztec/stdlib/logs';
18
+ import { MessageContext, deriveAppSiloedSharedSecret } 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
- import type { AccessScopes } from '../../access_scopes.js';
24
- import { createContractLogger, logContractMessage } from '../../contract_logging.js';
24
+ import { createContractLogger, logContractMessage, stripAztecnrLogPrefix } from '../../contract_logging.js';
25
+ import type { ContractSyncService } from '../../contract_sync/contract_sync_service.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';
30
- import type { CapsuleStore } from '../../storage/capsule_store/capsule_store.js';
32
+ import type { CapsuleService } from '../../storage/capsule_store/capsule_service.js';
31
33
  import type { ContractStore } from '../../storage/contract_store/contract_store.js';
32
34
  import type { NoteStore } from '../../storage/note_store/note_store.js';
33
35
  import type { PrivateEventStore } from '../../storage/private_event_store/private_event_store.js';
@@ -56,11 +58,13 @@ export type UtilityExecutionOracleArgs = {
56
58
  aztecNode: AztecNode;
57
59
  recipientTaggingStore: RecipientTaggingStore;
58
60
  senderAddressBookStore: SenderAddressBookStore;
59
- capsuleStore: CapsuleStore;
61
+ capsuleService: CapsuleService;
60
62
  privateEventStore: PrivateEventStore;
63
+ messageContextService: MessageContextService;
64
+ contractSyncService: ContractSyncService;
61
65
  jobId: string;
62
66
  log?: ReturnType<typeof createLogger>;
63
- scopes: AccessScopes;
67
+ scopes: AztecAddress[];
64
68
  };
65
69
 
66
70
  /**
@@ -71,6 +75,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
71
75
  isUtility = true as const;
72
76
 
73
77
  private contractLogger: Logger | undefined;
78
+ private aztecnrLogger: Logger | undefined;
79
+ private offchainEffects: OffchainEffect[] = [];
74
80
 
75
81
  protected readonly contractAddress: AztecAddress;
76
82
  protected readonly authWitnesses: AuthWitness[];
@@ -83,11 +89,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
83
89
  protected readonly aztecNode: AztecNode;
84
90
  protected readonly recipientTaggingStore: RecipientTaggingStore;
85
91
  protected readonly senderAddressBookStore: SenderAddressBookStore;
86
- protected readonly capsuleStore: CapsuleStore;
92
+ protected readonly capsuleService: CapsuleService;
87
93
  protected readonly privateEventStore: PrivateEventStore;
94
+ protected readonly messageContextService: MessageContextService;
95
+ protected readonly contractSyncService: ContractSyncService;
88
96
  protected readonly jobId: string;
89
97
  protected logger: ReturnType<typeof createLogger>;
90
- protected readonly scopes: AccessScopes;
98
+ protected readonly scopes: AztecAddress[];
91
99
 
92
100
  constructor(args: UtilityExecutionOracleArgs) {
93
101
  this.contractAddress = args.contractAddress;
@@ -101,16 +109,43 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
101
109
  this.aztecNode = args.aztecNode;
102
110
  this.recipientTaggingStore = args.recipientTaggingStore;
103
111
  this.senderAddressBookStore = args.senderAddressBookStore;
104
- this.capsuleStore = args.capsuleStore;
112
+ this.capsuleService = args.capsuleService;
105
113
  this.privateEventStore = args.privateEventStore;
114
+ this.messageContextService = args.messageContextService;
115
+ this.contractSyncService = args.contractSyncService;
106
116
  this.jobId = args.jobId;
107
117
  this.logger = args.log ?? createLogger('simulator:client_view_context');
108
118
  this.scopes = args.scopes;
109
119
  }
110
120
 
111
121
  public assertCompatibleOracleVersion(version: number): void {
122
+ // TODO(F-416): Remove this hack on v5 when protocol contracts are redeployed.
123
+ // Protocol contracts/canonical contracts shipped with committed bytecode that cannot be changed. Assert they use
124
+ // the expected pinned version or the current one. We want to allow for both the pinned and the current versions
125
+ // because we want this code to work with both the pinned and unpinned version since some branches do not have the
126
+ // pinned contracts (like e.g. next)
127
+ const LEGACY_ORACLE_VERSION = 12;
128
+ if (isProtocolContract(this.contractAddress)) {
129
+ if (version !== LEGACY_ORACLE_VERSION && version !== ORACLE_VERSION) {
130
+ const hint =
131
+ version > ORACLE_VERSION
132
+ ? 'The contract was compiled with a newer version of Aztec.nr than your private environment supports. Upgrade your private environment to a compatible version.'
133
+ : 'The contract was compiled with an older version of Aztec.nr than your private environment supports. Recompile the contract with a compatible version of Aztec.nr.';
134
+ throw new Error(
135
+ `Incompatible private environment version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle version ${LEGACY_ORACLE_VERSION} or ${ORACLE_VERSION}, got ${version})`,
136
+ );
137
+ }
138
+ return;
139
+ }
140
+
112
141
  if (version !== ORACLE_VERSION) {
113
- throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
142
+ const hint =
143
+ version > ORACLE_VERSION
144
+ ? 'The contract was compiled with a newer version of Aztec.nr than your private environment supports. Upgrade your private environment to a compatible version.'
145
+ : 'The contract was compiled with an older version of Aztec.nr than your private environment supports. Recompile the contract with a compatible version of Aztec.nr.';
146
+ throw new Error(
147
+ `Incompatible private environment version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle version ${ORACLE_VERSION}, got ${version})`,
148
+ );
114
149
  }
115
150
  }
116
151
 
@@ -130,33 +165,32 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
130
165
  * @throws If scopes are defined and the account is not in the scopes.
131
166
  */
132
167
  public async getKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
133
- // If scopes are defined, check that the key belongs to an account in the scopes.
134
- if (this.scopes !== 'ALL_SCOPES' && this.scopes.length > 0) {
135
- let hasAccess = false;
136
- for (let i = 0; i < this.scopes.length && !hasAccess; i++) {
137
- if (await this.keyStore.accountHasKey(this.scopes[i], pkMHash)) {
138
- hasAccess = true;
139
- }
140
- }
141
- if (!hasAccess) {
142
- throw new Error(`Key validation request denied: no scoped account has a key with hash ${pkMHash.toString()}.`);
168
+ let hasAccess = false;
169
+ for (let i = 0; i < this.scopes.length && !hasAccess; i++) {
170
+ if (await this.keyStore.accountHasKey(this.scopes[i], pkMHash)) {
171
+ hasAccess = true;
143
172
  }
144
173
  }
174
+ if (!hasAccess) {
175
+ throw new Error(`Key validation request denied: no scoped account has a key with hash ${pkMHash.toString()}.`);
176
+ }
145
177
  return this.keyStore.getKeyValidationRequest(pkMHash, this.contractAddress);
146
178
  }
147
179
 
148
180
  /**
149
181
  * Fetches the index and sibling path of a leaf at a given block from the note hash tree.
150
- * @param anchorBlockHash - The hash of a block that contains the note hash tree root in which to find the membership
151
- * witness.
182
+ * @param blockHash - The hash of a block that contains the note hash tree root in which to find the
183
+ * membership witness.
152
184
  * @param noteHash - The note hash to find in the note hash tree.
153
185
  * @returns The membership witness containing the leaf index and sibling path
154
186
  */
155
187
  public getNoteHashMembershipWitness(
156
- anchorBlockHash: BlockHash,
188
+ blockHash: BlockHash,
157
189
  noteHash: Fr,
158
190
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
159
- return this.aztecNode.getNoteHashMembershipWitness(anchorBlockHash, noteHash);
191
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
192
+ this.aztecNode.getNoteHashMembershipWitness(blockHash, noteHash),
193
+ );
160
194
  }
161
195
 
162
196
  /**
@@ -165,16 +199,21 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
165
199
  * Block hashes are the leaves of the archive tree. Each time a new block is added to the chain,
166
200
  * its block hash is appended as a new leaf to the archive tree.
167
201
  *
168
- * @param anchorBlockHash - The hash of a block that contains the archive tree root in which to find the membership
202
+ * @param referenceBlockHash - The hash of a block that contains the archive tree root in which to find the membership
169
203
  * witness.
170
204
  * @param blockHash - The block hash to find in the archive tree.
171
205
  * @returns The membership witness containing the leaf index and sibling path
172
206
  */
173
207
  public getBlockHashMembershipWitness(
174
- anchorBlockHash: BlockHash,
208
+ referenceBlockHash: BlockHash,
175
209
  blockHash: BlockHash,
176
210
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
177
- return this.aztecNode.getBlockHashMembershipWitness(anchorBlockHash, blockHash);
211
+ // Note that we validate that the reference block hash is at or before the anchor block - we don't test the block
212
+ // hash at all. If the block hash did not exist by the reference block hash, then the node will not return the
213
+ // membership witness as there is none.
214
+ return this.#queryWithBlockHashNotAfterAnchor(referenceBlockHash, () =>
215
+ this.aztecNode.getBlockHashMembershipWitness(referenceBlockHash, blockHash),
216
+ );
178
217
  }
179
218
 
180
219
  /**
@@ -187,7 +226,9 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
187
226
  blockHash: BlockHash,
188
227
  nullifier: Fr,
189
228
  ): Promise<NullifierMembershipWitness | undefined> {
190
- return this.aztecNode.getNullifierMembershipWitness(blockHash, nullifier);
229
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
230
+ this.aztecNode.getNullifierMembershipWitness(blockHash, nullifier),
231
+ );
191
232
  }
192
233
 
193
234
  /**
@@ -203,7 +244,9 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
203
244
  blockHash: BlockHash,
204
245
  nullifier: Fr,
205
246
  ): Promise<NullifierMembershipWitness | undefined> {
206
- return this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier);
247
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
248
+ this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier),
249
+ );
207
250
  }
208
251
 
209
252
  /**
@@ -213,7 +256,9 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
213
256
  * @returns - The witness
214
257
  */
215
258
  public getPublicDataWitness(blockHash: BlockHash, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
216
- return this.aztecNode.getPublicDataWitness(blockHash, leafSlot);
259
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
260
+ this.aztecNode.getPublicDataWitness(blockHash, leafSlot),
261
+ );
217
262
  }
218
263
 
219
264
  /**
@@ -236,7 +281,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
236
281
  * @param account - The account address.
237
282
  * @returns The public keys and partial address, or `undefined` if the account is not registered.
238
283
  */
239
- public async tryGetPublicKeysAndPartialAddress(
284
+ public async getPublicKeysAndPartialAddress(
240
285
  account: AztecAddress,
241
286
  ): Promise<{ publicKeys: PublicKeys; partialAddress: PartialAddress } | undefined> {
242
287
  const completeAddress = await this.addressStore.getCompleteAddress(account);
@@ -342,7 +387,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
342
387
  * @param innerNullifier - The inner nullifier.
343
388
  * @returns A boolean indicating whether the nullifier exists in the tree or not.
344
389
  */
345
- public async checkNullifierExists(innerNullifier: Fr) {
390
+ public async doesNullifierExist(innerNullifier: Fr) {
346
391
  const [nullifier, anchorBlockHash] = await Promise.all([
347
392
  siloNullifier(this.contractAddress, innerNullifier!),
348
393
  this.anchorBlockHeader.hash(),
@@ -354,7 +399,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
354
399
  }
355
400
 
356
401
  /**
357
- * Fetches a message from the executionStore, given its key.
402
+ * Returns the membership witness of an un-nullified L1 to L2 message.
358
403
  * @param contractAddress - Address of a contract by which the message was emitted.
359
404
  * @param messageHash - Hash of the message.
360
405
  * @param secret - Secret used to compute a nullifier.
@@ -367,6 +412,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
367
412
  contractAddress,
368
413
  messageHash,
369
414
  secret,
415
+ await this.anchorBlockHeader.hash(),
370
416
  );
371
417
 
372
418
  return new MessageLoadOracleInputs(messageIndex, siblingPath);
@@ -379,29 +425,31 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
379
425
  * @param startStorageSlot - The starting storage slot.
380
426
  * @param numberOfElements - Number of elements to read from the starting storage slot.
381
427
  */
382
- public async storageRead(
428
+ public getFromPublicStorage(
383
429
  blockHash: BlockHash,
384
430
  contractAddress: AztecAddress,
385
431
  startStorageSlot: Fr,
386
432
  numberOfElements: number,
387
433
  ) {
388
- const slots = Array(numberOfElements)
389
- .fill(0)
390
- .map((_, i) => new Fr(startStorageSlot.value + BigInt(i)));
434
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, async () => {
435
+ const slots = Array(numberOfElements)
436
+ .fill(0)
437
+ .map((_, i) => new Fr(startStorageSlot.value + BigInt(i)));
391
438
 
392
- const values = await Promise.all(
393
- slots.map(storageSlot => this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot)),
394
- );
439
+ const values = await Promise.all(
440
+ slots.map(storageSlot => this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot)),
441
+ );
395
442
 
396
- this.logger.debug(
397
- `Oracle storage read: slots=[${slots.map(slot => slot.toString()).join(', ')}] address=${contractAddress.toString()} values=[${values.join(', ')}]`,
398
- );
443
+ this.logger.debug(
444
+ `Oracle storage read: slots=[${slots.map(slot => slot.toString()).join(', ')}] address=${contractAddress.toString()} values=[${values.join(', ')}]`,
445
+ );
399
446
 
400
- return values;
447
+ return values;
448
+ });
401
449
  }
402
450
 
403
451
  /**
404
- * Returns a per-contract logger whose output is prefixed with `contract_log::<name>(<addrAbbrev>)`.
452
+ * Returns a per-contract logger whose output is prefixed with `contract:<name>(<addrAbbrev>)`.
405
453
  */
406
454
  async #getContractLogger(): Promise<Logger> {
407
455
  if (!this.contractLogger) {
@@ -410,26 +458,47 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
410
458
  this.contractLogger = await createContractLogger(
411
459
  this.contractAddress,
412
460
  addr => this.contractStore.getDebugContractName(addr),
461
+ 'user',
413
462
  { instanceId: this.jobId },
414
463
  );
415
464
  }
416
465
  return this.contractLogger;
417
466
  }
418
467
 
468
+ /**
469
+ * Returns a per-contract logger whose output is prefixed with `aztecnr:<name>(<addrAbbrev>)`.
470
+ */
471
+ async #getAztecnrLogger(): Promise<Logger> {
472
+ if (!this.aztecnrLogger) {
473
+ // Purpose of instanceId is to distinguish logs from different instances of the same component. It makes sense
474
+ // to re-use jobId as instanceId here as executions of different PXE jobs are isolated.
475
+ this.aztecnrLogger = await createContractLogger(
476
+ this.contractAddress,
477
+ addr => this.contractStore.getDebugContractName(addr),
478
+ 'aztecnr',
479
+ { instanceId: this.jobId },
480
+ );
481
+ }
482
+ return this.aztecnrLogger;
483
+ }
484
+
419
485
  public async log(level: number, message: string, fields: Fr[]): Promise<void> {
420
486
  if (!LogLevels[level]) {
421
487
  throw new Error(`Invalid log level: ${level}`);
422
488
  }
423
- const logger = await this.#getContractLogger();
424
- logContractMessage(logger, LogLevels[level], message, fields);
489
+
490
+ const { kind, message: strippedMessage } = stripAztecnrLogPrefix(message);
491
+
492
+ const logger = kind == 'aztecnr' ? await this.#getAztecnrLogger() : await this.#getContractLogger();
493
+ logContractMessage(logger, LogLevels[level], strippedMessage, fields);
425
494
  }
426
495
 
427
- public async fetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) {
496
+ public async getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr, scope: AztecAddress) {
428
497
  const logService = new LogService(
429
498
  this.aztecNode,
430
499
  this.anchorBlockHeader,
431
500
  this.keyStore,
432
- this.capsuleStore,
501
+ this.capsuleService,
433
502
  this.recipientTaggingStore,
434
503
  this.senderAddressBookStore,
435
504
  this.addressStore,
@@ -437,7 +506,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
437
506
  this.logger.getBindings(),
438
507
  );
439
508
 
440
- await logService.fetchTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
509
+ await logService.fetchTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, scope);
441
510
  }
442
511
 
443
512
  /**
@@ -456,6 +525,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
456
525
  eventValidationRequestsArrayBaseSlot: Fr,
457
526
  maxNotePackedLen: number,
458
527
  maxEventSerializedLen: number,
528
+ scope: AztecAddress,
459
529
  ) {
460
530
  // TODO(#10727): allow other contracts to store notes
461
531
  if (!this.contractAddress.equals(contractAddress)) {
@@ -465,11 +535,21 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
465
535
  // We read all note and event validation requests and process them all concurrently. This makes the process much
466
536
  // faster as we don't need to wait for the network round-trip.
467
537
  const noteValidationRequests = (
468
- await this.capsuleStore.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, this.jobId)
538
+ await this.capsuleService.readCapsuleArray(
539
+ contractAddress,
540
+ noteValidationRequestsArrayBaseSlot,
541
+ this.jobId,
542
+ scope,
543
+ )
469
544
  ).map(fields => NoteValidationRequest.fromFields(fields, maxNotePackedLen));
470
545
 
471
546
  const eventValidationRequests = (
472
- await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId)
547
+ await this.capsuleService.readCapsuleArray(
548
+ contractAddress,
549
+ eventValidationRequestsArrayBaseSlot,
550
+ this.jobId,
551
+ scope,
552
+ )
473
553
  ).map(fields => EventValidationRequest.fromFields(fields, maxEventSerializedLen));
474
554
 
475
555
  const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
@@ -484,7 +564,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
484
564
  request.noteHash,
485
565
  request.nullifier,
486
566
  request.txHash,
487
- request.recipient,
567
+ scope,
488
568
  ),
489
569
  );
490
570
 
@@ -497,21 +577,34 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
497
577
  request.serializedEvent,
498
578
  request.eventCommitment,
499
579
  request.txHash,
500
- request.recipient,
580
+ scope,
501
581
  ),
502
582
  );
503
583
 
504
584
  await Promise.all([...noteStorePromises, ...eventStorePromises]);
505
585
 
506
586
  // Requests are cleared once we're done.
507
- await this.capsuleStore.setCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, [], this.jobId);
508
- await this.capsuleStore.setCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, [], this.jobId);
587
+ await this.capsuleService.setCapsuleArray(
588
+ contractAddress,
589
+ noteValidationRequestsArrayBaseSlot,
590
+ [],
591
+ this.jobId,
592
+ scope,
593
+ );
594
+ await this.capsuleService.setCapsuleArray(
595
+ contractAddress,
596
+ eventValidationRequestsArrayBaseSlot,
597
+ [],
598
+ this.jobId,
599
+ scope,
600
+ );
509
601
  }
510
602
 
511
- public async bulkRetrieveLogs(
603
+ public async getLogsByTag(
512
604
  contractAddress: AztecAddress,
513
605
  logRetrievalRequestsArrayBaseSlot: Fr,
514
606
  logRetrievalResponsesArrayBaseSlot: Fr,
607
+ scope: AztecAddress,
515
608
  ) {
516
609
  // TODO(#10727): allow other contracts to process partial notes
517
610
  if (!this.contractAddress.equals(contractAddress)) {
@@ -521,14 +614,14 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
521
614
  // We read all log retrieval requests and process them all concurrently. This makes the process much faster as we
522
615
  // don't need to wait for the network round-trip.
523
616
  const logRetrievalRequests = (
524
- await this.capsuleStore.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, this.jobId)
617
+ await this.capsuleService.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, this.jobId, scope)
525
618
  ).map(LogRetrievalRequest.fromFields);
526
619
 
527
620
  const logService = new LogService(
528
621
  this.aztecNode,
529
622
  this.anchorBlockHeader,
530
623
  this.keyStore,
531
- this.capsuleStore,
624
+ this.capsuleService,
532
625
  this.recipientTaggingStore,
533
626
  this.senderAddressBookStore,
534
627
  this.addressStore,
@@ -536,77 +629,185 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
536
629
  this.logger.getBindings(),
537
630
  );
538
631
 
539
- const maybeLogRetrievalResponses = await logService.bulkRetrieveLogs(logRetrievalRequests);
632
+ const maybeLogRetrievalResponses = await logService.fetchLogsByTag(contractAddress, logRetrievalRequests);
540
633
 
541
634
  // Requests are cleared once we're done.
542
- await this.capsuleStore.setCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, [], this.jobId);
635
+ await this.capsuleService.setCapsuleArray(
636
+ contractAddress,
637
+ logRetrievalRequestsArrayBaseSlot,
638
+ [],
639
+ this.jobId,
640
+ scope,
641
+ );
543
642
 
544
643
  // The responses are stored as Option<LogRetrievalResponse> in a second CapsuleArray.
545
- await this.capsuleStore.setCapsuleArray(
644
+ await this.capsuleService.setCapsuleArray(
546
645
  contractAddress,
547
646
  logRetrievalResponsesArrayBaseSlot,
548
647
  maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption),
549
648
  this.jobId,
649
+ scope,
550
650
  );
551
651
  }
552
652
 
553
- public storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
653
+ public async getMessageContextsByTxHash(
654
+ contractAddress: AztecAddress,
655
+ messageContextRequestsArrayBaseSlot: Fr,
656
+ messageContextResponsesArrayBaseSlot: Fr,
657
+ scope: AztecAddress,
658
+ ) {
659
+ try {
660
+ if (!this.contractAddress.equals(contractAddress)) {
661
+ throw new Error(`Got a message context request from ${contractAddress}, expected ${this.contractAddress}`);
662
+ }
663
+
664
+ // TODO(@mverzilli): this is a prime example of where using a volatile array would make much more sense, we don't
665
+ // need scopes here, we just need a bit of shared memory to cross boundaries between Noir and TS.
666
+ // At the same time, we don't want to allow any global scope access other than where backwards compatibility
667
+ // forces us to. Hence we need the scope here to be artificial.
668
+ const requestCapsules = await this.capsuleService.readCapsuleArray(
669
+ contractAddress,
670
+ messageContextRequestsArrayBaseSlot,
671
+ this.jobId,
672
+ scope,
673
+ );
674
+
675
+ const txHashes = requestCapsules.map((fields, i) => {
676
+ if (fields.length !== 1) {
677
+ throw new Error(
678
+ `Malformed message context request at index ${i}: expected 1 field (tx hash), got ${fields.length}`,
679
+ );
680
+ }
681
+ return fields[0];
682
+ });
683
+
684
+ const maybeMessageContexts = await this.messageContextService.getMessageContextsByTxHash(
685
+ txHashes,
686
+ this.anchorBlockHeader.getBlockNumber(),
687
+ );
688
+
689
+ // Leave response in response capsule array.
690
+ await this.capsuleService.setCapsuleArray(
691
+ contractAddress,
692
+ messageContextResponsesArrayBaseSlot,
693
+ maybeMessageContexts.map(MessageContext.toSerializedOption),
694
+ this.jobId,
695
+ scope,
696
+ );
697
+ } finally {
698
+ await this.capsuleService.setCapsuleArray(
699
+ contractAddress,
700
+ messageContextRequestsArrayBaseSlot,
701
+ [],
702
+ this.jobId,
703
+ scope,
704
+ );
705
+ }
706
+ }
707
+
708
+ public setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], scope: AztecAddress): void {
554
709
  if (!contractAddress.equals(this.contractAddress)) {
555
710
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
556
711
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
557
712
  }
558
- this.capsuleStore.storeCapsule(this.contractAddress, slot, capsule, this.jobId);
559
- return Promise.resolve();
713
+ this.capsuleService.setCapsule(contractAddress, slot, capsule, this.jobId, scope);
560
714
  }
561
715
 
562
- public async loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
716
+ public getCapsule(contractAddress: AztecAddress, slot: Fr, scope: AztecAddress): Promise<Fr[] | null> {
563
717
  if (!contractAddress.equals(this.contractAddress)) {
564
718
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
565
719
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
566
720
  }
567
- return (
568
- // TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
569
- this.capsules.find(c => c.contractAddress.equals(contractAddress) && c.storageSlot.equals(slot))?.data ??
570
- (await this.capsuleStore.loadCapsule(this.contractAddress, slot, this.jobId))
571
- );
721
+ return this.capsuleService.getCapsule(contractAddress, slot, this.jobId, scope, this.capsules);
572
722
  }
573
723
 
574
- public deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void> {
724
+ public deleteCapsule(contractAddress: AztecAddress, slot: Fr, scope: AztecAddress): void {
575
725
  if (!contractAddress.equals(this.contractAddress)) {
576
726
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
577
727
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
578
728
  }
579
- this.capsuleStore.deleteCapsule(this.contractAddress, slot, this.jobId);
580
- return Promise.resolve();
729
+ this.capsuleService.deleteCapsule(contractAddress, slot, this.jobId, scope);
581
730
  }
582
731
 
583
- public copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void> {
732
+ public copyCapsule(
733
+ contractAddress: AztecAddress,
734
+ srcSlot: Fr,
735
+ dstSlot: Fr,
736
+ numEntries: number,
737
+ scope: AztecAddress,
738
+ ): Promise<void> {
584
739
  if (!contractAddress.equals(this.contractAddress)) {
585
740
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
586
741
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
587
742
  }
588
- return this.capsuleStore.copyCapsule(this.contractAddress, srcSlot, dstSlot, numEntries, this.jobId);
743
+ return this.capsuleService.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, this.jobId, scope);
744
+ }
745
+
746
+ /**
747
+ * Clears cached sync state for a contract for a set of scopes, forcing re-sync on the next query so that newly
748
+ * stored notes or events are discovered.
749
+ */
750
+ public setContractSyncCacheInvalid(contractAddress: AztecAddress, scopes: AztecAddress[]): void {
751
+ if (!contractAddress.equals(this.contractAddress)) {
752
+ throw new Error(`Contract ${this.contractAddress} cannot invalidate sync cache of ${contractAddress}`);
753
+ }
754
+ this.contractSyncService.invalidateContractForScopes(contractAddress, scopes);
589
755
  }
590
756
 
591
757
  // TODO(#11849): consider replacing this oracle with a pure Noir implementation of aes decryption.
592
- public aes128Decrypt(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer> {
758
+ public decryptAes128(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer> {
593
759
  const aes128 = new Aes128();
594
760
  return aes128.decryptBufferCBC(ciphertext, iv, symKey);
595
761
  }
596
762
 
597
763
  /**
598
- * Retrieves the shared secret for a given address and ephemeral public key.
764
+ * Retrieves the app-siloed shared secret for a given address and ephemeral public key.
599
765
  * @param address - The address to get the secret for.
600
766
  * @param ephPk - The ephemeral public key to get the secret for.
601
- * @returns The secret for the given address.
767
+ * @param contractAddress - The contract address for app-siloing (validated against execution context).
768
+ * @returns The app-siloed shared secret as a Field.
602
769
  */
603
- public async getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
604
- // TODO(#12656): return an app-siloed secret
770
+ public async getSharedSecret(address: AztecAddress, ephPk: Point, contractAddress: AztecAddress): Promise<Fr> {
771
+ if (!contractAddress.equals(this.contractAddress)) {
772
+ throw new Error(
773
+ `getSharedSecret called with contract address ${contractAddress}, expected ${this.contractAddress}`,
774
+ );
775
+ }
605
776
  const recipientCompleteAddress = await this.getCompleteAddressOrFail(address);
606
777
  const ivskM = await this.keyStore.getMasterSecretKey(
607
778
  recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey,
608
779
  );
609
780
  const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
610
- return deriveEcdhSharedSecret(addressSecret, ephPk);
781
+ return deriveAppSiloedSharedSecret(addressSecret, ephPk, this.contractAddress);
782
+ }
783
+
784
+ public emitOffchainEffect(data: Fr[]): Promise<void> {
785
+ this.offchainEffects.push({ data, contractAddress: this.contractAddress });
786
+ return Promise.resolve();
787
+ }
788
+
789
+ /** Returns offchain effects collected during execution. */
790
+ public getOffchainEffects(): OffchainEffect[] {
791
+ return this.offchainEffects;
792
+ }
793
+
794
+ /** Runs a query concurrently with a validation that the block hash is not ahead of the anchor block. */
795
+ async #queryWithBlockHashNotAfterAnchor<T>(blockHash: BlockHash, query: () => Promise<T>): Promise<T> {
796
+ const [response] = await Promise.all([
797
+ query(),
798
+ (async () => {
799
+ const header = await this.aztecNode.getBlockHeader(blockHash);
800
+ if (!header) {
801
+ throw new Error(`Could not find block header for block hash ${blockHash}`);
802
+ }
803
+
804
+ if (header.getBlockNumber() > this.anchorBlockHeader.getBlockNumber()) {
805
+ throw new Error(
806
+ `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()}).`,
807
+ );
808
+ }
809
+ })(),
810
+ ]);
811
+ return response;
611
812
  }
612
813
  }