@aztec/pxe 0.0.1-commit.dbf9cec → 0.0.1-commit.ddcf04837

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 (197) hide show
  1. package/dest/bin/check_oracle_version.js +4 -4
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +1 -1
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +6 -0
  5. package/dest/config/index.d.ts +2 -2
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +8 -15
  8. package/dest/contract_function_simulator/contract_function_simulator.d.ts +13 -5
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.js +36 -9
  11. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  12. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  13. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  14. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
  15. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/execution_tagging_index_cache.js +17 -9
  17. package/dest/contract_function_simulator/index.d.ts +2 -1
  18. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/index.js +1 -0
  20. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -6
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +8 -10
  23. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  24. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
  25. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
  26. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
  28. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +4 -7
  29. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +6 -11
  31. package/dest/contract_function_simulator/oracle/interfaces.d.ts +61 -45
  32. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  34. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  35. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
  36. package/dest/contract_function_simulator/oracle/oracle.d.ts +75 -44
  37. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/oracle.js +281 -96
  39. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +23 -49
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +42 -64
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +92 -57
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +274 -107
  46. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  47. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  48. package/dest/contract_function_simulator/pick_notes.js +9 -2
  49. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  50. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  51. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  52. package/dest/contract_logging.d.ts +9 -4
  53. package/dest/contract_logging.d.ts.map +1 -1
  54. package/dest/contract_logging.js +21 -6
  55. package/dest/contract_sync/contract_sync_service.d.ts +6 -5
  56. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  57. package/dest/contract_sync/contract_sync_service.js +62 -43
  58. package/dest/contract_sync/helpers.d.ts +2 -3
  59. package/dest/contract_sync/helpers.d.ts.map +1 -1
  60. package/dest/contract_sync/helpers.js +7 -2
  61. package/dest/debug/pxe_debug_utils.d.ts +3 -3
  62. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  63. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  64. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  65. package/dest/entrypoints/client/bundle/index.js +0 -1
  66. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  67. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  68. package/dest/entrypoints/client/bundle/utils.js +2 -2
  69. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  70. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  71. package/dest/entrypoints/client/lazy/index.js +0 -1
  72. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  73. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  74. package/dest/entrypoints/client/lazy/utils.js +2 -2
  75. package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
  76. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  77. package/dest/entrypoints/pxe_creation_options.js +3 -1
  78. package/dest/entrypoints/server/index.d.ts +2 -3
  79. package/dest/entrypoints/server/index.d.ts.map +1 -1
  80. package/dest/entrypoints/server/index.js +1 -2
  81. package/dest/entrypoints/server/utils.d.ts +2 -2
  82. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  83. package/dest/entrypoints/server/utils.js +2 -2
  84. package/dest/events/event_service.d.ts +3 -2
  85. package/dest/events/event_service.d.ts.map +1 -1
  86. package/dest/events/event_service.js +16 -4
  87. package/dest/events/private_event_filter_validator.d.ts +3 -2
  88. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  89. package/dest/events/private_event_filter_validator.js +15 -0
  90. package/dest/logs/log_service.d.ts +7 -8
  91. package/dest/logs/log_service.d.ts.map +1 -1
  92. package/dest/logs/log_service.js +27 -37
  93. package/dest/messages/message_context_service.d.ts +17 -0
  94. package/dest/messages/message_context_service.d.ts.map +1 -0
  95. package/dest/messages/message_context_service.js +36 -0
  96. package/dest/notes/note_service.d.ts +4 -5
  97. package/dest/notes/note_service.d.ts.map +1 -1
  98. package/dest/notes/note_service.js +14 -5
  99. package/dest/notes_filter.d.ts +2 -3
  100. package/dest/notes_filter.d.ts.map +1 -1
  101. package/dest/oracle_version.d.ts +4 -3
  102. package/dest/oracle_version.d.ts.map +1 -1
  103. package/dest/oracle_version.js +20 -10
  104. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  105. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  106. package/dest/private_kernel/private_kernel_execution_prover.js +4 -7
  107. package/dest/pxe.d.ts +12 -8
  108. package/dest/pxe.d.ts.map +1 -1
  109. package/dest/pxe.js +51 -26
  110. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  111. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  112. package/dest/storage/capsule_store/capsule_service.js +50 -0
  113. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  114. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  115. package/dest/storage/capsule_store/capsule_store.js +33 -28
  116. package/dest/storage/capsule_store/index.d.ts +2 -1
  117. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  118. package/dest/storage/capsule_store/index.js +1 -0
  119. package/dest/storage/metadata.d.ts +1 -1
  120. package/dest/storage/metadata.js +1 -1
  121. package/dest/storage/note_store/note_store.d.ts +1 -1
  122. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  123. package/dest/storage/note_store/note_store.js +2 -2
  124. package/dest/storage/private_event_store/stored_private_event.js +1 -1
  125. package/dest/storage/tagging_store/sender_tagging_store.d.ts +26 -25
  126. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  127. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  128. package/dest/tagging/index.d.ts +2 -2
  129. package/dest/tagging/index.d.ts.map +1 -1
  130. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -2
  131. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  132. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +1 -15
  133. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +1 -1
  134. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  135. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +10 -1
  136. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  137. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  138. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  139. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +2 -1
  140. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  141. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +24 -11
  142. package/package.json +16 -16
  143. package/src/bin/check_oracle_version.ts +4 -4
  144. package/src/block_synchronizer/block_synchronizer.ts +6 -0
  145. package/src/config/index.ts +3 -9
  146. package/src/contract_function_simulator/contract_function_simulator.ts +50 -13
  147. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  148. package/src/contract_function_simulator/execution_tagging_index_cache.ts +16 -11
  149. package/src/contract_function_simulator/index.ts +1 -0
  150. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +9 -9
  151. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  152. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
  153. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -10
  154. package/src/contract_function_simulator/oracle/interfaces.ts +82 -54
  155. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
  156. package/src/contract_function_simulator/oracle/oracle.ts +363 -139
  157. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  158. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +46 -84
  159. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +449 -144
  160. package/src/contract_function_simulator/pick_notes.ts +9 -2
  161. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  162. package/src/contract_logging.ts +18 -5
  163. package/src/contract_sync/contract_sync_service.ts +99 -75
  164. package/src/contract_sync/helpers.ts +4 -4
  165. package/src/debug/pxe_debug_utils.ts +3 -3
  166. package/src/entrypoints/client/bundle/index.ts +0 -1
  167. package/src/entrypoints/client/bundle/utils.ts +2 -3
  168. package/src/entrypoints/client/lazy/index.ts +0 -1
  169. package/src/entrypoints/client/lazy/utils.ts +2 -3
  170. package/src/entrypoints/pxe_creation_options.ts +7 -0
  171. package/src/entrypoints/server/index.ts +1 -2
  172. package/src/entrypoints/server/utils.ts +2 -3
  173. package/src/events/event_service.ts +17 -4
  174. package/src/events/private_event_filter_validator.ts +21 -1
  175. package/src/logs/log_service.ts +57 -78
  176. package/src/messages/message_context_service.ts +44 -0
  177. package/src/notes/note_service.ts +18 -8
  178. package/src/notes_filter.ts +1 -3
  179. package/src/oracle_version.ts +20 -10
  180. package/src/private_kernel/private_kernel_execution_prover.ts +4 -9
  181. package/src/pxe.ts +78 -31
  182. package/src/storage/capsule_store/capsule_service.ts +90 -0
  183. package/src/storage/capsule_store/capsule_store.ts +34 -26
  184. package/src/storage/capsule_store/index.ts +1 -0
  185. package/src/storage/metadata.ts +1 -1
  186. package/src/storage/note_store/note_store.ts +2 -5
  187. package/src/storage/private_event_store/stored_private_event.ts +1 -1
  188. package/src/storage/tagging_store/sender_tagging_store.ts +182 -135
  189. package/src/tagging/index.ts +1 -1
  190. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +2 -14
  191. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +19 -1
  192. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  193. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +19 -9
  194. package/dest/access_scopes.d.ts +0 -9
  195. package/dest/access_scopes.d.ts.map +0 -1
  196. package/dest/access_scopes.js +0 -6
  197. package/src/access_scopes.ts +0 -9
package/src/pxe.ts CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  } from '@aztec/stdlib/abi';
19
19
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
20
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
21
+ import type { L2TipsProvider } from '@aztec/stdlib/block';
21
22
  import {
22
23
  CompleteAddress,
23
24
  type ContractInstanceWithAddress,
@@ -52,7 +53,6 @@ import {
52
53
 
53
54
  import { inspect } from 'util';
54
55
 
55
- import type { AccessScopes } from './access_scopes.js';
56
56
  import { BlockSynchronizer } from './block_synchronizer/index.js';
57
57
  import type { PXEConfig } from './config/index.js';
58
58
  import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
@@ -68,6 +68,7 @@ import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
68
68
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
69
69
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
70
70
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
71
+ import { MessageContextService } from './messages/message_context_service.js';
71
72
  import {
72
73
  PrivateKernelExecutionProver,
73
74
  type PrivateKernelExecutionProverConfig,
@@ -95,7 +96,7 @@ export type ProfileTxOpts = {
95
96
  /** If true, proof generation is skipped during profiling. Defaults to true. */
96
97
  skipProofGeneration?: boolean;
97
98
  /** Addresses whose private state and keys are accessible during private execution. */
98
- scopes: AccessScopes;
99
+ scopes: AztecAddress[];
99
100
  };
100
101
 
101
102
  /** Options for PXE.simulateTx. */
@@ -106,10 +107,12 @@ export type SimulateTxOpts = {
106
107
  skipTxValidation?: boolean;
107
108
  /** If false, fees are enforced. */
108
109
  skipFeeEnforcement?: boolean;
109
- /** State overrides for the simulation, such as contract instances and artifacts. */
110
+ /** If true, kernel logic is emulated in TS for simulation */
111
+ skipKernels?: boolean;
112
+ /** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
110
113
  overrides?: SimulationOverrides;
111
114
  /** Addresses whose private state and keys are accessible during private execution */
112
- scopes: AccessScopes;
115
+ scopes: AztecAddress[];
113
116
  };
114
117
 
115
118
  /** Options for PXE.executeUtility. */
@@ -117,7 +120,7 @@ export type ExecuteUtilityOpts = {
117
120
  /** The authentication witnesses required for the function call. */
118
121
  authwits?: AuthWitness[];
119
122
  /** The accounts whose notes we can access in this call */
120
- scopes: AccessScopes;
123
+ scopes: AztecAddress[];
121
124
  };
122
125
 
123
126
  /** Args for PXE.create. */
@@ -145,6 +148,7 @@ export type PXECreateArgs = {
145
148
  export class PXE {
146
149
  private constructor(
147
150
  private node: AztecNode,
151
+ private db: AztecAsyncKVStore,
148
152
  private blockStateSynchronizer: BlockSynchronizer,
149
153
  private keyStore: KeyStore,
150
154
  private contractStore: ContractStore,
@@ -157,6 +161,8 @@ export class PXE {
157
161
  private addressStore: AddressStore,
158
162
  private privateEventStore: PrivateEventStore,
159
163
  private contractSyncService: ContractSyncService,
164
+ private messageContextService: MessageContextService,
165
+ private l2TipsStore: L2TipsProvider,
160
166
  private simulator: CircuitSimulator,
161
167
  private proverEnabled: boolean,
162
168
  private proofCreator: PrivateKernelProver,
@@ -212,6 +218,8 @@ export class PXE {
212
218
  noteStore,
213
219
  createLogger('pxe:contract_sync', bindings),
214
220
  );
221
+ const messageContextService = new MessageContextService(node);
222
+
215
223
  const synchronizer = new BlockSynchronizer(
216
224
  node,
217
225
  store,
@@ -240,6 +248,7 @@ export class PXE {
240
248
 
241
249
  const pxe = new PXE(
242
250
  node,
251
+ store,
243
252
  synchronizer,
244
253
  keyStore,
245
254
  contractStore,
@@ -252,6 +261,8 @@ export class PXE {
252
261
  addressStore,
253
262
  privateEventStore,
254
263
  contractSyncService,
264
+ messageContextService,
265
+ tipsStore,
255
266
  simulator,
256
267
  proverEnabled,
257
268
  proofCreator,
@@ -286,6 +297,7 @@ export class PXE {
286
297
  keyStore: this.keyStore,
287
298
  addressStore: this.addressStore,
288
299
  aztecNode: BenchmarkedNodeFactory.create(this.node),
300
+ l2TipsStore: this.l2TipsStore,
289
301
  senderTaggingStore: this.senderTaggingStore,
290
302
  recipientTaggingStore: this.recipientTaggingStore,
291
303
  senderAddressBookStore: this.senderAddressBookStore,
@@ -293,6 +305,7 @@ export class PXE {
293
305
  privateEventStore: this.privateEventStore,
294
306
  simulator: this.simulator,
295
307
  contractSyncService: this.contractSyncService,
308
+ messageContextService: this.messageContextService,
296
309
  });
297
310
  }
298
311
 
@@ -358,7 +371,7 @@ export class PXE {
358
371
  async #executePrivate(
359
372
  contractFunctionSimulator: ContractFunctionSimulator,
360
373
  txRequest: TxExecutionRequest,
361
- scopes: AccessScopes,
374
+ scopes: AztecAddress[],
362
375
  jobId: string,
363
376
  ): Promise<PrivateExecutionResult> {
364
377
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -407,12 +420,19 @@ export class PXE {
407
420
  contractFunctionSimulator: ContractFunctionSimulator,
408
421
  call: FunctionCall,
409
422
  authWitnesses: AuthWitness[] | undefined,
410
- scopes: AccessScopes,
423
+ scopes: AztecAddress[],
411
424
  jobId: string,
412
425
  ) {
413
426
  try {
414
427
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
415
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
428
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
429
+ call,
430
+ authWitnesses ?? [],
431
+ anchorBlockHeader,
432
+ scopes,
433
+ jobId,
434
+ );
435
+ return { result, offchainEffects };
416
436
  } catch (err) {
417
437
  if (err instanceof SimulationError) {
418
438
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -485,7 +505,9 @@ export class PXE {
485
505
  * @returns The synced block header
486
506
  */
487
507
  public getSyncedBlockHeader(): Promise<BlockHeader> {
488
- return this.anchorBlockStore.getBlockHeader();
508
+ return this.#putInJobQueue(() => {
509
+ return this.anchorBlockStore.getBlockHeader();
510
+ });
489
511
  }
490
512
 
491
513
  /**
@@ -542,6 +564,12 @@ export class PXE {
542
564
  * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
543
565
  */
544
566
  public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
567
+ if (!(await sender.isValid())) {
568
+ throw new Error(
569
+ `Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
570
+ );
571
+ }
572
+
545
573
  const accounts = await this.keyStore.getAccounts();
546
574
  if (accounts.includes(sender)) {
547
575
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
@@ -552,6 +580,9 @@ export class PXE {
552
580
 
553
581
  if (wasAdded) {
554
582
  this.log.info(`Added sender:\n ${sender.toString()}`);
583
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
584
+ // all contracts must re-sync to discover them.
585
+ this.contractSyncService.wipe();
555
586
  } else {
556
587
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
557
588
  }
@@ -764,17 +795,17 @@ export class PXE {
764
795
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
765
796
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
766
797
  // storing the tags here prevents linkage of txs sent from the same PXE.
767
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
768
- if (preTagsUsedInTheTx.length > 0) {
798
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
799
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
769
800
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
770
801
  const txHash = (await txProvingResult.toTx()).txHash;
771
802
 
772
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
773
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
774
- preTagsUsedInTheTx,
803
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
804
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
805
+ taggingIndexRangesUsedInTheTx,
775
806
  });
776
807
  } else {
777
- this.log.debug(`No pre-tags used in the tx`);
808
+ this.log.debug(`No tagging index ranges used in the tx`);
778
809
  }
779
810
 
780
811
  return txProvingResult;
@@ -881,7 +912,14 @@ export class PXE {
881
912
  */
882
913
  public simulateTx(
883
914
  txRequest: TxExecutionRequest,
884
- { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
915
+ {
916
+ simulatePublic,
917
+ skipTxValidation = false,
918
+ skipFeeEnforcement = false,
919
+ skipKernels = true,
920
+ overrides,
921
+ scopes,
922
+ }: SimulateTxOpts,
885
923
  ): Promise<TxSimulationResult> {
886
924
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
887
925
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -905,17 +943,20 @@ export class PXE {
905
943
  await this.blockStateSynchronizer.sync();
906
944
  const syncTime = syncTimer.ms();
907
945
 
908
- const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
909
- // Temporary: in case there are overrides, we have to skip the kernels or validations
910
- // will fail. Consider handing control to the user/wallet on whether they want to run them
911
- // or not.
912
946
  const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
913
947
  const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
914
- const skipKernels = hasOverriddenContracts;
915
948
 
916
- // Set overridden contracts on the sync service so it knows to skip syncing them
949
+ if (hasOverriddenContracts && !skipKernels) {
950
+ throw new Error(
951
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
952
+ );
953
+ }
954
+ const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
955
+
917
956
  if (hasOverriddenContracts) {
918
- this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
957
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
958
+ // We exclude them so the sync service skips them entirely.
959
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
919
960
  }
920
961
 
921
962
  // Execution of private functions only; no proving, and no kernel logic.
@@ -1010,7 +1051,7 @@ export class PXE {
1010
1051
  inspect(txRequest),
1011
1052
  `simulatePublic=${simulatePublic}`,
1012
1053
  `skipTxValidation=${skipTxValidation}`,
1013
- `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1054
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1014
1055
  );
1015
1056
  }
1016
1057
  });
@@ -1022,7 +1063,7 @@ export class PXE {
1022
1063
  */
1023
1064
  public executeUtility(
1024
1065
  call: FunctionCall,
1025
- { authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
1066
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1026
1067
  ): Promise<UtilityExecutionResult> {
1027
1068
  // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
1028
1069
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -1047,7 +1088,7 @@ export class PXE {
1047
1088
  scopes,
1048
1089
  );
1049
1090
 
1050
- const executionResult = await this.#executeUtility(
1091
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1051
1092
  contractFunctionSimulator,
1052
1093
  call,
1053
1094
  authwits ?? [],
@@ -1068,14 +1109,19 @@ export class PXE {
1068
1109
  };
1069
1110
 
1070
1111
  const simulationStats = contractFunctionSimulator.getStats();
1071
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1112
+ return {
1113
+ result: executionResult,
1114
+ offchainEffects,
1115
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1116
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1117
+ };
1072
1118
  } catch (err: any) {
1073
1119
  const { to, name, args } = call;
1074
1120
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1075
1121
  throw this.#contextualizeError(
1076
1122
  err,
1077
1123
  `executeUtility ${to}:${name}(${stringifiedArgs})`,
1078
- `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1124
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1079
1125
  );
1080
1126
  }
1081
1127
  });
@@ -1130,9 +1176,10 @@ export class PXE {
1130
1176
  }
1131
1177
 
1132
1178
  /**
1133
- * Stops the PXE's job queue.
1179
+ * Stops the PXE's job queue and closes the backing store.
1134
1180
  */
1135
- public stop(): Promise<void> {
1136
- return this.jobQueue.end();
1181
+ public async stop(): Promise<void> {
1182
+ await this.jobQueue.end();
1183
+ await this.db.close();
1137
1184
  }
1138
1185
  }
@@ -0,0 +1,90 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { Capsule } from '@aztec/stdlib/tx';
4
+
5
+ import type { CapsuleStore } from './capsule_store.js';
6
+
7
+ /**
8
+ * Wraps a CapsuleStore with scope-based access control. Each operation asserts that the requested scope is in the
9
+ * allowed scopes list before delegating to the underlying store.
10
+ */
11
+ export class CapsuleService {
12
+ constructor(
13
+ private readonly capsuleStore: CapsuleStore,
14
+ private readonly allowedScopes: AztecAddress[],
15
+ ) {}
16
+
17
+ setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string, scope: AztecAddress) {
18
+ assertAllowedScope(scope, this.allowedScopes);
19
+ this.capsuleStore.setCapsule(contractAddress, slot, capsule, jobId, scope);
20
+ }
21
+
22
+ async getCapsule(
23
+ contractAddress: AztecAddress,
24
+ slot: Fr,
25
+ jobId: string,
26
+ scope: AztecAddress,
27
+ transientCapsules?: Capsule[],
28
+ ): Promise<Fr[] | null> {
29
+ assertAllowedScope(scope, this.allowedScopes);
30
+
31
+ // TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
32
+ const maybeTransientCapsule = transientCapsules?.find(
33
+ c =>
34
+ c.contractAddress.equals(contractAddress) &&
35
+ c.storageSlot.equals(slot) &&
36
+ (c.scope ?? AztecAddress.ZERO).equals(scope),
37
+ )?.data;
38
+
39
+ return maybeTransientCapsule ?? (await this.capsuleStore.getCapsule(contractAddress, slot, jobId, scope));
40
+ }
41
+
42
+ deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress) {
43
+ assertAllowedScope(scope, this.allowedScopes);
44
+ this.capsuleStore.deleteCapsule(contractAddress, slot, jobId, scope);
45
+ }
46
+
47
+ copyCapsule(
48
+ contractAddress: AztecAddress,
49
+ srcSlot: Fr,
50
+ dstSlot: Fr,
51
+ numEntries: number,
52
+ jobId: string,
53
+ scope: AztecAddress,
54
+ ): Promise<void> {
55
+ assertAllowedScope(scope, this.allowedScopes);
56
+ return this.capsuleStore.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId, scope);
57
+ }
58
+
59
+ appendToCapsuleArray(
60
+ contractAddress: AztecAddress,
61
+ baseSlot: Fr,
62
+ content: Fr[][],
63
+ jobId: string,
64
+ scope: AztecAddress,
65
+ ): Promise<void> {
66
+ assertAllowedScope(scope, this.allowedScopes);
67
+ return this.capsuleStore.appendToCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
68
+ }
69
+
70
+ readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[][]> {
71
+ assertAllowedScope(scope, this.allowedScopes);
72
+ return this.capsuleStore.readCapsuleArray(contractAddress, baseSlot, jobId, scope);
73
+ }
74
+
75
+ setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress) {
76
+ assertAllowedScope(scope, this.allowedScopes);
77
+ return this.capsuleStore.setCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
78
+ }
79
+ }
80
+
81
+ function assertAllowedScope(scope: AztecAddress, allowedScopes: AztecAddress[]) {
82
+ if (scope.equals(AztecAddress.ZERO)) {
83
+ return;
84
+ }
85
+ if (!allowedScopes.some((allowed: AztecAddress) => allowed.equals(scope))) {
86
+ throw new Error(
87
+ `Scope ${scope.toString()} is not in the allowed scopes list: [${allowedScopes.map((s: AztecAddress) => s.toString()).join(', ')}]. See https://docs.aztec.network/errors/10`,
88
+ );
89
+ }
90
+ }
@@ -1,7 +1,7 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
3
  import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
4
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
 
6
6
  import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
7
7
 
@@ -10,11 +10,12 @@ export class CapsuleStore implements StagedStore {
10
10
 
11
11
  #store: AztecAsyncKVStore;
12
12
 
13
- // Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${key}`
13
+ // Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${scope}:${key}`, using the zero
14
+ // address for the global scope.
14
15
  #capsules: AztecAsyncMap<string, Buffer>;
15
16
 
16
- // jobId => `${contractAddress}:${key}` => capsule data
17
- // when `#stagedCapsules.get('some-job-id').get('${some-contract-address:some-key') === null`,
17
+ // jobId => `${contractAddress}:${scope}:${key}` => capsule data
18
+ // when `#stagedCapsules.get('some-job-id').get('${some-contract-address}:${some-scope}:${some-key}') === null`,
18
19
  // it signals that the capsule was deleted during the job, so it needs to be deleted on commit
19
20
  #stagedCapsules: Map<string, Map<string, Buffer | null>>;
20
21
 
@@ -134,8 +135,8 @@ export class CapsuleStore implements StagedStore {
134
135
  * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
135
136
  * network state it's backed by local PXE db.
136
137
  */
137
- storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string) {
138
- const dbSlotKey = dbSlotToKey(contractAddress, slot);
138
+ setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string, scope: AztecAddress) {
139
+ const dbSlotKey = dbSlotToKey(contractAddress, slot, scope);
139
140
 
140
141
  // A store overrides any pre-existing data on the slot
141
142
  this.#setOnStage(jobId, dbSlotKey, Buffer.concat(capsule.map(value => value.toBuffer())));
@@ -147,8 +148,8 @@ export class CapsuleStore implements StagedStore {
147
148
  * @param slot - The slot in the database to read.
148
149
  * @returns The stored data or `null` if no data is stored under the slot.
149
150
  */
150
- async loadCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string): Promise<Fr[] | null> {
151
- const dataBuffer = await this.#getFromStage(jobId, dbSlotToKey(contractAddress, slot));
151
+ async getCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[] | null> {
152
+ const dataBuffer = await this.#getFromStage(jobId, dbSlotToKey(contractAddress, slot, scope));
152
153
  if (!dataBuffer) {
153
154
  this.logger.trace(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
154
155
  return null;
@@ -165,9 +166,9 @@ export class CapsuleStore implements StagedStore {
165
166
  * @param contractAddress - The contract address under which the data is scoped.
166
167
  * @param slot - The slot in the database to delete.
167
168
  */
168
- deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string) {
169
+ deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress) {
169
170
  // When we commit this, we will interpret null as a deletion, so we'll propagate the delete to the KV store
170
- this.#deleteOnStage(jobId, dbSlotToKey(contractAddress, slot));
171
+ this.#deleteOnStage(jobId, dbSlotToKey(contractAddress, slot, scope));
171
172
  }
172
173
 
173
174
  /**
@@ -187,6 +188,7 @@ export class CapsuleStore implements StagedStore {
187
188
  dstSlot: Fr,
188
189
  numEntries: number,
189
190
  jobId: string,
191
+ scope: AztecAddress,
190
192
  ): Promise<void> {
191
193
  // This transactional context gives us "copy atomicity":
192
194
  // there shouldn't be concurrent writes to what's being copied here.
@@ -203,8 +205,8 @@ export class CapsuleStore implements StagedStore {
203
205
  }
204
206
 
205
207
  for (const i of indexes) {
206
- const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)));
207
- const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)));
208
+ const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)), scope);
209
+ const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)), scope);
208
210
 
209
211
  const toCopy = await this.#getFromStage(jobId, currentSrcSlot);
210
212
  if (!toCopy) {
@@ -224,7 +226,13 @@ export class CapsuleStore implements StagedStore {
224
226
  * @param baseSlot - The slot where the array length is stored
225
227
  * @param content - Array of capsule data to append
226
228
  */
227
- appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string): Promise<void> {
229
+ appendToCapsuleArray(
230
+ contractAddress: AztecAddress,
231
+ baseSlot: Fr,
232
+ content: Fr[][],
233
+ jobId: string,
234
+ scope: AztecAddress,
235
+ ): Promise<void> {
228
236
  // We wrap this in a transaction to serialize concurrent calls from Promise.all.
229
237
  // Without this, concurrent appends to the same array could race: both read length=0,
230
238
  // both write at the same slots, one overwrites the other.
@@ -232,22 +240,22 @@ export class CapsuleStore implements StagedStore {
232
240
  // and not using a transaction here would heavily impact performance.
233
241
  return this.#store.transactionAsync(async () => {
234
242
  // Load current length, defaulting to 0 if not found
235
- const lengthData = await this.loadCapsule(contractAddress, baseSlot, jobId);
243
+ const lengthData = await this.getCapsule(contractAddress, baseSlot, jobId, scope);
236
244
  const currentLength = lengthData ? lengthData[0].toNumber() : 0;
237
245
 
238
246
  // Store each capsule at consecutive slots after baseSlot + 1 + currentLength
239
247
  for (let i = 0; i < content.length; i++) {
240
248
  const nextSlot = arraySlot(baseSlot, currentLength + i);
241
- this.storeCapsule(contractAddress, nextSlot, content[i], jobId);
249
+ this.setCapsule(contractAddress, nextSlot, content[i], jobId, scope);
242
250
  }
243
251
 
244
252
  // Update length to include all new capsules
245
253
  const newLength = currentLength + content.length;
246
- this.storeCapsule(contractAddress, baseSlot, [new Fr(newLength)], jobId);
254
+ this.setCapsule(contractAddress, baseSlot, [new Fr(newLength)], jobId, scope);
247
255
  });
248
256
  }
249
257
 
250
- readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string): Promise<Fr[][]> {
258
+ readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[][]> {
251
259
  // I'm leaving this transactional context here though because I'm assuming this
252
260
  // gives us "read array atomicity": there shouldn't be concurrent writes to what's being copied
253
261
  // here.
@@ -255,14 +263,14 @@ export class CapsuleStore implements StagedStore {
255
263
  // of jobs: different calls running concurrently on the same contract may cause trouble.
256
264
  return this.#store.transactionAsync(async () => {
257
265
  // Load length, defaulting to 0 if not found
258
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot, jobId);
266
+ const maybeLength = await this.getCapsule(contractAddress, baseSlot, jobId, scope);
259
267
  const length = maybeLength ? maybeLength[0].toBigInt() : 0n;
260
268
 
261
269
  const values: Fr[][] = [];
262
270
 
263
271
  // Read each capsule at consecutive slots after baseSlot
264
272
  for (let i = 0; i < length; i++) {
265
- const currentValue = await this.loadCapsule(contractAddress, arraySlot(baseSlot, i), jobId);
273
+ const currentValue = await this.getCapsule(contractAddress, arraySlot(baseSlot, i), jobId, scope);
266
274
  if (currentValue == undefined) {
267
275
  throw new Error(
268
276
  `Expected non-empty value at capsule array in base slot ${baseSlot} at index ${i} for contract ${contractAddress}`,
@@ -276,7 +284,7 @@ export class CapsuleStore implements StagedStore {
276
284
  });
277
285
  }
278
286
 
279
- setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string) {
287
+ setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress) {
280
288
  // This transactional context in theory isn't so critical now because we aren't
281
289
  // writing to DB so if there's exceptions midway and it blows up, no visible impact
282
290
  // to persistent storage will happen.
@@ -287,27 +295,27 @@ export class CapsuleStore implements StagedStore {
287
295
  // of jobs: different calls running concurrently on the same contract may cause trouble.
288
296
  return this.#store.transactionAsync(async () => {
289
297
  // Load current length, defaulting to 0 if not found
290
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot, jobId);
298
+ const maybeLength = await this.getCapsule(contractAddress, baseSlot, jobId, scope);
291
299
  const originalLength = maybeLength ? maybeLength[0].toNumber() : 0;
292
300
 
293
301
  // Set the new length
294
- this.storeCapsule(contractAddress, baseSlot, [new Fr(content.length)], jobId);
302
+ this.setCapsule(contractAddress, baseSlot, [new Fr(content.length)], jobId, scope);
295
303
 
296
304
  // Store the new content, possibly overwriting existing values
297
305
  for (let i = 0; i < content.length; i++) {
298
- this.storeCapsule(contractAddress, arraySlot(baseSlot, i), content[i], jobId);
306
+ this.setCapsule(contractAddress, arraySlot(baseSlot, i), content[i], jobId, scope);
299
307
  }
300
308
 
301
309
  // Clear any stragglers
302
310
  for (let i = content.length; i < originalLength; i++) {
303
- this.deleteCapsule(contractAddress, arraySlot(baseSlot, i), jobId);
311
+ this.deleteCapsule(contractAddress, arraySlot(baseSlot, i), jobId, scope);
304
312
  }
305
313
  });
306
314
  }
307
315
  }
308
316
 
309
- function dbSlotToKey(contractAddress: AztecAddress, slot: Fr): string {
310
- return `${contractAddress.toString()}:${slot.toString()}`;
317
+ function dbSlotToKey(contractAddress: AztecAddress, slot: Fr, scope: AztecAddress): string {
318
+ return [contractAddress.toString(), scope.toString(), slot.toString()].join(':');
311
319
  }
312
320
 
313
321
  function arraySlot(baseSlot: Fr, index: number) {
@@ -1 +1,2 @@
1
+ export { CapsuleService } from './capsule_service.js';
1
2
  export { CapsuleStore } from './capsule_store.js';
@@ -1 +1 @@
1
- export const PXE_DATA_SCHEMA_VERSION = 3;
1
+ export const PXE_DATA_SCHEMA_VERSION = 5;
@@ -106,7 +106,7 @@ export class NoteStore implements StagedStore {
106
106
  * returned once if this is the case)
107
107
  */
108
108
  getNotes(filter: NotesFilter, jobId: string): Promise<NoteDao[]> {
109
- if (filter.scopes !== 'ALL_SCOPES' && filter.scopes.length === 0) {
109
+ if (filter.scopes.length === 0) {
110
110
  return Promise.resolve([]);
111
111
  }
112
112
 
@@ -180,10 +180,7 @@ export class NoteStore implements StagedStore {
180
180
  continue;
181
181
  }
182
182
 
183
- if (
184
- filter.scopes !== 'ALL_SCOPES' &&
185
- note.scopes.intersection(new Set(filter.scopes.map(s => s.toString()))).size === 0
186
- ) {
183
+ if (note.scopes.intersection(new Set(filter.scopes.map(s => s.toString()))).size === 0) {
187
184
  continue;
188
185
  }
189
186
 
@@ -49,7 +49,7 @@ export class StoredPrivateEvent {
49
49
  const msgContentLength = reader.readNumber();
50
50
  const msgContent = reader.readArray(msgContentLength, Fr);
51
51
  const l2BlockNumber = reader.readNumber();
52
- const l2BlockHash = new BlockHash(Fr.fromBuffer(reader));
52
+ const l2BlockHash = BlockHash.fromBuffer(reader);
53
53
  const txHash = TxHash.fromBuffer(reader);
54
54
  const txIndexInBlock = reader.readNumber();
55
55
  const eventIndexInTx = reader.readNumber();