@aztec/pxe 0.0.1-commit.f146247c → 0.0.1-commit.f1b29a41e

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 (212) 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 +13 -1
  7. package/dest/config/index.d.ts +2 -2
  8. package/dest/config/index.d.ts.map +1 -1
  9. package/dest/config/index.js +1 -1
  10. package/dest/config/package_info.js +1 -1
  11. package/dest/contract_function_simulator/contract_function_simulator.d.ts +61 -29
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/contract_function_simulator.js +201 -72
  14. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  15. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  17. package/dest/contract_function_simulator/index.d.ts +2 -1
  18. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/index.js +1 -0
  20. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -5
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -9
  23. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  24. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
  26. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -6
  27. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +5 -10
  29. package/dest/contract_function_simulator/oracle/interfaces.d.ts +50 -45
  30. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  32. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  33. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +38 -0
  34. package/dest/contract_function_simulator/oracle/oracle.d.ts +64 -44
  35. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/oracle/oracle.js +206 -104
  37. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  38. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +54 -78
  39. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +99 -86
  41. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +93 -53
  42. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +233 -119
  44. package/dest/contract_logging.d.ts +27 -0
  45. package/dest/contract_logging.d.ts.map +1 -0
  46. package/dest/contract_logging.js +38 -0
  47. package/dest/contract_sync/contract_sync_service.d.ts +46 -0
  48. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  49. package/dest/contract_sync/contract_sync_service.js +124 -0
  50. package/dest/contract_sync/helpers.d.ts +29 -0
  51. package/dest/contract_sync/helpers.d.ts.map +1 -0
  52. package/dest/contract_sync/{index.js → helpers.js} +19 -13
  53. package/dest/debug/pxe_debug_utils.d.ts +14 -10
  54. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  55. package/dest/debug/pxe_debug_utils.js +16 -15
  56. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  57. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  58. package/dest/entrypoints/client/bundle/index.js +3 -0
  59. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  60. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  61. package/dest/entrypoints/client/bundle/utils.js +9 -1
  62. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  63. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  64. package/dest/entrypoints/client/lazy/index.js +3 -0
  65. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  66. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  67. package/dest/entrypoints/client/lazy/utils.js +9 -1
  68. package/dest/entrypoints/server/index.d.ts +4 -2
  69. package/dest/entrypoints/server/index.d.ts.map +1 -1
  70. package/dest/entrypoints/server/index.js +3 -1
  71. package/dest/entrypoints/server/utils.js +9 -1
  72. package/dest/events/event_service.d.ts +3 -2
  73. package/dest/events/event_service.d.ts.map +1 -1
  74. package/dest/events/event_service.js +16 -4
  75. package/dest/logs/log_service.d.ts +6 -6
  76. package/dest/logs/log_service.d.ts.map +1 -1
  77. package/dest/logs/log_service.js +32 -43
  78. package/dest/messages/message_context_service.d.ts +17 -0
  79. package/dest/messages/message_context_service.d.ts.map +1 -0
  80. package/dest/messages/message_context_service.js +36 -0
  81. package/dest/notes/note_service.d.ts +5 -4
  82. package/dest/notes/note_service.d.ts.map +1 -1
  83. package/dest/notes/note_service.js +17 -7
  84. package/dest/notes_filter.d.ts +25 -0
  85. package/dest/notes_filter.d.ts.map +1 -0
  86. package/dest/notes_filter.js +4 -0
  87. package/dest/oracle_version.d.ts +2 -2
  88. package/dest/oracle_version.js +3 -3
  89. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  90. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  91. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  92. package/dest/private_kernel/hints/index.d.ts +1 -1
  93. package/dest/private_kernel/hints/index.js +1 -1
  94. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  95. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  96. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  97. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  98. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  99. package/dest/private_kernel/hints/test_utils.js +203 -0
  100. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  101. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  102. package/dest/private_kernel/private_kernel_execution_prover.js +19 -11
  103. package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
  104. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  105. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  106. package/dest/pxe.d.ts +74 -24
  107. package/dest/pxe.d.ts.map +1 -1
  108. package/dest/pxe.js +126 -74
  109. package/dest/storage/capsule_store/capsule_service.d.ts +22 -0
  110. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  111. package/dest/storage/capsule_store/capsule_service.js +50 -0
  112. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  113. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  114. package/dest/storage/capsule_store/capsule_store.js +33 -28
  115. package/dest/storage/capsule_store/index.d.ts +2 -1
  116. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  117. package/dest/storage/capsule_store/index.js +1 -0
  118. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  119. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  120. package/dest/storage/contract_store/contract_store.js +145 -69
  121. package/dest/storage/metadata.d.ts +1 -1
  122. package/dest/storage/metadata.js +1 -1
  123. package/dest/storage/note_store/note_store.d.ts +3 -3
  124. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  125. package/dest/storage/note_store/note_store.js +6 -4
  126. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  127. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  128. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  129. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  130. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  131. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  132. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  133. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  134. package/dest/tagging/index.d.ts +3 -3
  135. package/dest/tagging/index.d.ts.map +1 -1
  136. package/dest/tagging/index.js +1 -1
  137. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  138. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  139. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
  140. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  141. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  142. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  143. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  144. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  145. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  146. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  147. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  148. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  149. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  150. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
  151. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  152. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  153. package/package.json +25 -16
  154. package/src/access_scopes.ts +9 -0
  155. package/src/block_synchronizer/block_synchronizer.ts +12 -0
  156. package/src/config/index.ts +1 -1
  157. package/src/config/package_info.ts +1 -1
  158. package/src/contract_function_simulator/contract_function_simulator.ts +361 -133
  159. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  160. package/src/contract_function_simulator/index.ts +1 -0
  161. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -8
  162. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
  163. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -9
  164. package/src/contract_function_simulator/oracle/interfaces.ts +63 -54
  165. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +98 -0
  166. package/src/contract_function_simulator/oracle/oracle.ts +233 -142
  167. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  168. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +125 -179
  169. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +399 -136
  170. package/src/contract_logging.ts +52 -0
  171. package/src/contract_sync/contract_sync_service.ts +192 -0
  172. package/src/contract_sync/{index.ts → helpers.ts} +23 -22
  173. package/src/debug/pxe_debug_utils.ts +48 -18
  174. package/src/entrypoints/client/bundle/index.ts +3 -0
  175. package/src/entrypoints/client/bundle/utils.ts +9 -1
  176. package/src/entrypoints/client/lazy/index.ts +3 -0
  177. package/src/entrypoints/client/lazy/utils.ts +9 -1
  178. package/src/entrypoints/server/index.ts +3 -1
  179. package/src/entrypoints/server/utils.ts +7 -7
  180. package/src/events/event_service.ts +17 -4
  181. package/src/logs/log_service.ts +63 -65
  182. package/src/messages/message_context_service.ts +44 -0
  183. package/src/notes/note_service.ts +20 -8
  184. package/src/notes_filter.ts +26 -0
  185. package/src/oracle_version.ts +3 -3
  186. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  187. package/src/private_kernel/hints/index.ts +1 -1
  188. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  189. package/src/private_kernel/hints/test_utils.ts +325 -0
  190. package/src/private_kernel/private_kernel_execution_prover.ts +19 -12
  191. package/src/private_kernel/private_kernel_oracle.ts +7 -7
  192. package/src/pxe.ts +231 -124
  193. package/src/storage/capsule_store/capsule_service.ts +91 -0
  194. package/src/storage/capsule_store/capsule_store.ts +34 -26
  195. package/src/storage/capsule_store/index.ts +1 -0
  196. package/src/storage/contract_store/contract_store.ts +174 -75
  197. package/src/storage/metadata.ts +1 -1
  198. package/src/storage/note_store/note_store.ts +12 -5
  199. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  200. package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
  201. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  202. package/src/tagging/index.ts +2 -2
  203. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
  204. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  205. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  206. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
  207. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  208. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
  209. package/dest/contract_sync/index.d.ts +0 -23
  210. package/dest/contract_sync/index.d.ts.map +0 -1
  211. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  212. 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,11 +61,14 @@ 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';
66
70
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
71
+ import { MessageContextService } from './messages/message_context_service.js';
67
72
  import {
68
73
  PrivateKernelExecutionProver,
69
74
  type PrivateKernelExecutionProverConfig,
@@ -84,6 +89,58 @@ export type PackedPrivateEvent = InTx & {
84
89
  eventSelector: EventSelector;
85
90
  };
86
91
 
92
+ /** Options for PXE.profileTx. */
93
+ export type ProfileTxOpts = {
94
+ /** The profiling mode to use. */
95
+ profileMode: 'full' | 'execution-steps' | 'gates';
96
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
97
+ skipProofGeneration?: boolean;
98
+ /** Addresses whose private state and keys are accessible during private execution. */
99
+ scopes: AccessScopes;
100
+ };
101
+
102
+ /** Options for PXE.simulateTx. */
103
+ export type SimulateTxOpts = {
104
+ /** Whether to simulate the public part of the transaction. */
105
+ simulatePublic: boolean;
106
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
107
+ skipTxValidation?: boolean;
108
+ /** If false, fees are enforced. */
109
+ skipFeeEnforcement?: boolean;
110
+ /** If true, kernel logic is emulated in TS for simulation */
111
+ skipKernels?: boolean;
112
+ /** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
113
+ overrides?: SimulationOverrides;
114
+ /** Addresses whose private state and keys are accessible during private execution */
115
+ scopes: AccessScopes;
116
+ };
117
+
118
+ /** Options for PXE.executeUtility. */
119
+ export type ExecuteUtilityOpts = {
120
+ /** The authentication witnesses required for the function call. */
121
+ authwits?: AuthWitness[];
122
+ /** The accounts whose notes we can access in this call */
123
+ scopes: AccessScopes;
124
+ };
125
+
126
+ /** Args for PXE.create. */
127
+ export type PXECreateArgs = {
128
+ /** The Aztec node to connect to. */
129
+ node: AztecNode;
130
+ /** The key-value store for persisting PXE state. */
131
+ store: AztecAsyncKVStore;
132
+ /** The prover for generating private kernel proofs. */
133
+ proofCreator: PrivateKernelProver;
134
+ /** The circuit simulator for executing ACIR circuits. */
135
+ simulator: CircuitSimulator;
136
+ /** Provider for protocol contract artifacts and instances. */
137
+ protocolContractsProvider: ProtocolContractsProvider;
138
+ /** PXE configuration options. */
139
+ config: PXEConfig;
140
+ /** Optional logger instance or string suffix for the logger name. */
141
+ loggerOrSuffix?: string | Logger;
142
+ };
143
+
87
144
  /**
88
145
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
89
146
  * manage private state of users.
@@ -91,6 +148,7 @@ export type PackedPrivateEvent = InTx & {
91
148
  export class PXE {
92
149
  private constructor(
93
150
  private node: AztecNode,
151
+ private db: AztecAsyncKVStore,
94
152
  private blockStateSynchronizer: BlockSynchronizer,
95
153
  private keyStore: KeyStore,
96
154
  private contractStore: ContractStore,
@@ -102,6 +160,8 @@ export class PXE {
102
160
  private recipientTaggingStore: RecipientTaggingStore,
103
161
  private addressStore: AddressStore,
104
162
  private privateEventStore: PrivateEventStore,
163
+ private contractSyncService: ContractSyncService,
164
+ private messageContextService: MessageContextService,
105
165
  private simulator: CircuitSimulator,
106
166
  private proverEnabled: boolean,
107
167
  private proofCreator: PrivateKernelProver,
@@ -119,15 +179,15 @@ export class PXE {
119
179
  *
120
180
  * @returns A promise that resolves PXE is ready to be used.
121
181
  */
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
- ) {
182
+ public static async create({
183
+ node,
184
+ store,
185
+ proofCreator,
186
+ simulator,
187
+ protocolContractsProvider,
188
+ config,
189
+ loggerOrSuffix,
190
+ }: PXECreateArgs) {
131
191
  // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
132
192
  const bindings: LoggerBindings | undefined =
133
193
  loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
@@ -137,7 +197,9 @@ export class PXE {
137
197
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
138
198
  : loggerOrSuffix;
139
199
 
140
- const proverEnabled = !!config.proverEnabled;
200
+ const info = await node.getNodeInfo();
201
+
202
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
141
203
  const addressStore = new AddressStore(store);
142
204
  const privateEventStore = new PrivateEventStore(store);
143
205
  const contractStore = new ContractStore(store);
@@ -149,6 +211,15 @@ export class PXE {
149
211
  const capsuleStore = new CapsuleStore(store);
150
212
  const keyStore = new KeyStore(store);
151
213
  const tipsStore = new L2TipsKVStore(store, 'pxe');
214
+ const contractSyncService = new ContractSyncService(
215
+ node,
216
+ contractStore,
217
+ noteStore,
218
+ () => keyStore.getAccounts(),
219
+ createLogger('pxe:contract_sync', bindings),
220
+ );
221
+ const messageContextService = new MessageContextService(node);
222
+
152
223
  const synchronizer = new BlockSynchronizer(
153
224
  node,
154
225
  store,
@@ -156,6 +227,7 @@ export class PXE {
156
227
  noteStore,
157
228
  privateEventStore,
158
229
  tipsStore,
230
+ contractSyncService,
159
231
  config,
160
232
  bindings,
161
233
  );
@@ -167,14 +239,16 @@ export class PXE {
167
239
  recipientTaggingStore,
168
240
  privateEventStore,
169
241
  noteStore,
242
+ contractSyncService,
170
243
  ]);
171
244
 
172
- const debugUtils = new PXEDebugUtils(contractStore, noteStore, synchronizer, anchorBlockStore);
245
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
173
246
 
174
247
  const jobQueue = new SerialQueue();
175
248
 
176
249
  const pxe = new PXE(
177
250
  node,
251
+ store,
178
252
  synchronizer,
179
253
  keyStore,
180
254
  contractStore,
@@ -186,6 +260,8 @@ export class PXE {
186
260
  recipientTaggingStore,
187
261
  addressStore,
188
262
  privateEventStore,
263
+ contractSyncService,
264
+ messageContextService,
189
265
  simulator,
190
266
  proverEnabled,
191
267
  proofCreator,
@@ -196,12 +272,15 @@ export class PXE {
196
272
  debugUtils,
197
273
  );
198
274
 
199
- debugUtils.setPXE(pxe, pxe.#putInJobQueue.bind(pxe));
275
+ debugUtils.setPXEHelpers(
276
+ pxe.#putInJobQueue.bind(pxe),
277
+ pxe.#getSimulatorForTx.bind(pxe),
278
+ pxe.#executeUtility.bind(pxe),
279
+ );
200
280
 
201
281
  pxe.jobQueue.start();
202
282
 
203
283
  await pxe.#registerProtocolContracts();
204
- const info = await node.getNodeInfo();
205
284
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
206
285
  return pxe;
207
286
  }
@@ -211,19 +290,21 @@ export class PXE {
211
290
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
212
291
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
213
292
 
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
- );
293
+ return new ContractFunctionSimulator({
294
+ contractStore: proxyContractStore,
295
+ noteStore: this.noteStore,
296
+ keyStore: this.keyStore,
297
+ addressStore: this.addressStore,
298
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
299
+ senderTaggingStore: this.senderTaggingStore,
300
+ recipientTaggingStore: this.recipientTaggingStore,
301
+ senderAddressBookStore: this.senderAddressBookStore,
302
+ capsuleStore: this.capsuleStore,
303
+ privateEventStore: this.privateEventStore,
304
+ simulator: this.simulator,
305
+ contractSyncService: this.contractSyncService,
306
+ messageContextService: this.messageContextService,
307
+ });
227
308
  }
228
309
 
229
310
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -275,9 +356,8 @@ export class PXE {
275
356
  async #registerProtocolContracts() {
276
357
  const registered: Record<string, string> = {};
277
358
  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);
359
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
360
+ await this.contractStore.addContractArtifact(artifact);
281
361
  await this.contractStore.addContractInstance(instance);
282
362
  registered[name] = address.toString();
283
363
  }
@@ -289,7 +369,7 @@ export class PXE {
289
369
  async #executePrivate(
290
370
  contractFunctionSimulator: ContractFunctionSimulator,
291
371
  txRequest: TxExecutionRequest,
292
- scopes: AztecAddress[] | undefined,
372
+ scopes: AccessScopes,
293
373
  jobId: string,
294
374
  ): Promise<PrivateExecutionResult> {
295
375
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -297,27 +377,23 @@ export class PXE {
297
377
  try {
298
378
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
299
379
 
300
- await ensureContractSynced(
380
+ await this.contractSyncService.ensureContractSynced(
301
381
  contractAddress,
302
382
  functionSelector,
303
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
304
- this.node,
305
- this.contractStore,
383
+ (privateSyncCall, execScopes) =>
384
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
306
385
  anchorBlockHeader,
386
+ jobId,
387
+ scopes,
307
388
  );
308
389
 
309
- const result = await contractFunctionSimulator.run(
310
- txRequest,
390
+ const result = await contractFunctionSimulator.run(txRequest, {
311
391
  contractAddress,
312
- functionSelector,
313
- undefined,
392
+ selector: functionSelector,
314
393
  anchorBlockHeader,
315
- // The sender for tags is set by contracts, typically by an account
316
- // contract entrypoint
317
- undefined, // senderForTags
318
394
  scopes,
319
395
  jobId,
320
- );
396
+ });
321
397
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
322
398
  return result;
323
399
  } catch (err) {
@@ -329,25 +405,32 @@ export class PXE {
329
405
  }
330
406
 
331
407
  /**
332
- * Simulate a utility function call on the given contract.
408
+ * Execute a utility function call on the given contract.
333
409
  * @param contractFunctionSimulator - The simulator to use for the function call.
334
410
  * @param call - The function call to execute.
335
411
  * @param authWitnesses - Authentication witnesses required for the function call.
336
412
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
337
413
  * accounts if not specified.
338
414
  * @param jobId - The job ID for staged writes.
339
- * @returns The simulation result containing the outputs of the utility function.
415
+ * @returns The execution result containing the outputs of the utility function.
340
416
  */
341
- async #simulateUtility(
417
+ async #executeUtility(
342
418
  contractFunctionSimulator: ContractFunctionSimulator,
343
419
  call: FunctionCall,
344
420
  authWitnesses: AuthWitness[] | undefined,
345
- scopes: AztecAddress[] | undefined,
421
+ scopes: AccessScopes,
346
422
  jobId: string,
347
423
  ) {
348
424
  try {
349
425
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
350
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
426
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
427
+ call,
428
+ authWitnesses ?? [],
429
+ anchorBlockHeader,
430
+ scopes,
431
+ jobId,
432
+ );
433
+ return { result, offchainEffects };
351
434
  } catch (err) {
352
435
  if (err instanceof SimulationError) {
353
436
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -415,6 +498,21 @@ export class PXE {
415
498
 
416
499
  // Public API
417
500
 
501
+ /**
502
+ * Returns the block header up to which the PXE has synced.
503
+ * @returns The synced block header
504
+ */
505
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
506
+ return this.#putInJobQueue(() => {
507
+ return this.anchorBlockStore.getBlockHeader();
508
+ });
509
+ }
510
+
511
+ /**
512
+ * Returns the contract instance for a given address, if it's registered in the PXE.
513
+ * @param address - The contract address.
514
+ * @returns The contract instance if found, undefined otherwise.
515
+ */
418
516
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
419
517
  return this.contractStore.getContractInstance(address);
420
518
  }
@@ -474,6 +572,9 @@ export class PXE {
474
572
 
475
573
  if (wasAdded) {
476
574
  this.log.info(`Added sender:\n ${sender.toString()}`);
575
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
576
+ // all contracts must re-sync to discover them.
577
+ this.contractSyncService.wipe();
477
578
  } else {
478
579
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
479
580
  }
@@ -523,8 +624,7 @@ export class PXE {
523
624
  * @param artifact - The build artifact for the contract class.
524
625
  */
525
626
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
526
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
527
- await this.contractStore.addContractArtifact(contractClassId, artifact);
627
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
528
628
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
529
629
  }
530
630
 
@@ -543,17 +643,17 @@ export class PXE {
543
643
  if (artifact) {
544
644
  // If the user provides an artifact, validate it against the expected class id and register it
545
645
  const contractClass = await getContractClassFromArtifact(artifact);
546
- const contractClassId = contractClass.id;
547
- if (!contractClassId.equals(instance.currentContractClassId)) {
646
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
548
647
  throw new Error(
549
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
648
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
550
649
  );
551
650
  }
552
651
  const computedAddress = await computeContractAddressFromInstance(instance);
553
652
  if (!computedAddress.equals(instance.address)) {
554
653
  throw new Error('Added a contract in which the address does not match the contract instance.');
555
654
  }
556
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
655
+
656
+ await this.contractStore.addContractArtifact(artifact, contractClass);
557
657
 
558
658
  const publicFunctionSignatures = artifact.functions
559
659
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -602,15 +702,16 @@ export class PXE {
602
702
  throw new Error('Could not update contract to a class different from the current one.');
603
703
  }
604
704
 
605
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
606
-
607
705
  const publicFunctionSignatures = artifact.functions
608
706
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
609
707
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
610
708
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
611
709
 
612
710
  currentInstance.currentContractClassId = contractClass.id;
613
- await this.contractStore.addContractInstance(currentInstance);
711
+ await Promise.all([
712
+ this.contractStore.addContractArtifact(artifact, contractClass),
713
+ this.contractStore.addContractInstance(currentInstance),
714
+ ]);
614
715
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
615
716
  });
616
717
  }
@@ -628,11 +729,12 @@ export class PXE {
628
729
  * (where validators prove the public portion).
629
730
  *
630
731
  * @param txRequest - An authenticated tx request ready for proving
732
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
631
733
  * @returns A result containing the proof and public inputs of the tail circuit.
632
734
  * @throws If contract code not found, or public simulation reverts.
633
735
  * Also throws if simulatePublic is true and public simulation reverts.
634
736
  */
635
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
737
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
636
738
  let privateExecutionResult: PrivateExecutionResult;
637
739
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
638
740
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -643,7 +745,7 @@ export class PXE {
643
745
  await this.blockStateSynchronizer.sync();
644
746
  const syncTime = syncTimer.ms();
645
747
  const contractFunctionSimulator = this.#getSimulatorForTx();
646
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
748
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
647
749
 
648
750
  const {
649
751
  publicInputs,
@@ -685,17 +787,17 @@ export class PXE {
685
787
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
686
788
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
687
789
  // storing the tags here prevents linkage of txs sent from the same PXE.
688
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
689
- if (preTagsUsedInTheTx.length > 0) {
790
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
791
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
690
792
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
691
793
  const txHash = (await txProvingResult.toTx()).txHash;
692
794
 
693
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
694
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
695
- preTagsUsedInTheTx,
795
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
796
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
797
+ taggingIndexRangesUsedInTheTx,
696
798
  });
697
799
  } else {
698
- this.log.debug(`No pre-tags used in the tx`);
800
+ this.log.debug(`No tagging index ranges used in the tx`);
699
801
  }
700
802
 
701
803
  return txProvingResult;
@@ -707,17 +809,13 @@ export class PXE {
707
809
 
708
810
  /**
709
811
  * 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.
812
+ * @param txRequest - An authenticated tx request ready for simulation.
714
813
  * @returns A trace of the program execution with gate counts.
715
814
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
716
815
  */
717
816
  public profileTx(
718
817
  txRequest: TxExecutionRequest,
719
- profileMode: 'full' | 'execution-steps' | 'gates',
720
- skipProofGeneration: boolean = true,
818
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
721
819
  ): Promise<TxProfileResult> {
722
820
  // We disable concurrent profiles for consistency with simulateTx.
723
821
  return this.#putInJobQueue(async jobId => {
@@ -740,12 +838,7 @@ export class PXE {
740
838
  const syncTime = syncTimer.ms();
741
839
 
742
840
  const contractFunctionSimulator = this.#getSimulatorForTx();
743
- const privateExecutionResult = await this.#executePrivate(
744
- contractFunctionSimulator,
745
- txRequest,
746
- undefined,
747
- jobId,
748
- );
841
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
749
842
 
750
843
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
751
844
  txRequest,
@@ -802,12 +895,7 @@ export class PXE {
802
895
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
803
896
  *
804
897
  *
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.
898
+ * @param txRequest - An authenticated tx request ready for simulation.
811
899
  * @returns A simulated transaction result object that includes public and private return values.
812
900
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
813
901
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -816,11 +904,14 @@ export class PXE {
816
904
  */
817
905
  public simulateTx(
818
906
  txRequest: TxExecutionRequest,
819
- simulatePublic: boolean,
820
- skipTxValidation: boolean = false,
821
- skipFeeEnforcement: boolean = false,
822
- overrides?: SimulationOverrides,
823
- scopes?: AztecAddress[],
907
+ {
908
+ simulatePublic,
909
+ skipTxValidation = false,
910
+ skipFeeEnforcement = false,
911
+ skipKernels = true,
912
+ overrides,
913
+ scopes,
914
+ }: SimulateTxOpts,
824
915
  ): Promise<TxSimulationResult> {
825
916
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
826
917
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -844,11 +935,21 @@ export class PXE {
844
935
  await this.blockStateSynchronizer.sync();
845
936
  const syncTime = syncTimer.ms();
846
937
 
938
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
939
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
940
+
941
+ if (hasOverriddenContracts && !skipKernels) {
942
+ throw new Error(
943
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
944
+ );
945
+ }
847
946
  const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
848
- // Temporary: in case there are overrides, we have to skip the kernels or validations
849
- // will fail. Consider handing control to the user/wallet on whether they want to run them
850
- // or not.
851
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
947
+
948
+ if (hasOverriddenContracts) {
949
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
950
+ // We exclude them so the sync service skips them entirely.
951
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
952
+ }
852
953
 
853
954
  // Execution of private functions only; no proving, and no kernel logic.
854
955
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -859,7 +960,8 @@ export class PXE {
859
960
  if (skipKernels) {
860
961
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
861
962
  privateExecutionResult,
862
- this.contractStore,
963
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
964
+ this.node,
863
965
  ));
864
966
  } else {
865
967
  // Kernel logic, plus proving of all private functions and kernels.
@@ -878,6 +980,9 @@ export class PXE {
878
980
  const publicSimulationTimer = new Timer();
879
981
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
880
982
  publicSimulationTime = publicSimulationTimer.ms();
983
+ if (publicOutput?.debugLogs?.length) {
984
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
985
+ }
881
986
  }
882
987
 
883
988
  let validationTime: number | undefined;
@@ -886,7 +991,8 @@ export class PXE {
886
991
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
887
992
  validationTime = validationTimer.ms();
888
993
  if (validationResult.result === 'invalid') {
889
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
994
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
995
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
890
996
  }
891
997
  }
892
998
 
@@ -937,29 +1043,23 @@ export class PXE {
937
1043
  inspect(txRequest),
938
1044
  `simulatePublic=${simulatePublic}`,
939
1045
  `skipTxValidation=${skipTxValidation}`,
940
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1046
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
941
1047
  );
942
1048
  }
943
1049
  });
944
1050
  }
945
1051
 
946
1052
  /**
947
- * Simulate the execution of a contract utility function.
948
- *
1053
+ * Executes a contract utility function.
949
1054
  * @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
1055
  */
955
- public simulateUtility(
1056
+ public executeUtility(
956
1057
  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.
1058
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
1059
+ ): Promise<UtilityExecutionResult> {
1060
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
961
1061
  // 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).
1062
+ // delete the same read value, or reading values that another execution is currently modifying).
963
1063
  return this.#putInJobQueue(async jobId => {
964
1064
  try {
965
1065
  const totalTimer = new Timer();
@@ -970,16 +1070,17 @@ export class PXE {
970
1070
  const contractFunctionSimulator = this.#getSimulatorForTx();
971
1071
 
972
1072
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
973
- await ensureContractSynced(
1073
+ await this.contractSyncService.ensureContractSynced(
974
1074
  call.to,
975
1075
  call.selector,
976
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
977
- this.node,
978
- this.contractStore,
1076
+ (privateSyncCall, execScopes) =>
1077
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
979
1078
  anchorBlockHeader,
1079
+ jobId,
1080
+ scopes,
980
1081
  );
981
1082
 
982
- const executionResult = await this.#simulateUtility(
1083
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
983
1084
  contractFunctionSimulator,
984
1085
  call,
985
1086
  authwits ?? [],
@@ -1000,14 +1101,19 @@ export class PXE {
1000
1101
  };
1001
1102
 
1002
1103
  const simulationStats = contractFunctionSimulator.getStats();
1003
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1104
+ return {
1105
+ result: executionResult,
1106
+ offchainEffects,
1107
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1108
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1109
+ };
1004
1110
  } catch (err: any) {
1005
1111
  const { to, name, args } = call;
1006
1112
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1007
1113
  throw this.#contextualizeError(
1008
1114
  err,
1009
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1010
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1115
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1116
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1011
1117
  );
1012
1118
  }
1013
1119
  });
@@ -1040,14 +1146,14 @@ export class PXE {
1040
1146
 
1041
1147
  const contractFunctionSimulator = this.#getSimulatorForTx();
1042
1148
 
1043
- await ensureContractSynced(
1149
+ await this.contractSyncService.ensureContractSynced(
1044
1150
  filter.contractAddress,
1045
1151
  null,
1046
- async privateSyncCall =>
1047
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1048
- this.node,
1049
- this.contractStore,
1152
+ async (privateSyncCall, execScopes) =>
1153
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1050
1154
  anchorBlockHeader,
1155
+ jobId,
1156
+ filter.scopes,
1051
1157
  );
1052
1158
  });
1053
1159
 
@@ -1062,9 +1168,10 @@ export class PXE {
1062
1168
  }
1063
1169
 
1064
1170
  /**
1065
- * Stops the PXE's job queue.
1171
+ * Stops the PXE's job queue and closes the backing store.
1066
1172
  */
1067
- public stop(): Promise<void> {
1068
- return this.jobQueue.end();
1173
+ public async stop(): Promise<void> {
1174
+ await this.jobQueue.end();
1175
+ await this.db.close();
1069
1176
  }
1070
1177
  }