@aztec/pxe 0.0.1-commit.6230a0c → 0.0.1-commit.64b6bbb

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 (65) hide show
  1. package/dest/block_synchronizer/block_synchronizer.d.ts +4 -2
  2. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  3. package/dest/block_synchronizer/block_synchronizer.js +7 -1
  4. package/dest/contract_function_simulator/contract_function_simulator.d.ts +50 -26
  5. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  6. package/dest/contract_function_simulator/contract_function_simulator.js +66 -30
  7. package/dest/contract_function_simulator/oracle/interfaces.d.ts +2 -2
  8. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -2
  10. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/oracle/oracle.js +3 -3
  12. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +35 -35
  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 +64 -19
  15. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +31 -11
  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 +53 -29
  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} +6 -12
  24. package/dest/debug/pxe_debug_utils.d.ts +12 -9
  25. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  26. package/dest/debug/pxe_debug_utils.js +16 -15
  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 +9 -1
  30. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  31. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  32. package/dest/entrypoints/client/lazy/utils.js +9 -1
  33. package/dest/entrypoints/server/index.d.ts +2 -2
  34. package/dest/entrypoints/server/index.d.ts.map +1 -1
  35. package/dest/entrypoints/server/index.js +1 -1
  36. package/dest/entrypoints/server/utils.js +9 -1
  37. package/dest/oracle_version.d.ts +2 -2
  38. package/dest/oracle_version.js +2 -2
  39. package/dest/pxe.d.ts +64 -22
  40. package/dest/pxe.d.ts.map +1 -1
  41. package/dest/pxe.js +62 -37
  42. package/dest/storage/contract_store/contract_store.js +5 -5
  43. package/dest/storage/note_store/note_store.d.ts +1 -1
  44. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  45. package/dest/storage/note_store/note_store.js +3 -0
  46. package/package.json +25 -16
  47. package/src/block_synchronizer/block_synchronizer.ts +6 -0
  48. package/src/contract_function_simulator/contract_function_simulator.ts +109 -71
  49. package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
  50. package/src/contract_function_simulator/oracle/oracle.ts +3 -3
  51. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +83 -96
  52. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +94 -28
  53. package/src/contract_sync/contract_sync_service.ts +129 -0
  54. package/src/contract_sync/{index.ts → helpers.ts} +6 -32
  55. package/src/debug/pxe_debug_utils.ts +45 -17
  56. package/src/entrypoints/client/bundle/utils.ts +9 -1
  57. package/src/entrypoints/client/lazy/utils.ts +9 -1
  58. package/src/entrypoints/server/index.ts +1 -1
  59. package/src/entrypoints/server/utils.ts +7 -7
  60. package/src/oracle_version.ts +2 -2
  61. package/src/pxe.ts +124 -72
  62. package/src/storage/contract_store/contract_store.ts +4 -4
  63. package/src/storage/note_store/note_store.ts +4 -0
  64. package/dest/contract_sync/index.d.ts +0 -24
  65. package/dest/contract_sync/index.d.ts.map +0 -1
@@ -1,10 +1,12 @@
1
- import { randomBytes } from '@aztec/foundation/crypto/random';
1
+ import type { FunctionCall } from '@aztec/stdlib/abi';
2
+ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
4
  import type { NoteDao, NotesFilter } from '@aztec/stdlib/note';
3
- import type { BlockHeader } from '@aztec/stdlib/tx';
5
+ import type { ContractOverrides } from '@aztec/stdlib/tx';
4
6
 
5
7
  import type { BlockSynchronizer } from '../block_synchronizer/block_synchronizer.js';
6
- import type { PXE } from '../pxe.js';
7
- import type { ContractStore } from '../storage/contract_store/contract_store.js';
8
+ import type { ContractFunctionSimulator } from '../contract_function_simulator/contract_function_simulator.js';
9
+ import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
8
10
  import type { AnchorBlockStore } from '../storage/index.js';
9
11
  import type { NoteStore } from '../storage/note_store/note_store.js';
10
12
 
@@ -13,20 +15,38 @@ import type { NoteStore } from '../storage/note_store/note_store.js';
13
15
  * No backwards compatibility or API stability should be expected. Use at your own risk.
14
16
  */
15
17
  export class PXEDebugUtils {
16
- #pxe!: PXE;
17
18
  #putJobInQueue!: <T>(job: (jobId: string) => Promise<T>) => Promise<T>;
19
+ #getSimulatorForTx!: (overrides?: { contracts?: ContractOverrides }) => ContractFunctionSimulator;
20
+ #simulateUtility!: (
21
+ contractFunctionSimulator: ContractFunctionSimulator,
22
+ call: FunctionCall,
23
+ authWitnesses: AuthWitness[] | undefined,
24
+ scopes: AztecAddress[] | undefined,
25
+ jobId: string,
26
+ ) => Promise<any>;
18
27
 
19
28
  constructor(
20
- private contractStore: ContractStore,
29
+ private contractSyncService: ContractSyncService,
21
30
  private noteStore: NoteStore,
22
31
  private blockStateSynchronizer: BlockSynchronizer,
23
32
  private anchorBlockStore: AnchorBlockStore,
24
33
  ) {}
25
34
 
26
35
  /** Not injected through constructor since they're are co-dependant */
27
- public setPXE(pxe: PXE, putJobInQueue: <T>(job: (jobId: string) => Promise<T>) => Promise<T>) {
28
- this.#pxe = pxe;
36
+ public setPXEHelpers(
37
+ putJobInQueue: <T>(job: (jobId: string) => Promise<T>) => Promise<T>,
38
+ getSimulatorForTx: (overrides?: { contracts?: ContractOverrides }) => ContractFunctionSimulator,
39
+ simulateUtility: (
40
+ contractFunctionSimulator: ContractFunctionSimulator,
41
+ call: FunctionCall,
42
+ authWitnesses: AuthWitness[] | undefined,
43
+ scopes: AztecAddress[] | undefined,
44
+ jobId: string,
45
+ ) => Promise<any>,
46
+ ) {
29
47
  this.#putJobInQueue = putJobInQueue;
48
+ this.#getSimulatorForTx = getSimulatorForTx;
49
+ this.#simulateUtility = simulateUtility;
30
50
  }
31
51
 
32
52
  /**
@@ -40,17 +60,25 @@ export class PXEDebugUtils {
40
60
  * @param filter - The filter to apply to the notes.
41
61
  * @returns The requested notes.
42
62
  */
43
- public async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
44
- // We need to manually trigger private state sync to have a guarantee that all the notes are available.
45
- const call = await this.contractStore.getFunctionCall('sync_state', [], filter.contractAddress);
46
- await this.#pxe.simulateUtility(call);
63
+ public getNotes(filter: NotesFilter): Promise<NoteDao[]> {
64
+ return this.#putJobInQueue(async (jobId: string) => {
65
+ await this.blockStateSynchronizer.sync();
47
66
 
48
- return this.noteStore.getNotes(filter, randomBytes(8).toString('hex'));
49
- }
67
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
68
+
69
+ const contractFunctionSimulator = this.#getSimulatorForTx();
70
+
71
+ await this.contractSyncService.ensureContractSynced(
72
+ filter.contractAddress,
73
+ null,
74
+ async privateSyncCall =>
75
+ await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
76
+ anchorBlockHeader,
77
+ jobId,
78
+ );
50
79
 
51
- /** Returns the block header up to which the PXE has synced. */
52
- public getSyncedBlockHeader(): Promise<BlockHeader> {
53
- return this.anchorBlockStore.getBlockHeader();
80
+ return this.noteStore.getNotes(filter, jobId);
81
+ });
54
82
  }
55
83
 
56
84
  /**
@@ -52,6 +52,14 @@ export async function createPXE(
52
52
  const protocolContractsProvider = new BundledProtocolContractsProvider();
53
53
 
54
54
  const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
55
- const pxe = await PXE.create(aztecNode, store, prover, simulator, protocolContractsProvider, config, pxeLogger);
55
+ const pxe = await PXE.create({
56
+ node: aztecNode,
57
+ store,
58
+ proofCreator: prover,
59
+ simulator,
60
+ protocolContractsProvider,
61
+ config,
62
+ loggerOrSuffix: pxeLogger,
63
+ });
56
64
  return pxe;
57
65
  }
@@ -52,6 +52,14 @@ export async function createPXE(
52
52
  const protocolContractsProvider = new LazyProtocolContractsProvider();
53
53
 
54
54
  const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
55
- const pxe = await PXE.create(aztecNode, store, prover, simulator, protocolContractsProvider, config, pxeLogger);
55
+ const pxe = await PXE.create({
56
+ node: aztecNode,
57
+ store,
58
+ proofCreator: prover,
59
+ simulator,
60
+ protocolContractsProvider,
61
+ config,
62
+ loggerOrSuffix: pxeLogger,
63
+ });
56
64
  return pxe;
57
65
  }
@@ -7,4 +7,4 @@ export { NoteService } from '../../notes/note_service.js';
7
7
  export { ORACLE_VERSION } from '../../oracle_version.js';
8
8
  export { type PXECreationOptions } from '../pxe_creation_options.js';
9
9
  export { JobCoordinator } from '../../job_coordinator/job_coordinator.js';
10
- export { syncState } from '../../contract_sync/index.js';
10
+ export { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
@@ -58,14 +58,14 @@ export async function createPXE(
58
58
  const protocolContractsProvider = new BundledProtocolContractsProvider();
59
59
 
60
60
  const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
61
- const pxe = await PXE.create(
62
- aztecNode,
63
- options.store,
64
- prover,
61
+ const pxe = await PXE.create({
62
+ node: aztecNode,
63
+ store: options.store,
64
+ proofCreator: prover,
65
65
  simulator,
66
66
  protocolContractsProvider,
67
- configWithContracts,
68
- pxeLogger,
69
- );
67
+ config: configWithContracts,
68
+ loggerOrSuffix: pxeLogger,
69
+ });
70
70
  return pxe;
71
71
  }
@@ -4,9 +4,9 @@
4
4
  ///
5
5
  /// @dev Whenever a contract function or Noir test is run, the `utilityAssertCompatibleOracleVersion` oracle is called
6
6
  /// and if the oracle version is incompatible an error is thrown.
7
- export const ORACLE_VERSION = 11;
7
+ export const ORACLE_VERSION = 12;
8
8
 
9
9
  /// This hash is computed as by hashing the Oracle interface and it is used to detect when the Oracle interface changes,
10
10
  /// which in turn implies that you need to update the ORACLE_VERSION constant in this file and in
11
11
  /// `noir-projects/aztec-nr/aztec/src/oracle/version.nr`.
12
- export const ORACLE_INTERFACE_HASH = '20c4d02d8cd5e448c11001a5f72ea2e0927630aeda75e537550872a9627bf40b';
12
+ export const ORACLE_INTERFACE_HASH = '666a8a7fc697f72b29dbf0ae7464db269cf5afa019acac8861f814543147dbb4';
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,
@@ -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,15 @@ 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) {
131
182
  // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
132
183
  const bindings: LoggerBindings | undefined =
133
184
  loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
@@ -149,6 +200,12 @@ export class PXE {
149
200
  const capsuleStore = new CapsuleStore(store);
150
201
  const keyStore = new KeyStore(store);
151
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
+ );
152
209
  const synchronizer = new BlockSynchronizer(
153
210
  node,
154
211
  store,
@@ -156,6 +213,7 @@ export class PXE {
156
213
  noteStore,
157
214
  privateEventStore,
158
215
  tipsStore,
216
+ contractSyncService,
159
217
  config,
160
218
  bindings,
161
219
  );
@@ -167,9 +225,10 @@ export class PXE {
167
225
  recipientTaggingStore,
168
226
  privateEventStore,
169
227
  noteStore,
228
+ contractSyncService,
170
229
  ]);
171
230
 
172
- const debugUtils = new PXEDebugUtils(contractStore, noteStore, synchronizer, anchorBlockStore);
231
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
173
232
 
174
233
  const jobQueue = new SerialQueue();
175
234
 
@@ -186,6 +245,7 @@ export class PXE {
186
245
  recipientTaggingStore,
187
246
  addressStore,
188
247
  privateEventStore,
248
+ contractSyncService,
189
249
  simulator,
190
250
  proverEnabled,
191
251
  proofCreator,
@@ -196,7 +256,11 @@ export class PXE {
196
256
  debugUtils,
197
257
  );
198
258
 
199
- debugUtils.setPXE(pxe, pxe.#putInJobQueue.bind(pxe));
259
+ debugUtils.setPXEHelpers(
260
+ pxe.#putInJobQueue.bind(pxe),
261
+ pxe.#getSimulatorForTx.bind(pxe),
262
+ pxe.#simulateUtility.bind(pxe),
263
+ );
200
264
 
201
265
  pxe.jobQueue.start();
202
266
 
@@ -211,19 +275,20 @@ export class PXE {
211
275
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
212
276
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
213
277
 
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
- );
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
+ });
227
292
  }
228
293
 
229
294
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -297,29 +362,21 @@ export class PXE {
297
362
  try {
298
363
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
299
364
 
300
- await ensureContractSynced(
365
+ await this.contractSyncService.ensureContractSynced(
301
366
  contractAddress,
302
367
  functionSelector,
303
368
  privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
304
- this.node,
305
- this.contractStore,
306
- this.noteStore,
307
369
  anchorBlockHeader,
308
370
  jobId,
309
371
  );
310
372
 
311
- const result = await contractFunctionSimulator.run(
312
- txRequest,
373
+ const result = await contractFunctionSimulator.run(txRequest, {
313
374
  contractAddress,
314
- functionSelector,
315
- undefined,
375
+ selector: functionSelector,
316
376
  anchorBlockHeader,
317
- // The sender for tags is set by contracts, typically by an account
318
- // contract entrypoint
319
- undefined, // senderForTags
320
377
  scopes,
321
378
  jobId,
322
- );
379
+ });
323
380
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
324
381
  return result;
325
382
  } catch (err) {
@@ -417,6 +474,19 @@ export class PXE {
417
474
 
418
475
  // Public API
419
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
+ */
420
490
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
421
491
  return this.contractStore.getContractInstance(address);
422
492
  }
@@ -709,17 +779,13 @@ export class PXE {
709
779
 
710
780
  /**
711
781
  * 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.
782
+ * @param txRequest - An authenticated tx request ready for simulation.
716
783
  * @returns A trace of the program execution with gate counts.
717
784
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
718
785
  */
719
786
  public profileTx(
720
787
  txRequest: TxExecutionRequest,
721
- profileMode: 'full' | 'execution-steps' | 'gates',
722
- skipProofGeneration: boolean = true,
788
+ { profileMode, skipProofGeneration = true }: ProfileTxOpts,
723
789
  ): Promise<TxProfileResult> {
724
790
  // We disable concurrent profiles for consistency with simulateTx.
725
791
  return this.#putInJobQueue(async jobId => {
@@ -804,12 +870,7 @@ export class PXE {
804
870
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
805
871
  *
806
872
  *
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.
873
+ * @param txRequest - An authenticated tx request ready for simulation.
813
874
  * @returns A simulated transaction result object that includes public and private return values.
814
875
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
815
876
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -818,11 +879,7 @@ export class PXE {
818
879
  */
819
880
  public simulateTx(
820
881
  txRequest: TxExecutionRequest,
821
- simulatePublic: boolean,
822
- skipTxValidation: boolean = false,
823
- skipFeeEnforcement: boolean = false,
824
- overrides?: SimulationOverrides,
825
- scopes?: AztecAddress[],
882
+ { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
826
883
  ): Promise<TxSimulationResult> {
827
884
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
828
885
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -850,7 +907,14 @@ export class PXE {
850
907
  // Temporary: in case there are overrides, we have to skip the kernels or validations
851
908
  // will fail. Consider handing control to the user/wallet on whether they want to run them
852
909
  // or not.
853
- 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
+ }
854
918
 
855
919
  // Execution of private functions only; no proving, and no kernel logic.
856
920
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -861,7 +925,7 @@ export class PXE {
861
925
  if (skipKernels) {
862
926
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
863
927
  privateExecutionResult,
864
- this.contractStore,
928
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
865
929
  ));
866
930
  } else {
867
931
  // Kernel logic, plus proving of all private functions and kernels.
@@ -946,18 +1010,12 @@ export class PXE {
946
1010
  }
947
1011
 
948
1012
  /**
949
- * Simulate the execution of a contract utility function.
950
- *
1013
+ * Simulates the execution of a contract utility function.
951
1014
  * @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
1015
  */
957
1016
  public simulateUtility(
958
1017
  call: FunctionCall,
959
- authwits?: AuthWitness[],
960
- scopes?: AztecAddress[],
1018
+ { authwits, scopes }: SimulateUtilityOpts = {},
961
1019
  ): Promise<UtilitySimulationResult> {
962
1020
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
963
1021
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -972,13 +1030,10 @@ export class PXE {
972
1030
  const contractFunctionSimulator = this.#getSimulatorForTx();
973
1031
 
974
1032
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
975
- await ensureContractSynced(
1033
+ await this.contractSyncService.ensureContractSynced(
976
1034
  call.to,
977
1035
  call.selector,
978
1036
  privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
979
- this.node,
980
- this.contractStore,
981
- this.noteStore,
982
1037
  anchorBlockHeader,
983
1038
  jobId,
984
1039
  );
@@ -1044,14 +1099,11 @@ export class PXE {
1044
1099
 
1045
1100
  const contractFunctionSimulator = this.#getSimulatorForTx();
1046
1101
 
1047
- await ensureContractSynced(
1102
+ await this.contractSyncService.ensureContractSynced(
1048
1103
  filter.contractAddress,
1049
1104
  null,
1050
1105
  async privateSyncCall =>
1051
1106
  await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1052
- this.node,
1053
- this.contractStore,
1054
- this.noteStore,
1055
1107
  anchorBlockHeader,
1056
1108
  jobId,
1057
1109
  );
@@ -316,15 +316,15 @@ export class ContractStore {
316
316
  throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
317
317
  }
318
318
 
319
- return {
319
+ return FunctionCall.from({
320
320
  name: functionDao.name,
321
- args: encodeArguments(functionDao, args),
321
+ to,
322
322
  selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
323
323
  type: functionDao.functionType,
324
- to,
325
324
  hideMsgSender: false,
326
325
  isStatic: functionDao.isStatic,
326
+ args: encodeArguments(functionDao, args),
327
327
  returnTypes: functionDao.returnTypes,
328
- };
328
+ });
329
329
  }
330
330
  }
@@ -220,6 +220,10 @@ export class NoteStore implements StagedStore {
220
220
  return Promise.resolve([]);
221
221
  }
222
222
 
223
+ if (nullifiers.some(n => n.l2BlockNumber === 0)) {
224
+ return Promise.reject(new Error('applyNullifiers: nullifiers cannot have been emitted at block 0'));
225
+ }
226
+
223
227
  return this.#withJobLock(jobId, () =>
224
228
  this.#store.transactionAsync(async () => {
225
229
  const notesToNullify = await Promise.all(
@@ -1,24 +0,0 @@
1
- import type { FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
2
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
- import type { ContractInstance } from '@aztec/stdlib/contract';
4
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
- import type { BlockHeader } from '@aztec/stdlib/tx';
6
- import type { ContractStore } from '../storage/contract_store/contract_store.js';
7
- import type { NoteStore } from '../storage/note_store/note_store.js';
8
- /**
9
- * Read the current class id of a contract from the execution data provider or AztecNode. If not found, class id
10
- * from the instance is used.
11
- * @param contractAddress - The address of the contract to read the class id for.
12
- * @param instance - The instance of the contract.
13
- * @param aztecNode - The Aztec node to query for storage.
14
- * @param header - The header of the block at which to load the DelayedPublicMutable storing the class id.
15
- * @returns The current class id.
16
- */
17
- export declare function readCurrentClassId(contractAddress: AztecAddress, instance: ContractInstance, aztecNode: AztecNode, header: BlockHeader): Promise<import("@aztec/foundation/schemas").Fr>;
18
- export declare function syncState(contractAddress: AztecAddress, contractStore: ContractStore, functionToInvokeAfterSync: FunctionSelector | null, utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>, noteStore: NoteStore, aztecNode: AztecNode, header: BlockHeader, jobId: string): Promise<void>;
19
- /**
20
- * Ensures the contract's private state is synchronized and that the PXE holds the current class artifact for
21
- * the contract.
22
- */
23
- export declare function ensureContractSynced(contractAddress: AztecAddress, functionToInvokeAfterSync: FunctionSelector | null, utilityExecutor: (call: FunctionCall) => Promise<any>, aztecNode: AztecNode, contractStore: ContractStore, noteStore: NoteStore, header: BlockHeader, jobId: string): Promise<void>;
24
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL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