@aztec/pxe 0.0.1-commit.87a0206 → 0.0.1-commit.88c5703d4

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 (194) hide show
  1. package/dest/access_scopes.d.ts +9 -0
  2. package/dest/access_scopes.d.ts.map +1 -0
  3. package/dest/access_scopes.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 +60 -30
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.js +183 -72
  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 +2 -3
  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 +5 -4
  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/message_tx_context.d.ts +16 -0
  24. package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts.map +1 -0
  25. package/dest/contract_function_simulator/noir-structs/message_tx_context.js +57 -0
  26. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -4
  27. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +3 -5
  29. package/dest/contract_function_simulator/oracle/interfaces.d.ts +49 -45
  30. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  32. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  33. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +52 -0
  34. package/dest/contract_function_simulator/oracle/oracle.d.ts +44 -44
  35. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/oracle/oracle.js +143 -94
  37. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  38. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +56 -79
  39. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +99 -84
  41. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +73 -43
  42. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +137 -75
  44. package/dest/contract_logging.d.ts +22 -0
  45. package/dest/contract_logging.d.ts.map +1 -0
  46. package/dest/contract_logging.js +23 -0
  47. package/dest/contract_sync/contract_sync_service.d.ts +4 -2
  48. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  49. package/dest/contract_sync/contract_sync_service.js +34 -19
  50. package/dest/contract_sync/helpers.d.ts +3 -2
  51. package/dest/contract_sync/helpers.d.ts.map +1 -1
  52. package/dest/contract_sync/helpers.js +3 -3
  53. package/dest/debug/pxe_debug_utils.d.ts +5 -4
  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 +4 -1
  57. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  58. package/dest/entrypoints/client/bundle/index.js +3 -0
  59. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  60. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  61. package/dest/entrypoints/client/bundle/utils.js +9 -1
  62. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  63. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  64. package/dest/entrypoints/client/lazy/index.js +3 -0
  65. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  66. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  67. package/dest/entrypoints/client/lazy/utils.js +9 -1
  68. package/dest/entrypoints/server/index.d.ts +3 -1
  69. package/dest/entrypoints/server/index.d.ts.map +1 -1
  70. package/dest/entrypoints/server/index.js +2 -0
  71. package/dest/entrypoints/server/utils.js +9 -1
  72. package/dest/logs/log_service.d.ts +3 -2
  73. package/dest/logs/log_service.d.ts.map +1 -1
  74. package/dest/logs/log_service.js +9 -14
  75. package/dest/messages/message_context_service.d.ts +17 -0
  76. package/dest/messages/message_context_service.d.ts.map +1 -0
  77. package/dest/messages/message_context_service.js +36 -0
  78. package/dest/notes/note_service.d.ts +4 -3
  79. package/dest/notes/note_service.d.ts.map +1 -1
  80. package/dest/notes/note_service.js +3 -2
  81. package/dest/notes_filter.d.ts +25 -0
  82. package/dest/notes_filter.d.ts.map +1 -0
  83. package/dest/notes_filter.js +4 -0
  84. package/dest/oracle_version.d.ts +2 -2
  85. package/dest/oracle_version.js +3 -3
  86. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  87. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  88. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  89. package/dest/private_kernel/hints/index.d.ts +1 -1
  90. package/dest/private_kernel/hints/index.js +1 -1
  91. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  92. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  93. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  94. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  95. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  96. package/dest/private_kernel/hints/test_utils.js +203 -0
  97. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  98. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  99. package/dest/private_kernel/private_kernel_execution_prover.js +19 -11
  100. package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
  101. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  102. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  103. package/dest/pxe.d.ts +61 -24
  104. package/dest/pxe.d.ts.map +1 -1
  105. package/dest/pxe.js +91 -65
  106. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  107. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  108. package/dest/storage/contract_store/contract_store.js +140 -64
  109. package/dest/storage/metadata.d.ts +1 -1
  110. package/dest/storage/metadata.js +1 -1
  111. package/dest/storage/note_store/note_store.d.ts +3 -3
  112. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  113. package/dest/storage/note_store/note_store.js +3 -4
  114. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  115. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  116. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  117. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  118. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  119. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  120. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  121. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  122. package/dest/tagging/index.d.ts +3 -3
  123. package/dest/tagging/index.d.ts.map +1 -1
  124. package/dest/tagging/index.js +1 -1
  125. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  126. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  127. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
  128. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  129. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  130. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  131. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  132. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  133. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  134. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  135. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  136. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  137. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  138. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
  139. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  140. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  141. package/package.json +16 -16
  142. package/src/access_scopes.ts +9 -0
  143. package/src/config/index.ts +1 -1
  144. package/src/config/package_info.ts +1 -1
  145. package/src/contract_function_simulator/contract_function_simulator.ts +335 -133
  146. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  147. package/src/contract_function_simulator/index.ts +1 -0
  148. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -5
  149. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
  150. package/src/contract_function_simulator/noir-structs/message_tx_context.ts +55 -0
  151. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -6
  152. package/src/contract_function_simulator/oracle/interfaces.ts +53 -54
  153. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +77 -0
  154. package/src/contract_function_simulator/oracle/oracle.ts +156 -138
  155. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  156. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +125 -176
  157. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +210 -82
  158. package/src/contract_logging.ts +39 -0
  159. package/src/contract_sync/contract_sync_service.ts +49 -26
  160. package/src/contract_sync/helpers.ts +7 -2
  161. package/src/debug/pxe_debug_utils.ts +11 -9
  162. package/src/entrypoints/client/bundle/index.ts +3 -0
  163. package/src/entrypoints/client/bundle/utils.ts +9 -1
  164. package/src/entrypoints/client/lazy/index.ts +3 -0
  165. package/src/entrypoints/client/lazy/utils.ts +9 -1
  166. package/src/entrypoints/server/index.ts +2 -0
  167. package/src/entrypoints/server/utils.ts +7 -7
  168. package/src/logs/log_service.ts +17 -24
  169. package/src/messages/message_context_service.ts +45 -0
  170. package/src/notes/note_service.ts +4 -3
  171. package/src/notes_filter.ts +26 -0
  172. package/src/oracle_version.ts +3 -3
  173. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  174. package/src/private_kernel/hints/index.ts +1 -1
  175. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  176. package/src/private_kernel/hints/test_utils.ts +325 -0
  177. package/src/private_kernel/private_kernel_execution_prover.ts +19 -12
  178. package/src/private_kernel/private_kernel_oracle.ts +7 -7
  179. package/src/pxe.ts +164 -109
  180. package/src/storage/contract_store/contract_store.ts +170 -71
  181. package/src/storage/metadata.ts +1 -1
  182. package/src/storage/note_store/note_store.ts +8 -5
  183. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  184. package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
  185. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  186. package/src/tagging/index.ts +2 -2
  187. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
  188. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  189. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  190. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
  191. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  192. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
  193. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  194. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
package/src/pxe.ts CHANGED
@@ -47,11 +47,12 @@ 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';
55
56
  import { BlockSynchronizer } from './block_synchronizer/index.js';
56
57
  import type { PXEConfig } from './config/index.js';
57
58
  import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
@@ -60,12 +61,14 @@ import {
60
61
  generateSimulatedProvingResult,
61
62
  } from './contract_function_simulator/contract_function_simulator.js';
62
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
64
+ import { displayDebugLogs } from './contract_logging.js';
63
65
  import { ContractSyncService } from './contract_sync/contract_sync_service.js';
64
66
  import { readCurrentClassId } from './contract_sync/helpers.js';
65
67
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
66
68
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
67
69
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
68
70
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
71
+ import { MessageContextService } from './messages/message_context_service.js';
69
72
  import {
70
73
  PrivateKernelExecutionProver,
71
74
  type PrivateKernelExecutionProverConfig,
@@ -86,6 +89,56 @@ export type PackedPrivateEvent = InTx & {
86
89
  eventSelector: EventSelector;
87
90
  };
88
91
 
92
+ /** Options for PXE.profileTx. */
93
+ export type ProfileTxOpts = {
94
+ /** The profiling mode to use. */
95
+ profileMode: 'full' | 'execution-steps' | 'gates';
96
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
97
+ skipProofGeneration?: boolean;
98
+ /** Addresses whose private state and keys are accessible during private execution. */
99
+ scopes: AccessScopes;
100
+ };
101
+
102
+ /** Options for PXE.simulateTx. */
103
+ export type SimulateTxOpts = {
104
+ /** Whether to simulate the public part of the transaction. */
105
+ simulatePublic: boolean;
106
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
107
+ skipTxValidation?: boolean;
108
+ /** If false, fees are enforced. */
109
+ skipFeeEnforcement?: boolean;
110
+ /** State overrides for the simulation, such as contract instances and artifacts. */
111
+ overrides?: SimulationOverrides;
112
+ /** Addresses whose private state and keys are accessible during private execution */
113
+ scopes: AccessScopes;
114
+ };
115
+
116
+ /** Options for PXE.executeUtility. */
117
+ export type ExecuteUtilityOpts = {
118
+ /** The authentication witnesses required for the function call. */
119
+ authwits?: AuthWitness[];
120
+ /** The accounts whose notes we can access in this call */
121
+ scopes: AccessScopes;
122
+ };
123
+
124
+ /** Args for PXE.create. */
125
+ export type PXECreateArgs = {
126
+ /** The Aztec node to connect to. */
127
+ node: AztecNode;
128
+ /** The key-value store for persisting PXE state. */
129
+ store: AztecAsyncKVStore;
130
+ /** The prover for generating private kernel proofs. */
131
+ proofCreator: PrivateKernelProver;
132
+ /** The circuit simulator for executing ACIR circuits. */
133
+ simulator: CircuitSimulator;
134
+ /** Provider for protocol contract artifacts and instances. */
135
+ protocolContractsProvider: ProtocolContractsProvider;
136
+ /** PXE configuration options. */
137
+ config: PXEConfig;
138
+ /** Optional logger instance or string suffix for the logger name. */
139
+ loggerOrSuffix?: string | Logger;
140
+ };
141
+
89
142
  /**
90
143
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
91
144
  * manage private state of users.
@@ -93,6 +146,7 @@ export type PackedPrivateEvent = InTx & {
93
146
  export class PXE {
94
147
  private constructor(
95
148
  private node: AztecNode,
149
+ private db: AztecAsyncKVStore,
96
150
  private blockStateSynchronizer: BlockSynchronizer,
97
151
  private keyStore: KeyStore,
98
152
  private contractStore: ContractStore,
@@ -105,6 +159,7 @@ export class PXE {
105
159
  private addressStore: AddressStore,
106
160
  private privateEventStore: PrivateEventStore,
107
161
  private contractSyncService: ContractSyncService,
162
+ private messageContextService: MessageContextService,
108
163
  private simulator: CircuitSimulator,
109
164
  private proverEnabled: boolean,
110
165
  private proofCreator: PrivateKernelProver,
@@ -122,15 +177,15 @@ export class PXE {
122
177
  *
123
178
  * @returns A promise that resolves PXE is ready to be used.
124
179
  */
125
- public static async create(
126
- node: AztecNode,
127
- store: AztecAsyncKVStore,
128
- proofCreator: PrivateKernelProver,
129
- simulator: CircuitSimulator,
130
- protocolContractsProvider: ProtocolContractsProvider,
131
- config: PXEConfig,
132
- loggerOrSuffix?: string | Logger,
133
- ) {
180
+ public static async create({
181
+ node,
182
+ store,
183
+ proofCreator,
184
+ simulator,
185
+ protocolContractsProvider,
186
+ config,
187
+ loggerOrSuffix,
188
+ }: PXECreateArgs) {
134
189
  // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
135
190
  const bindings: LoggerBindings | undefined =
136
191
  loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
@@ -140,7 +195,9 @@ export class PXE {
140
195
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
141
196
  : loggerOrSuffix;
142
197
 
143
- const proverEnabled = !!config.proverEnabled;
198
+ const info = await node.getNodeInfo();
199
+
200
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
144
201
  const addressStore = new AddressStore(store);
145
202
  const privateEventStore = new PrivateEventStore(store);
146
203
  const contractStore = new ContractStore(store);
@@ -158,6 +215,8 @@ export class PXE {
158
215
  noteStore,
159
216
  createLogger('pxe:contract_sync', bindings),
160
217
  );
218
+ const messageContextService = new MessageContextService(node);
219
+
161
220
  const synchronizer = new BlockSynchronizer(
162
221
  node,
163
222
  store,
@@ -186,6 +245,7 @@ export class PXE {
186
245
 
187
246
  const pxe = new PXE(
188
247
  node,
248
+ store,
189
249
  synchronizer,
190
250
  keyStore,
191
251
  contractStore,
@@ -198,6 +258,7 @@ export class PXE {
198
258
  addressStore,
199
259
  privateEventStore,
200
260
  contractSyncService,
261
+ messageContextService,
201
262
  simulator,
202
263
  proverEnabled,
203
264
  proofCreator,
@@ -211,13 +272,12 @@ export class PXE {
211
272
  debugUtils.setPXEHelpers(
212
273
  pxe.#putInJobQueue.bind(pxe),
213
274
  pxe.#getSimulatorForTx.bind(pxe),
214
- pxe.#simulateUtility.bind(pxe),
275
+ pxe.#executeUtility.bind(pxe),
215
276
  );
216
277
 
217
278
  pxe.jobQueue.start();
218
279
 
219
280
  await pxe.#registerProtocolContracts();
220
- const info = await node.getNodeInfo();
221
281
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
222
282
  return pxe;
223
283
  }
@@ -227,20 +287,21 @@ export class PXE {
227
287
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
228
288
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
229
289
 
230
- return new ContractFunctionSimulator(
231
- proxyContractStore,
232
- this.noteStore,
233
- this.keyStore,
234
- this.addressStore,
235
- BenchmarkedNodeFactory.create(this.node),
236
- this.senderTaggingStore,
237
- this.recipientTaggingStore,
238
- this.senderAddressBookStore,
239
- this.capsuleStore,
240
- this.privateEventStore,
241
- this.simulator,
242
- this.contractSyncService,
243
- );
290
+ return new ContractFunctionSimulator({
291
+ contractStore: proxyContractStore,
292
+ noteStore: this.noteStore,
293
+ keyStore: this.keyStore,
294
+ addressStore: this.addressStore,
295
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
296
+ senderTaggingStore: this.senderTaggingStore,
297
+ recipientTaggingStore: this.recipientTaggingStore,
298
+ senderAddressBookStore: this.senderAddressBookStore,
299
+ capsuleStore: this.capsuleStore,
300
+ privateEventStore: this.privateEventStore,
301
+ simulator: this.simulator,
302
+ contractSyncService: this.contractSyncService,
303
+ messageContextService: this.messageContextService,
304
+ });
244
305
  }
245
306
 
246
307
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -292,9 +353,8 @@ export class PXE {
292
353
  async #registerProtocolContracts() {
293
354
  const registered: Record<string, string> = {};
294
355
  for (const name of protocolContractNames) {
295
- const { address, contractClass, instance, artifact } =
296
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
297
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
356
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
357
+ await this.contractStore.addContractArtifact(artifact);
298
358
  await this.contractStore.addContractInstance(instance);
299
359
  registered[name] = address.toString();
300
360
  }
@@ -306,7 +366,7 @@ export class PXE {
306
366
  async #executePrivate(
307
367
  contractFunctionSimulator: ContractFunctionSimulator,
308
368
  txRequest: TxExecutionRequest,
309
- scopes: AztecAddress[] | undefined,
369
+ scopes: AccessScopes,
310
370
  jobId: string,
311
371
  ): Promise<PrivateExecutionResult> {
312
372
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -317,23 +377,20 @@ export class PXE {
317
377
  await this.contractSyncService.ensureContractSynced(
318
378
  contractAddress,
319
379
  functionSelector,
320
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
380
+ (privateSyncCall, execScopes) =>
381
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
321
382
  anchorBlockHeader,
322
383
  jobId,
384
+ scopes,
323
385
  );
324
386
 
325
- const result = await contractFunctionSimulator.run(
326
- txRequest,
387
+ const result = await contractFunctionSimulator.run(txRequest, {
327
388
  contractAddress,
328
- functionSelector,
329
- undefined,
389
+ selector: functionSelector,
330
390
  anchorBlockHeader,
331
- // The sender for tags is set by contracts, typically by an account
332
- // contract entrypoint
333
- undefined, // senderForTags
334
391
  scopes,
335
392
  jobId,
336
- );
393
+ });
337
394
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
338
395
  return result;
339
396
  } catch (err) {
@@ -345,25 +402,32 @@ export class PXE {
345
402
  }
346
403
 
347
404
  /**
348
- * Simulate a utility function call on the given contract.
405
+ * Execute a utility function call on the given contract.
349
406
  * @param contractFunctionSimulator - The simulator to use for the function call.
350
407
  * @param call - The function call to execute.
351
408
  * @param authWitnesses - Authentication witnesses required for the function call.
352
409
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
353
410
  * accounts if not specified.
354
411
  * @param jobId - The job ID for staged writes.
355
- * @returns The simulation result containing the outputs of the utility function.
412
+ * @returns The execution result containing the outputs of the utility function.
356
413
  */
357
- async #simulateUtility(
414
+ async #executeUtility(
358
415
  contractFunctionSimulator: ContractFunctionSimulator,
359
416
  call: FunctionCall,
360
417
  authWitnesses: AuthWitness[] | undefined,
361
- scopes: AztecAddress[] | undefined,
418
+ scopes: AccessScopes,
362
419
  jobId: string,
363
420
  ) {
364
421
  try {
365
422
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
366
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
423
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
424
+ call,
425
+ authWitnesses ?? [],
426
+ anchorBlockHeader,
427
+ scopes,
428
+ jobId,
429
+ );
430
+ return { result, offchainEffects };
367
431
  } catch (err) {
368
432
  if (err instanceof SimulationError) {
369
433
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -552,8 +616,7 @@ export class PXE {
552
616
  * @param artifact - The build artifact for the contract class.
553
617
  */
554
618
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
555
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
556
- await this.contractStore.addContractArtifact(contractClassId, artifact);
619
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
557
620
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
558
621
  }
559
622
 
@@ -572,17 +635,17 @@ export class PXE {
572
635
  if (artifact) {
573
636
  // If the user provides an artifact, validate it against the expected class id and register it
574
637
  const contractClass = await getContractClassFromArtifact(artifact);
575
- const contractClassId = contractClass.id;
576
- if (!contractClassId.equals(instance.currentContractClassId)) {
638
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
577
639
  throw new Error(
578
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
640
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
579
641
  );
580
642
  }
581
643
  const computedAddress = await computeContractAddressFromInstance(instance);
582
644
  if (!computedAddress.equals(instance.address)) {
583
645
  throw new Error('Added a contract in which the address does not match the contract instance.');
584
646
  }
585
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
647
+
648
+ await this.contractStore.addContractArtifact(artifact, contractClass);
586
649
 
587
650
  const publicFunctionSignatures = artifact.functions
588
651
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -631,15 +694,16 @@ export class PXE {
631
694
  throw new Error('Could not update contract to a class different from the current one.');
632
695
  }
633
696
 
634
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
635
-
636
697
  const publicFunctionSignatures = artifact.functions
637
698
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
638
699
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
639
700
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
640
701
 
641
702
  currentInstance.currentContractClassId = contractClass.id;
642
- await this.contractStore.addContractInstance(currentInstance);
703
+ await Promise.all([
704
+ this.contractStore.addContractArtifact(artifact, contractClass),
705
+ this.contractStore.addContractInstance(currentInstance),
706
+ ]);
643
707
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
644
708
  });
645
709
  }
@@ -657,11 +721,12 @@ export class PXE {
657
721
  * (where validators prove the public portion).
658
722
  *
659
723
  * @param txRequest - An authenticated tx request ready for proving
724
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
660
725
  * @returns A result containing the proof and public inputs of the tail circuit.
661
726
  * @throws If contract code not found, or public simulation reverts.
662
727
  * Also throws if simulatePublic is true and public simulation reverts.
663
728
  */
664
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
729
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
665
730
  let privateExecutionResult: PrivateExecutionResult;
666
731
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
667
732
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -672,7 +737,7 @@ export class PXE {
672
737
  await this.blockStateSynchronizer.sync();
673
738
  const syncTime = syncTimer.ms();
674
739
  const contractFunctionSimulator = this.#getSimulatorForTx();
675
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
740
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
676
741
 
677
742
  const {
678
743
  publicInputs,
@@ -714,17 +779,17 @@ export class PXE {
714
779
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
715
780
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
716
781
  // storing the tags here prevents linkage of txs sent from the same PXE.
717
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
718
- if (preTagsUsedInTheTx.length > 0) {
782
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
783
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
719
784
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
720
785
  const txHash = (await txProvingResult.toTx()).txHash;
721
786
 
722
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
723
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
724
- preTagsUsedInTheTx,
787
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
788
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
789
+ taggingIndexRangesUsedInTheTx,
725
790
  });
726
791
  } else {
727
- this.log.debug(`No pre-tags used in the tx`);
792
+ this.log.debug(`No tagging index ranges used in the tx`);
728
793
  }
729
794
 
730
795
  return txProvingResult;
@@ -736,17 +801,13 @@ export class PXE {
736
801
 
737
802
  /**
738
803
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
739
- *
740
- * @param txRequest - An authenticated tx request ready for simulation
741
- * @param msgSender - (Optional) The message sender to use for the simulation.
742
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
804
+ * @param txRequest - An authenticated tx request ready for simulation.
743
805
  * @returns A trace of the program execution with gate counts.
744
806
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
745
807
  */
746
808
  public profileTx(
747
809
  txRequest: TxExecutionRequest,
748
- profileMode: 'full' | 'execution-steps' | 'gates',
749
- skipProofGeneration: boolean = true,
810
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
750
811
  ): Promise<TxProfileResult> {
751
812
  // We disable concurrent profiles for consistency with simulateTx.
752
813
  return this.#putInJobQueue(async jobId => {
@@ -769,12 +830,7 @@ export class PXE {
769
830
  const syncTime = syncTimer.ms();
770
831
 
771
832
  const contractFunctionSimulator = this.#getSimulatorForTx();
772
- const privateExecutionResult = await this.#executePrivate(
773
- contractFunctionSimulator,
774
- txRequest,
775
- undefined,
776
- jobId,
777
- );
833
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
778
834
 
779
835
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
780
836
  txRequest,
@@ -831,12 +887,7 @@ export class PXE {
831
887
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
832
888
  *
833
889
  *
834
- * @param txRequest - An authenticated tx request ready for simulation
835
- * @param simulatePublic - Whether to simulate the public part of the transaction.
836
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
837
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
838
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
839
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
890
+ * @param txRequest - An authenticated tx request ready for simulation.
840
891
  * @returns A simulated transaction result object that includes public and private return values.
841
892
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
842
893
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -845,11 +896,7 @@ export class PXE {
845
896
  */
846
897
  public simulateTx(
847
898
  txRequest: TxExecutionRequest,
848
- simulatePublic: boolean,
849
- skipTxValidation: boolean = false,
850
- skipFeeEnforcement: boolean = false,
851
- overrides?: SimulationOverrides,
852
- scopes?: AztecAddress[],
899
+ { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
853
900
  ): Promise<TxSimulationResult> {
854
901
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
855
902
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -896,6 +943,7 @@ export class PXE {
896
943
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
897
944
  privateExecutionResult,
898
945
  (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
946
+ this.node,
899
947
  ));
900
948
  } else {
901
949
  // Kernel logic, plus proving of all private functions and kernels.
@@ -914,6 +962,9 @@ export class PXE {
914
962
  const publicSimulationTimer = new Timer();
915
963
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
916
964
  publicSimulationTime = publicSimulationTimer.ms();
965
+ if (publicOutput?.debugLogs?.length) {
966
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
967
+ }
917
968
  }
918
969
 
919
970
  let validationTime: number | undefined;
@@ -922,7 +973,8 @@ export class PXE {
922
973
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
923
974
  validationTime = validationTimer.ms();
924
975
  if (validationResult.result === 'invalid') {
925
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
976
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
977
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
926
978
  }
927
979
  }
928
980
 
@@ -973,29 +1025,23 @@ export class PXE {
973
1025
  inspect(txRequest),
974
1026
  `simulatePublic=${simulatePublic}`,
975
1027
  `skipTxValidation=${skipTxValidation}`,
976
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1028
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
977
1029
  );
978
1030
  }
979
1031
  });
980
1032
  }
981
1033
 
982
1034
  /**
983
- * Simulate the execution of a contract utility function.
984
- *
1035
+ * Executes a contract utility function.
985
1036
  * @param call - The function call containing the function details, arguments, and target contract address.
986
- * @param authwits - (Optional) The authentication witnesses required for the function call.
987
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
988
- * default to all.
989
- * @returns The result of the utility function call, structured based on the function ABI.
990
1037
  */
991
- public simulateUtility(
1038
+ public executeUtility(
992
1039
  call: FunctionCall,
993
- authwits?: AuthWitness[],
994
- scopes?: AztecAddress[],
995
- ): Promise<UtilitySimulationResult> {
996
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1040
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
1041
+ ): Promise<UtilityExecutionResult> {
1042
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
997
1043
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
998
- // delete the same read value, or reading values that another simulation is currently modifying).
1044
+ // delete the same read value, or reading values that another execution is currently modifying).
999
1045
  return this.#putInJobQueue(async jobId => {
1000
1046
  try {
1001
1047
  const totalTimer = new Timer();
@@ -1009,12 +1055,14 @@ export class PXE {
1009
1055
  await this.contractSyncService.ensureContractSynced(
1010
1056
  call.to,
1011
1057
  call.selector,
1012
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1058
+ (privateSyncCall, execScopes) =>
1059
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1013
1060
  anchorBlockHeader,
1014
1061
  jobId,
1062
+ scopes,
1015
1063
  );
1016
1064
 
1017
- const executionResult = await this.#simulateUtility(
1065
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1018
1066
  contractFunctionSimulator,
1019
1067
  call,
1020
1068
  authwits ?? [],
@@ -1035,14 +1083,19 @@ export class PXE {
1035
1083
  };
1036
1084
 
1037
1085
  const simulationStats = contractFunctionSimulator.getStats();
1038
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1086
+ return {
1087
+ result: executionResult,
1088
+ offchainEffects,
1089
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1090
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1091
+ };
1039
1092
  } catch (err: any) {
1040
1093
  const { to, name, args } = call;
1041
1094
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1042
1095
  throw this.#contextualizeError(
1043
1096
  err,
1044
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1045
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1097
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1098
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1046
1099
  );
1047
1100
  }
1048
1101
  });
@@ -1078,10 +1131,11 @@ export class PXE {
1078
1131
  await this.contractSyncService.ensureContractSynced(
1079
1132
  filter.contractAddress,
1080
1133
  null,
1081
- async privateSyncCall =>
1082
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1134
+ async (privateSyncCall, execScopes) =>
1135
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1083
1136
  anchorBlockHeader,
1084
1137
  jobId,
1138
+ filter.scopes,
1085
1139
  );
1086
1140
  });
1087
1141
 
@@ -1096,9 +1150,10 @@ export class PXE {
1096
1150
  }
1097
1151
 
1098
1152
  /**
1099
- * Stops the PXE's job queue.
1153
+ * Stops the PXE's job queue and closes the backing store.
1100
1154
  */
1101
- public stop(): Promise<void> {
1102
- return this.jobQueue.end();
1155
+ public async stop(): Promise<void> {
1156
+ await this.jobQueue.end();
1157
+ await this.db.close();
1103
1158
  }
1104
1159
  }