@aztec/pxe 0.0.1-commit.64b6bbb → 0.0.1-commit.684755437

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 (155) 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 +8 -6
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.js +114 -44
  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 +49 -45
  19. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/oracle/oracle.d.ts +44 -44
  21. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/oracle.js +132 -89
  23. package/dest/contract_function_simulator/oracle/private_execution.js +1 -1
  24. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +22 -21
  25. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +37 -37
  27. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +39 -36
  28. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +56 -53
  30. package/dest/contract_logging.d.ts +22 -0
  31. package/dest/contract_logging.d.ts.map +1 -0
  32. package/dest/contract_logging.js +23 -0
  33. package/dest/contract_sync/contract_sync_service.d.ts +4 -2
  34. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  35. package/dest/contract_sync/contract_sync_service.js +34 -19
  36. package/dest/contract_sync/helpers.d.ts +3 -2
  37. package/dest/contract_sync/helpers.d.ts.map +1 -1
  38. package/dest/contract_sync/helpers.js +3 -3
  39. package/dest/debug/pxe_debug_utils.d.ts +5 -4
  40. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  41. package/dest/debug/pxe_debug_utils.js +4 -4
  42. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  43. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  44. package/dest/entrypoints/client/bundle/index.js +3 -0
  45. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  46. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  47. package/dest/entrypoints/client/lazy/index.js +3 -0
  48. package/dest/entrypoints/server/index.d.ts +3 -1
  49. package/dest/entrypoints/server/index.d.ts.map +1 -1
  50. package/dest/entrypoints/server/index.js +2 -0
  51. package/dest/logs/log_service.d.ts +3 -2
  52. package/dest/logs/log_service.d.ts.map +1 -1
  53. package/dest/logs/log_service.js +9 -14
  54. package/dest/notes/note_service.d.ts +4 -3
  55. package/dest/notes/note_service.d.ts.map +1 -1
  56. package/dest/notes/note_service.js +3 -2
  57. package/dest/notes_filter.d.ts +25 -0
  58. package/dest/notes_filter.d.ts.map +1 -0
  59. package/dest/notes_filter.js +4 -0
  60. package/dest/oracle_version.d.ts +2 -2
  61. package/dest/oracle_version.js +3 -3
  62. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  63. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  64. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  65. package/dest/private_kernel/hints/index.d.ts +1 -1
  66. package/dest/private_kernel/hints/index.js +1 -1
  67. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  68. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  69. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  70. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  71. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  72. package/dest/private_kernel/hints/test_utils.js +203 -0
  73. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  74. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  75. package/dest/private_kernel/private_kernel_execution_prover.js +19 -11
  76. package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
  77. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  78. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  79. package/dest/pxe.d.ts +18 -13
  80. package/dest/pxe.d.ts.map +1 -1
  81. package/dest/pxe.js +48 -37
  82. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  83. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  84. package/dest/storage/contract_store/contract_store.js +140 -64
  85. package/dest/storage/note_store/note_store.d.ts +3 -3
  86. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  87. package/dest/storage/note_store/note_store.js +3 -4
  88. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  89. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  90. package/dest/storage/tagging_store/sender_tagging_store.d.ts +5 -5
  91. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  92. package/dest/storage/tagging_store/sender_tagging_store.js +4 -4
  93. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  94. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  95. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  96. package/dest/tagging/index.d.ts +2 -2
  97. package/dest/tagging/index.d.ts.map +1 -1
  98. package/dest/tagging/index.js +1 -1
  99. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  100. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  101. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
  102. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  103. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  104. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  105. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  106. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  107. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  108. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +3 -6
  109. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +4 -7
  110. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  111. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +14 -15
  112. package/package.json +16 -16
  113. package/src/access_scopes.ts +9 -0
  114. package/src/config/index.ts +1 -1
  115. package/src/config/package_info.ts +1 -1
  116. package/src/contract_function_simulator/contract_function_simulator.ts +220 -63
  117. package/src/contract_function_simulator/execution_tagging_index_cache.ts +5 -5
  118. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  119. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  120. package/src/contract_function_simulator/oracle/interfaces.ts +47 -44
  121. package/src/contract_function_simulator/oracle/oracle.ts +135 -107
  122. package/src/contract_function_simulator/oracle/private_execution.ts +1 -1
  123. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +44 -39
  124. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +64 -64
  125. package/src/contract_logging.ts +39 -0
  126. package/src/contract_sync/contract_sync_service.ts +49 -26
  127. package/src/contract_sync/helpers.ts +7 -2
  128. package/src/debug/pxe_debug_utils.ts +11 -9
  129. package/src/entrypoints/client/bundle/index.ts +3 -0
  130. package/src/entrypoints/client/lazy/index.ts +3 -0
  131. package/src/entrypoints/server/index.ts +2 -0
  132. package/src/logs/log_service.ts +17 -24
  133. package/src/notes/note_service.ts +4 -3
  134. package/src/notes_filter.ts +26 -0
  135. package/src/oracle_version.ts +3 -3
  136. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  137. package/src/private_kernel/hints/index.ts +1 -1
  138. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  139. package/src/private_kernel/hints/test_utils.ts +325 -0
  140. package/src/private_kernel/private_kernel_execution_prover.ts +19 -12
  141. package/src/private_kernel/private_kernel_oracle.ts +7 -7
  142. package/src/pxe.ts +67 -54
  143. package/src/storage/contract_store/contract_store.ts +170 -71
  144. package/src/storage/note_store/note_store.ts +8 -5
  145. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  146. package/src/storage/tagging_store/sender_tagging_store.ts +8 -8
  147. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  148. package/src/tagging/index.ts +1 -1
  149. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
  150. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  151. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  152. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +4 -9
  153. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +11 -20
  154. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  155. 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';
@@ -92,6 +94,8 @@ export type ProfileTxOpts = {
92
94
  profileMode: 'full' | 'execution-steps' | 'gates';
93
95
  /** If true, proof generation is skipped during profiling. Defaults to true. */
94
96
  skipProofGeneration?: boolean;
97
+ /** Addresses whose private state and keys are accessible during private execution. */
98
+ scopes: AccessScopes;
95
99
  };
96
100
 
97
101
  /** Options for PXE.simulateTx. */
@@ -104,16 +108,16 @@ export type SimulateTxOpts = {
104
108
  skipFeeEnforcement?: boolean;
105
109
  /** State overrides for the simulation, such as contract instances and artifacts. */
106
110
  overrides?: SimulationOverrides;
107
- /** The accounts whose notes we can access in this call. Defaults to all. */
108
- scopes?: AztecAddress[];
111
+ /** Addresses whose private state and keys are accessible during private execution */
112
+ scopes: AccessScopes;
109
113
  };
110
114
 
111
- /** Options for PXE.simulateUtility. */
112
- export type SimulateUtilityOpts = {
115
+ /** Options for PXE.executeUtility. */
116
+ export type ExecuteUtilityOpts = {
113
117
  /** The authentication witnesses required for the function call. */
114
118
  authwits?: AuthWitness[];
115
- /** The accounts whose notes we can access in this call. Defaults to all. */
116
- scopes?: AztecAddress[];
119
+ /** The accounts whose notes we can access in this call */
120
+ scopes: AccessScopes;
117
121
  };
118
122
 
119
123
  /** Args for PXE.create. */
@@ -141,6 +145,7 @@ export type PXECreateArgs = {
141
145
  export class PXE {
142
146
  private constructor(
143
147
  private node: AztecNode,
148
+ private db: AztecAsyncKVStore,
144
149
  private blockStateSynchronizer: BlockSynchronizer,
145
150
  private keyStore: KeyStore,
146
151
  private contractStore: ContractStore,
@@ -188,7 +193,9 @@ export class PXE {
188
193
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
189
194
  : loggerOrSuffix;
190
195
 
191
- const proverEnabled = !!config.proverEnabled;
196
+ const info = await node.getNodeInfo();
197
+
198
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
192
199
  const addressStore = new AddressStore(store);
193
200
  const privateEventStore = new PrivateEventStore(store);
194
201
  const contractStore = new ContractStore(store);
@@ -234,6 +241,7 @@ export class PXE {
234
241
 
235
242
  const pxe = new PXE(
236
243
  node,
244
+ store,
237
245
  synchronizer,
238
246
  keyStore,
239
247
  contractStore,
@@ -259,13 +267,12 @@ export class PXE {
259
267
  debugUtils.setPXEHelpers(
260
268
  pxe.#putInJobQueue.bind(pxe),
261
269
  pxe.#getSimulatorForTx.bind(pxe),
262
- pxe.#simulateUtility.bind(pxe),
270
+ pxe.#executeUtility.bind(pxe),
263
271
  );
264
272
 
265
273
  pxe.jobQueue.start();
266
274
 
267
275
  await pxe.#registerProtocolContracts();
268
- const info = await node.getNodeInfo();
269
276
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
270
277
  return pxe;
271
278
  }
@@ -340,9 +347,8 @@ export class PXE {
340
347
  async #registerProtocolContracts() {
341
348
  const registered: Record<string, string> = {};
342
349
  for (const name of protocolContractNames) {
343
- const { address, contractClass, instance, artifact } =
344
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
345
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
350
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
351
+ await this.contractStore.addContractArtifact(artifact);
346
352
  await this.contractStore.addContractInstance(instance);
347
353
  registered[name] = address.toString();
348
354
  }
@@ -354,7 +360,7 @@ export class PXE {
354
360
  async #executePrivate(
355
361
  contractFunctionSimulator: ContractFunctionSimulator,
356
362
  txRequest: TxExecutionRequest,
357
- scopes: AztecAddress[] | undefined,
363
+ scopes: AccessScopes,
358
364
  jobId: string,
359
365
  ): Promise<PrivateExecutionResult> {
360
366
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -365,9 +371,11 @@ export class PXE {
365
371
  await this.contractSyncService.ensureContractSynced(
366
372
  contractAddress,
367
373
  functionSelector,
368
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
374
+ (privateSyncCall, execScopes) =>
375
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
369
376
  anchorBlockHeader,
370
377
  jobId,
378
+ scopes,
371
379
  );
372
380
 
373
381
  const result = await contractFunctionSimulator.run(txRequest, {
@@ -388,20 +396,20 @@ export class PXE {
388
396
  }
389
397
 
390
398
  /**
391
- * Simulate a utility function call on the given contract.
399
+ * Execute a utility function call on the given contract.
392
400
  * @param contractFunctionSimulator - The simulator to use for the function call.
393
401
  * @param call - The function call to execute.
394
402
  * @param authWitnesses - Authentication witnesses required for the function call.
395
403
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
396
404
  * accounts if not specified.
397
405
  * @param jobId - The job ID for staged writes.
398
- * @returns The simulation result containing the outputs of the utility function.
406
+ * @returns The execution result containing the outputs of the utility function.
399
407
  */
400
- async #simulateUtility(
408
+ async #executeUtility(
401
409
  contractFunctionSimulator: ContractFunctionSimulator,
402
410
  call: FunctionCall,
403
411
  authWitnesses: AuthWitness[] | undefined,
404
- scopes: AztecAddress[] | undefined,
412
+ scopes: AccessScopes,
405
413
  jobId: string,
406
414
  ) {
407
415
  try {
@@ -595,8 +603,7 @@ export class PXE {
595
603
  * @param artifact - The build artifact for the contract class.
596
604
  */
597
605
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
598
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
599
- await this.contractStore.addContractArtifact(contractClassId, artifact);
606
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
600
607
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
601
608
  }
602
609
 
@@ -615,17 +622,17 @@ export class PXE {
615
622
  if (artifact) {
616
623
  // If the user provides an artifact, validate it against the expected class id and register it
617
624
  const contractClass = await getContractClassFromArtifact(artifact);
618
- const contractClassId = contractClass.id;
619
- if (!contractClassId.equals(instance.currentContractClassId)) {
625
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
620
626
  throw new Error(
621
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
627
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
622
628
  );
623
629
  }
624
630
  const computedAddress = await computeContractAddressFromInstance(instance);
625
631
  if (!computedAddress.equals(instance.address)) {
626
632
  throw new Error('Added a contract in which the address does not match the contract instance.');
627
633
  }
628
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
634
+
635
+ await this.contractStore.addContractArtifact(artifact, contractClass);
629
636
 
630
637
  const publicFunctionSignatures = artifact.functions
631
638
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -674,15 +681,16 @@ export class PXE {
674
681
  throw new Error('Could not update contract to a class different from the current one.');
675
682
  }
676
683
 
677
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
678
-
679
684
  const publicFunctionSignatures = artifact.functions
680
685
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
681
686
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
682
687
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
683
688
 
684
689
  currentInstance.currentContractClassId = contractClass.id;
685
- await this.contractStore.addContractInstance(currentInstance);
690
+ await Promise.all([
691
+ this.contractStore.addContractArtifact(artifact, contractClass),
692
+ this.contractStore.addContractInstance(currentInstance),
693
+ ]);
686
694
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
687
695
  });
688
696
  }
@@ -700,11 +708,12 @@ export class PXE {
700
708
  * (where validators prove the public portion).
701
709
  *
702
710
  * @param txRequest - An authenticated tx request ready for proving
711
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
703
712
  * @returns A result containing the proof and public inputs of the tail circuit.
704
713
  * @throws If contract code not found, or public simulation reverts.
705
714
  * Also throws if simulatePublic is true and public simulation reverts.
706
715
  */
707
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
716
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
708
717
  let privateExecutionResult: PrivateExecutionResult;
709
718
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
710
719
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -715,7 +724,7 @@ export class PXE {
715
724
  await this.blockStateSynchronizer.sync();
716
725
  const syncTime = syncTimer.ms();
717
726
  const contractFunctionSimulator = this.#getSimulatorForTx();
718
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
727
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
719
728
 
720
729
  const {
721
730
  publicInputs,
@@ -785,7 +794,7 @@ export class PXE {
785
794
  */
786
795
  public profileTx(
787
796
  txRequest: TxExecutionRequest,
788
- { profileMode, skipProofGeneration = true }: ProfileTxOpts,
797
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
789
798
  ): Promise<TxProfileResult> {
790
799
  // We disable concurrent profiles for consistency with simulateTx.
791
800
  return this.#putInJobQueue(async jobId => {
@@ -808,12 +817,7 @@ export class PXE {
808
817
  const syncTime = syncTimer.ms();
809
818
 
810
819
  const contractFunctionSimulator = this.#getSimulatorForTx();
811
- const privateExecutionResult = await this.#executePrivate(
812
- contractFunctionSimulator,
813
- txRequest,
814
- undefined,
815
- jobId,
816
- );
820
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
817
821
 
818
822
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
819
823
  txRequest,
@@ -926,6 +930,7 @@ export class PXE {
926
930
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
927
931
  privateExecutionResult,
928
932
  (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
933
+ this.node,
929
934
  ));
930
935
  } else {
931
936
  // Kernel logic, plus proving of all private functions and kernels.
@@ -944,6 +949,9 @@ export class PXE {
944
949
  const publicSimulationTimer = new Timer();
945
950
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
946
951
  publicSimulationTime = publicSimulationTimer.ms();
952
+ if (publicOutput?.debugLogs?.length) {
953
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
954
+ }
947
955
  }
948
956
 
949
957
  let validationTime: number | undefined;
@@ -952,7 +960,8 @@ export class PXE {
952
960
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
953
961
  validationTime = validationTimer.ms();
954
962
  if (validationResult.result === 'invalid') {
955
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
963
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
964
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
956
965
  }
957
966
  }
958
967
 
@@ -1003,23 +1012,23 @@ export class PXE {
1003
1012
  inspect(txRequest),
1004
1013
  `simulatePublic=${simulatePublic}`,
1005
1014
  `skipTxValidation=${skipTxValidation}`,
1006
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1015
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1007
1016
  );
1008
1017
  }
1009
1018
  });
1010
1019
  }
1011
1020
 
1012
1021
  /**
1013
- * Simulates the execution of a contract utility function.
1022
+ * Executes a contract utility function.
1014
1023
  * @param call - The function call containing the function details, arguments, and target contract address.
1015
1024
  */
1016
- public simulateUtility(
1025
+ public executeUtility(
1017
1026
  call: FunctionCall,
1018
- { authwits, scopes }: SimulateUtilityOpts = {},
1019
- ): Promise<UtilitySimulationResult> {
1020
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1027
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
1028
+ ): Promise<UtilityExecutionResult> {
1029
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
1021
1030
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
1022
- // delete the same read value, or reading values that another simulation is currently modifying).
1031
+ // delete the same read value, or reading values that another execution is currently modifying).
1023
1032
  return this.#putInJobQueue(async jobId => {
1024
1033
  try {
1025
1034
  const totalTimer = new Timer();
@@ -1033,12 +1042,14 @@ export class PXE {
1033
1042
  await this.contractSyncService.ensureContractSynced(
1034
1043
  call.to,
1035
1044
  call.selector,
1036
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1045
+ (privateSyncCall, execScopes) =>
1046
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1037
1047
  anchorBlockHeader,
1038
1048
  jobId,
1049
+ scopes,
1039
1050
  );
1040
1051
 
1041
- const executionResult = await this.#simulateUtility(
1052
+ const executionResult = await this.#executeUtility(
1042
1053
  contractFunctionSimulator,
1043
1054
  call,
1044
1055
  authwits ?? [],
@@ -1065,8 +1076,8 @@ export class PXE {
1065
1076
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1066
1077
  throw this.#contextualizeError(
1067
1078
  err,
1068
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1069
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1079
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1080
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1070
1081
  );
1071
1082
  }
1072
1083
  });
@@ -1102,10 +1113,11 @@ export class PXE {
1102
1113
  await this.contractSyncService.ensureContractSynced(
1103
1114
  filter.contractAddress,
1104
1115
  null,
1105
- async privateSyncCall =>
1106
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1116
+ async (privateSyncCall, execScopes) =>
1117
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1107
1118
  anchorBlockHeader,
1108
1119
  jobId,
1120
+ filter.scopes,
1109
1121
  );
1110
1122
  });
1111
1123
 
@@ -1120,9 +1132,10 @@ export class PXE {
1120
1132
  }
1121
1133
 
1122
1134
  /**
1123
- * Stops the PXE's job queue.
1135
+ * Stops the PXE's job queue and closes the backing store.
1124
1136
  */
1125
- public stop(): Promise<void> {
1126
- return this.jobQueue.end();
1137
+ public async stop(): Promise<void> {
1138
+ await this.jobQueue.end();
1139
+ await this.db.close();
1127
1140
  }
1128
1141
  }