@aztec/pxe 0.0.1-commit.d6f2b3f94 → 0.0.1-commit.dbf9cec

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 (159) 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/package_info.js +1 -1
  5. package/dest/contract_function_simulator/contract_function_simulator.d.ts +53 -29
  6. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  7. package/dest/contract_function_simulator/contract_function_simulator.js +172 -68
  8. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
  9. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/execution_tagging_index_cache.js +3 -3
  11. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  12. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -2
  13. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  15. package/dest/contract_function_simulator/oracle/interfaces.d.ts +2 -2
  16. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -2
  18. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/oracle/oracle.js +2 -2
  20. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +35 -36
  21. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +71 -26
  23. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +30 -12
  24. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +36 -36
  26. package/dest/contract_logging.d.ts +22 -0
  27. package/dest/contract_logging.d.ts.map +1 -0
  28. package/dest/contract_logging.js +23 -0
  29. package/dest/contract_sync/contract_sync_service.d.ts +4 -2
  30. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  31. package/dest/contract_sync/contract_sync_service.js +34 -19
  32. package/dest/contract_sync/helpers.d.ts +3 -2
  33. package/dest/contract_sync/helpers.d.ts.map +1 -1
  34. package/dest/contract_sync/helpers.js +3 -3
  35. package/dest/debug/pxe_debug_utils.d.ts +5 -4
  36. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  37. package/dest/debug/pxe_debug_utils.js +4 -4
  38. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  39. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  40. package/dest/entrypoints/client/bundle/index.js +3 -0
  41. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  42. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  43. package/dest/entrypoints/client/bundle/utils.js +9 -1
  44. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  45. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  46. package/dest/entrypoints/client/lazy/index.js +3 -0
  47. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  48. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  49. package/dest/entrypoints/client/lazy/utils.js +9 -1
  50. package/dest/entrypoints/server/index.d.ts +3 -1
  51. package/dest/entrypoints/server/index.d.ts.map +1 -1
  52. package/dest/entrypoints/server/index.js +2 -0
  53. package/dest/entrypoints/server/utils.js +9 -1
  54. package/dest/logs/log_service.d.ts +3 -2
  55. package/dest/logs/log_service.d.ts.map +1 -1
  56. package/dest/logs/log_service.js +9 -14
  57. package/dest/notes/note_service.d.ts +4 -3
  58. package/dest/notes/note_service.d.ts.map +1 -1
  59. package/dest/notes/note_service.js +3 -2
  60. package/dest/notes_filter.d.ts +25 -0
  61. package/dest/notes_filter.d.ts.map +1 -0
  62. package/dest/notes_filter.js +4 -0
  63. package/dest/oracle_version.d.ts +2 -2
  64. package/dest/oracle_version.js +2 -2
  65. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  66. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  67. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  68. package/dest/private_kernel/hints/index.d.ts +1 -1
  69. package/dest/private_kernel/hints/index.js +1 -1
  70. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  71. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  72. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  73. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  74. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  75. package/dest/private_kernel/hints/test_utils.js +203 -0
  76. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  77. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  78. package/dest/private_kernel/private_kernel_execution_prover.js +19 -11
  79. package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
  80. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  81. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  82. package/dest/pxe.d.ts +58 -23
  83. package/dest/pxe.d.ts.map +1 -1
  84. package/dest/pxe.js +65 -53
  85. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  86. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  87. package/dest/storage/contract_store/contract_store.js +140 -64
  88. package/dest/storage/note_store/note_store.d.ts +3 -3
  89. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  90. package/dest/storage/note_store/note_store.js +3 -4
  91. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  92. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  93. package/dest/storage/tagging_store/sender_tagging_store.d.ts +5 -5
  94. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  95. package/dest/storage/tagging_store/sender_tagging_store.js +4 -4
  96. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  97. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  98. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  99. package/dest/tagging/index.d.ts +2 -2
  100. package/dest/tagging/index.d.ts.map +1 -1
  101. package/dest/tagging/index.js +1 -1
  102. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  103. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  104. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
  105. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  106. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  107. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  108. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  109. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  110. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  111. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +3 -6
  112. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +4 -7
  113. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  114. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +14 -15
  115. package/package.json +16 -16
  116. package/src/access_scopes.ts +9 -0
  117. package/src/config/package_info.ts +1 -1
  118. package/src/contract_function_simulator/contract_function_simulator.ts +320 -128
  119. package/src/contract_function_simulator/execution_tagging_index_cache.ts +5 -5
  120. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  121. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  122. package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
  123. package/src/contract_function_simulator/oracle/oracle.ts +2 -2
  124. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +95 -102
  125. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +77 -33
  126. package/src/contract_logging.ts +39 -0
  127. package/src/contract_sync/contract_sync_service.ts +49 -26
  128. package/src/contract_sync/helpers.ts +7 -2
  129. package/src/debug/pxe_debug_utils.ts +11 -9
  130. package/src/entrypoints/client/bundle/index.ts +3 -0
  131. package/src/entrypoints/client/bundle/utils.ts +9 -1
  132. package/src/entrypoints/client/lazy/index.ts +3 -0
  133. package/src/entrypoints/client/lazy/utils.ts +9 -1
  134. package/src/entrypoints/server/index.ts +2 -0
  135. package/src/entrypoints/server/utils.ts +7 -7
  136. package/src/logs/log_service.ts +17 -24
  137. package/src/notes/note_service.ts +4 -3
  138. package/src/notes_filter.ts +26 -0
  139. package/src/oracle_version.ts +2 -2
  140. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  141. package/src/private_kernel/hints/index.ts +1 -1
  142. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  143. package/src/private_kernel/hints/test_utils.ts +325 -0
  144. package/src/private_kernel/private_kernel_execution_prover.ts +19 -12
  145. package/src/private_kernel/private_kernel_oracle.ts +7 -7
  146. package/src/pxe.ts +132 -98
  147. package/src/storage/contract_store/contract_store.ts +170 -71
  148. package/src/storage/note_store/note_store.ts +8 -5
  149. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  150. package/src/storage/tagging_store/sender_tagging_store.ts +8 -8
  151. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  152. package/src/tagging/index.ts +1 -1
  153. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
  154. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  155. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  156. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +4 -9
  157. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +11 -20
  158. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  159. 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,6 +61,7 @@ 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';
@@ -86,6 +88,56 @@ export type PackedPrivateEvent = InTx & {
86
88
  eventSelector: EventSelector;
87
89
  };
88
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
+
89
141
  /**
90
142
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
91
143
  * manage private state of users.
@@ -122,15 +174,15 @@ export class PXE {
122
174
  *
123
175
  * @returns A promise that resolves PXE is ready to be used.
124
176
  */
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
- ) {
177
+ public static async create({
178
+ node,
179
+ store,
180
+ proofCreator,
181
+ simulator,
182
+ protocolContractsProvider,
183
+ config,
184
+ loggerOrSuffix,
185
+ }: PXECreateArgs) {
134
186
  // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
135
187
  const bindings: LoggerBindings | undefined =
136
188
  loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
@@ -140,7 +192,9 @@ export class PXE {
140
192
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
141
193
  : loggerOrSuffix;
142
194
 
143
- const proverEnabled = !!config.proverEnabled;
195
+ const info = await node.getNodeInfo();
196
+
197
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
144
198
  const addressStore = new AddressStore(store);
145
199
  const privateEventStore = new PrivateEventStore(store);
146
200
  const contractStore = new ContractStore(store);
@@ -211,13 +265,12 @@ export class PXE {
211
265
  debugUtils.setPXEHelpers(
212
266
  pxe.#putInJobQueue.bind(pxe),
213
267
  pxe.#getSimulatorForTx.bind(pxe),
214
- pxe.#simulateUtility.bind(pxe),
268
+ pxe.#executeUtility.bind(pxe),
215
269
  );
216
270
 
217
271
  pxe.jobQueue.start();
218
272
 
219
273
  await pxe.#registerProtocolContracts();
220
- const info = await node.getNodeInfo();
221
274
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
222
275
  return pxe;
223
276
  }
@@ -227,20 +280,20 @@ export class PXE {
227
280
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
228
281
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
229
282
 
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
- );
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
+ });
244
297
  }
245
298
 
246
299
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -292,9 +345,8 @@ export class PXE {
292
345
  async #registerProtocolContracts() {
293
346
  const registered: Record<string, string> = {};
294
347
  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);
348
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
349
+ await this.contractStore.addContractArtifact(artifact);
298
350
  await this.contractStore.addContractInstance(instance);
299
351
  registered[name] = address.toString();
300
352
  }
@@ -306,7 +358,7 @@ export class PXE {
306
358
  async #executePrivate(
307
359
  contractFunctionSimulator: ContractFunctionSimulator,
308
360
  txRequest: TxExecutionRequest,
309
- scopes: AztecAddress[] | undefined,
361
+ scopes: AccessScopes,
310
362
  jobId: string,
311
363
  ): Promise<PrivateExecutionResult> {
312
364
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -317,23 +369,20 @@ export class PXE {
317
369
  await this.contractSyncService.ensureContractSynced(
318
370
  contractAddress,
319
371
  functionSelector,
320
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
372
+ (privateSyncCall, execScopes) =>
373
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
321
374
  anchorBlockHeader,
322
375
  jobId,
376
+ scopes,
323
377
  );
324
378
 
325
- const result = await contractFunctionSimulator.run(
326
- txRequest,
379
+ const result = await contractFunctionSimulator.run(txRequest, {
327
380
  contractAddress,
328
- functionSelector,
329
- undefined,
381
+ selector: functionSelector,
330
382
  anchorBlockHeader,
331
- // The sender for tags is set by contracts, typically by an account
332
- // contract entrypoint
333
- undefined, // senderForTags
334
383
  scopes,
335
384
  jobId,
336
- );
385
+ });
337
386
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
338
387
  return result;
339
388
  } catch (err) {
@@ -345,20 +394,20 @@ export class PXE {
345
394
  }
346
395
 
347
396
  /**
348
- * Simulate a utility function call on the given contract.
397
+ * Execute a utility function call on the given contract.
349
398
  * @param contractFunctionSimulator - The simulator to use for the function call.
350
399
  * @param call - The function call to execute.
351
400
  * @param authWitnesses - Authentication witnesses required for the function call.
352
401
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
353
402
  * accounts if not specified.
354
403
  * @param jobId - The job ID for staged writes.
355
- * @returns The simulation result containing the outputs of the utility function.
404
+ * @returns The execution result containing the outputs of the utility function.
356
405
  */
357
- async #simulateUtility(
406
+ async #executeUtility(
358
407
  contractFunctionSimulator: ContractFunctionSimulator,
359
408
  call: FunctionCall,
360
409
  authWitnesses: AuthWitness[] | undefined,
361
- scopes: AztecAddress[] | undefined,
410
+ scopes: AccessScopes,
362
411
  jobId: string,
363
412
  ) {
364
413
  try {
@@ -552,8 +601,7 @@ export class PXE {
552
601
  * @param artifact - The build artifact for the contract class.
553
602
  */
554
603
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
555
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
556
- await this.contractStore.addContractArtifact(contractClassId, artifact);
604
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
557
605
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
558
606
  }
559
607
 
@@ -572,17 +620,17 @@ export class PXE {
572
620
  if (artifact) {
573
621
  // If the user provides an artifact, validate it against the expected class id and register it
574
622
  const contractClass = await getContractClassFromArtifact(artifact);
575
- const contractClassId = contractClass.id;
576
- if (!contractClassId.equals(instance.currentContractClassId)) {
623
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
577
624
  throw new Error(
578
- `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})`,
579
626
  );
580
627
  }
581
628
  const computedAddress = await computeContractAddressFromInstance(instance);
582
629
  if (!computedAddress.equals(instance.address)) {
583
630
  throw new Error('Added a contract in which the address does not match the contract instance.');
584
631
  }
585
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
632
+
633
+ await this.contractStore.addContractArtifact(artifact, contractClass);
586
634
 
587
635
  const publicFunctionSignatures = artifact.functions
588
636
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -631,15 +679,16 @@ export class PXE {
631
679
  throw new Error('Could not update contract to a class different from the current one.');
632
680
  }
633
681
 
634
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
635
-
636
682
  const publicFunctionSignatures = artifact.functions
637
683
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
638
684
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
639
685
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
640
686
 
641
687
  currentInstance.currentContractClassId = contractClass.id;
642
- await this.contractStore.addContractInstance(currentInstance);
688
+ await Promise.all([
689
+ this.contractStore.addContractArtifact(artifact, contractClass),
690
+ this.contractStore.addContractInstance(currentInstance),
691
+ ]);
643
692
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
644
693
  });
645
694
  }
@@ -657,11 +706,12 @@ export class PXE {
657
706
  * (where validators prove the public portion).
658
707
  *
659
708
  * @param txRequest - An authenticated tx request ready for proving
709
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
660
710
  * @returns A result containing the proof and public inputs of the tail circuit.
661
711
  * @throws If contract code not found, or public simulation reverts.
662
712
  * Also throws if simulatePublic is true and public simulation reverts.
663
713
  */
664
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
714
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
665
715
  let privateExecutionResult: PrivateExecutionResult;
666
716
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
667
717
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -672,7 +722,7 @@ export class PXE {
672
722
  await this.blockStateSynchronizer.sync();
673
723
  const syncTime = syncTimer.ms();
674
724
  const contractFunctionSimulator = this.#getSimulatorForTx();
675
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
725
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
676
726
 
677
727
  const {
678
728
  publicInputs,
@@ -736,17 +786,13 @@ export class PXE {
736
786
 
737
787
  /**
738
788
  * 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.
789
+ * @param txRequest - An authenticated tx request ready for simulation.
743
790
  * @returns A trace of the program execution with gate counts.
744
791
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
745
792
  */
746
793
  public profileTx(
747
794
  txRequest: TxExecutionRequest,
748
- profileMode: 'full' | 'execution-steps' | 'gates',
749
- skipProofGeneration: boolean = true,
795
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
750
796
  ): Promise<TxProfileResult> {
751
797
  // We disable concurrent profiles for consistency with simulateTx.
752
798
  return this.#putInJobQueue(async jobId => {
@@ -769,12 +815,7 @@ export class PXE {
769
815
  const syncTime = syncTimer.ms();
770
816
 
771
817
  const contractFunctionSimulator = this.#getSimulatorForTx();
772
- const privateExecutionResult = await this.#executePrivate(
773
- contractFunctionSimulator,
774
- txRequest,
775
- undefined,
776
- jobId,
777
- );
818
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
778
819
 
779
820
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
780
821
  txRequest,
@@ -831,12 +872,7 @@ export class PXE {
831
872
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
832
873
  *
833
874
  *
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.
875
+ * @param txRequest - An authenticated tx request ready for simulation.
840
876
  * @returns A simulated transaction result object that includes public and private return values.
841
877
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
842
878
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -845,11 +881,7 @@ export class PXE {
845
881
  */
846
882
  public simulateTx(
847
883
  txRequest: TxExecutionRequest,
848
- simulatePublic: boolean,
849
- skipTxValidation: boolean = false,
850
- skipFeeEnforcement: boolean = false,
851
- overrides?: SimulationOverrides,
852
- scopes?: AztecAddress[],
884
+ { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
853
885
  ): Promise<TxSimulationResult> {
854
886
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
855
887
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -896,6 +928,7 @@ export class PXE {
896
928
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
897
929
  privateExecutionResult,
898
930
  (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
931
+ this.node,
899
932
  ));
900
933
  } else {
901
934
  // Kernel logic, plus proving of all private functions and kernels.
@@ -914,6 +947,9 @@ export class PXE {
914
947
  const publicSimulationTimer = new Timer();
915
948
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
916
949
  publicSimulationTime = publicSimulationTimer.ms();
950
+ if (publicOutput?.debugLogs?.length) {
951
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
952
+ }
917
953
  }
918
954
 
919
955
  let validationTime: number | undefined;
@@ -922,7 +958,8 @@ export class PXE {
922
958
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
923
959
  validationTime = validationTimer.ms();
924
960
  if (validationResult.result === 'invalid') {
925
- 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}`);
926
963
  }
927
964
  }
928
965
 
@@ -973,29 +1010,23 @@ export class PXE {
973
1010
  inspect(txRequest),
974
1011
  `simulatePublic=${simulatePublic}`,
975
1012
  `skipTxValidation=${skipTxValidation}`,
976
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1013
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
977
1014
  );
978
1015
  }
979
1016
  });
980
1017
  }
981
1018
 
982
1019
  /**
983
- * Simulate the execution of a contract utility function.
984
- *
1020
+ * Executes a contract utility function.
985
1021
  * @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
1022
  */
991
- public simulateUtility(
1023
+ public executeUtility(
992
1024
  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.
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.
997
1028
  // 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).
1029
+ // delete the same read value, or reading values that another execution is currently modifying).
999
1030
  return this.#putInJobQueue(async jobId => {
1000
1031
  try {
1001
1032
  const totalTimer = new Timer();
@@ -1009,12 +1040,14 @@ export class PXE {
1009
1040
  await this.contractSyncService.ensureContractSynced(
1010
1041
  call.to,
1011
1042
  call.selector,
1012
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1043
+ (privateSyncCall, execScopes) =>
1044
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1013
1045
  anchorBlockHeader,
1014
1046
  jobId,
1047
+ scopes,
1015
1048
  );
1016
1049
 
1017
- const executionResult = await this.#simulateUtility(
1050
+ const executionResult = await this.#executeUtility(
1018
1051
  contractFunctionSimulator,
1019
1052
  call,
1020
1053
  authwits ?? [],
@@ -1041,8 +1074,8 @@ export class PXE {
1041
1074
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1042
1075
  throw this.#contextualizeError(
1043
1076
  err,
1044
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1045
- `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(', ')}`,
1046
1079
  );
1047
1080
  }
1048
1081
  });
@@ -1078,10 +1111,11 @@ export class PXE {
1078
1111
  await this.contractSyncService.ensureContractSynced(
1079
1112
  filter.contractAddress,
1080
1113
  null,
1081
- async privateSyncCall =>
1082
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1114
+ async (privateSyncCall, execScopes) =>
1115
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1083
1116
  anchorBlockHeader,
1084
1117
  jobId,
1118
+ filter.scopes,
1085
1119
  );
1086
1120
  });
1087
1121