@aztec/pxe 0.0.1-commit.6d63667d → 0.0.1-commit.858058eac

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 (47) hide show
  1. package/dest/contract_function_simulator/contract_function_simulator.d.ts +49 -27
  2. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  3. package/dest/contract_function_simulator/contract_function_simulator.js +65 -31
  4. package/dest/contract_function_simulator/oracle/interfaces.d.ts +2 -2
  5. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -2
  7. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  8. package/dest/contract_function_simulator/oracle/oracle.js +3 -3
  9. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +34 -36
  10. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +62 -17
  12. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +30 -11
  13. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +44 -28
  15. package/dest/debug/pxe_debug_utils.d.ts +2 -4
  16. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  17. package/dest/debug/pxe_debug_utils.js +0 -3
  18. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  19. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  20. package/dest/entrypoints/client/bundle/utils.js +9 -1
  21. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  22. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  23. package/dest/entrypoints/client/lazy/utils.js +9 -1
  24. package/dest/entrypoints/server/utils.js +9 -1
  25. package/dest/oracle_version.d.ts +2 -2
  26. package/dest/oracle_version.js +2 -2
  27. package/dest/pxe.d.ts +63 -22
  28. package/dest/pxe.d.ts.map +1 -1
  29. package/dest/pxe.js +42 -28
  30. package/dest/storage/contract_store/contract_store.js +5 -5
  31. package/dest/storage/note_store/note_store.d.ts +1 -1
  32. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  33. package/dest/storage/note_store/note_store.js +3 -0
  34. package/package.json +16 -16
  35. package/src/contract_function_simulator/contract_function_simulator.ts +108 -73
  36. package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
  37. package/src/contract_function_simulator/oracle/oracle.ts +3 -3
  38. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +81 -93
  39. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +85 -27
  40. package/src/debug/pxe_debug_utils.ts +1 -6
  41. package/src/entrypoints/client/bundle/utils.ts +9 -1
  42. package/src/entrypoints/client/lazy/utils.ts +9 -1
  43. package/src/entrypoints/server/utils.ts +7 -7
  44. package/src/oracle_version.ts +2 -2
  45. package/src/pxe.ts +98 -59
  46. package/src/storage/contract_store/contract_store.ts +4 -4
  47. package/src/storage/note_store/note_store.ts +4 -0
@@ -2,7 +2,7 @@ import type { FunctionCall } from '@aztec/stdlib/abi';
2
2
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { NoteDao, NotesFilter } from '@aztec/stdlib/note';
5
- import type { BlockHeader, ContractOverrides } from '@aztec/stdlib/tx';
5
+ import type { ContractOverrides } from '@aztec/stdlib/tx';
6
6
 
7
7
  import type { BlockSynchronizer } from '../block_synchronizer/block_synchronizer.js';
8
8
  import type { ContractFunctionSimulator } from '../contract_function_simulator/contract_function_simulator.js';
@@ -81,11 +81,6 @@ export class PXEDebugUtils {
81
81
  });
82
82
  }
83
83
 
84
- /** Returns the block header up to which the PXE has synced. */
85
- public getSyncedBlockHeader(): Promise<BlockHeader> {
86
- return this.anchorBlockStore.getBlockHeader();
87
- }
88
-
89
84
  /**
90
85
  * Triggers a sync of the PXE with the node.
91
86
  * Blocks until the sync is complete.
@@ -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
  }
@@ -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,
@@ -85,6 +86,54 @@ export type PackedPrivateEvent = InTx & {
85
86
  eventSelector: EventSelector;
86
87
  };
87
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
+
88
137
  /**
89
138
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
90
139
  * manage private state of users.
@@ -121,15 +170,15 @@ export class PXE {
121
170
  *
122
171
  * @returns A promise that resolves PXE is ready to be used.
123
172
  */
124
- public static async create(
125
- node: AztecNode,
126
- store: AztecAsyncKVStore,
127
- proofCreator: PrivateKernelProver,
128
- simulator: CircuitSimulator,
129
- protocolContractsProvider: ProtocolContractsProvider,
130
- config: PXEConfig,
131
- loggerOrSuffix?: string | Logger,
132
- ) {
173
+ public static async create({
174
+ node,
175
+ store,
176
+ proofCreator,
177
+ simulator,
178
+ protocolContractsProvider,
179
+ config,
180
+ loggerOrSuffix,
181
+ }: PXECreateArgs) {
133
182
  // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
134
183
  const bindings: LoggerBindings | undefined =
135
184
  loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
@@ -139,7 +188,9 @@ export class PXE {
139
188
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
140
189
  : loggerOrSuffix;
141
190
 
142
- const proverEnabled = !!config.proverEnabled;
191
+ const info = await node.getNodeInfo();
192
+
193
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
143
194
  const addressStore = new AddressStore(store);
144
195
  const privateEventStore = new PrivateEventStore(store);
145
196
  const contractStore = new ContractStore(store);
@@ -216,7 +267,6 @@ export class PXE {
216
267
  pxe.jobQueue.start();
217
268
 
218
269
  await pxe.#registerProtocolContracts();
219
- const info = await node.getNodeInfo();
220
270
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
221
271
  return pxe;
222
272
  }
@@ -226,20 +276,20 @@ export class PXE {
226
276
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
227
277
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
228
278
 
229
- return new ContractFunctionSimulator(
230
- proxyContractStore,
231
- this.noteStore,
232
- this.keyStore,
233
- this.addressStore,
234
- BenchmarkedNodeFactory.create(this.node),
235
- this.senderTaggingStore,
236
- this.recipientTaggingStore,
237
- this.senderAddressBookStore,
238
- this.capsuleStore,
239
- this.privateEventStore,
240
- this.simulator,
241
- this.contractSyncService,
242
- );
279
+ return new ContractFunctionSimulator({
280
+ contractStore: proxyContractStore,
281
+ noteStore: this.noteStore,
282
+ keyStore: this.keyStore,
283
+ addressStore: this.addressStore,
284
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
285
+ senderTaggingStore: this.senderTaggingStore,
286
+ recipientTaggingStore: this.recipientTaggingStore,
287
+ senderAddressBookStore: this.senderAddressBookStore,
288
+ capsuleStore: this.capsuleStore,
289
+ privateEventStore: this.privateEventStore,
290
+ simulator: this.simulator,
291
+ contractSyncService: this.contractSyncService,
292
+ });
243
293
  }
244
294
 
245
295
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -321,18 +371,13 @@ export class PXE {
321
371
  jobId,
322
372
  );
323
373
 
324
- const result = await contractFunctionSimulator.run(
325
- txRequest,
374
+ const result = await contractFunctionSimulator.run(txRequest, {
326
375
  contractAddress,
327
- functionSelector,
328
- undefined,
376
+ selector: functionSelector,
329
377
  anchorBlockHeader,
330
- // The sender for tags is set by contracts, typically by an account
331
- // contract entrypoint
332
- undefined, // senderForTags
333
378
  scopes,
334
379
  jobId,
335
- );
380
+ });
336
381
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
337
382
  return result;
338
383
  } catch (err) {
@@ -430,6 +475,19 @@ export class PXE {
430
475
 
431
476
  // Public API
432
477
 
478
+ /**
479
+ * Returns the block header up to which the PXE has synced.
480
+ * @returns The synced block header
481
+ */
482
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
483
+ return this.anchorBlockStore.getBlockHeader();
484
+ }
485
+
486
+ /**
487
+ * Returns the contract instance for a given address, if it's registered in the PXE.
488
+ * @param address - The contract address.
489
+ * @returns The contract instance if found, undefined otherwise.
490
+ */
433
491
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
434
492
  return this.contractStore.getContractInstance(address);
435
493
  }
@@ -722,17 +780,13 @@ export class PXE {
722
780
 
723
781
  /**
724
782
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
725
- *
726
- * @param txRequest - An authenticated tx request ready for simulation
727
- * @param msgSender - (Optional) The message sender to use for the simulation.
728
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
783
+ * @param txRequest - An authenticated tx request ready for simulation.
729
784
  * @returns A trace of the program execution with gate counts.
730
785
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
731
786
  */
732
787
  public profileTx(
733
788
  txRequest: TxExecutionRequest,
734
- profileMode: 'full' | 'execution-steps' | 'gates',
735
- skipProofGeneration: boolean = true,
789
+ { profileMode, skipProofGeneration = true }: ProfileTxOpts,
736
790
  ): Promise<TxProfileResult> {
737
791
  // We disable concurrent profiles for consistency with simulateTx.
738
792
  return this.#putInJobQueue(async jobId => {
@@ -817,12 +871,7 @@ export class PXE {
817
871
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
818
872
  *
819
873
  *
820
- * @param txRequest - An authenticated tx request ready for simulation
821
- * @param simulatePublic - Whether to simulate the public part of the transaction.
822
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
823
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
824
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
825
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
874
+ * @param txRequest - An authenticated tx request ready for simulation.
826
875
  * @returns A simulated transaction result object that includes public and private return values.
827
876
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
828
877
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -831,11 +880,7 @@ export class PXE {
831
880
  */
832
881
  public simulateTx(
833
882
  txRequest: TxExecutionRequest,
834
- simulatePublic: boolean,
835
- skipTxValidation: boolean = false,
836
- skipFeeEnforcement: boolean = false,
837
- overrides?: SimulationOverrides,
838
- scopes?: AztecAddress[],
883
+ { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
839
884
  ): Promise<TxSimulationResult> {
840
885
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
841
886
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -881,7 +926,7 @@ export class PXE {
881
926
  if (skipKernels) {
882
927
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
883
928
  privateExecutionResult,
884
- this.contractStore,
929
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
885
930
  ));
886
931
  } else {
887
932
  // Kernel logic, plus proving of all private functions and kernels.
@@ -966,18 +1011,12 @@ export class PXE {
966
1011
  }
967
1012
 
968
1013
  /**
969
- * Simulate the execution of a contract utility function.
970
- *
1014
+ * Simulates the execution of a contract utility function.
971
1015
  * @param call - The function call containing the function details, arguments, and target contract address.
972
- * @param authwits - (Optional) The authentication witnesses required for the function call.
973
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
974
- * default to all.
975
- * @returns The result of the utility function call, structured based on the function ABI.
976
1016
  */
977
1017
  public simulateUtility(
978
1018
  call: FunctionCall,
979
- authwits?: AuthWitness[],
980
- scopes?: AztecAddress[],
1019
+ { authwits, scopes }: SimulateUtilityOpts = {},
981
1020
  ): Promise<UtilitySimulationResult> {
982
1021
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
983
1022
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -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(