@aztec/pxe 0.0.1-commit.e2b2873ed → 0.0.1-commit.e304674f1

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 (216) hide show
  1. package/dest/block_synchronizer/block_synchronizer.d.ts +1 -1
  2. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  3. package/dest/block_synchronizer/block_synchronizer.js +6 -0
  4. package/dest/config/index.d.ts +2 -2
  5. package/dest/config/index.d.ts.map +1 -1
  6. package/dest/config/index.js +1 -1
  7. package/dest/config/package_info.js +1 -1
  8. package/dest/contract_function_simulator/contract_function_simulator.d.ts +14 -7
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.js +138 -45
  11. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  12. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  14. package/dest/contract_function_simulator/index.d.ts +2 -1
  15. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/index.js +1 -0
  17. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -5
  18. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -9
  20. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  21. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
  23. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -6
  24. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +5 -10
  26. package/dest/contract_function_simulator/oracle/interfaces.d.ts +50 -45
  27. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  29. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  30. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +38 -0
  31. package/dest/contract_function_simulator/oracle/oracle.d.ts +64 -44
  32. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/oracle.js +187 -97
  34. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  35. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +23 -48
  36. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  37. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +50 -81
  38. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +66 -46
  39. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +190 -99
  41. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  42. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/pick_notes.js +9 -2
  44. package/dest/contract_logging.d.ts +27 -0
  45. package/dest/contract_logging.d.ts.map +1 -0
  46. package/dest/contract_logging.js +38 -0
  47. package/dest/contract_sync/contract_sync_service.d.ts +7 -5
  48. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  49. package/dest/contract_sync/contract_sync_service.js +45 -38
  50. package/dest/contract_sync/helpers.d.ts +2 -2
  51. package/dest/contract_sync/helpers.d.ts.map +1 -1
  52. package/dest/contract_sync/helpers.js +9 -4
  53. package/dest/debug/pxe_debug_utils.d.ts +4 -3
  54. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  55. package/dest/debug/pxe_debug_utils.js +4 -4
  56. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  57. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  58. package/dest/entrypoints/client/bundle/index.js +2 -0
  59. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  60. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  61. package/dest/entrypoints/client/bundle/utils.js +2 -2
  62. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  63. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  64. package/dest/entrypoints/client/lazy/index.js +2 -0
  65. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  66. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  67. package/dest/entrypoints/client/lazy/utils.js +2 -2
  68. package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
  69. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  70. package/dest/entrypoints/pxe_creation_options.js +3 -1
  71. package/dest/entrypoints/server/index.d.ts +2 -1
  72. package/dest/entrypoints/server/index.d.ts.map +1 -1
  73. package/dest/entrypoints/server/index.js +1 -0
  74. package/dest/entrypoints/server/utils.d.ts +2 -2
  75. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  76. package/dest/entrypoints/server/utils.js +2 -2
  77. package/dest/events/event_service.d.ts +3 -2
  78. package/dest/events/event_service.d.ts.map +1 -1
  79. package/dest/events/event_service.js +16 -4
  80. package/dest/logs/log_service.d.ts +6 -6
  81. package/dest/logs/log_service.d.ts.map +1 -1
  82. package/dest/logs/log_service.js +34 -32
  83. package/dest/messages/message_context_service.d.ts +17 -0
  84. package/dest/messages/message_context_service.d.ts.map +1 -0
  85. package/dest/messages/message_context_service.js +36 -0
  86. package/dest/notes/note_service.d.ts +4 -4
  87. package/dest/notes/note_service.d.ts.map +1 -1
  88. package/dest/notes/note_service.js +17 -7
  89. package/dest/notes_filter.d.ts +24 -0
  90. package/dest/notes_filter.d.ts.map +1 -0
  91. package/dest/notes_filter.js +4 -0
  92. package/dest/oracle_version.d.ts +2 -2
  93. package/dest/oracle_version.js +3 -3
  94. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  95. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  96. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  97. package/dest/private_kernel/hints/index.d.ts +1 -1
  98. package/dest/private_kernel/hints/index.js +1 -1
  99. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  100. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  101. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  102. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  103. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  104. package/dest/private_kernel/hints/test_utils.js +203 -0
  105. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  106. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  107. package/dest/private_kernel/private_kernel_execution_prover.js +19 -11
  108. package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
  109. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  110. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  111. package/dest/pxe.d.ts +18 -14
  112. package/dest/pxe.d.ts.map +1 -1
  113. package/dest/pxe.js +74 -48
  114. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  115. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  116. package/dest/storage/capsule_store/capsule_service.js +50 -0
  117. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  118. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  119. package/dest/storage/capsule_store/capsule_store.js +33 -28
  120. package/dest/storage/capsule_store/index.d.ts +2 -1
  121. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  122. package/dest/storage/capsule_store/index.js +1 -0
  123. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  124. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  125. package/dest/storage/contract_store/contract_store.js +140 -64
  126. package/dest/storage/metadata.d.ts +1 -1
  127. package/dest/storage/metadata.js +1 -1
  128. package/dest/storage/note_store/note_store.d.ts +3 -2
  129. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  130. package/dest/storage/note_store/note_store.js +2 -2
  131. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  132. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  133. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  134. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  135. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  136. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  137. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  138. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  139. package/dest/tagging/index.d.ts +3 -3
  140. package/dest/tagging/index.d.ts.map +1 -1
  141. package/dest/tagging/index.js +1 -1
  142. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  143. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  144. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
  145. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  146. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  147. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  148. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  149. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  150. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  151. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  152. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  153. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  154. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  155. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
  156. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  157. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  158. package/package.json +16 -16
  159. package/src/block_synchronizer/block_synchronizer.ts +6 -0
  160. package/src/config/index.ts +1 -1
  161. package/src/config/package_info.ts +1 -1
  162. package/src/contract_function_simulator/contract_function_simulator.ts +254 -65
  163. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  164. package/src/contract_function_simulator/index.ts +1 -0
  165. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -8
  166. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
  167. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -9
  168. package/src/contract_function_simulator/oracle/interfaces.ts +63 -54
  169. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +98 -0
  170. package/src/contract_function_simulator/oracle/oracle.ts +223 -139
  171. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  172. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +58 -102
  173. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +320 -122
  174. package/src/contract_function_simulator/pick_notes.ts +9 -2
  175. package/src/contract_logging.ts +52 -0
  176. package/src/contract_sync/contract_sync_service.ts +79 -54
  177. package/src/contract_sync/helpers.ts +8 -3
  178. package/src/debug/pxe_debug_utils.ts +8 -7
  179. package/src/entrypoints/client/bundle/index.ts +2 -0
  180. package/src/entrypoints/client/bundle/utils.ts +2 -3
  181. package/src/entrypoints/client/lazy/index.ts +2 -0
  182. package/src/entrypoints/client/lazy/utils.ts +2 -3
  183. package/src/entrypoints/pxe_creation_options.ts +7 -0
  184. package/src/entrypoints/server/index.ts +1 -0
  185. package/src/entrypoints/server/utils.ts +2 -3
  186. package/src/events/event_service.ts +17 -4
  187. package/src/logs/log_service.ts +68 -51
  188. package/src/messages/message_context_service.ts +44 -0
  189. package/src/notes/note_service.ts +19 -8
  190. package/src/notes_filter.ts +24 -0
  191. package/src/oracle_version.ts +3 -3
  192. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  193. package/src/private_kernel/hints/index.ts +1 -1
  194. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  195. package/src/private_kernel/hints/test_utils.ts +325 -0
  196. package/src/private_kernel/private_kernel_execution_prover.ts +19 -12
  197. package/src/private_kernel/private_kernel_oracle.ts +7 -7
  198. package/src/pxe.ts +104 -61
  199. package/src/storage/capsule_store/capsule_service.ts +90 -0
  200. package/src/storage/capsule_store/capsule_store.ts +34 -26
  201. package/src/storage/capsule_store/index.ts +1 -0
  202. package/src/storage/contract_store/contract_store.ts +170 -71
  203. package/src/storage/metadata.ts +1 -1
  204. package/src/storage/note_store/note_store.ts +4 -3
  205. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  206. package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
  207. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  208. package/src/tagging/index.ts +2 -2
  209. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
  210. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  211. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  212. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
  213. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  214. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
  215. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  216. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
package/src/pxe.ts CHANGED
@@ -47,7 +47,7 @@ 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';
@@ -60,12 +60,14 @@ import {
60
60
  generateSimulatedProvingResult,
61
61
  } from './contract_function_simulator/contract_function_simulator.js';
62
62
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
+ import { displayDebugLogs } from './contract_logging.js';
63
64
  import { ContractSyncService } from './contract_sync/contract_sync_service.js';
64
65
  import { readCurrentClassId } from './contract_sync/helpers.js';
65
66
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
66
67
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
67
68
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
68
69
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
70
+ import { MessageContextService } from './messages/message_context_service.js';
69
71
  import {
70
72
  PrivateKernelExecutionProver,
71
73
  type PrivateKernelExecutionProverConfig,
@@ -93,7 +95,7 @@ export type ProfileTxOpts = {
93
95
  /** If true, proof generation is skipped during profiling. Defaults to true. */
94
96
  skipProofGeneration?: boolean;
95
97
  /** Addresses whose private state and keys are accessible during private execution. */
96
- scopes?: AztecAddress[];
98
+ scopes: AztecAddress[];
97
99
  };
98
100
 
99
101
  /** Options for PXE.simulateTx. */
@@ -104,18 +106,20 @@ export type SimulateTxOpts = {
104
106
  skipTxValidation?: boolean;
105
107
  /** If false, fees are enforced. */
106
108
  skipFeeEnforcement?: boolean;
107
- /** 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 */
108
112
  overrides?: SimulationOverrides;
109
- /** Addresses whose private state and keys are accessible during private execution. Defaults to all. */
110
- scopes?: AztecAddress[];
113
+ /** Addresses whose private state and keys are accessible during private execution */
114
+ scopes: AztecAddress[];
111
115
  };
112
116
 
113
- /** Options for PXE.simulateUtility. */
114
- export type SimulateUtilityOpts = {
117
+ /** Options for PXE.executeUtility. */
118
+ export type ExecuteUtilityOpts = {
115
119
  /** The authentication witnesses required for the function call. */
116
120
  authwits?: AuthWitness[];
117
- /** The accounts whose notes we can access in this call. Defaults to all. */
118
- scopes?: AztecAddress[];
121
+ /** The accounts whose notes we can access in this call */
122
+ scopes: AztecAddress[];
119
123
  };
120
124
 
121
125
  /** Args for PXE.create. */
@@ -143,6 +147,7 @@ export type PXECreateArgs = {
143
147
  export class PXE {
144
148
  private constructor(
145
149
  private node: AztecNode,
150
+ private db: AztecAsyncKVStore,
146
151
  private blockStateSynchronizer: BlockSynchronizer,
147
152
  private keyStore: KeyStore,
148
153
  private contractStore: ContractStore,
@@ -155,6 +160,7 @@ export class PXE {
155
160
  private addressStore: AddressStore,
156
161
  private privateEventStore: PrivateEventStore,
157
162
  private contractSyncService: ContractSyncService,
163
+ private messageContextService: MessageContextService,
158
164
  private simulator: CircuitSimulator,
159
165
  private proverEnabled: boolean,
160
166
  private proofCreator: PrivateKernelProver,
@@ -210,6 +216,8 @@ export class PXE {
210
216
  noteStore,
211
217
  createLogger('pxe:contract_sync', bindings),
212
218
  );
219
+ const messageContextService = new MessageContextService(node);
220
+
213
221
  const synchronizer = new BlockSynchronizer(
214
222
  node,
215
223
  store,
@@ -238,6 +246,7 @@ export class PXE {
238
246
 
239
247
  const pxe = new PXE(
240
248
  node,
249
+ store,
241
250
  synchronizer,
242
251
  keyStore,
243
252
  contractStore,
@@ -250,6 +259,7 @@ export class PXE {
250
259
  addressStore,
251
260
  privateEventStore,
252
261
  contractSyncService,
262
+ messageContextService,
253
263
  simulator,
254
264
  proverEnabled,
255
265
  proofCreator,
@@ -263,7 +273,7 @@ export class PXE {
263
273
  debugUtils.setPXEHelpers(
264
274
  pxe.#putInJobQueue.bind(pxe),
265
275
  pxe.#getSimulatorForTx.bind(pxe),
266
- pxe.#simulateUtility.bind(pxe),
276
+ pxe.#executeUtility.bind(pxe),
267
277
  );
268
278
 
269
279
  pxe.jobQueue.start();
@@ -291,6 +301,7 @@ export class PXE {
291
301
  privateEventStore: this.privateEventStore,
292
302
  simulator: this.simulator,
293
303
  contractSyncService: this.contractSyncService,
304
+ messageContextService: this.messageContextService,
294
305
  });
295
306
  }
296
307
 
@@ -343,9 +354,8 @@ export class PXE {
343
354
  async #registerProtocolContracts() {
344
355
  const registered: Record<string, string> = {};
345
356
  for (const name of protocolContractNames) {
346
- const { address, contractClass, instance, artifact } =
347
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
348
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
357
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
358
+ await this.contractStore.addContractArtifact(artifact);
349
359
  await this.contractStore.addContractInstance(instance);
350
360
  registered[name] = address.toString();
351
361
  }
@@ -357,7 +367,7 @@ export class PXE {
357
367
  async #executePrivate(
358
368
  contractFunctionSimulator: ContractFunctionSimulator,
359
369
  txRequest: TxExecutionRequest,
360
- scopes: AztecAddress[] | undefined,
370
+ scopes: AztecAddress[],
361
371
  jobId: string,
362
372
  ): Promise<PrivateExecutionResult> {
363
373
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -369,7 +379,7 @@ export class PXE {
369
379
  contractAddress,
370
380
  functionSelector,
371
381
  (privateSyncCall, execScopes) =>
372
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
382
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
373
383
  anchorBlockHeader,
374
384
  jobId,
375
385
  scopes,
@@ -393,25 +403,32 @@ export class PXE {
393
403
  }
394
404
 
395
405
  /**
396
- * Simulate a utility function call on the given contract.
406
+ * Execute a utility function call on the given contract.
397
407
  * @param contractFunctionSimulator - The simulator to use for the function call.
398
408
  * @param call - The function call to execute.
399
409
  * @param authWitnesses - Authentication witnesses required for the function call.
400
410
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
401
411
  * accounts if not specified.
402
412
  * @param jobId - The job ID for staged writes.
403
- * @returns The simulation result containing the outputs of the utility function.
413
+ * @returns The execution result containing the outputs of the utility function.
404
414
  */
405
- async #simulateUtility(
415
+ async #executeUtility(
406
416
  contractFunctionSimulator: ContractFunctionSimulator,
407
417
  call: FunctionCall,
408
418
  authWitnesses: AuthWitness[] | undefined,
409
- scopes: AztecAddress[] | undefined,
419
+ scopes: AztecAddress[],
410
420
  jobId: string,
411
421
  ) {
412
422
  try {
413
423
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
414
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
424
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
425
+ call,
426
+ authWitnesses ?? [],
427
+ anchorBlockHeader,
428
+ scopes,
429
+ jobId,
430
+ );
431
+ return { result, offchainEffects };
415
432
  } catch (err) {
416
433
  if (err instanceof SimulationError) {
417
434
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -484,7 +501,9 @@ export class PXE {
484
501
  * @returns The synced block header
485
502
  */
486
503
  public getSyncedBlockHeader(): Promise<BlockHeader> {
487
- return this.anchorBlockStore.getBlockHeader();
504
+ return this.#putInJobQueue(() => {
505
+ return this.anchorBlockStore.getBlockHeader();
506
+ });
488
507
  }
489
508
 
490
509
  /**
@@ -551,6 +570,9 @@ export class PXE {
551
570
 
552
571
  if (wasAdded) {
553
572
  this.log.info(`Added sender:\n ${sender.toString()}`);
573
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
574
+ // all contracts must re-sync to discover them.
575
+ this.contractSyncService.wipe();
554
576
  } else {
555
577
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
556
578
  }
@@ -600,8 +622,7 @@ export class PXE {
600
622
  * @param artifact - The build artifact for the contract class.
601
623
  */
602
624
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
603
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
604
- await this.contractStore.addContractArtifact(contractClassId, artifact);
625
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
605
626
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
606
627
  }
607
628
 
@@ -620,17 +641,17 @@ export class PXE {
620
641
  if (artifact) {
621
642
  // If the user provides an artifact, validate it against the expected class id and register it
622
643
  const contractClass = await getContractClassFromArtifact(artifact);
623
- const contractClassId = contractClass.id;
624
- if (!contractClassId.equals(instance.currentContractClassId)) {
644
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
625
645
  throw new Error(
626
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
646
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
627
647
  );
628
648
  }
629
649
  const computedAddress = await computeContractAddressFromInstance(instance);
630
650
  if (!computedAddress.equals(instance.address)) {
631
651
  throw new Error('Added a contract in which the address does not match the contract instance.');
632
652
  }
633
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
653
+
654
+ await this.contractStore.addContractArtifact(artifact, contractClass);
634
655
 
635
656
  const publicFunctionSignatures = artifact.functions
636
657
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -679,15 +700,16 @@ export class PXE {
679
700
  throw new Error('Could not update contract to a class different from the current one.');
680
701
  }
681
702
 
682
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
683
-
684
703
  const publicFunctionSignatures = artifact.functions
685
704
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
686
705
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
687
706
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
688
707
 
689
708
  currentInstance.currentContractClassId = contractClass.id;
690
- await this.contractStore.addContractInstance(currentInstance);
709
+ await Promise.all([
710
+ this.contractStore.addContractArtifact(artifact, contractClass),
711
+ this.contractStore.addContractInstance(currentInstance),
712
+ ]);
691
713
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
692
714
  });
693
715
  }
@@ -763,17 +785,17 @@ export class PXE {
763
785
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
764
786
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
765
787
  // storing the tags here prevents linkage of txs sent from the same PXE.
766
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
767
- if (preTagsUsedInTheTx.length > 0) {
788
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
789
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
768
790
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
769
791
  const txHash = (await txProvingResult.toTx()).txHash;
770
792
 
771
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
772
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
773
- preTagsUsedInTheTx,
793
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
794
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
795
+ taggingIndexRangesUsedInTheTx,
774
796
  });
775
797
  } else {
776
- this.log.debug(`No pre-tags used in the tx`);
798
+ this.log.debug(`No tagging index ranges used in the tx`);
777
799
  }
778
800
 
779
801
  return txProvingResult;
@@ -880,7 +902,14 @@ export class PXE {
880
902
  */
881
903
  public simulateTx(
882
904
  txRequest: TxExecutionRequest,
883
- { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
905
+ {
906
+ simulatePublic,
907
+ skipTxValidation = false,
908
+ skipFeeEnforcement = false,
909
+ skipKernels = true,
910
+ overrides,
911
+ scopes,
912
+ }: SimulateTxOpts,
884
913
  ): Promise<TxSimulationResult> {
885
914
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
886
915
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -904,17 +933,20 @@ export class PXE {
904
933
  await this.blockStateSynchronizer.sync();
905
934
  const syncTime = syncTimer.ms();
906
935
 
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
936
  const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
912
937
  const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
913
- const skipKernels = hasOverriddenContracts;
914
938
 
915
- // Set overridden contracts on the sync service so it knows to skip syncing them
939
+ if (hasOverriddenContracts && !skipKernels) {
940
+ throw new Error(
941
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
942
+ );
943
+ }
944
+ const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
945
+
916
946
  if (hasOverriddenContracts) {
917
- this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
947
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
948
+ // We exclude them so the sync service skips them entirely.
949
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
918
950
  }
919
951
 
920
952
  // Execution of private functions only; no proving, and no kernel logic.
@@ -927,6 +959,7 @@ export class PXE {
927
959
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
928
960
  privateExecutionResult,
929
961
  (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
962
+ this.node,
930
963
  ));
931
964
  } else {
932
965
  // Kernel logic, plus proving of all private functions and kernels.
@@ -945,6 +978,9 @@ export class PXE {
945
978
  const publicSimulationTimer = new Timer();
946
979
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
947
980
  publicSimulationTime = publicSimulationTimer.ms();
981
+ if (publicOutput?.debugLogs?.length) {
982
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
983
+ }
948
984
  }
949
985
 
950
986
  let validationTime: number | undefined;
@@ -953,7 +989,8 @@ export class PXE {
953
989
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
954
990
  validationTime = validationTimer.ms();
955
991
  if (validationResult.result === 'invalid') {
956
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
992
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
993
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
957
994
  }
958
995
  }
959
996
 
@@ -1004,23 +1041,23 @@ export class PXE {
1004
1041
  inspect(txRequest),
1005
1042
  `simulatePublic=${simulatePublic}`,
1006
1043
  `skipTxValidation=${skipTxValidation}`,
1007
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1044
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1008
1045
  );
1009
1046
  }
1010
1047
  });
1011
1048
  }
1012
1049
 
1013
1050
  /**
1014
- * Simulates the execution of a contract utility function.
1051
+ * Executes a contract utility function.
1015
1052
  * @param call - The function call containing the function details, arguments, and target contract address.
1016
1053
  */
1017
- public simulateUtility(
1054
+ public executeUtility(
1018
1055
  call: FunctionCall,
1019
- { authwits, scopes }: SimulateUtilityOpts = {},
1020
- ): Promise<UtilitySimulationResult> {
1021
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1056
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1057
+ ): Promise<UtilityExecutionResult> {
1058
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
1022
1059
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
1023
- // delete the same read value, or reading values that another simulation is currently modifying).
1060
+ // delete the same read value, or reading values that another execution is currently modifying).
1024
1061
  return this.#putInJobQueue(async jobId => {
1025
1062
  try {
1026
1063
  const totalTimer = new Timer();
@@ -1035,13 +1072,13 @@ export class PXE {
1035
1072
  call.to,
1036
1073
  call.selector,
1037
1074
  (privateSyncCall, execScopes) =>
1038
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1075
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1039
1076
  anchorBlockHeader,
1040
1077
  jobId,
1041
1078
  scopes,
1042
1079
  );
1043
1080
 
1044
- const executionResult = await this.#simulateUtility(
1081
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1045
1082
  contractFunctionSimulator,
1046
1083
  call,
1047
1084
  authwits ?? [],
@@ -1062,14 +1099,19 @@ export class PXE {
1062
1099
  };
1063
1100
 
1064
1101
  const simulationStats = contractFunctionSimulator.getStats();
1065
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1102
+ return {
1103
+ result: executionResult,
1104
+ offchainEffects,
1105
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1106
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1107
+ };
1066
1108
  } catch (err: any) {
1067
1109
  const { to, name, args } = call;
1068
1110
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1069
1111
  throw this.#contextualizeError(
1070
1112
  err,
1071
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1072
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1113
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1114
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1073
1115
  );
1074
1116
  }
1075
1117
  });
@@ -1106,7 +1148,7 @@ export class PXE {
1106
1148
  filter.contractAddress,
1107
1149
  null,
1108
1150
  async (privateSyncCall, execScopes) =>
1109
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1151
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1110
1152
  anchorBlockHeader,
1111
1153
  jobId,
1112
1154
  filter.scopes,
@@ -1124,9 +1166,10 @@ export class PXE {
1124
1166
  }
1125
1167
 
1126
1168
  /**
1127
- * Stops the PXE's job queue.
1169
+ * Stops the PXE's job queue and closes the backing store.
1128
1170
  */
1129
- public stop(): Promise<void> {
1130
- return this.jobQueue.end();
1171
+ public async stop(): Promise<void> {
1172
+ await this.jobQueue.end();
1173
+ await this.db.close();
1131
1174
  }
1132
1175
  }
@@ -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
+ }