@aztec/pxe 0.0.1-commit.2ed92850 → 0.0.1-commit.3d8f95d

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 (144) hide show
  1. package/dest/block_synchronizer/block_synchronizer.d.ts +5 -3
  2. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  3. package/dest/block_synchronizer/block_synchronizer.js +11 -5
  4. package/dest/contract_function_simulator/contract_function_simulator.d.ts +50 -28
  5. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  6. package/dest/contract_function_simulator/contract_function_simulator.js +70 -36
  7. package/dest/contract_function_simulator/oracle/interfaces.d.ts +10 -10
  8. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/contract_function_simulator/oracle/oracle.d.ts +5 -5
  10. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/oracle/oracle.js +38 -26
  12. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +35 -36
  13. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +66 -21
  15. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +52 -29
  16. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +80 -61
  18. package/dest/contract_sync/contract_sync_service.d.ts +41 -0
  19. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  20. package/dest/contract_sync/contract_sync_service.js +82 -0
  21. package/dest/contract_sync/helpers.d.ts +28 -0
  22. package/dest/contract_sync/helpers.d.ts.map +1 -0
  23. package/dest/contract_sync/{index.js → helpers.js} +13 -12
  24. package/dest/debug/pxe_debug_utils.d.ts +22 -9
  25. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  26. package/dest/debug/pxe_debug_utils.js +28 -18
  27. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  28. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  29. package/dest/entrypoints/client/bundle/utils.js +21 -7
  30. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  31. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  32. package/dest/entrypoints/client/lazy/utils.js +22 -8
  33. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  34. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  35. package/dest/entrypoints/server/index.d.ts +2 -2
  36. package/dest/entrypoints/server/index.d.ts.map +1 -1
  37. package/dest/entrypoints/server/index.js +1 -1
  38. package/dest/entrypoints/server/utils.d.ts +1 -1
  39. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  40. package/dest/entrypoints/server/utils.js +28 -9
  41. package/dest/events/event_service.d.ts +4 -5
  42. package/dest/events/event_service.d.ts.map +1 -1
  43. package/dest/events/event_service.js +5 -6
  44. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  45. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  46. package/dest/job_coordinator/job_coordinator.js +3 -2
  47. package/dest/logs/log_service.d.ts +6 -5
  48. package/dest/logs/log_service.d.ts.map +1 -1
  49. package/dest/logs/log_service.js +10 -15
  50. package/dest/notes/note_service.d.ts +4 -5
  51. package/dest/notes/note_service.d.ts.map +1 -1
  52. package/dest/notes/note_service.js +6 -7
  53. package/dest/oracle_version.d.ts +3 -3
  54. package/dest/oracle_version.d.ts.map +1 -1
  55. package/dest/oracle_version.js +2 -2
  56. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  57. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  58. package/dest/private_kernel/private_kernel_execution_prover.js +2 -2
  59. package/dest/private_kernel/private_kernel_oracle.d.ts +3 -3
  60. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  61. package/dest/pxe.d.ts +64 -22
  62. package/dest/pxe.d.ts.map +1 -1
  63. package/dest/pxe.js +66 -39
  64. package/dest/storage/address_store/address_store.d.ts +1 -1
  65. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  66. package/dest/storage/address_store/address_store.js +12 -11
  67. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  68. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  69. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  70. package/dest/storage/capsule_store/capsule_store.js +6 -8
  71. package/dest/storage/contract_store/contract_store.d.ts +1 -1
  72. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  73. package/dest/storage/contract_store/contract_store.js +27 -18
  74. package/dest/storage/metadata.d.ts +1 -1
  75. package/dest/storage/metadata.js +1 -1
  76. package/dest/storage/note_store/note_store.d.ts +11 -1
  77. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  78. package/dest/storage/note_store/note_store.js +146 -105
  79. package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
  80. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  81. package/dest/storage/private_event_store/private_event_store.js +84 -61
  82. package/dest/storage/private_event_store/stored_private_event.d.ts +4 -4
  83. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
  84. package/dest/storage/private_event_store/stored_private_event.js +2 -2
  85. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +1 -1
  86. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  87. package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
  88. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  89. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  90. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  91. package/dest/storage/tagging_store/sender_tagging_store.d.ts +1 -1
  92. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  93. package/dest/storage/tagging_store/sender_tagging_store.js +183 -113
  94. package/dest/tagging/get_all_logs_by_tags.d.ts +4 -4
  95. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  96. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -3
  97. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  98. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -3
  99. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  100. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -3
  101. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  102. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +3 -3
  103. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  104. package/package.json +25 -16
  105. package/src/block_synchronizer/block_synchronizer.ts +23 -19
  106. package/src/contract_function_simulator/contract_function_simulator.ts +115 -77
  107. package/src/contract_function_simulator/oracle/interfaces.ts +12 -12
  108. package/src/contract_function_simulator/oracle/oracle.ts +41 -24
  109. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +86 -101
  110. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +131 -69
  111. package/src/contract_sync/contract_sync_service.ts +129 -0
  112. package/src/contract_sync/{index.ts → helpers.ts} +15 -20
  113. package/src/debug/pxe_debug_utils.ts +60 -18
  114. package/src/entrypoints/client/bundle/utils.ts +16 -15
  115. package/src/entrypoints/client/lazy/utils.ts +17 -15
  116. package/src/entrypoints/pxe_creation_options.ts +2 -1
  117. package/src/entrypoints/server/index.ts +1 -1
  118. package/src/entrypoints/server/utils.ts +22 -26
  119. package/src/events/event_service.ts +4 -6
  120. package/src/job_coordinator/job_coordinator.ts +4 -3
  121. package/src/logs/log_service.ts +14 -14
  122. package/src/notes/note_service.ts +5 -7
  123. package/src/oracle_version.ts +2 -2
  124. package/src/private_kernel/private_kernel_execution_prover.ts +6 -3
  125. package/src/private_kernel/private_kernel_oracle.ts +2 -2
  126. package/src/pxe.ts +140 -74
  127. package/src/storage/address_store/address_store.ts +15 -15
  128. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  129. package/src/storage/capsule_store/capsule_store.ts +8 -8
  130. package/src/storage/contract_store/contract_store.ts +26 -15
  131. package/src/storage/metadata.ts +1 -1
  132. package/src/storage/note_store/note_store.ts +163 -129
  133. package/src/storage/private_event_store/private_event_store.ts +102 -81
  134. package/src/storage/private_event_store/stored_private_event.ts +3 -3
  135. package/src/storage/tagging_store/recipient_tagging_store.ts +31 -21
  136. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  137. package/src/storage/tagging_store/sender_tagging_store.ts +210 -126
  138. package/src/tagging/get_all_logs_by_tags.ts +3 -3
  139. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +2 -2
  140. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +2 -2
  141. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +2 -2
  142. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +3 -3
  143. package/dest/contract_sync/index.d.ts +0 -23
  144. package/dest/contract_sync/index.d.ts.map +0 -1
package/src/pxe.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
5
  import { SerialQueue } from '@aztec/foundation/queue';
6
6
  import { Timer } from '@aztec/foundation/timer';
7
7
  import { KeyStore } from '@aztec/key-store';
@@ -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,
@@ -59,7 +60,8 @@ import {
59
60
  generateSimulatedProvingResult,
60
61
  } from './contract_function_simulator/contract_function_simulator.js';
61
62
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
62
- import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
63
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
64
+ import { readCurrentClassId } from './contract_sync/helpers.js';
63
65
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
64
66
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
65
67
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
@@ -84,6 +86,54 @@ export type PackedPrivateEvent = InTx & {
84
86
  eventSelector: EventSelector;
85
87
  };
86
88
 
89
+ /** Options for PXE.profileTx. */
90
+ export type ProfileTxOpts = {
91
+ /** The profiling mode to use. */
92
+ profileMode: 'full' | 'execution-steps' | 'gates';
93
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
94
+ skipProofGeneration?: boolean;
95
+ };
96
+
97
+ /** Options for PXE.simulateTx. */
98
+ export type SimulateTxOpts = {
99
+ /** Whether to simulate the public part of the transaction. */
100
+ simulatePublic: boolean;
101
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
102
+ skipTxValidation?: boolean;
103
+ /** If false, fees are enforced. */
104
+ skipFeeEnforcement?: boolean;
105
+ /** State overrides for the simulation, such as contract instances and artifacts. */
106
+ overrides?: SimulationOverrides;
107
+ /** The accounts whose notes we can access in this call. Defaults to all. */
108
+ scopes?: AztecAddress[];
109
+ };
110
+
111
+ /** Options for PXE.simulateUtility. */
112
+ export type SimulateUtilityOpts = {
113
+ /** The authentication witnesses required for the function call. */
114
+ authwits?: AuthWitness[];
115
+ /** The accounts whose notes we can access in this call. Defaults to all. */
116
+ scopes?: AztecAddress[];
117
+ };
118
+
119
+ /** Args for PXE.create. */
120
+ export type PXECreateArgs = {
121
+ /** The Aztec node to connect to. */
122
+ node: AztecNode;
123
+ /** The key-value store for persisting PXE state. */
124
+ store: AztecAsyncKVStore;
125
+ /** The prover for generating private kernel proofs. */
126
+ proofCreator: PrivateKernelProver;
127
+ /** The circuit simulator for executing ACIR circuits. */
128
+ simulator: CircuitSimulator;
129
+ /** Provider for protocol contract artifacts and instances. */
130
+ protocolContractsProvider: ProtocolContractsProvider;
131
+ /** PXE configuration options. */
132
+ config: PXEConfig;
133
+ /** Optional logger instance or string suffix for the logger name. */
134
+ loggerOrSuffix?: string | Logger;
135
+ };
136
+
87
137
  /**
88
138
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
89
139
  * manage private state of users.
@@ -102,6 +152,7 @@ export class PXE {
102
152
  private recipientTaggingStore: RecipientTaggingStore,
103
153
  private addressStore: AddressStore,
104
154
  private privateEventStore: PrivateEventStore,
155
+ private contractSyncService: ContractSyncService,
105
156
  private simulator: CircuitSimulator,
106
157
  private proverEnabled: boolean,
107
158
  private proofCreator: PrivateKernelProver,
@@ -119,15 +170,19 @@ export class PXE {
119
170
  *
120
171
  * @returns A promise that resolves PXE is ready to be used.
121
172
  */
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
- ) {
173
+ public static async create({
174
+ node,
175
+ store,
176
+ proofCreator,
177
+ simulator,
178
+ protocolContractsProvider,
179
+ config,
180
+ loggerOrSuffix,
181
+ }: PXECreateArgs) {
182
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
183
+ const bindings: LoggerBindings | undefined =
184
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
185
+
131
186
  const log =
132
187
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
133
188
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
@@ -145,6 +200,12 @@ export class PXE {
145
200
  const capsuleStore = new CapsuleStore(store);
146
201
  const keyStore = new KeyStore(store);
147
202
  const tipsStore = new L2TipsKVStore(store, 'pxe');
203
+ const contractSyncService = new ContractSyncService(
204
+ node,
205
+ contractStore,
206
+ noteStore,
207
+ createLogger('pxe:contract_sync', bindings),
208
+ );
148
209
  const synchronizer = new BlockSynchronizer(
149
210
  node,
150
211
  store,
@@ -152,20 +213,22 @@ export class PXE {
152
213
  noteStore,
153
214
  privateEventStore,
154
215
  tipsStore,
216
+ contractSyncService,
155
217
  config,
156
- loggerOrSuffix,
218
+ bindings,
157
219
  );
158
220
 
159
- const jobCoordinator = new JobCoordinator(store);
221
+ const jobCoordinator = new JobCoordinator(store, bindings);
160
222
  jobCoordinator.registerStores([
161
223
  capsuleStore,
162
224
  senderTaggingStore,
163
225
  recipientTaggingStore,
164
226
  privateEventStore,
165
227
  noteStore,
228
+ contractSyncService,
166
229
  ]);
167
230
 
168
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
231
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
169
232
 
170
233
  const jobQueue = new SerialQueue();
171
234
 
@@ -182,6 +245,7 @@ export class PXE {
182
245
  recipientTaggingStore,
183
246
  addressStore,
184
247
  privateEventStore,
248
+ contractSyncService,
185
249
  simulator,
186
250
  proverEnabled,
187
251
  proofCreator,
@@ -192,7 +256,11 @@ export class PXE {
192
256
  debugUtils,
193
257
  );
194
258
 
195
- debugUtils.setPXE(pxe);
259
+ debugUtils.setPXEHelpers(
260
+ pxe.#putInJobQueue.bind(pxe),
261
+ pxe.#getSimulatorForTx.bind(pxe),
262
+ pxe.#simulateUtility.bind(pxe),
263
+ );
196
264
 
197
265
  pxe.jobQueue.start();
198
266
 
@@ -207,20 +275,20 @@ export class PXE {
207
275
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
208
276
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
209
277
 
210
- return new ContractFunctionSimulator(
211
- proxyContractStore,
212
- this.noteStore,
213
- this.keyStore,
214
- this.addressStore,
215
- BenchmarkedNodeFactory.create(this.node),
216
- this.anchorBlockStore,
217
- this.senderTaggingStore,
218
- this.recipientTaggingStore,
219
- this.senderAddressBookStore,
220
- this.capsuleStore,
221
- this.privateEventStore,
222
- this.simulator,
223
- );
278
+ return new ContractFunctionSimulator({
279
+ contractStore: proxyContractStore,
280
+ noteStore: this.noteStore,
281
+ keyStore: this.keyStore,
282
+ addressStore: this.addressStore,
283
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
284
+ senderTaggingStore: this.senderTaggingStore,
285
+ recipientTaggingStore: this.recipientTaggingStore,
286
+ senderAddressBookStore: this.senderAddressBookStore,
287
+ capsuleStore: this.capsuleStore,
288
+ privateEventStore: this.privateEventStore,
289
+ simulator: this.simulator,
290
+ contractSyncService: this.contractSyncService,
291
+ });
224
292
  }
225
293
 
226
294
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -294,27 +362,21 @@ export class PXE {
294
362
  try {
295
363
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
296
364
 
297
- await ensureContractSynced(
365
+ await this.contractSyncService.ensureContractSynced(
298
366
  contractAddress,
299
367
  functionSelector,
300
368
  privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
301
- this.node,
302
- this.contractStore,
303
369
  anchorBlockHeader,
370
+ jobId,
304
371
  );
305
372
 
306
- const result = await contractFunctionSimulator.run(
307
- txRequest,
373
+ const result = await contractFunctionSimulator.run(txRequest, {
308
374
  contractAddress,
309
- functionSelector,
310
- undefined,
375
+ selector: functionSelector,
311
376
  anchorBlockHeader,
312
- // The sender for tags is set by contracts, typically by an account
313
- // contract entrypoint
314
- undefined, // senderForTags
315
377
  scopes,
316
378
  jobId,
317
- );
379
+ });
318
380
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
319
381
  return result;
320
382
  } catch (err) {
@@ -400,13 +462,31 @@ export class PXE {
400
462
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
401
463
  const anchorBlockHash = await anchorBlockHeader.hash();
402
464
  const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
403
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
465
+ const kernelTraceProver = new PrivateKernelExecutionProver(
466
+ kernelOracle,
467
+ proofCreator,
468
+ !this.proverEnabled,
469
+ this.log.getBindings(),
470
+ );
404
471
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
405
472
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
406
473
  }
407
474
 
408
475
  // Public API
409
476
 
477
+ /**
478
+ * Returns the block header up to which the PXE has synced.
479
+ * @returns The synced block header
480
+ */
481
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
482
+ return this.anchorBlockStore.getBlockHeader();
483
+ }
484
+
485
+ /**
486
+ * Returns the contract instance for a given address, if it's registered in the PXE.
487
+ * @param address - The contract address.
488
+ * @returns The contract instance if found, undefined otherwise.
489
+ */
410
490
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
411
491
  return this.contractStore.getContractInstance(address);
412
492
  }
@@ -699,17 +779,13 @@ export class PXE {
699
779
 
700
780
  /**
701
781
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
702
- *
703
- * @param txRequest - An authenticated tx request ready for simulation
704
- * @param msgSender - (Optional) The message sender to use for the simulation.
705
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
782
+ * @param txRequest - An authenticated tx request ready for simulation.
706
783
  * @returns A trace of the program execution with gate counts.
707
784
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
708
785
  */
709
786
  public profileTx(
710
787
  txRequest: TxExecutionRequest,
711
- profileMode: 'full' | 'execution-steps' | 'gates',
712
- skipProofGeneration: boolean = true,
788
+ { profileMode, skipProofGeneration = true }: ProfileTxOpts,
713
789
  ): Promise<TxProfileResult> {
714
790
  // We disable concurrent profiles for consistency with simulateTx.
715
791
  return this.#putInJobQueue(async jobId => {
@@ -794,12 +870,7 @@ export class PXE {
794
870
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
795
871
  *
796
872
  *
797
- * @param txRequest - An authenticated tx request ready for simulation
798
- * @param simulatePublic - Whether to simulate the public part of the transaction.
799
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
800
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
801
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
802
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
873
+ * @param txRequest - An authenticated tx request ready for simulation.
803
874
  * @returns A simulated transaction result object that includes public and private return values.
804
875
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
805
876
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -808,11 +879,7 @@ export class PXE {
808
879
  */
809
880
  public simulateTx(
810
881
  txRequest: TxExecutionRequest,
811
- simulatePublic: boolean,
812
- skipTxValidation: boolean = false,
813
- skipFeeEnforcement: boolean = false,
814
- overrides?: SimulationOverrides,
815
- scopes?: AztecAddress[],
882
+ { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
816
883
  ): Promise<TxSimulationResult> {
817
884
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
818
885
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -840,7 +907,14 @@ export class PXE {
840
907
  // Temporary: in case there are overrides, we have to skip the kernels or validations
841
908
  // will fail. Consider handing control to the user/wallet on whether they want to run them
842
909
  // or not.
843
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
910
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
911
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
912
+ const skipKernels = hasOverriddenContracts;
913
+
914
+ // Set overridden contracts on the sync service so it knows to skip syncing them
915
+ if (hasOverriddenContracts) {
916
+ this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
917
+ }
844
918
 
845
919
  // Execution of private functions only; no proving, and no kernel logic.
846
920
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -851,7 +925,7 @@ export class PXE {
851
925
  if (skipKernels) {
852
926
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
853
927
  privateExecutionResult,
854
- this.contractStore,
928
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
855
929
  ));
856
930
  } else {
857
931
  // Kernel logic, plus proving of all private functions and kernels.
@@ -936,18 +1010,12 @@ export class PXE {
936
1010
  }
937
1011
 
938
1012
  /**
939
- * Simulate the execution of a contract utility function.
940
- *
1013
+ * Simulates the execution of a contract utility function.
941
1014
  * @param call - The function call containing the function details, arguments, and target contract address.
942
- * @param authwits - (Optional) The authentication witnesses required for the function call.
943
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
944
- * default to all.
945
- * @returns The result of the utility function call, structured based on the function ABI.
946
1015
  */
947
1016
  public simulateUtility(
948
1017
  call: FunctionCall,
949
- authwits?: AuthWitness[],
950
- scopes?: AztecAddress[],
1018
+ { authwits, scopes }: SimulateUtilityOpts = {},
951
1019
  ): Promise<UtilitySimulationResult> {
952
1020
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
953
1021
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -962,13 +1030,12 @@ export class PXE {
962
1030
  const contractFunctionSimulator = this.#getSimulatorForTx();
963
1031
 
964
1032
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
965
- await ensureContractSynced(
1033
+ await this.contractSyncService.ensureContractSynced(
966
1034
  call.to,
967
1035
  call.selector,
968
1036
  privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
969
- this.node,
970
- this.contractStore,
971
1037
  anchorBlockHeader,
1038
+ jobId,
972
1039
  );
973
1040
 
974
1041
  const executionResult = await this.#simulateUtility(
@@ -1032,14 +1099,13 @@ export class PXE {
1032
1099
 
1033
1100
  const contractFunctionSimulator = this.#getSimulatorForTx();
1034
1101
 
1035
- await ensureContractSynced(
1102
+ await this.contractSyncService.ensureContractSynced(
1036
1103
  filter.contractAddress,
1037
1104
  null,
1038
1105
  async privateSyncCall =>
1039
1106
  await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1040
- this.node,
1041
- this.contractStore,
1042
1107
  anchorBlockHeader,
1108
+ jobId,
1043
1109
  );
1044
1110
  });
1045
1111
 
@@ -43,23 +43,23 @@ export class AddressStore {
43
43
  });
44
44
  }
45
45
 
46
- async #getCompleteAddress(address: AztecAddress): Promise<CompleteAddress | undefined> {
47
- const index = await this.#completeAddressIndex.getAsync(address.toString());
48
- if (index === undefined) {
49
- return undefined;
50
- }
51
-
52
- const value = await this.#completeAddresses.atAsync(index);
53
- return value ? await CompleteAddress.fromBuffer(value) : undefined;
54
- }
55
-
56
46
  getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
57
- return this.#getCompleteAddress(account);
47
+ return this.#store.transactionAsync(async () => {
48
+ const index = await this.#completeAddressIndex.getAsync(account.toString());
49
+ if (index === undefined) {
50
+ return undefined;
51
+ }
52
+
53
+ const value = await this.#completeAddresses.atAsync(index);
54
+ return value ? await CompleteAddress.fromBuffer(value) : undefined;
55
+ });
58
56
  }
59
57
 
60
- async getCompleteAddresses(): Promise<CompleteAddress[]> {
61
- return await Promise.all(
62
- (await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
63
- );
58
+ getCompleteAddresses(): Promise<CompleteAddress[]> {
59
+ return this.#store.transactionAsync(async () => {
60
+ return await Promise.all(
61
+ (await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
62
+ );
63
+ });
64
64
  }
65
65
  }
@@ -10,6 +10,14 @@ export class AnchorBlockStore {
10
10
  this.#synchronizedHeader = this.#store.openSingleton('header');
11
11
  }
12
12
 
13
+ /**
14
+ * Sets the currently synchronized block
15
+ *
16
+ * Important: this method is only called from BlockSynchronizer, and since we need it to run atomically with other
17
+ * stores in the case of a reorg, it MUST NOT be wrapped in a `transactionAsync` call. Doing so would result in a
18
+ * deadlock when the backend is IndexedDB, because `transactionAsync` is not designed to support reentrancy.
19
+ *
20
+ */
13
21
  async setHeader(header: BlockHeader): Promise<void> {
14
22
  await this.#synchronizedHeader.set(header.toBuffer());
15
23
  }
@@ -57,14 +57,14 @@ export class CapsuleStore implements StagedStore {
57
57
  */
58
58
  async #getFromStage(jobId: string, dbSlotKey: string): Promise<Buffer | null | undefined> {
59
59
  const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
60
- let staged: Buffer | null | undefined = jobStagedCapsules.get(dbSlotKey);
61
- // Note that if staged === null, we marked it for deletion, so we don't want to
62
- // re-read it from DB
63
- if (staged === undefined) {
64
- // If we don't have a staged version of this dbSlotKey, first we check if there's one in DB
65
- staged = await this.#loadCapsuleFromDb(dbSlotKey);
66
- }
67
- return staged;
60
+ const staged: Buffer | null | undefined = jobStagedCapsules.get(dbSlotKey);
61
+
62
+ // Always issue DB read to keep IndexedDB transaction alive, even if the value is in the job staged data. This
63
+ // keeps IndexedDB transactions alive (they auto-commit when a new micro-task starts and there are no pending read
64
+ // requests). The staged value still takes precedence if it exists (including null for deletions).
65
+ const dbValue = await this.#loadCapsuleFromDb(dbSlotKey);
66
+
67
+ return staged !== undefined ? staged : dbValue;
68
68
  }
69
69
 
70
70
  /**
@@ -42,10 +42,12 @@ export class ContractStore {
42
42
  /** Map from contract address to contract class id */
43
43
  #contractClassIdMap: Map<string, Fr> = new Map();
44
44
 
45
+ #store: AztecAsyncKVStore;
45
46
  #contractArtifacts: AztecAsyncMap<string, Buffer>;
46
47
  #contractInstances: AztecAsyncMap<string, Buffer>;
47
48
 
48
49
  constructor(store: AztecAsyncKVStore) {
50
+ this.#store = store;
49
51
  this.#contractArtifacts = store.openMap('contract_artifacts');
50
52
  this.#contractInstances = store.openMap('contracts_instances');
51
53
  }
@@ -53,6 +55,7 @@ export class ContractStore {
53
55
  // Setters
54
56
 
55
57
  public async addContractArtifact(id: Fr, contract: ContractArtifact): Promise<void> {
58
+ // Validation outside transactionAsync - these are not DB operations
56
59
  const privateFunctions = contract.functions.filter(
57
60
  functionArtifact => functionArtifact.functionType === FunctionType.PRIVATE,
58
61
  );
@@ -69,7 +72,9 @@ export class ContractStore {
69
72
  throw new Error('Repeated function selectors of private functions');
70
73
  }
71
74
 
72
- await this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract));
75
+ await this.#store.transactionAsync(() =>
76
+ this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract)),
77
+ );
73
78
  }
74
79
 
75
80
  async addContractInstance(contract: ContractInstanceWithAddress): Promise<void> {
@@ -123,21 +128,27 @@ export class ContractStore {
123
128
 
124
129
  // Public getters
125
130
 
126
- async getContractsAddresses(): Promise<AztecAddress[]> {
127
- const keys = await toArray(this.#contractInstances.keysAsync());
128
- return keys.map(AztecAddress.fromString);
131
+ getContractsAddresses(): Promise<AztecAddress[]> {
132
+ return this.#store.transactionAsync(async () => {
133
+ const keys = await toArray(this.#contractInstances.keysAsync());
134
+ return keys.map(AztecAddress.fromString);
135
+ });
129
136
  }
130
137
 
131
138
  /** Returns a contract instance for a given address. Throws if not found. */
132
- public async getContractInstance(contractAddress: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
133
- const contract = await this.#contractInstances.getAsync(contractAddress.toString());
134
- return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
139
+ public getContractInstance(contractAddress: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
140
+ return this.#store.transactionAsync(async () => {
141
+ const contract = await this.#contractInstances.getAsync(contractAddress.toString());
142
+ return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
143
+ });
135
144
  }
136
145
 
137
- public async getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | undefined> {
138
- const contract = await this.#contractArtifacts.getAsync(contractClassId.toString());
139
- // TODO(@spalladino): AztecAsyncMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from.
140
- return contract && contractArtifactFromBuffer(Buffer.from(contract));
146
+ public getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | undefined> {
147
+ return this.#store.transactionAsync(async () => {
148
+ const contract = await this.#contractArtifacts.getAsync(contractClassId.toString());
149
+ // TODO(@spalladino): AztecAsyncMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from.
150
+ return contract && contractArtifactFromBuffer(Buffer.from(contract));
151
+ });
141
152
  }
142
153
 
143
154
  /** Returns a contract class for a given class id. Throws if not found. */
@@ -305,15 +316,15 @@ export class ContractStore {
305
316
  throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
306
317
  }
307
318
 
308
- return {
319
+ return FunctionCall.from({
309
320
  name: functionDao.name,
310
- args: encodeArguments(functionDao, args),
321
+ to,
311
322
  selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
312
323
  type: functionDao.functionType,
313
- to,
314
324
  hideMsgSender: false,
315
325
  isStatic: functionDao.isStatic,
326
+ args: encodeArguments(functionDao, args),
316
327
  returnTypes: functionDao.returnTypes,
317
- };
328
+ });
318
329
  }
319
330
  }
@@ -1 +1 @@
1
- export const PXE_DATA_SCHEMA_VERSION = 2;
1
+ export const PXE_DATA_SCHEMA_VERSION = 3;