@aztec/pxe 0.0.1-commit.b1c78909e → 0.0.1-commit.b2a5d0dd1

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 (210) hide show
  1. package/dest/bin/check_oracle_version.js +4 -4
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +6 -2
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +19 -1
  5. package/dest/config/index.d.ts +1 -1
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +7 -14
  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 +35 -10
  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 +3 -4
  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 +3 -6
  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 +1 -1
  26. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -1
  27. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -4
  28. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +3 -6
  30. package/dest/contract_function_simulator/oracle/interfaces.d.ts +32 -19
  31. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  33. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  34. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
  35. package/dest/contract_function_simulator/oracle/oracle.d.ts +50 -18
  36. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  37. package/dest/contract_function_simulator/oracle/oracle.js +186 -39
  38. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  39. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +12 -23
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +30 -28
  42. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +74 -42
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +252 -87
  45. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  46. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  47. package/dest/contract_function_simulator/pick_notes.js +20 -3
  48. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  49. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  50. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  51. package/dest/contract_logging.d.ts +9 -4
  52. package/dest/contract_logging.d.ts.map +1 -1
  53. package/dest/contract_logging.js +21 -6
  54. package/dest/contract_sync/contract_sync_service.d.ts +6 -5
  55. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  56. package/dest/contract_sync/contract_sync_service.js +62 -43
  57. package/dest/contract_sync/helpers.d.ts +2 -3
  58. package/dest/contract_sync/helpers.d.ts.map +1 -1
  59. package/dest/contract_sync/helpers.js +7 -2
  60. package/dest/debug/pxe_debug_utils.d.ts +3 -3
  61. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  62. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  63. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  64. package/dest/entrypoints/client/bundle/index.js +0 -1
  65. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  66. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  67. package/dest/entrypoints/client/bundle/utils.js +2 -2
  68. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  69. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  70. package/dest/entrypoints/client/lazy/index.js +0 -1
  71. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  72. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  73. package/dest/entrypoints/client/lazy/utils.js +2 -2
  74. package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
  75. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  76. package/dest/entrypoints/pxe_creation_options.js +3 -1
  77. package/dest/entrypoints/server/index.d.ts +2 -3
  78. package/dest/entrypoints/server/index.d.ts.map +1 -1
  79. package/dest/entrypoints/server/index.js +1 -2
  80. package/dest/entrypoints/server/utils.d.ts +2 -2
  81. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  82. package/dest/entrypoints/server/utils.js +2 -2
  83. package/dest/events/event_service.d.ts +3 -2
  84. package/dest/events/event_service.d.ts.map +1 -1
  85. package/dest/events/event_service.js +26 -5
  86. package/dest/events/private_event_filter_validator.d.ts +3 -2
  87. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  88. package/dest/events/private_event_filter_validator.js +15 -0
  89. package/dest/logs/log_service.d.ts +7 -8
  90. package/dest/logs/log_service.d.ts.map +1 -1
  91. package/dest/logs/log_service.js +27 -37
  92. package/dest/messages/message_context_service.d.ts +17 -0
  93. package/dest/messages/message_context_service.d.ts.map +1 -0
  94. package/dest/messages/message_context_service.js +36 -0
  95. package/dest/notes/note_service.d.ts +4 -5
  96. package/dest/notes/note_service.d.ts.map +1 -1
  97. package/dest/notes/note_service.js +14 -5
  98. package/dest/notes_filter.d.ts +2 -3
  99. package/dest/notes_filter.d.ts.map +1 -1
  100. package/dest/oracle_version.d.ts +4 -3
  101. package/dest/oracle_version.d.ts.map +1 -1
  102. package/dest/oracle_version.js +20 -10
  103. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  104. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  105. package/dest/private_kernel/private_kernel_execution_prover.js +4 -7
  106. package/dest/private_kernel/private_kernel_oracle.d.ts +5 -5
  107. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  108. package/dest/private_kernel/private_kernel_oracle.js +12 -15
  109. package/dest/pxe.d.ts +10 -7
  110. package/dest/pxe.d.ts.map +1 -1
  111. package/dest/pxe.js +58 -35
  112. package/dest/storage/anchor_block_store/anchor_block_store.js +1 -1
  113. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  114. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  115. package/dest/storage/capsule_store/capsule_service.js +50 -0
  116. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  117. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  118. package/dest/storage/capsule_store/capsule_store.js +36 -28
  119. package/dest/storage/capsule_store/index.d.ts +2 -1
  120. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  121. package/dest/storage/capsule_store/index.js +1 -0
  122. package/dest/storage/contract_store/contract_store.d.ts +1 -1
  123. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  124. package/dest/storage/contract_store/contract_store.js +4 -2
  125. package/dest/storage/metadata.d.ts +1 -1
  126. package/dest/storage/metadata.js +1 -1
  127. package/dest/storage/note_store/note_store.d.ts +1 -1
  128. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  129. package/dest/storage/note_store/note_store.js +2 -2
  130. package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
  131. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  132. package/dest/storage/private_event_store/private_event_store.js +3 -0
  133. package/dest/storage/private_event_store/stored_private_event.js +1 -1
  134. package/dest/storage/tagging_store/sender_tagging_store.d.ts +26 -25
  135. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  136. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  137. package/dest/tagging/index.d.ts +2 -2
  138. package/dest/tagging/index.d.ts.map +1 -1
  139. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -2
  140. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  141. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +2 -16
  142. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +1 -1
  143. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  144. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +10 -1
  145. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  146. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  147. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  148. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +2 -1
  149. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  150. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +24 -11
  151. package/package.json +16 -16
  152. package/src/bin/check_oracle_version.ts +4 -4
  153. package/src/block_synchronizer/block_synchronizer.ts +22 -2
  154. package/src/config/index.ts +2 -8
  155. package/src/contract_function_simulator/contract_function_simulator.ts +49 -14
  156. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  157. package/src/contract_function_simulator/execution_tagging_index_cache.ts +16 -11
  158. package/src/contract_function_simulator/index.ts +1 -0
  159. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -4
  160. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  161. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
  162. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -4
  163. package/src/contract_function_simulator/oracle/interfaces.ts +51 -17
  164. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
  165. package/src/contract_function_simulator/oracle/oracle.ts +258 -34
  166. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  167. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +40 -34
  168. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +423 -114
  169. package/src/contract_function_simulator/pick_notes.ts +22 -3
  170. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  171. package/src/contract_logging.ts +18 -5
  172. package/src/contract_sync/contract_sync_service.ts +99 -75
  173. package/src/contract_sync/helpers.ts +4 -4
  174. package/src/debug/pxe_debug_utils.ts +3 -3
  175. package/src/entrypoints/client/bundle/index.ts +0 -1
  176. package/src/entrypoints/client/bundle/utils.ts +2 -3
  177. package/src/entrypoints/client/lazy/index.ts +0 -1
  178. package/src/entrypoints/client/lazy/utils.ts +2 -3
  179. package/src/entrypoints/pxe_creation_options.ts +7 -0
  180. package/src/entrypoints/server/index.ts +1 -2
  181. package/src/entrypoints/server/utils.ts +2 -3
  182. package/src/events/event_service.ts +30 -5
  183. package/src/events/private_event_filter_validator.ts +21 -1
  184. package/src/logs/log_service.ts +57 -78
  185. package/src/messages/message_context_service.ts +44 -0
  186. package/src/notes/note_service.ts +18 -8
  187. package/src/notes_filter.ts +1 -3
  188. package/src/oracle_version.ts +20 -10
  189. package/src/private_kernel/private_kernel_execution_prover.ts +4 -9
  190. package/src/private_kernel/private_kernel_oracle.ts +14 -14
  191. package/src/pxe.ts +113 -42
  192. package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
  193. package/src/storage/capsule_store/capsule_service.ts +90 -0
  194. package/src/storage/capsule_store/capsule_store.ts +44 -26
  195. package/src/storage/capsule_store/index.ts +1 -0
  196. package/src/storage/contract_store/contract_store.ts +8 -6
  197. package/src/storage/metadata.ts +1 -1
  198. package/src/storage/note_store/note_store.ts +2 -5
  199. package/src/storage/private_event_store/private_event_store.ts +4 -0
  200. package/src/storage/private_event_store/stored_private_event.ts +1 -1
  201. package/src/storage/tagging_store/sender_tagging_store.ts +182 -135
  202. package/src/tagging/index.ts +1 -1
  203. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +5 -15
  204. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +19 -1
  205. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  206. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +19 -9
  207. package/dest/access_scopes.d.ts +0 -9
  208. package/dest/access_scopes.d.ts.map +0 -1
  209. package/dest/access_scopes.js +0 -6
  210. 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. */
@@ -158,6 +161,8 @@ export class PXE {
158
161
  private addressStore: AddressStore,
159
162
  private privateEventStore: PrivateEventStore,
160
163
  private contractSyncService: ContractSyncService,
164
+ private messageContextService: MessageContextService,
165
+ private l2TipsStore: L2TipsProvider,
161
166
  private simulator: CircuitSimulator,
162
167
  private proverEnabled: boolean,
163
168
  private proofCreator: PrivateKernelProver,
@@ -213,6 +218,8 @@ export class PXE {
213
218
  noteStore,
214
219
  createLogger('pxe:contract_sync', bindings),
215
220
  );
221
+ const messageContextService = new MessageContextService(node);
222
+
216
223
  const synchronizer = new BlockSynchronizer(
217
224
  node,
218
225
  store,
@@ -254,6 +261,8 @@ export class PXE {
254
261
  addressStore,
255
262
  privateEventStore,
256
263
  contractSyncService,
264
+ messageContextService,
265
+ tipsStore,
257
266
  simulator,
258
267
  proverEnabled,
259
268
  proofCreator,
@@ -288,6 +297,7 @@ export class PXE {
288
297
  keyStore: this.keyStore,
289
298
  addressStore: this.addressStore,
290
299
  aztecNode: BenchmarkedNodeFactory.create(this.node),
300
+ l2TipsStore: this.l2TipsStore,
291
301
  senderTaggingStore: this.senderTaggingStore,
292
302
  recipientTaggingStore: this.recipientTaggingStore,
293
303
  senderAddressBookStore: this.senderAddressBookStore,
@@ -295,6 +305,7 @@ export class PXE {
295
305
  privateEventStore: this.privateEventStore,
296
306
  simulator: this.simulator,
297
307
  contractSyncService: this.contractSyncService,
308
+ messageContextService: this.messageContextService,
298
309
  });
299
310
  }
300
311
 
@@ -360,14 +371,13 @@ export class PXE {
360
371
  async #executePrivate(
361
372
  contractFunctionSimulator: ContractFunctionSimulator,
362
373
  txRequest: TxExecutionRequest,
363
- scopes: AccessScopes,
374
+ anchorBlockHeader: BlockHeader,
375
+ scopes: AztecAddress[],
364
376
  jobId: string,
365
377
  ): Promise<PrivateExecutionResult> {
366
378
  const { origin: contractAddress, functionSelector } = txRequest;
367
379
 
368
380
  try {
369
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
370
-
371
381
  await this.contractSyncService.ensureContractSynced(
372
382
  contractAddress,
373
383
  functionSelector,
@@ -409,12 +419,19 @@ export class PXE {
409
419
  contractFunctionSimulator: ContractFunctionSimulator,
410
420
  call: FunctionCall,
411
421
  authWitnesses: AuthWitness[] | undefined,
412
- scopes: AccessScopes,
422
+ scopes: AztecAddress[],
413
423
  jobId: string,
414
424
  ) {
415
425
  try {
416
426
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
417
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
427
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
428
+ call,
429
+ authWitnesses ?? [],
430
+ anchorBlockHeader,
431
+ scopes,
432
+ jobId,
433
+ );
434
+ return { result, offchainEffects };
418
435
  } catch (err) {
419
436
  if (err instanceof SimulationError) {
420
437
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -465,11 +482,10 @@ export class PXE {
465
482
  txExecutionRequest: TxExecutionRequest,
466
483
  proofCreator: PrivateKernelProver,
467
484
  privateExecutionResult: PrivateExecutionResult,
485
+ anchorBlockHeader: BlockHeader,
468
486
  config: PrivateKernelExecutionProverConfig,
469
487
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
470
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
471
- const anchorBlockHash = await anchorBlockHeader.hash();
472
- const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
488
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
473
489
  const kernelTraceProver = new PrivateKernelExecutionProver(
474
490
  kernelOracle,
475
491
  proofCreator,
@@ -487,7 +503,9 @@ export class PXE {
487
503
  * @returns The synced block header
488
504
  */
489
505
  public getSyncedBlockHeader(): Promise<BlockHeader> {
490
- return this.anchorBlockStore.getBlockHeader();
506
+ return this.#putInJobQueue(() => {
507
+ return this.anchorBlockStore.getBlockHeader();
508
+ });
491
509
  }
492
510
 
493
511
  /**
@@ -544,6 +562,12 @@ export class PXE {
544
562
  * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
545
563
  */
546
564
  public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
565
+ if (!(await sender.isValid())) {
566
+ throw new Error(
567
+ `Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
568
+ );
569
+ }
570
+
547
571
  const accounts = await this.keyStore.getAccounts();
548
572
  if (accounts.includes(sender)) {
549
573
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
@@ -554,6 +578,9 @@ export class PXE {
554
578
 
555
579
  if (wasAdded) {
556
580
  this.log.info(`Added sender:\n ${sender.toString()}`);
581
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
582
+ // all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
583
+ await this.#putInJobQueue(() => Promise.resolve(this.contractSyncService.wipe()));
557
584
  } else {
558
585
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
559
586
  }
@@ -722,16 +749,23 @@ export class PXE {
722
749
  try {
723
750
  const syncTimer = new Timer();
724
751
  await this.blockStateSynchronizer.sync();
752
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
725
753
  const syncTime = syncTimer.ms();
726
754
  const contractFunctionSimulator = this.#getSimulatorForTx();
727
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
755
+ privateExecutionResult = await this.#executePrivate(
756
+ contractFunctionSimulator,
757
+ txRequest,
758
+ anchorBlockHeader,
759
+ scopes,
760
+ jobId,
761
+ );
728
762
 
729
763
  const {
730
764
  publicInputs,
731
765
  chonkProof,
732
766
  executionSteps,
733
767
  timings: { proving } = {},
734
- } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
768
+ } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
735
769
  simulate: false,
736
770
  skipFeeEnforcement: false,
737
771
  profileMode: 'none',
@@ -766,17 +800,17 @@ export class PXE {
766
800
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
767
801
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
768
802
  // storing the tags here prevents linkage of txs sent from the same PXE.
769
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
770
- if (preTagsUsedInTheTx.length > 0) {
803
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
804
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
771
805
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
772
806
  const txHash = (await txProvingResult.toTx()).txHash;
773
807
 
774
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
775
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
776
- preTagsUsedInTheTx,
808
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
809
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
810
+ taggingIndexRangesUsedInTheTx,
777
811
  });
778
812
  } else {
779
- this.log.debug(`No pre-tags used in the tx`);
813
+ this.log.debug(`No tagging index ranges used in the tx`);
780
814
  }
781
815
 
782
816
  return txProvingResult;
@@ -814,15 +848,23 @@ export class PXE {
814
848
  );
815
849
  const syncTimer = new Timer();
816
850
  await this.blockStateSynchronizer.sync();
851
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
817
852
  const syncTime = syncTimer.ms();
818
853
 
819
854
  const contractFunctionSimulator = this.#getSimulatorForTx();
820
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
855
+ const privateExecutionResult = await this.#executePrivate(
856
+ contractFunctionSimulator,
857
+ txRequest,
858
+ anchorBlockHeader,
859
+ scopes,
860
+ jobId,
861
+ );
821
862
 
822
863
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
823
864
  txRequest,
824
865
  this.proofCreator,
825
866
  privateExecutionResult,
867
+ anchorBlockHeader,
826
868
  {
827
869
  simulate: skipProofGeneration,
828
870
  skipFeeEnforcement: false,
@@ -883,7 +925,14 @@ export class PXE {
883
925
  */
884
926
  public simulateTx(
885
927
  txRequest: TxExecutionRequest,
886
- { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
928
+ {
929
+ simulatePublic,
930
+ skipTxValidation = false,
931
+ skipFeeEnforcement = false,
932
+ skipKernels = true,
933
+ overrides,
934
+ scopes,
935
+ }: SimulateTxOpts,
887
936
  ): Promise<TxSimulationResult> {
888
937
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
889
938
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -905,23 +954,33 @@ export class PXE {
905
954
  );
906
955
  const syncTimer = new Timer();
907
956
  await this.blockStateSynchronizer.sync();
957
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
908
958
  const syncTime = syncTimer.ms();
909
959
 
910
- const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
911
- // Temporary: in case there are overrides, we have to skip the kernels or validations
912
- // will fail. Consider handing control to the user/wallet on whether they want to run them
913
- // or not.
914
960
  const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
915
961
  const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
916
- const skipKernels = hasOverriddenContracts;
917
962
 
918
- // Set overridden contracts on the sync service so it knows to skip syncing them
963
+ if (hasOverriddenContracts && !skipKernels) {
964
+ throw new Error(
965
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
966
+ );
967
+ }
968
+ const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
969
+
919
970
  if (hasOverriddenContracts) {
920
- this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
971
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
972
+ // We exclude them so the sync service skips them entirely.
973
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
921
974
  }
922
975
 
923
976
  // Execution of private functions only; no proving, and no kernel logic.
924
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
977
+ const privateExecutionResult = await this.#executePrivate(
978
+ contractFunctionSimulator,
979
+ txRequest,
980
+ anchorBlockHeader,
981
+ scopes,
982
+ jobId,
983
+ );
925
984
 
926
985
  let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
927
986
  let executionSteps: PrivateExecutionStep[] = [];
@@ -934,11 +993,17 @@ export class PXE {
934
993
  ));
935
994
  } else {
936
995
  // Kernel logic, plus proving of all private functions and kernels.
937
- ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
938
- simulate: true,
939
- skipFeeEnforcement,
940
- profileMode: 'none',
941
- }));
996
+ ({ publicInputs, executionSteps } = await this.#prove(
997
+ txRequest,
998
+ this.proofCreator,
999
+ privateExecutionResult,
1000
+ anchorBlockHeader,
1001
+ {
1002
+ simulate: true,
1003
+ skipFeeEnforcement,
1004
+ profileMode: 'none',
1005
+ },
1006
+ ));
942
1007
  }
943
1008
 
944
1009
  const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
@@ -1012,7 +1077,7 @@ export class PXE {
1012
1077
  inspect(txRequest),
1013
1078
  `simulatePublic=${simulatePublic}`,
1014
1079
  `skipTxValidation=${skipTxValidation}`,
1015
- `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1080
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1016
1081
  );
1017
1082
  }
1018
1083
  });
@@ -1024,7 +1089,7 @@ export class PXE {
1024
1089
  */
1025
1090
  public executeUtility(
1026
1091
  call: FunctionCall,
1027
- { authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
1092
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1028
1093
  ): Promise<UtilityExecutionResult> {
1029
1094
  // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
1030
1095
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -1049,7 +1114,7 @@ export class PXE {
1049
1114
  scopes,
1050
1115
  );
1051
1116
 
1052
- const executionResult = await this.#executeUtility(
1117
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1053
1118
  contractFunctionSimulator,
1054
1119
  call,
1055
1120
  authwits ?? [],
@@ -1070,14 +1135,19 @@ export class PXE {
1070
1135
  };
1071
1136
 
1072
1137
  const simulationStats = contractFunctionSimulator.getStats();
1073
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1138
+ return {
1139
+ result: executionResult,
1140
+ offchainEffects,
1141
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1142
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1143
+ };
1074
1144
  } catch (err: any) {
1075
1145
  const { to, name, args } = call;
1076
1146
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1077
1147
  throw this.#contextualizeError(
1078
1148
  err,
1079
1149
  `executeUtility ${to}:${name}(${stringifiedArgs})`,
1080
- `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1150
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1081
1151
  );
1082
1152
  }
1083
1153
  });
@@ -1136,6 +1206,7 @@ export class PXE {
1136
1206
  */
1137
1207
  public async stop(): Promise<void> {
1138
1208
  await this.jobQueue.end();
1209
+ await this.blockStateSynchronizer.stop();
1139
1210
  await this.db.close();
1140
1211
  }
1141
1212
  }
@@ -23,7 +23,7 @@ export class AnchorBlockStore {
23
23
  }
24
24
 
25
25
  async getBlockHeader(): Promise<BlockHeader> {
26
- const headerBuffer = await this.#synchronizedHeader.getAsync();
26
+ const headerBuffer = await this.#store.transactionAsync(() => this.#synchronizedHeader.getAsync());
27
27
  if (!headerBuffer) {
28
28
  throw new Error(`Trying to get block header with a not-yet-synchronized PXE - this should never happen`);
29
29
  }
@@ -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
+ }