@aztec/pxe 4.0.0-devnet.2-patch.3 → 4.0.0-devnet.3-patch.0

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 (168) hide show
  1. package/dest/config/package_info.js +1 -1
  2. package/dest/contract_function_simulator/contract_function_simulator.d.ts +10 -5
  3. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  4. package/dest/contract_function_simulator/contract_function_simulator.js +35 -12
  5. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  6. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  7. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  8. package/dest/contract_function_simulator/index.d.ts +2 -1
  9. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/index.js +1 -0
  11. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -5
  12. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -9
  14. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  15. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
  17. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -6
  18. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +5 -10
  20. package/dest/contract_function_simulator/oracle/interfaces.d.ts +50 -45
  21. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  23. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  24. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +38 -0
  25. package/dest/contract_function_simulator/oracle/oracle.d.ts +64 -44
  26. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/oracle/oracle.js +187 -97
  28. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  29. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +23 -49
  30. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +50 -81
  32. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +66 -47
  33. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +190 -99
  35. package/dest/contract_logging.d.ts +27 -0
  36. package/dest/contract_logging.d.ts.map +1 -0
  37. package/dest/contract_logging.js +38 -0
  38. package/dest/contract_sync/contract_sync_service.d.ts +6 -5
  39. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  40. package/dest/contract_sync/contract_sync_service.js +44 -37
  41. package/dest/contract_sync/helpers.d.ts +2 -3
  42. package/dest/contract_sync/helpers.d.ts.map +1 -1
  43. package/dest/contract_sync/helpers.js +7 -2
  44. package/dest/debug/pxe_debug_utils.d.ts +3 -3
  45. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  46. package/dest/debug/pxe_debug_utils.js +4 -4
  47. package/dest/entrypoints/client/bundle/index.d.ts +2 -2
  48. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  49. package/dest/entrypoints/client/bundle/index.js +1 -1
  50. package/dest/entrypoints/client/lazy/index.d.ts +2 -2
  51. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  52. package/dest/entrypoints/client/lazy/index.js +1 -1
  53. package/dest/entrypoints/server/index.d.ts +1 -2
  54. package/dest/entrypoints/server/index.d.ts.map +1 -1
  55. package/dest/entrypoints/server/index.js +0 -1
  56. package/dest/events/event_service.d.ts +3 -2
  57. package/dest/events/event_service.d.ts.map +1 -1
  58. package/dest/events/event_service.js +16 -4
  59. package/dest/logs/log_service.d.ts +6 -7
  60. package/dest/logs/log_service.d.ts.map +1 -1
  61. package/dest/logs/log_service.js +34 -32
  62. package/dest/messages/message_context_service.d.ts +17 -0
  63. package/dest/messages/message_context_service.d.ts.map +1 -0
  64. package/dest/messages/message_context_service.js +36 -0
  65. package/dest/notes/note_service.d.ts +4 -5
  66. package/dest/notes/note_service.d.ts.map +1 -1
  67. package/dest/notes/note_service.js +14 -5
  68. package/dest/notes_filter.d.ts +2 -3
  69. package/dest/notes_filter.d.ts.map +1 -1
  70. package/dest/oracle_version.d.ts +2 -2
  71. package/dest/oracle_version.js +3 -3
  72. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  73. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  74. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +125 -64
  75. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  76. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  77. package/dest/private_kernel/hints/test_utils.js +203 -0
  78. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  79. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  80. package/dest/private_kernel/private_kernel_execution_prover.js +13 -5
  81. package/dest/pxe.d.ts +14 -12
  82. package/dest/pxe.d.ts.map +1 -1
  83. package/dest/pxe.js +56 -35
  84. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  85. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  86. package/dest/storage/capsule_store/capsule_service.js +50 -0
  87. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  88. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  89. package/dest/storage/capsule_store/capsule_store.js +33 -28
  90. package/dest/storage/capsule_store/index.d.ts +2 -1
  91. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  92. package/dest/storage/capsule_store/index.js +1 -0
  93. package/dest/storage/metadata.d.ts +1 -1
  94. package/dest/storage/metadata.js +1 -1
  95. package/dest/storage/note_store/note_store.d.ts +1 -1
  96. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  97. package/dest/storage/note_store/note_store.js +2 -2
  98. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  99. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  100. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  101. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  102. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  103. package/dest/tagging/index.d.ts +3 -3
  104. package/dest/tagging/index.d.ts.map +1 -1
  105. package/dest/tagging/index.js +1 -1
  106. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  107. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  108. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +3 -3
  109. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  110. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  111. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  112. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  113. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  114. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  115. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  116. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  117. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  118. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
  119. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  120. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  121. package/package.json +16 -16
  122. package/src/config/package_info.ts +1 -1
  123. package/src/contract_function_simulator/contract_function_simulator.ts +55 -24
  124. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  125. package/src/contract_function_simulator/index.ts +1 -0
  126. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -8
  127. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
  128. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -9
  129. package/src/contract_function_simulator/oracle/interfaces.ts +63 -54
  130. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +98 -0
  131. package/src/contract_function_simulator/oracle/oracle.ts +223 -139
  132. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  133. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +58 -103
  134. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +320 -123
  135. package/src/contract_logging.ts +52 -0
  136. package/src/contract_sync/contract_sync_service.ts +77 -59
  137. package/src/contract_sync/helpers.ts +4 -4
  138. package/src/debug/pxe_debug_utils.ts +7 -7
  139. package/src/entrypoints/client/bundle/index.ts +1 -1
  140. package/src/entrypoints/client/lazy/index.ts +1 -1
  141. package/src/entrypoints/server/index.ts +0 -1
  142. package/src/events/event_service.ts +17 -4
  143. package/src/logs/log_service.ts +72 -52
  144. package/src/messages/message_context_service.ts +44 -0
  145. package/src/notes/note_service.ts +18 -8
  146. package/src/notes_filter.ts +1 -3
  147. package/src/oracle_version.ts +3 -3
  148. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +157 -110
  149. package/src/private_kernel/hints/test_utils.ts +325 -0
  150. package/src/private_kernel/private_kernel_execution_prover.ts +13 -6
  151. package/src/pxe.ts +84 -45
  152. package/src/storage/capsule_store/capsule_service.ts +90 -0
  153. package/src/storage/capsule_store/capsule_store.ts +34 -26
  154. package/src/storage/capsule_store/index.ts +1 -0
  155. package/src/storage/metadata.ts +1 -1
  156. package/src/storage/note_store/note_store.ts +2 -5
  157. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  158. package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
  159. package/src/tagging/index.ts +2 -2
  160. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +3 -6
  161. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  162. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
  163. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  164. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
  165. package/dest/access_scopes.d.ts +0 -9
  166. package/dest/access_scopes.d.ts.map +0 -1
  167. package/dest/access_scopes.js +0 -6
  168. package/src/access_scopes.ts +0 -9
package/src/pxe.ts CHANGED
@@ -47,12 +47,11 @@ import {
47
47
  TxProfileResult,
48
48
  TxProvingResult,
49
49
  TxSimulationResult,
50
- UtilitySimulationResult,
50
+ UtilityExecutionResult,
51
51
  } from '@aztec/stdlib/tx';
52
52
 
53
53
  import { inspect } from 'util';
54
54
 
55
- import type { AccessScopes } from './access_scopes.js';
56
55
  import { BlockSynchronizer } from './block_synchronizer/index.js';
57
56
  import type { PXEConfig } from './config/index.js';
58
57
  import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
@@ -61,12 +60,14 @@ import {
61
60
  generateSimulatedProvingResult,
62
61
  } from './contract_function_simulator/contract_function_simulator.js';
63
62
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
+ import { displayDebugLogs } from './contract_logging.js';
64
64
  import { ContractSyncService } from './contract_sync/contract_sync_service.js';
65
65
  import { readCurrentClassId } from './contract_sync/helpers.js';
66
66
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
67
67
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
68
68
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
69
69
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
70
+ import { MessageContextService } from './messages/message_context_service.js';
70
71
  import {
71
72
  PrivateKernelExecutionProver,
72
73
  type PrivateKernelExecutionProverConfig,
@@ -94,7 +95,7 @@ export type ProfileTxOpts = {
94
95
  /** If true, proof generation is skipped during profiling. Defaults to true. */
95
96
  skipProofGeneration?: boolean;
96
97
  /** Addresses whose private state and keys are accessible during private execution. */
97
- scopes: AccessScopes;
98
+ scopes: AztecAddress[];
98
99
  };
99
100
 
100
101
  /** Options for PXE.simulateTx. */
@@ -105,18 +106,20 @@ export type SimulateTxOpts = {
105
106
  skipTxValidation?: boolean;
106
107
  /** If false, fees are enforced. */
107
108
  skipFeeEnforcement?: boolean;
108
- /** State overrides for the simulation, such as contract instances and artifacts. */
109
+ /** If true, kernel logic is emulated in TS for simulation */
110
+ skipKernels?: boolean;
111
+ /** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
109
112
  overrides?: SimulationOverrides;
110
113
  /** Addresses whose private state and keys are accessible during private execution */
111
- scopes: AccessScopes;
114
+ scopes: AztecAddress[];
112
115
  };
113
116
 
114
- /** Options for PXE.simulateUtility. */
115
- export type SimulateUtilityOpts = {
117
+ /** Options for PXE.executeUtility. */
118
+ export type ExecuteUtilityOpts = {
116
119
  /** The authentication witnesses required for the function call. */
117
120
  authwits?: AuthWitness[];
118
121
  /** The accounts whose notes we can access in this call */
119
- scopes: AccessScopes;
122
+ scopes: AztecAddress[];
120
123
  };
121
124
 
122
125
  /** Args for PXE.create. */
@@ -156,6 +159,7 @@ export class PXE {
156
159
  private addressStore: AddressStore,
157
160
  private privateEventStore: PrivateEventStore,
158
161
  private contractSyncService: ContractSyncService,
162
+ private messageContextService: MessageContextService,
159
163
  private simulator: CircuitSimulator,
160
164
  private proverEnabled: boolean,
161
165
  private proofCreator: PrivateKernelProver,
@@ -211,6 +215,8 @@ export class PXE {
211
215
  noteStore,
212
216
  createLogger('pxe:contract_sync', bindings),
213
217
  );
218
+ const messageContextService = new MessageContextService(node);
219
+
214
220
  const synchronizer = new BlockSynchronizer(
215
221
  node,
216
222
  store,
@@ -251,6 +257,7 @@ export class PXE {
251
257
  addressStore,
252
258
  privateEventStore,
253
259
  contractSyncService,
260
+ messageContextService,
254
261
  simulator,
255
262
  proverEnabled,
256
263
  proofCreator,
@@ -264,7 +271,7 @@ export class PXE {
264
271
  debugUtils.setPXEHelpers(
265
272
  pxe.#putInJobQueue.bind(pxe),
266
273
  pxe.#getSimulatorForTx.bind(pxe),
267
- pxe.#simulateUtility.bind(pxe),
274
+ pxe.#executeUtility.bind(pxe),
268
275
  );
269
276
 
270
277
  pxe.jobQueue.start();
@@ -292,6 +299,7 @@ export class PXE {
292
299
  privateEventStore: this.privateEventStore,
293
300
  simulator: this.simulator,
294
301
  contractSyncService: this.contractSyncService,
302
+ messageContextService: this.messageContextService,
295
303
  });
296
304
  }
297
305
 
@@ -357,7 +365,7 @@ export class PXE {
357
365
  async #executePrivate(
358
366
  contractFunctionSimulator: ContractFunctionSimulator,
359
367
  txRequest: TxExecutionRequest,
360
- scopes: AccessScopes,
368
+ scopes: AztecAddress[],
361
369
  jobId: string,
362
370
  ): Promise<PrivateExecutionResult> {
363
371
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -369,7 +377,7 @@ export class PXE {
369
377
  contractAddress,
370
378
  functionSelector,
371
379
  (privateSyncCall, execScopes) =>
372
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
380
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
373
381
  anchorBlockHeader,
374
382
  jobId,
375
383
  scopes,
@@ -393,25 +401,32 @@ export class PXE {
393
401
  }
394
402
 
395
403
  /**
396
- * Simulate a utility function call on the given contract.
404
+ * Execute a utility function call on the given contract.
397
405
  * @param contractFunctionSimulator - The simulator to use for the function call.
398
406
  * @param call - The function call to execute.
399
407
  * @param authWitnesses - Authentication witnesses required for the function call.
400
408
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
401
409
  * accounts if not specified.
402
410
  * @param jobId - The job ID for staged writes.
403
- * @returns The simulation result containing the outputs of the utility function.
411
+ * @returns The execution result containing the outputs of the utility function.
404
412
  */
405
- async #simulateUtility(
413
+ async #executeUtility(
406
414
  contractFunctionSimulator: ContractFunctionSimulator,
407
415
  call: FunctionCall,
408
416
  authWitnesses: AuthWitness[] | undefined,
409
- scopes: AccessScopes,
417
+ scopes: AztecAddress[],
410
418
  jobId: string,
411
419
  ) {
412
420
  try {
413
421
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
414
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
422
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
423
+ call,
424
+ authWitnesses ?? [],
425
+ anchorBlockHeader,
426
+ scopes,
427
+ jobId,
428
+ );
429
+ return { result, offchainEffects };
415
430
  } catch (err) {
416
431
  if (err instanceof SimulationError) {
417
432
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -484,7 +499,9 @@ export class PXE {
484
499
  * @returns The synced block header
485
500
  */
486
501
  public getSyncedBlockHeader(): Promise<BlockHeader> {
487
- return this.anchorBlockStore.getBlockHeader();
502
+ return this.#putInJobQueue(() => {
503
+ return this.anchorBlockStore.getBlockHeader();
504
+ });
488
505
  }
489
506
 
490
507
  /**
@@ -551,6 +568,9 @@ export class PXE {
551
568
 
552
569
  if (wasAdded) {
553
570
  this.log.info(`Added sender:\n ${sender.toString()}`);
571
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
572
+ // all contracts must re-sync to discover them.
573
+ this.contractSyncService.wipe();
554
574
  } else {
555
575
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
556
576
  }
@@ -763,17 +783,17 @@ export class PXE {
763
783
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
764
784
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
765
785
  // storing the tags here prevents linkage of txs sent from the same PXE.
766
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
767
- if (preTagsUsedInTheTx.length > 0) {
786
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
787
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
768
788
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
769
789
  const txHash = (await txProvingResult.toTx()).txHash;
770
790
 
771
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
772
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
773
- preTagsUsedInTheTx,
791
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
792
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
793
+ taggingIndexRangesUsedInTheTx,
774
794
  });
775
795
  } else {
776
- this.log.debug(`No pre-tags used in the tx`);
796
+ this.log.debug(`No tagging index ranges used in the tx`);
777
797
  }
778
798
 
779
799
  return txProvingResult;
@@ -880,7 +900,14 @@ export class PXE {
880
900
  */
881
901
  public simulateTx(
882
902
  txRequest: TxExecutionRequest,
883
- { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
903
+ {
904
+ simulatePublic,
905
+ skipTxValidation = false,
906
+ skipFeeEnforcement = false,
907
+ skipKernels = true,
908
+ overrides,
909
+ scopes,
910
+ }: SimulateTxOpts,
884
911
  ): Promise<TxSimulationResult> {
885
912
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
886
913
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -904,17 +931,20 @@ export class PXE {
904
931
  await this.blockStateSynchronizer.sync();
905
932
  const syncTime = syncTimer.ms();
906
933
 
907
- const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
908
- // Temporary: in case there are overrides, we have to skip the kernels or validations
909
- // will fail. Consider handing control to the user/wallet on whether they want to run them
910
- // or not.
911
934
  const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
912
935
  const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
913
- const skipKernels = hasOverriddenContracts;
914
936
 
915
- // Set overridden contracts on the sync service so it knows to skip syncing them
937
+ if (hasOverriddenContracts && !skipKernels) {
938
+ throw new Error(
939
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
940
+ );
941
+ }
942
+ const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
943
+
916
944
  if (hasOverriddenContracts) {
917
- this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
945
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
946
+ // We exclude them so the sync service skips them entirely.
947
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
918
948
  }
919
949
 
920
950
  // Execution of private functions only; no proving, and no kernel logic.
@@ -946,6 +976,9 @@ export class PXE {
946
976
  const publicSimulationTimer = new Timer();
947
977
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
948
978
  publicSimulationTime = publicSimulationTimer.ms();
979
+ if (publicOutput?.debugLogs?.length) {
980
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
981
+ }
949
982
  }
950
983
 
951
984
  let validationTime: number | undefined;
@@ -954,7 +987,8 @@ export class PXE {
954
987
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
955
988
  validationTime = validationTimer.ms();
956
989
  if (validationResult.result === 'invalid') {
957
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
990
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
991
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
958
992
  }
959
993
  }
960
994
 
@@ -1005,23 +1039,23 @@ export class PXE {
1005
1039
  inspect(txRequest),
1006
1040
  `simulatePublic=${simulatePublic}`,
1007
1041
  `skipTxValidation=${skipTxValidation}`,
1008
- `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1042
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1009
1043
  );
1010
1044
  }
1011
1045
  });
1012
1046
  }
1013
1047
 
1014
1048
  /**
1015
- * Simulates the execution of a contract utility function.
1049
+ * Executes a contract utility function.
1016
1050
  * @param call - The function call containing the function details, arguments, and target contract address.
1017
1051
  */
1018
- public simulateUtility(
1052
+ public executeUtility(
1019
1053
  call: FunctionCall,
1020
- { authwits, scopes }: SimulateUtilityOpts = { scopes: 'ALL_SCOPES' },
1021
- ): Promise<UtilitySimulationResult> {
1022
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1054
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1055
+ ): Promise<UtilityExecutionResult> {
1056
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
1023
1057
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
1024
- // delete the same read value, or reading values that another simulation is currently modifying).
1058
+ // delete the same read value, or reading values that another execution is currently modifying).
1025
1059
  return this.#putInJobQueue(async jobId => {
1026
1060
  try {
1027
1061
  const totalTimer = new Timer();
@@ -1036,13 +1070,13 @@ export class PXE {
1036
1070
  call.to,
1037
1071
  call.selector,
1038
1072
  (privateSyncCall, execScopes) =>
1039
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1073
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1040
1074
  anchorBlockHeader,
1041
1075
  jobId,
1042
1076
  scopes,
1043
1077
  );
1044
1078
 
1045
- const executionResult = await this.#simulateUtility(
1079
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1046
1080
  contractFunctionSimulator,
1047
1081
  call,
1048
1082
  authwits ?? [],
@@ -1063,14 +1097,19 @@ export class PXE {
1063
1097
  };
1064
1098
 
1065
1099
  const simulationStats = contractFunctionSimulator.getStats();
1066
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1100
+ return {
1101
+ result: executionResult,
1102
+ offchainEffects,
1103
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1104
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1105
+ };
1067
1106
  } catch (err: any) {
1068
1107
  const { to, name, args } = call;
1069
1108
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1070
1109
  throw this.#contextualizeError(
1071
1110
  err,
1072
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1073
- `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1111
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1112
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1074
1113
  );
1075
1114
  }
1076
1115
  });
@@ -1107,7 +1146,7 @@ export class PXE {
1107
1146
  filter.contractAddress,
1108
1147
  null,
1109
1148
  async (privateSyncCall, execScopes) =>
1110
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1149
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1111
1150
  anchorBlockHeader,
1112
1151
  jobId,
1113
1152
  filter.scopes,
@@ -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