@aztec/pxe 0.0.1-commit.6b90f3f5 → 0.0.1-commit.6c354eb4c

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 (166) 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/block_synchronizer/block_synchronizer.d.ts +4 -2
  5. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  6. package/dest/block_synchronizer/block_synchronizer.js +7 -1
  7. package/dest/config/package_info.js +1 -1
  8. package/dest/contract_function_simulator/contract_function_simulator.d.ts +54 -28
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.js +174 -68
  11. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
  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 +3 -3
  14. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  15. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -2
  16. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  18. package/dest/contract_function_simulator/oracle/interfaces.d.ts +9 -9
  19. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/oracle/oracle.d.ts +5 -5
  21. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/oracle.js +32 -20
  23. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +36 -35
  24. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +73 -28
  26. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +48 -22
  27. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +78 -55
  29. package/dest/contract_logging.d.ts +22 -0
  30. package/dest/contract_logging.d.ts.map +1 -0
  31. package/dest/contract_logging.js +23 -0
  32. package/dest/contract_sync/contract_sync_service.d.ts +43 -0
  33. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  34. package/dest/contract_sync/contract_sync_service.js +97 -0
  35. package/dest/contract_sync/helpers.d.ts +29 -0
  36. package/dest/contract_sync/helpers.d.ts.map +1 -0
  37. package/dest/contract_sync/{index.js → helpers.js} +13 -12
  38. package/dest/debug/pxe_debug_utils.d.ts +14 -10
  39. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  40. package/dest/debug/pxe_debug_utils.js +16 -15
  41. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  42. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  43. package/dest/entrypoints/client/bundle/index.js +3 -0
  44. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  45. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  46. package/dest/entrypoints/client/bundle/utils.js +9 -1
  47. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  48. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  49. package/dest/entrypoints/client/lazy/index.js +3 -0
  50. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  51. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  52. package/dest/entrypoints/client/lazy/utils.js +9 -1
  53. package/dest/entrypoints/server/index.d.ts +4 -2
  54. package/dest/entrypoints/server/index.d.ts.map +1 -1
  55. package/dest/entrypoints/server/index.js +3 -1
  56. package/dest/entrypoints/server/utils.js +9 -1
  57. package/dest/logs/log_service.d.ts +3 -2
  58. package/dest/logs/log_service.d.ts.map +1 -1
  59. package/dest/logs/log_service.js +11 -18
  60. package/dest/notes/note_service.d.ts +4 -3
  61. package/dest/notes/note_service.d.ts.map +1 -1
  62. package/dest/notes/note_service.js +3 -2
  63. package/dest/notes_filter.d.ts +25 -0
  64. package/dest/notes_filter.d.ts.map +1 -0
  65. package/dest/notes_filter.js +4 -0
  66. package/dest/oracle_version.d.ts +3 -3
  67. package/dest/oracle_version.d.ts.map +1 -1
  68. package/dest/oracle_version.js +2 -2
  69. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  70. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  71. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  72. package/dest/private_kernel/hints/index.d.ts +1 -1
  73. package/dest/private_kernel/hints/index.js +1 -1
  74. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  75. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  76. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  77. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  78. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  79. package/dest/private_kernel/hints/test_utils.js +203 -0
  80. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  81. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  82. package/dest/private_kernel/private_kernel_execution_prover.js +19 -11
  83. package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
  84. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  85. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  86. package/dest/pxe.d.ts +69 -23
  87. package/dest/pxe.d.ts.map +1 -1
  88. package/dest/pxe.js +94 -61
  89. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  90. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  91. package/dest/storage/contract_store/contract_store.js +145 -69
  92. package/dest/storage/note_store/note_store.d.ts +3 -3
  93. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  94. package/dest/storage/note_store/note_store.js +6 -4
  95. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  96. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  97. package/dest/storage/tagging_store/sender_tagging_store.d.ts +5 -5
  98. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  99. package/dest/storage/tagging_store/sender_tagging_store.js +4 -4
  100. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  101. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  102. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  103. package/dest/tagging/index.d.ts +2 -2
  104. package/dest/tagging/index.d.ts.map +1 -1
  105. package/dest/tagging/index.js +1 -1
  106. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  107. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  108. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
  109. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  110. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  111. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  112. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  113. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  114. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  115. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +3 -6
  116. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +4 -7
  117. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  118. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +14 -15
  119. package/package.json +25 -16
  120. package/src/access_scopes.ts +9 -0
  121. package/src/block_synchronizer/block_synchronizer.ts +6 -0
  122. package/src/config/package_info.ts +1 -1
  123. package/src/contract_function_simulator/contract_function_simulator.ts +323 -128
  124. package/src/contract_function_simulator/execution_tagging_index_cache.ts +5 -5
  125. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  126. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  127. package/src/contract_function_simulator/oracle/interfaces.ts +10 -10
  128. package/src/contract_function_simulator/oracle/oracle.ts +35 -18
  129. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +99 -105
  130. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +125 -56
  131. package/src/contract_logging.ts +39 -0
  132. package/src/contract_sync/contract_sync_service.ts +152 -0
  133. package/src/contract_sync/{index.ts → helpers.ts} +21 -21
  134. package/src/debug/pxe_debug_utils.ts +48 -18
  135. package/src/entrypoints/client/bundle/index.ts +3 -0
  136. package/src/entrypoints/client/bundle/utils.ts +9 -1
  137. package/src/entrypoints/client/lazy/index.ts +3 -0
  138. package/src/entrypoints/client/lazy/utils.ts +9 -1
  139. package/src/entrypoints/server/index.ts +3 -1
  140. package/src/entrypoints/server/utils.ts +7 -7
  141. package/src/logs/log_service.ts +18 -25
  142. package/src/notes/note_service.ts +4 -3
  143. package/src/notes_filter.ts +26 -0
  144. package/src/oracle_version.ts +2 -2
  145. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  146. package/src/private_kernel/hints/index.ts +1 -1
  147. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  148. package/src/private_kernel/hints/test_utils.ts +325 -0
  149. package/src/private_kernel/private_kernel_execution_prover.ts +19 -12
  150. package/src/private_kernel/private_kernel_oracle.ts +7 -7
  151. package/src/pxe.ts +178 -110
  152. package/src/storage/contract_store/contract_store.ts +174 -75
  153. package/src/storage/note_store/note_store.ts +12 -5
  154. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  155. package/src/storage/tagging_store/sender_tagging_store.ts +8 -8
  156. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  157. package/src/tagging/index.ts +1 -1
  158. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
  159. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  160. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  161. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +4 -9
  162. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +11 -20
  163. package/dest/contract_sync/index.d.ts +0 -23
  164. package/dest/contract_sync/index.d.ts.map +0 -1
  165. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  166. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
package/src/pxe.ts CHANGED
@@ -33,6 +33,7 @@ import type {
33
33
  PrivateKernelTailCircuitPublicInputs,
34
34
  } from '@aztec/stdlib/kernel';
35
35
  import {
36
+ BlockHeader,
36
37
  type ContractOverrides,
37
38
  type InTx,
38
39
  PrivateExecutionResult,
@@ -46,11 +47,12 @@ import {
46
47
  TxProfileResult,
47
48
  TxProvingResult,
48
49
  TxSimulationResult,
49
- UtilitySimulationResult,
50
+ UtilityExecutionResult,
50
51
  } from '@aztec/stdlib/tx';
51
52
 
52
53
  import { inspect } from 'util';
53
54
 
55
+ import type { AccessScopes } from './access_scopes.js';
54
56
  import { BlockSynchronizer } from './block_synchronizer/index.js';
55
57
  import type { PXEConfig } from './config/index.js';
56
58
  import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
@@ -59,7 +61,9 @@ import {
59
61
  generateSimulatedProvingResult,
60
62
  } from './contract_function_simulator/contract_function_simulator.js';
61
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
62
- import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
64
+ import { displayDebugLogs } from './contract_logging.js';
65
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
66
+ import { readCurrentClassId } from './contract_sync/helpers.js';
63
67
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
64
68
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
65
69
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
@@ -84,6 +88,56 @@ export type PackedPrivateEvent = InTx & {
84
88
  eventSelector: EventSelector;
85
89
  };
86
90
 
91
+ /** Options for PXE.profileTx. */
92
+ export type ProfileTxOpts = {
93
+ /** The profiling mode to use. */
94
+ profileMode: 'full' | 'execution-steps' | 'gates';
95
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
96
+ skipProofGeneration?: boolean;
97
+ /** Addresses whose private state and keys are accessible during private execution. */
98
+ scopes: AccessScopes;
99
+ };
100
+
101
+ /** Options for PXE.simulateTx. */
102
+ export type SimulateTxOpts = {
103
+ /** Whether to simulate the public part of the transaction. */
104
+ simulatePublic: boolean;
105
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
106
+ skipTxValidation?: boolean;
107
+ /** If false, fees are enforced. */
108
+ skipFeeEnforcement?: boolean;
109
+ /** State overrides for the simulation, such as contract instances and artifacts. */
110
+ overrides?: SimulationOverrides;
111
+ /** Addresses whose private state and keys are accessible during private execution */
112
+ scopes: AccessScopes;
113
+ };
114
+
115
+ /** Options for PXE.executeUtility. */
116
+ export type ExecuteUtilityOpts = {
117
+ /** The authentication witnesses required for the function call. */
118
+ authwits?: AuthWitness[];
119
+ /** The accounts whose notes we can access in this call */
120
+ scopes: AccessScopes;
121
+ };
122
+
123
+ /** Args for PXE.create. */
124
+ export type PXECreateArgs = {
125
+ /** The Aztec node to connect to. */
126
+ node: AztecNode;
127
+ /** The key-value store for persisting PXE state. */
128
+ store: AztecAsyncKVStore;
129
+ /** The prover for generating private kernel proofs. */
130
+ proofCreator: PrivateKernelProver;
131
+ /** The circuit simulator for executing ACIR circuits. */
132
+ simulator: CircuitSimulator;
133
+ /** Provider for protocol contract artifacts and instances. */
134
+ protocolContractsProvider: ProtocolContractsProvider;
135
+ /** PXE configuration options. */
136
+ config: PXEConfig;
137
+ /** Optional logger instance or string suffix for the logger name. */
138
+ loggerOrSuffix?: string | Logger;
139
+ };
140
+
87
141
  /**
88
142
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
89
143
  * manage private state of users.
@@ -102,6 +156,7 @@ export class PXE {
102
156
  private recipientTaggingStore: RecipientTaggingStore,
103
157
  private addressStore: AddressStore,
104
158
  private privateEventStore: PrivateEventStore,
159
+ private contractSyncService: ContractSyncService,
105
160
  private simulator: CircuitSimulator,
106
161
  private proverEnabled: boolean,
107
162
  private proofCreator: PrivateKernelProver,
@@ -119,15 +174,15 @@ export class PXE {
119
174
  *
120
175
  * @returns A promise that resolves PXE is ready to be used.
121
176
  */
122
- public static async create(
123
- node: AztecNode,
124
- store: AztecAsyncKVStore,
125
- proofCreator: PrivateKernelProver,
126
- simulator: CircuitSimulator,
127
- protocolContractsProvider: ProtocolContractsProvider,
128
- config: PXEConfig,
129
- loggerOrSuffix?: string | Logger,
130
- ) {
177
+ public static async create({
178
+ node,
179
+ store,
180
+ proofCreator,
181
+ simulator,
182
+ protocolContractsProvider,
183
+ config,
184
+ loggerOrSuffix,
185
+ }: PXECreateArgs) {
131
186
  // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
132
187
  const bindings: LoggerBindings | undefined =
133
188
  loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
@@ -137,7 +192,9 @@ export class PXE {
137
192
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
138
193
  : loggerOrSuffix;
139
194
 
140
- const proverEnabled = !!config.proverEnabled;
195
+ const info = await node.getNodeInfo();
196
+
197
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
141
198
  const addressStore = new AddressStore(store);
142
199
  const privateEventStore = new PrivateEventStore(store);
143
200
  const contractStore = new ContractStore(store);
@@ -149,6 +206,12 @@ export class PXE {
149
206
  const capsuleStore = new CapsuleStore(store);
150
207
  const keyStore = new KeyStore(store);
151
208
  const tipsStore = new L2TipsKVStore(store, 'pxe');
209
+ const contractSyncService = new ContractSyncService(
210
+ node,
211
+ contractStore,
212
+ noteStore,
213
+ createLogger('pxe:contract_sync', bindings),
214
+ );
152
215
  const synchronizer = new BlockSynchronizer(
153
216
  node,
154
217
  store,
@@ -156,6 +219,7 @@ export class PXE {
156
219
  noteStore,
157
220
  privateEventStore,
158
221
  tipsStore,
222
+ contractSyncService,
159
223
  config,
160
224
  bindings,
161
225
  );
@@ -167,9 +231,10 @@ export class PXE {
167
231
  recipientTaggingStore,
168
232
  privateEventStore,
169
233
  noteStore,
234
+ contractSyncService,
170
235
  ]);
171
236
 
172
- const debugUtils = new PXEDebugUtils(contractStore, noteStore, synchronizer, anchorBlockStore);
237
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
173
238
 
174
239
  const jobQueue = new SerialQueue();
175
240
 
@@ -186,6 +251,7 @@ export class PXE {
186
251
  recipientTaggingStore,
187
252
  addressStore,
188
253
  privateEventStore,
254
+ contractSyncService,
189
255
  simulator,
190
256
  proverEnabled,
191
257
  proofCreator,
@@ -196,12 +262,15 @@ export class PXE {
196
262
  debugUtils,
197
263
  );
198
264
 
199
- debugUtils.setPXE(pxe, pxe.#putInJobQueue.bind(pxe));
265
+ debugUtils.setPXEHelpers(
266
+ pxe.#putInJobQueue.bind(pxe),
267
+ pxe.#getSimulatorForTx.bind(pxe),
268
+ pxe.#executeUtility.bind(pxe),
269
+ );
200
270
 
201
271
  pxe.jobQueue.start();
202
272
 
203
273
  await pxe.#registerProtocolContracts();
204
- const info = await node.getNodeInfo();
205
274
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
206
275
  return pxe;
207
276
  }
@@ -211,19 +280,20 @@ export class PXE {
211
280
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
212
281
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
213
282
 
214
- return new ContractFunctionSimulator(
215
- proxyContractStore,
216
- this.noteStore,
217
- this.keyStore,
218
- this.addressStore,
219
- BenchmarkedNodeFactory.create(this.node),
220
- this.senderTaggingStore,
221
- this.recipientTaggingStore,
222
- this.senderAddressBookStore,
223
- this.capsuleStore,
224
- this.privateEventStore,
225
- this.simulator,
226
- );
283
+ return new ContractFunctionSimulator({
284
+ contractStore: proxyContractStore,
285
+ noteStore: this.noteStore,
286
+ keyStore: this.keyStore,
287
+ addressStore: this.addressStore,
288
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
289
+ senderTaggingStore: this.senderTaggingStore,
290
+ recipientTaggingStore: this.recipientTaggingStore,
291
+ senderAddressBookStore: this.senderAddressBookStore,
292
+ capsuleStore: this.capsuleStore,
293
+ privateEventStore: this.privateEventStore,
294
+ simulator: this.simulator,
295
+ contractSyncService: this.contractSyncService,
296
+ });
227
297
  }
228
298
 
229
299
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -275,9 +345,8 @@ export class PXE {
275
345
  async #registerProtocolContracts() {
276
346
  const registered: Record<string, string> = {};
277
347
  for (const name of protocolContractNames) {
278
- const { address, contractClass, instance, artifact } =
279
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
280
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
348
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
349
+ await this.contractStore.addContractArtifact(artifact);
281
350
  await this.contractStore.addContractInstance(instance);
282
351
  registered[name] = address.toString();
283
352
  }
@@ -289,7 +358,7 @@ export class PXE {
289
358
  async #executePrivate(
290
359
  contractFunctionSimulator: ContractFunctionSimulator,
291
360
  txRequest: TxExecutionRequest,
292
- scopes: AztecAddress[] | undefined,
361
+ scopes: AccessScopes,
293
362
  jobId: string,
294
363
  ): Promise<PrivateExecutionResult> {
295
364
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -297,27 +366,23 @@ export class PXE {
297
366
  try {
298
367
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
299
368
 
300
- await ensureContractSynced(
369
+ await this.contractSyncService.ensureContractSynced(
301
370
  contractAddress,
302
371
  functionSelector,
303
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
304
- this.node,
305
- this.contractStore,
372
+ (privateSyncCall, execScopes) =>
373
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
306
374
  anchorBlockHeader,
375
+ jobId,
376
+ scopes,
307
377
  );
308
378
 
309
- const result = await contractFunctionSimulator.run(
310
- txRequest,
379
+ const result = await contractFunctionSimulator.run(txRequest, {
311
380
  contractAddress,
312
- functionSelector,
313
- undefined,
381
+ selector: functionSelector,
314
382
  anchorBlockHeader,
315
- // The sender for tags is set by contracts, typically by an account
316
- // contract entrypoint
317
- undefined, // senderForTags
318
383
  scopes,
319
384
  jobId,
320
- );
385
+ });
321
386
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
322
387
  return result;
323
388
  } catch (err) {
@@ -329,20 +394,20 @@ export class PXE {
329
394
  }
330
395
 
331
396
  /**
332
- * Simulate a utility function call on the given contract.
397
+ * Execute a utility function call on the given contract.
333
398
  * @param contractFunctionSimulator - The simulator to use for the function call.
334
399
  * @param call - The function call to execute.
335
400
  * @param authWitnesses - Authentication witnesses required for the function call.
336
401
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
337
402
  * accounts if not specified.
338
403
  * @param jobId - The job ID for staged writes.
339
- * @returns The simulation result containing the outputs of the utility function.
404
+ * @returns The execution result containing the outputs of the utility function.
340
405
  */
341
- async #simulateUtility(
406
+ async #executeUtility(
342
407
  contractFunctionSimulator: ContractFunctionSimulator,
343
408
  call: FunctionCall,
344
409
  authWitnesses: AuthWitness[] | undefined,
345
- scopes: AztecAddress[] | undefined,
410
+ scopes: AccessScopes,
346
411
  jobId: string,
347
412
  ) {
348
413
  try {
@@ -415,6 +480,19 @@ export class PXE {
415
480
 
416
481
  // Public API
417
482
 
483
+ /**
484
+ * Returns the block header up to which the PXE has synced.
485
+ * @returns The synced block header
486
+ */
487
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
488
+ return this.anchorBlockStore.getBlockHeader();
489
+ }
490
+
491
+ /**
492
+ * Returns the contract instance for a given address, if it's registered in the PXE.
493
+ * @param address - The contract address.
494
+ * @returns The contract instance if found, undefined otherwise.
495
+ */
418
496
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
419
497
  return this.contractStore.getContractInstance(address);
420
498
  }
@@ -523,8 +601,7 @@ export class PXE {
523
601
  * @param artifact - The build artifact for the contract class.
524
602
  */
525
603
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
526
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
527
- await this.contractStore.addContractArtifact(contractClassId, artifact);
604
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
528
605
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
529
606
  }
530
607
 
@@ -543,17 +620,17 @@ export class PXE {
543
620
  if (artifact) {
544
621
  // If the user provides an artifact, validate it against the expected class id and register it
545
622
  const contractClass = await getContractClassFromArtifact(artifact);
546
- const contractClassId = contractClass.id;
547
- if (!contractClassId.equals(instance.currentContractClassId)) {
623
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
548
624
  throw new Error(
549
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
625
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
550
626
  );
551
627
  }
552
628
  const computedAddress = await computeContractAddressFromInstance(instance);
553
629
  if (!computedAddress.equals(instance.address)) {
554
630
  throw new Error('Added a contract in which the address does not match the contract instance.');
555
631
  }
556
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
632
+
633
+ await this.contractStore.addContractArtifact(artifact, contractClass);
557
634
 
558
635
  const publicFunctionSignatures = artifact.functions
559
636
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -602,15 +679,16 @@ export class PXE {
602
679
  throw new Error('Could not update contract to a class different from the current one.');
603
680
  }
604
681
 
605
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
606
-
607
682
  const publicFunctionSignatures = artifact.functions
608
683
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
609
684
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
610
685
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
611
686
 
612
687
  currentInstance.currentContractClassId = contractClass.id;
613
- await this.contractStore.addContractInstance(currentInstance);
688
+ await Promise.all([
689
+ this.contractStore.addContractArtifact(artifact, contractClass),
690
+ this.contractStore.addContractInstance(currentInstance),
691
+ ]);
614
692
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
615
693
  });
616
694
  }
@@ -628,11 +706,12 @@ export class PXE {
628
706
  * (where validators prove the public portion).
629
707
  *
630
708
  * @param txRequest - An authenticated tx request ready for proving
709
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
631
710
  * @returns A result containing the proof and public inputs of the tail circuit.
632
711
  * @throws If contract code not found, or public simulation reverts.
633
712
  * Also throws if simulatePublic is true and public simulation reverts.
634
713
  */
635
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
714
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
636
715
  let privateExecutionResult: PrivateExecutionResult;
637
716
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
638
717
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -643,7 +722,7 @@ export class PXE {
643
722
  await this.blockStateSynchronizer.sync();
644
723
  const syncTime = syncTimer.ms();
645
724
  const contractFunctionSimulator = this.#getSimulatorForTx();
646
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
725
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
647
726
 
648
727
  const {
649
728
  publicInputs,
@@ -707,17 +786,13 @@ export class PXE {
707
786
 
708
787
  /**
709
788
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
710
- *
711
- * @param txRequest - An authenticated tx request ready for simulation
712
- * @param msgSender - (Optional) The message sender to use for the simulation.
713
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
789
+ * @param txRequest - An authenticated tx request ready for simulation.
714
790
  * @returns A trace of the program execution with gate counts.
715
791
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
716
792
  */
717
793
  public profileTx(
718
794
  txRequest: TxExecutionRequest,
719
- profileMode: 'full' | 'execution-steps' | 'gates',
720
- skipProofGeneration: boolean = true,
795
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
721
796
  ): Promise<TxProfileResult> {
722
797
  // We disable concurrent profiles for consistency with simulateTx.
723
798
  return this.#putInJobQueue(async jobId => {
@@ -740,12 +815,7 @@ export class PXE {
740
815
  const syncTime = syncTimer.ms();
741
816
 
742
817
  const contractFunctionSimulator = this.#getSimulatorForTx();
743
- const privateExecutionResult = await this.#executePrivate(
744
- contractFunctionSimulator,
745
- txRequest,
746
- undefined,
747
- jobId,
748
- );
818
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
749
819
 
750
820
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
751
821
  txRequest,
@@ -802,12 +872,7 @@ export class PXE {
802
872
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
803
873
  *
804
874
  *
805
- * @param txRequest - An authenticated tx request ready for simulation
806
- * @param simulatePublic - Whether to simulate the public part of the transaction.
807
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
808
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
809
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
810
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
875
+ * @param txRequest - An authenticated tx request ready for simulation.
811
876
  * @returns A simulated transaction result object that includes public and private return values.
812
877
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
813
878
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -816,11 +881,7 @@ export class PXE {
816
881
  */
817
882
  public simulateTx(
818
883
  txRequest: TxExecutionRequest,
819
- simulatePublic: boolean,
820
- skipTxValidation: boolean = false,
821
- skipFeeEnforcement: boolean = false,
822
- overrides?: SimulationOverrides,
823
- scopes?: AztecAddress[],
884
+ { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
824
885
  ): Promise<TxSimulationResult> {
825
886
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
826
887
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -848,7 +909,14 @@ export class PXE {
848
909
  // Temporary: in case there are overrides, we have to skip the kernels or validations
849
910
  // will fail. Consider handing control to the user/wallet on whether they want to run them
850
911
  // or not.
851
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
912
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
913
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
914
+ const skipKernels = hasOverriddenContracts;
915
+
916
+ // Set overridden contracts on the sync service so it knows to skip syncing them
917
+ if (hasOverriddenContracts) {
918
+ this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
919
+ }
852
920
 
853
921
  // Execution of private functions only; no proving, and no kernel logic.
854
922
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -859,7 +927,8 @@ export class PXE {
859
927
  if (skipKernels) {
860
928
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
861
929
  privateExecutionResult,
862
- this.contractStore,
930
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
931
+ this.node,
863
932
  ));
864
933
  } else {
865
934
  // Kernel logic, plus proving of all private functions and kernels.
@@ -878,6 +947,9 @@ export class PXE {
878
947
  const publicSimulationTimer = new Timer();
879
948
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
880
949
  publicSimulationTime = publicSimulationTimer.ms();
950
+ if (publicOutput?.debugLogs?.length) {
951
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
952
+ }
881
953
  }
882
954
 
883
955
  let validationTime: number | undefined;
@@ -886,7 +958,8 @@ export class PXE {
886
958
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
887
959
  validationTime = validationTimer.ms();
888
960
  if (validationResult.result === 'invalid') {
889
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
961
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
962
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
890
963
  }
891
964
  }
892
965
 
@@ -937,29 +1010,23 @@ export class PXE {
937
1010
  inspect(txRequest),
938
1011
  `simulatePublic=${simulatePublic}`,
939
1012
  `skipTxValidation=${skipTxValidation}`,
940
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1013
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
941
1014
  );
942
1015
  }
943
1016
  });
944
1017
  }
945
1018
 
946
1019
  /**
947
- * Simulate the execution of a contract utility function.
948
- *
1020
+ * Executes a contract utility function.
949
1021
  * @param call - The function call containing the function details, arguments, and target contract address.
950
- * @param authwits - (Optional) The authentication witnesses required for the function call.
951
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
952
- * default to all.
953
- * @returns The result of the utility function call, structured based on the function ABI.
954
1022
  */
955
- public simulateUtility(
1023
+ public executeUtility(
956
1024
  call: FunctionCall,
957
- authwits?: AuthWitness[],
958
- scopes?: AztecAddress[],
959
- ): Promise<UtilitySimulationResult> {
960
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1025
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
1026
+ ): Promise<UtilityExecutionResult> {
1027
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
961
1028
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
962
- // delete the same read value, or reading values that another simulation is currently modifying).
1029
+ // delete the same read value, or reading values that another execution is currently modifying).
963
1030
  return this.#putInJobQueue(async jobId => {
964
1031
  try {
965
1032
  const totalTimer = new Timer();
@@ -970,16 +1037,17 @@ export class PXE {
970
1037
  const contractFunctionSimulator = this.#getSimulatorForTx();
971
1038
 
972
1039
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
973
- await ensureContractSynced(
1040
+ await this.contractSyncService.ensureContractSynced(
974
1041
  call.to,
975
1042
  call.selector,
976
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
977
- this.node,
978
- this.contractStore,
1043
+ (privateSyncCall, execScopes) =>
1044
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
979
1045
  anchorBlockHeader,
1046
+ jobId,
1047
+ scopes,
980
1048
  );
981
1049
 
982
- const executionResult = await this.#simulateUtility(
1050
+ const executionResult = await this.#executeUtility(
983
1051
  contractFunctionSimulator,
984
1052
  call,
985
1053
  authwits ?? [],
@@ -1006,8 +1074,8 @@ export class PXE {
1006
1074
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1007
1075
  throw this.#contextualizeError(
1008
1076
  err,
1009
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1010
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1077
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1078
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1011
1079
  );
1012
1080
  }
1013
1081
  });
@@ -1040,14 +1108,14 @@ export class PXE {
1040
1108
 
1041
1109
  const contractFunctionSimulator = this.#getSimulatorForTx();
1042
1110
 
1043
- await ensureContractSynced(
1111
+ await this.contractSyncService.ensureContractSynced(
1044
1112
  filter.contractAddress,
1045
1113
  null,
1046
- async privateSyncCall =>
1047
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1048
- this.node,
1049
- this.contractStore,
1114
+ async (privateSyncCall, execScopes) =>
1115
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1050
1116
  anchorBlockHeader,
1117
+ jobId,
1118
+ filter.scopes,
1051
1119
  );
1052
1120
  });
1053
1121