@aztec/pxe 3.0.0-nightly.20251222 → 3.0.0-nightly.20251223

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 (108) hide show
  1. package/dest/contract_function_simulator/contract_function_simulator.d.ts +31 -6
  2. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  3. package/dest/contract_function_simulator/contract_function_simulator.js +35 -11
  4. package/dest/contract_function_simulator/oracle/private_execution.d.ts +6 -8
  5. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  6. package/dest/contract_function_simulator/oracle/private_execution.js +10 -9
  7. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +13 -4
  8. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  9. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +18 -13
  10. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +44 -6
  11. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  12. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +135 -30
  13. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +2 -2
  14. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  15. package/dest/contract_function_simulator/proxied_contract_data_source.js +18 -0
  16. package/dest/debug/pxe_debug_utils.d.ts +3 -2
  17. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  18. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  19. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  20. package/dest/entrypoints/client/bundle/index.js +0 -1
  21. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  22. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  23. package/dest/entrypoints/client/lazy/index.js +0 -1
  24. package/dest/entrypoints/server/index.d.ts +2 -2
  25. package/dest/entrypoints/server/index.d.ts.map +1 -1
  26. package/dest/entrypoints/server/index.js +1 -1
  27. package/dest/events/event_service.d.ts +15 -0
  28. package/dest/events/event_service.d.ts.map +1 -0
  29. package/dest/events/event_service.js +47 -0
  30. package/dest/events/private_event_filter_validator.d.ts +3 -2
  31. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  32. package/dest/logs/log_service.d.ts +43 -0
  33. package/dest/logs/log_service.d.ts.map +1 -0
  34. package/dest/logs/log_service.js +258 -0
  35. package/dest/notes/index.d.ts +2 -0
  36. package/dest/notes/index.d.ts.map +1 -0
  37. package/dest/notes/index.js +1 -0
  38. package/dest/notes/note_service.d.ts +48 -0
  39. package/dest/notes/note_service.d.ts.map +1 -0
  40. package/dest/notes/note_service.js +152 -0
  41. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +2 -2
  42. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
  43. package/dest/public_storage/public_storage_service.d.ts +24 -0
  44. package/dest/public_storage/public_storage_service.d.ts.map +1 -0
  45. package/dest/public_storage/public_storage_service.js +26 -0
  46. package/dest/pxe.d.ts +1 -1
  47. package/dest/pxe.d.ts.map +1 -1
  48. package/dest/pxe.js +3 -5
  49. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +33 -1
  50. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -1
  51. package/dest/storage/capsule_data_provider/capsule_data_provider.js +32 -4
  52. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +2 -1
  53. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -1
  54. package/dest/storage/contract_data_provider/contract_data_provider.js +11 -0
  55. package/dest/storage/tagging_data_provider/sender_tagging_data_provider.js +3 -3
  56. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +14 -0
  57. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  58. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  59. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts +21 -0
  60. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts.map +1 -0
  61. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.js +42 -0
  62. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  63. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  64. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  65. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +14 -0
  66. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  67. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +32 -0
  68. package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts +2 -2
  69. package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  70. package/dest/tagging/sync/sync_sender_tagging_indexes.js +3 -3
  71. package/dest/tree_membership/tree_membership_service.d.ts +52 -0
  72. package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
  73. package/dest/tree_membership/tree_membership_service.js +84 -0
  74. package/package.json +16 -16
  75. package/src/contract_function_simulator/contract_function_simulator.ts +59 -10
  76. package/src/contract_function_simulator/oracle/private_execution.ts +13 -10
  77. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +80 -20
  78. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +199 -38
  79. package/src/contract_function_simulator/proxied_contract_data_source.ts +18 -1
  80. package/src/debug/pxe_debug_utils.ts +2 -1
  81. package/src/entrypoints/client/bundle/index.ts +0 -1
  82. package/src/entrypoints/client/lazy/index.ts +0 -1
  83. package/src/entrypoints/server/index.ts +1 -1
  84. package/src/events/event_service.ts +77 -0
  85. package/src/events/private_event_filter_validator.ts +2 -1
  86. package/src/logs/log_service.ts +386 -0
  87. package/src/notes/index.ts +1 -0
  88. package/src/notes/note_service.ts +200 -0
  89. package/src/private_kernel/private_kernel_oracle_impl.ts +1 -1
  90. package/src/public_storage/public_storage_service.ts +33 -0
  91. package/src/pxe.ts +13 -11
  92. package/src/storage/capsule_data_provider/capsule_data_provider.ts +32 -0
  93. package/src/storage/contract_data_provider/contract_data_provider.ts +15 -0
  94. package/src/storage/tagging_data_provider/sender_tagging_data_provider.ts +3 -3
  95. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +129 -0
  96. package/src/tagging/recipient_sync/new_recipient_tagging_data_provider.ts +53 -0
  97. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  98. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +47 -0
  99. package/src/tagging/sync/sync_sender_tagging_indexes.ts +3 -3
  100. package/src/tree_membership/tree_membership_service.ts +112 -0
  101. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -248
  102. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  103. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  104. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -113
  105. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  106. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -648
  107. package/src/contract_function_simulator/execution_data_provider.ts +0 -322
  108. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -967
@@ -3,19 +3,41 @@ import { Aes128 } from '@aztec/foundation/crypto/aes128';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import { Point } from '@aztec/foundation/curves/grumpkin';
5
5
  import { LogLevels, applyStringFormatting, createLogger } from '@aztec/foundation/log';
6
+ import type { KeyStore } from '@aztec/key-store';
6
7
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
7
8
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
8
9
  import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
9
10
  import { siloNullifier } from '@aztec/stdlib/hash';
11
+ import type { AztecNode } from '@aztec/stdlib/interfaces/server';
10
12
  import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
13
+ import { computeAddressSecret } from '@aztec/stdlib/keys';
14
+ import { deriveEcdhSharedSecret } from '@aztec/stdlib/logs';
11
15
  import type { NoteStatus } from '@aztec/stdlib/note';
12
- import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
16
+ import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
13
17
  import type { BlockHeader, Capsule } from '@aztec/stdlib/tx';
14
18
 
15
- import type { ExecutionDataProvider } from '../execution_data_provider.js';
19
+ import { EventService } from '../../events/event_service.js';
20
+ import { LogService } from '../../logs/log_service.js';
21
+ import { NoteService } from '../../notes/note_service.js';
22
+ import { ORACLE_VERSION } from '../../oracle_version.js';
23
+ import { PublicStorageService } from '../../public_storage/public_storage_service.js';
24
+ import type { AddressDataProvider } from '../../storage/address_data_provider/address_data_provider.js';
25
+ import type { AnchorBlockDataProvider } from '../../storage/anchor_block_data_provider/anchor_block_data_provider.js';
26
+ import type { CapsuleDataProvider } from '../../storage/capsule_data_provider/capsule_data_provider.js';
27
+ import type { ContractDataProvider } from '../../storage/contract_data_provider/contract_data_provider.js';
28
+ import type { NoteDataProvider } from '../../storage/note_data_provider/note_data_provider.js';
29
+ import type { PrivateEventDataProvider } from '../../storage/private_event_data_provider/private_event_data_provider.js';
30
+ import type { RecipientTaggingDataProvider } from '../../storage/tagging_data_provider/recipient_tagging_data_provider.js';
31
+ import type { SenderTaggingDataProvider } from '../../storage/tagging_data_provider/sender_tagging_data_provider.js';
32
+ import { TreeMembershipService } from '../../tree_membership/tree_membership_service.js';
33
+ import { EventValidationRequest } from '../noir-structs/event_validation_request.js';
34
+ import { LogRetrievalRequest } from '../noir-structs/log_retrieval_request.js';
35
+ import { LogRetrievalResponse } from '../noir-structs/log_retrieval_response.js';
36
+ import { NoteValidationRequest } from '../noir-structs/note_validation_request.js';
16
37
  import { UtilityContext } from '../noir-structs/utility_context.js';
17
38
  import { pickNotes } from '../pick_notes.js';
18
39
  import type { IMiscOracle, IUtilityExecutionOracle, NoteData } from './interfaces.js';
40
+ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
19
41
 
20
42
  /**
21
43
  * The oracle for an execution of utility contract functions.
@@ -32,13 +54,24 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
32
54
  protected readonly authWitnesses: AuthWitness[],
33
55
  protected readonly capsules: Capsule[], // TODO(#12425): Rename to transientCapsules
34
56
  protected readonly anchorBlockHeader: BlockHeader,
35
- protected readonly executionDataProvider: ExecutionDataProvider,
57
+ protected readonly contractDataProvider: ContractDataProvider,
58
+ protected readonly noteDataProvider: NoteDataProvider,
59
+ protected readonly keyStore: KeyStore,
60
+ protected readonly addressDataProvider: AddressDataProvider,
61
+ protected readonly aztecNode: AztecNode,
62
+ protected readonly anchorBlockDataProvider: AnchorBlockDataProvider,
63
+ protected readonly senderTaggingDataProvider: SenderTaggingDataProvider,
64
+ protected readonly recipientTaggingDataProvider: RecipientTaggingDataProvider,
65
+ protected readonly capsuleDataProvider: CapsuleDataProvider,
66
+ protected readonly privateEventDataProvider: PrivateEventDataProvider,
36
67
  protected log = createLogger('simulator:client_view_context'),
37
68
  protected readonly scopes?: AztecAddress[],
38
69
  ) {}
39
70
 
40
71
  public utilityAssertCompatibleOracleVersion(version: number): void {
41
- this.executionDataProvider.assertCompatibleOracleVersion(version);
72
+ if (version !== ORACLE_VERSION) {
73
+ throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
74
+ }
42
75
  }
43
76
 
44
77
  public utilityGetRandomField(): Fr {
@@ -62,7 +95,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
62
95
  * @throws If the keys are not registered in the key store.
63
96
  */
64
97
  public utilityGetKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
65
- return this.executionDataProvider.getKeyValidationRequest(pkMHash, this.contractAddress);
98
+ return this.keyStore.getKeyValidationRequest(pkMHash, this.contractAddress);
66
99
  }
67
100
 
68
101
  /**
@@ -73,7 +106,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
73
106
  * @returns The index and sibling path concatenated [index, sibling_path]
74
107
  */
75
108
  public utilityGetMembershipWitness(blockNumber: BlockNumber, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
76
- return this.executionDataProvider.getMembershipWitness(blockNumber, treeId, leafValue);
109
+ const treeMembershipService = new TreeMembershipService(this.aztecNode, this.anchorBlockDataProvider);
110
+ return treeMembershipService.getMembershipWitness(blockNumber, treeId, leafValue);
77
111
  }
78
112
 
79
113
  /**
@@ -86,7 +120,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
86
120
  blockNumber: BlockNumber,
87
121
  nullifier: Fr,
88
122
  ): Promise<NullifierMembershipWitness | undefined> {
89
- return await this.executionDataProvider.getNullifierMembershipWitness(blockNumber, nullifier);
123
+ return await this.aztecNode.getNullifierMembershipWitness(blockNumber, nullifier);
90
124
  }
91
125
 
92
126
  /**
@@ -102,7 +136,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
102
136
  blockNumber: BlockNumber,
103
137
  nullifier: Fr,
104
138
  ): Promise<NullifierMembershipWitness | undefined> {
105
- return await this.executionDataProvider.getLowNullifierMembershipWitness(blockNumber, nullifier);
139
+ const treeMembershipService = new TreeMembershipService(this.aztecNode, this.anchorBlockDataProvider);
140
+ return await treeMembershipService.getLowNullifierMembershipWitness(blockNumber, nullifier);
106
141
  }
107
142
 
108
143
  /**
@@ -115,7 +150,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
115
150
  blockNumber: BlockNumber,
116
151
  leafSlot: Fr,
117
152
  ): Promise<PublicDataWitness | undefined> {
118
- return await this.executionDataProvider.getPublicDataWitness(blockNumber, leafSlot);
153
+ const treeMembershipService = new TreeMembershipService(this.aztecNode, this.anchorBlockDataProvider);
154
+ return await treeMembershipService.getPublicDataWitness(blockNumber, leafSlot);
119
155
  }
120
156
 
121
157
  /**
@@ -124,11 +160,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
124
160
  * @returns Block extracted from a block with block number `blockNumber`.
125
161
  */
126
162
  public async utilityGetBlockHeader(blockNumber: BlockNumber): Promise<BlockHeader | undefined> {
127
- const block = await this.executionDataProvider.getBlock(blockNumber);
128
- if (!block) {
129
- return undefined;
163
+ const anchorBlockNumber = (await this.anchorBlockDataProvider.getBlockHeader()).getBlockNumber();
164
+ if (blockNumber > anchorBlockNumber) {
165
+ throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
130
166
  }
131
- return block.getBlockHeader();
167
+
168
+ const block = await this.aztecNode.getBlock(blockNumber);
169
+ return block?.getBlockHeader() || undefined;
132
170
  }
133
171
 
134
172
  /**
@@ -138,7 +176,18 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
138
176
  * @throws An error if the account is not registered in the database.
139
177
  */
140
178
  public utilityGetPublicKeysAndPartialAddress(account: AztecAddress): Promise<CompleteAddress> {
141
- return this.executionDataProvider.getCompleteAddress(account);
179
+ return this.getCompleteAddress(account);
180
+ }
181
+
182
+ protected async getCompleteAddress(account: AztecAddress): Promise<CompleteAddress> {
183
+ const completeAddress = await this.addressDataProvider.getCompleteAddress(account);
184
+ if (!completeAddress) {
185
+ throw new Error(
186
+ `No public key registered for address ${account}.
187
+ Register it by calling pxe.addAccount(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`,
188
+ );
189
+ }
190
+ return completeAddress;
142
191
  }
143
192
 
144
193
  /**
@@ -147,7 +196,15 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
147
196
  * @returns A contract instance.
148
197
  */
149
198
  public utilityGetContractInstance(address: AztecAddress): Promise<ContractInstance> {
150
- return this.executionDataProvider.getContractInstance(address);
199
+ return this.getContractInstance(address);
200
+ }
201
+
202
+ protected async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
203
+ const instance = await this.contractDataProvider.getContractInstance(address);
204
+ if (!instance) {
205
+ throw new Error(`No contract instance found for address ${address.toString()}`);
206
+ }
207
+ return instance;
151
208
  }
152
209
 
153
210
  /**
@@ -199,13 +256,9 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
199
256
  offset: number,
200
257
  status: NoteStatus,
201
258
  ): Promise<NoteData[]> {
202
- const dbNotes = await this.executionDataProvider.getNotes(
203
- this.contractAddress,
204
- owner,
205
- storageSlot,
206
- status,
207
- this.scopes,
208
- );
259
+ const noteService = new NoteService(this.noteDataProvider, this.aztecNode, this.anchorBlockDataProvider);
260
+
261
+ const dbNotes = await noteService.getNotes(this.contractAddress, owner, storageSlot, status, this.scopes);
209
262
  return pickNotes<NoteData>(dbNotes, {
210
263
  selects: selectByIndexes.slice(0, numSelects).map((index, i) => ({
211
264
  selector: { index, offset: selectByOffsets[i], length: selectByLengths[i] },
@@ -228,7 +281,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
228
281
  */
229
282
  public async utilityCheckNullifierExists(innerNullifier: Fr) {
230
283
  const nullifier = await siloNullifier(this.contractAddress, innerNullifier!);
231
- const index = await this.executionDataProvider.getNullifierIndex(nullifier);
284
+ const treeMembershipService = new TreeMembershipService(this.aztecNode, this.anchorBlockDataProvider);
285
+ const index = await treeMembershipService.getNullifierIndex(nullifier);
232
286
  return index !== undefined;
233
287
  }
234
288
 
@@ -241,7 +295,15 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
241
295
  * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
242
296
  */
243
297
  public async utilityGetL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr) {
244
- return await this.executionDataProvider.getL1ToL2MembershipWitness(contractAddress, messageHash, secret);
298
+ const treeMembershipService = new TreeMembershipService(this.aztecNode, this.anchorBlockDataProvider);
299
+ const [messageIndex, siblingPath] = await treeMembershipService.getL1ToL2MembershipWitness(
300
+ contractAddress,
301
+ messageHash,
302
+ secret,
303
+ );
304
+
305
+ // Assuming messageIndex is what you intended to use for the index in MessageLoadOracleInputs
306
+ return new MessageLoadOracleInputs(messageIndex, siblingPath);
245
307
  }
246
308
 
247
309
  /**
@@ -258,9 +320,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
258
320
  numberOfElements: number,
259
321
  ) {
260
322
  const values = [];
323
+ const publicStorageService = new PublicStorageService(this.anchorBlockDataProvider, this.aztecNode);
324
+
325
+ // TODO: why do we serialize these requests? This should probably a single call
326
+ // Privacy considerations?
261
327
  for (let i = 0n; i < numberOfElements; i++) {
262
328
  const storageSlot = new Fr(startStorageSlot.value + i);
263
- const value = await this.executionDataProvider.getPublicStorageAt(blockNumber, contractAddress, storageSlot);
329
+ const value = await publicStorageService.getPublicStorageAt(blockNumber, contractAddress, storageSlot);
264
330
 
265
331
  this.log.debug(
266
332
  `Oracle storage read: slot=${storageSlot.toString()} address-${contractAddress.toString()} value=${value}`,
@@ -279,11 +345,31 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
279
345
  }
280
346
 
281
347
  public async utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) {
282
- await this.executionDataProvider.syncTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
348
+ const logService = new LogService(
349
+ this.aztecNode,
350
+ this.anchorBlockDataProvider,
351
+ this.keyStore,
352
+ this.capsuleDataProvider,
353
+ this.recipientTaggingDataProvider,
354
+ this.addressDataProvider,
355
+ );
356
+
357
+ await logService.syncTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
283
358
 
284
- await this.executionDataProvider.syncNoteNullifiers(this.contractAddress);
359
+ const noteService = new NoteService(this.noteDataProvider, this.aztecNode, this.anchorBlockDataProvider);
360
+ await noteService.syncNoteNullifiers(this.contractAddress);
285
361
  }
286
362
 
363
+ /**
364
+ * Validates all note and event validation requests enqueued via `enqueue_note_for_validation` and
365
+ * `enqueue_event_for_validation`, inserting them into the note database and event store respectively, making them
366
+ * queryable via `get_notes` and `getPrivateEvents`.
367
+ *
368
+ * This automatically clears both validation request queues, so no further work needs to be done by the caller.
369
+ * @param contractAddress - The address of the contract that the logs are tagged for.
370
+ * @param noteValidationRequestsArrayBaseSlot - The base slot of capsule array containing note validation requests.
371
+ * @param eventValidationRequestsArrayBaseSlot - The base slot of capsule array containing event validation requests.
372
+ */
287
373
  public async utilityValidateEnqueuedNotesAndEvents(
288
374
  contractAddress: AztecAddress,
289
375
  noteValidationRequestsArrayBaseSlot: Fr,
@@ -294,11 +380,49 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
294
380
  throw new Error(`Got a note validation request from ${contractAddress}, expected ${this.contractAddress}`);
295
381
  }
296
382
 
297
- await this.executionDataProvider.validateEnqueuedNotesAndEvents(
298
- contractAddress,
299
- noteValidationRequestsArrayBaseSlot,
300
- eventValidationRequestsArrayBaseSlot,
383
+ // We read all note and event validation requests and process them all concurrently. This makes the process much
384
+ // faster as we don't need to wait for the network round-trip.
385
+ const noteValidationRequests = (
386
+ await this.capsuleDataProvider.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot)
387
+ ).map(NoteValidationRequest.fromFields);
388
+
389
+ const eventValidationRequests = (
390
+ await this.capsuleDataProvider.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot)
391
+ ).map(EventValidationRequest.fromFields);
392
+
393
+ const noteService = new NoteService(this.noteDataProvider, this.aztecNode, this.anchorBlockDataProvider);
394
+ const noteDeliveries = noteValidationRequests.map(request =>
395
+ noteService.deliverNote(
396
+ request.contractAddress,
397
+ request.owner,
398
+ request.storageSlot,
399
+ request.randomness,
400
+ request.noteNonce,
401
+ request.content,
402
+ request.noteHash,
403
+ request.nullifier,
404
+ request.txHash,
405
+ request.recipient,
406
+ ),
301
407
  );
408
+
409
+ const eventService = new EventService(this.anchorBlockDataProvider, this.aztecNode, this.privateEventDataProvider);
410
+ const eventDeliveries = eventValidationRequests.map(request =>
411
+ eventService.deliverEvent(
412
+ request.contractAddress,
413
+ request.eventTypeId,
414
+ request.serializedEvent,
415
+ request.eventCommitment,
416
+ request.txHash,
417
+ request.recipient,
418
+ ),
419
+ );
420
+
421
+ await Promise.all([...noteDeliveries, ...eventDeliveries]);
422
+
423
+ // Requests are cleared once we're done.
424
+ await this.capsuleDataProvider.setCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, []);
425
+ await this.capsuleDataProvider.setCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, []);
302
426
  }
303
427
 
304
428
  public async utilityBulkRetrieveLogs(
@@ -311,10 +435,31 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
311
435
  throw new Error(`Got a note validation request from ${contractAddress}, expected ${this.contractAddress}`);
312
436
  }
313
437
 
314
- await this.executionDataProvider.bulkRetrieveLogs(
438
+ // We read all log retrieval requests and process them all concurrently. This makes the process much faster as we
439
+ // don't need to wait for the network round-trip.
440
+ const logRetrievalRequests = (
441
+ await this.capsuleDataProvider.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot)
442
+ ).map(LogRetrievalRequest.fromFields);
443
+
444
+ const logService = new LogService(
445
+ this.aztecNode,
446
+ this.anchorBlockDataProvider,
447
+ this.keyStore,
448
+ this.capsuleDataProvider,
449
+ this.recipientTaggingDataProvider,
450
+ this.addressDataProvider,
451
+ );
452
+
453
+ const maybeLogRetrievalResponses = await logService.bulkRetrieveLogs(logRetrievalRequests);
454
+
455
+ // Requests are cleared once we're done.
456
+ await this.capsuleDataProvider.setCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, []);
457
+
458
+ // The responses are stored as Option<LogRetrievalResponse> in a second CapsuleArray.
459
+ await this.capsuleDataProvider.setCapsuleArray(
315
460
  contractAddress,
316
- logRetrievalRequestsArrayBaseSlot,
317
461
  logRetrievalResponsesArrayBaseSlot,
462
+ maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption),
318
463
  );
319
464
  }
320
465
 
@@ -323,7 +468,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
323
468
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
324
469
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
325
470
  }
326
- return this.executionDataProvider.storeCapsule(this.contractAddress, slot, capsule);
471
+ return this.capsuleDataProvider.storeCapsule(this.contractAddress, slot, capsule);
327
472
  }
328
473
 
329
474
  public async utilityLoadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
@@ -334,7 +479,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
334
479
  return (
335
480
  // TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
336
481
  this.capsules.find(c => c.contractAddress.equals(contractAddress) && c.storageSlot.equals(slot))?.data ??
337
- (await this.executionDataProvider.loadCapsule(this.contractAddress, slot))
482
+ (await this.capsuleDataProvider.loadCapsule(this.contractAddress, slot))
338
483
  );
339
484
  }
340
485
 
@@ -343,7 +488,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
343
488
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
344
489
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
345
490
  }
346
- return this.executionDataProvider.deleteCapsule(this.contractAddress, slot);
491
+ return this.capsuleDataProvider.deleteCapsule(this.contractAddress, slot);
347
492
  }
348
493
 
349
494
  public utilityCopyCapsule(
@@ -356,7 +501,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
356
501
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
357
502
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
358
503
  }
359
- return this.executionDataProvider.copyCapsule(this.contractAddress, srcSlot, dstSlot, numEntries);
504
+ return this.capsuleDataProvider.copyCapsule(this.contractAddress, srcSlot, dstSlot, numEntries);
360
505
  }
361
506
 
362
507
  // TODO(#11849): consider replacing this oracle with a pure Noir implementation of aes decryption.
@@ -365,7 +510,23 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
365
510
  return aes128.decryptBufferCBC(ciphertext, iv, symKey);
366
511
  }
367
512
 
513
+ /**
514
+ * Retrieves the shared secret for a given address and ephemeral public key.
515
+ * @param address - The address to get the secret for.
516
+ * @param ephPk - The ephemeral public key to get the secret for.
517
+ * @returns The secret for the given address.
518
+ */
368
519
  public utilityGetSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
369
- return this.executionDataProvider.getSharedSecret(address, ephPk);
520
+ return this.getSharedSecret(address, ephPk);
521
+ }
522
+
523
+ protected async getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
524
+ // TODO(#12656): return an app-siloed secret
525
+ const recipientCompleteAddress = await this.getCompleteAddress(address);
526
+ const ivskM = await this.keyStore.getMasterSecretKey(
527
+ recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey,
528
+ );
529
+ const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
530
+ return deriveEcdhSharedSecret(addressSecret, ephPk);
370
531
  }
371
532
  }
@@ -2,7 +2,7 @@ import { FunctionSelector } from '@aztec/stdlib/abi';
2
2
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import type { ContractOverrides } from '@aztec/stdlib/tx';
4
4
 
5
- import type { ContractDataProvider } from '../storage/index.js';
5
+ import type { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
6
6
 
7
7
  /*
8
8
  * Proxy generator for a ContractDataProvider that allows overriding contract instances and artifacts, so
@@ -52,6 +52,23 @@ export class ProxiedContractDataProviderFactory {
52
52
  }
53
53
  };
54
54
  }
55
+ case 'getFunctionArtifactWithDebugMetadata': {
56
+ return async (contractAddress: AztecAddress, selector: FunctionSelector) => {
57
+ if (overrides[contractAddress.toString()]) {
58
+ const { artifact } = overrides[contractAddress.toString()]!;
59
+ const functions = artifact.functions;
60
+ for (let i = 0; i < functions.length; i++) {
61
+ const fn = functions[i];
62
+ const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
63
+ if (fnSelector.equals(selector)) {
64
+ return fn;
65
+ }
66
+ }
67
+ } else {
68
+ return target.getFunctionArtifactWithDebugMetadata(contractAddress, selector);
69
+ }
70
+ };
71
+ }
55
72
  default: {
56
73
  const value = Reflect.get(target, prop);
57
74
  if (typeof value === 'function') {
@@ -1,7 +1,8 @@
1
1
  import type { NoteDao, NotesFilter } from '@aztec/stdlib/note';
2
2
 
3
3
  import type { PXE } from '../pxe.js';
4
- import type { ContractDataProvider, NoteDataProvider } from '../storage/index.js';
4
+ import type { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
5
+ import type { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js';
5
6
 
6
7
  /**
7
8
  * Methods provided by this class might help debugging but must not be used in production.
@@ -3,5 +3,4 @@ export * from '../../../config/index.js';
3
3
  export * from '../../../error_enriching.js';
4
4
  export * from '../../../storage/index.js';
5
5
  export * from './utils.js';
6
- export { PXEOracleInterface } from '../../../contract_function_simulator/pxe_oracle_interface.js';
7
6
  export type { PXECreationOptions } from '../../pxe_creation_options.js';
@@ -3,5 +3,4 @@ export * from '../../../config/index.js';
3
3
  export * from '../../../storage/index.js';
4
4
  export * from '../../../error_enriching.js';
5
5
  export * from './utils.js';
6
- export { PXEOracleInterface } from '../../../contract_function_simulator/pxe_oracle_interface.js';
7
6
  export { type PXECreationOptions } from '../../pxe_creation_options.js';
@@ -3,6 +3,6 @@ export * from '../../config/index.js';
3
3
  export * from '../../error_enriching.js';
4
4
  export * from '../../storage/index.js';
5
5
  export * from './utils.js';
6
- export { PXEOracleInterface } from '../../contract_function_simulator/pxe_oracle_interface.js';
6
+ export { NoteService } from '../../notes/note_service.js';
7
7
  export { ORACLE_VERSION } from '../../oracle_version.js';
8
8
  export { type PXECreationOptions } from '../pxe_creation_options.js';
@@ -0,0 +1,77 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { EventSelector } from '@aztec/stdlib/abi';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { siloNullifier } from '@aztec/stdlib/hash';
5
+ import type { AztecNode } from '@aztec/stdlib/interfaces/server';
6
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
7
+ import type { TxHash } from '@aztec/stdlib/tx';
8
+
9
+ import { AnchorBlockDataProvider } from '../storage/anchor_block_data_provider/anchor_block_data_provider.js';
10
+ import { PrivateEventDataProvider } from '../storage/private_event_data_provider/private_event_data_provider.js';
11
+
12
+ export class EventService {
13
+ constructor(
14
+ private readonly anchorBlockDataProvider: AnchorBlockDataProvider,
15
+ private readonly aztecNode: AztecNode,
16
+ private readonly privateEventDataProvider: PrivateEventDataProvider,
17
+ ) {}
18
+
19
+ public async deliverEvent(
20
+ contractAddress: AztecAddress,
21
+ selector: EventSelector,
22
+ content: Fr[],
23
+ eventCommitment: Fr,
24
+ txHash: TxHash,
25
+ scope: AztecAddress,
26
+ ): Promise<void> {
27
+ // While using 'latest' block number would be fine for private events since they cannot be accessed from Aztec.nr
28
+ // (and thus we're less concerned about being ahead of the synced block), we use the synced block number to
29
+ // maintain consistent behavior in the PXE. Additionally, events should never be ahead of the synced block here
30
+ // since `fetchTaggedLogs` only processes logs up to the synced block.
31
+ const [syncedBlockHeader, siloedEventCommitment, txEffect] = await Promise.all([
32
+ this.anchorBlockDataProvider.getBlockHeader(),
33
+ siloNullifier(contractAddress, eventCommitment),
34
+ this.aztecNode.getTxEffect(txHash),
35
+ ]);
36
+
37
+ const syncedBlockNumber = syncedBlockHeader.getBlockNumber();
38
+
39
+ if (!txEffect) {
40
+ throw new Error(`Could not find tx effect for tx hash ${txHash}`);
41
+ }
42
+
43
+ if (txEffect.l2BlockNumber > syncedBlockNumber) {
44
+ throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${syncedBlockNumber}`);
45
+ }
46
+
47
+ const eventInTx = txEffect.data.nullifiers.some(n => n.equals(siloedEventCommitment));
48
+ if (!eventInTx) {
49
+ throw new Error(
50
+ `Event commitment ${eventCommitment} (siloed as ${siloedEventCommitment}) is not present in tx ${txHash}`,
51
+ );
52
+ }
53
+
54
+ const [nullifierIndex] = await this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [
55
+ siloedEventCommitment,
56
+ ]);
57
+
58
+ if (nullifierIndex === undefined) {
59
+ throw new Error(
60
+ `Event commitment ${eventCommitment} (siloed as ${siloedEventCommitment}) is not present on the nullifier tree at block ${syncedBlockNumber} (from tx ${txHash})`,
61
+ );
62
+ }
63
+
64
+ return this.privateEventDataProvider.storePrivateEventLog(
65
+ selector,
66
+ content,
67
+ Number(nullifierIndex.data), // Index of the event commitment in the nullifier tree
68
+ {
69
+ contractAddress,
70
+ scope,
71
+ txHash,
72
+ l2BlockNumber: nullifierIndex.l2BlockNumber, // Block number in which the event was emitted
73
+ l2BlockHash: nullifierIndex.l2BlockHash, // Block hash in which the event was emitted
74
+ },
75
+ );
76
+ }
77
+ }
@@ -2,7 +2,8 @@ import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
2
  import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
3
3
  import { BlockNumber } from '@aztec/foundation/branded-types';
4
4
 
5
- import type { AnchorBlockDataProvider, PrivateEventDataProviderFilter } from '../storage/index.js';
5
+ import { AnchorBlockDataProvider } from '../storage/anchor_block_data_provider/anchor_block_data_provider.js';
6
+ import type { PrivateEventDataProviderFilter } from '../storage/private_event_data_provider/private_event_data_provider.js';
6
7
 
7
8
  export class PrivateEventFilterValidator {
8
9
  constructor(private anchorBlockDataProvider: AnchorBlockDataProvider) {}