@aztec/pxe 0.0.1-commit.8afd444 → 0.0.1-commit.9117c5f5a

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