@aztec/pxe 0.0.1-commit.6d63667d → 0.0.1-commit.7cf39cb55

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 (55) hide show
  1. package/dest/contract_function_simulator/contract_function_simulator.d.ts +51 -28
  2. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  3. package/dest/contract_function_simulator/contract_function_simulator.js +168 -64
  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 +71 -18
  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 +53 -32
  15. package/dest/contract_sync/contract_sync_service.d.ts +3 -2
  16. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  17. package/dest/contract_sync/contract_sync_service.js +32 -17
  18. package/dest/debug/pxe_debug_utils.d.ts +2 -4
  19. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  20. package/dest/debug/pxe_debug_utils.js +1 -4
  21. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  22. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  23. package/dest/entrypoints/client/bundle/utils.js +9 -1
  24. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  25. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  26. package/dest/entrypoints/client/lazy/utils.js +9 -1
  27. package/dest/entrypoints/server/utils.js +9 -1
  28. package/dest/logs/log_service.d.ts +1 -1
  29. package/dest/logs/log_service.d.ts.map +1 -1
  30. package/dest/logs/log_service.js +4 -9
  31. package/dest/oracle_version.d.ts +2 -2
  32. package/dest/oracle_version.js +2 -2
  33. package/dest/pxe.d.ts +67 -23
  34. package/dest/pxe.d.ts.map +1 -1
  35. package/dest/pxe.js +49 -34
  36. package/dest/storage/contract_store/contract_store.js +5 -5
  37. package/dest/storage/note_store/note_store.d.ts +1 -2
  38. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  39. package/dest/storage/note_store/note_store.js +4 -2
  40. package/package.json +16 -16
  41. package/src/contract_function_simulator/contract_function_simulator.ts +314 -121
  42. package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
  43. package/src/contract_function_simulator/oracle/oracle.ts +3 -3
  44. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +91 -93
  45. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +94 -31
  46. package/src/contract_sync/contract_sync_service.ts +41 -25
  47. package/src/debug/pxe_debug_utils.ts +4 -8
  48. package/src/entrypoints/client/bundle/utils.ts +9 -1
  49. package/src/entrypoints/client/lazy/utils.ts +9 -1
  50. package/src/entrypoints/server/utils.ts +7 -7
  51. package/src/logs/log_service.ts +4 -13
  52. package/src/oracle_version.ts +2 -2
  53. package/src/pxe.ts +114 -71
  54. package/src/storage/contract_store/contract_store.ts +4 -4
  55. package/src/storage/note_store/note_store.ts +5 -2
@@ -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,56 @@ 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
+ /** Addresses whose private state and keys are accessible during private execution. */
96
+ scopes?: AztecAddress[];
97
+ };
98
+
99
+ /** Options for PXE.simulateTx. */
100
+ export type SimulateTxOpts = {
101
+ /** Whether to simulate the public part of the transaction. */
102
+ simulatePublic: boolean;
103
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
104
+ skipTxValidation?: boolean;
105
+ /** If false, fees are enforced. */
106
+ skipFeeEnforcement?: boolean;
107
+ /** State overrides for the simulation, such as contract instances and artifacts. */
108
+ overrides?: SimulationOverrides;
109
+ /** Addresses whose private state and keys are accessible during private execution. Defaults to all. */
110
+ scopes?: AztecAddress[];
111
+ };
112
+
113
+ /** Options for PXE.simulateUtility. */
114
+ export type SimulateUtilityOpts = {
115
+ /** The authentication witnesses required for the function call. */
116
+ authwits?: AuthWitness[];
117
+ /** The accounts whose notes we can access in this call. Defaults to all. */
118
+ scopes?: AztecAddress[];
119
+ };
120
+
121
+ /** Args for PXE.create. */
122
+ export type PXECreateArgs = {
123
+ /** The Aztec node to connect to. */
124
+ node: AztecNode;
125
+ /** The key-value store for persisting PXE state. */
126
+ store: AztecAsyncKVStore;
127
+ /** The prover for generating private kernel proofs. */
128
+ proofCreator: PrivateKernelProver;
129
+ /** The circuit simulator for executing ACIR circuits. */
130
+ simulator: CircuitSimulator;
131
+ /** Provider for protocol contract artifacts and instances. */
132
+ protocolContractsProvider: ProtocolContractsProvider;
133
+ /** PXE configuration options. */
134
+ config: PXEConfig;
135
+ /** Optional logger instance or string suffix for the logger name. */
136
+ loggerOrSuffix?: string | Logger;
137
+ };
138
+
88
139
  /**
89
140
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
90
141
  * manage private state of users.
@@ -121,15 +172,15 @@ export class PXE {
121
172
  *
122
173
  * @returns A promise that resolves PXE is ready to be used.
123
174
  */
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
- ) {
175
+ public static async create({
176
+ node,
177
+ store,
178
+ proofCreator,
179
+ simulator,
180
+ protocolContractsProvider,
181
+ config,
182
+ loggerOrSuffix,
183
+ }: PXECreateArgs) {
133
184
  // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
134
185
  const bindings: LoggerBindings | undefined =
135
186
  loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
@@ -139,7 +190,9 @@ export class PXE {
139
190
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
140
191
  : loggerOrSuffix;
141
192
 
142
- const proverEnabled = !!config.proverEnabled;
193
+ const info = await node.getNodeInfo();
194
+
195
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
143
196
  const addressStore = new AddressStore(store);
144
197
  const privateEventStore = new PrivateEventStore(store);
145
198
  const contractStore = new ContractStore(store);
@@ -216,7 +269,6 @@ export class PXE {
216
269
  pxe.jobQueue.start();
217
270
 
218
271
  await pxe.#registerProtocolContracts();
219
- const info = await node.getNodeInfo();
220
272
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
221
273
  return pxe;
222
274
  }
@@ -226,20 +278,20 @@ export class PXE {
226
278
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
227
279
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
228
280
 
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
- );
281
+ return new ContractFunctionSimulator({
282
+ contractStore: proxyContractStore,
283
+ noteStore: this.noteStore,
284
+ keyStore: this.keyStore,
285
+ addressStore: this.addressStore,
286
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
287
+ senderTaggingStore: this.senderTaggingStore,
288
+ recipientTaggingStore: this.recipientTaggingStore,
289
+ senderAddressBookStore: this.senderAddressBookStore,
290
+ capsuleStore: this.capsuleStore,
291
+ privateEventStore: this.privateEventStore,
292
+ simulator: this.simulator,
293
+ contractSyncService: this.contractSyncService,
294
+ });
243
295
  }
244
296
 
245
297
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -316,23 +368,20 @@ export class PXE {
316
368
  await this.contractSyncService.ensureContractSynced(
317
369
  contractAddress,
318
370
  functionSelector,
319
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
371
+ (privateSyncCall, execScopes) =>
372
+ this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
320
373
  anchorBlockHeader,
321
374
  jobId,
375
+ scopes,
322
376
  );
323
377
 
324
- const result = await contractFunctionSimulator.run(
325
- txRequest,
378
+ const result = await contractFunctionSimulator.run(txRequest, {
326
379
  contractAddress,
327
- functionSelector,
328
- undefined,
380
+ selector: functionSelector,
329
381
  anchorBlockHeader,
330
- // The sender for tags is set by contracts, typically by an account
331
- // contract entrypoint
332
- undefined, // senderForTags
333
382
  scopes,
334
383
  jobId,
335
- );
384
+ });
336
385
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
337
386
  return result;
338
387
  } catch (err) {
@@ -430,6 +479,19 @@ export class PXE {
430
479
 
431
480
  // Public API
432
481
 
482
+ /**
483
+ * Returns the block header up to which the PXE has synced.
484
+ * @returns The synced block header
485
+ */
486
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
487
+ return this.anchorBlockStore.getBlockHeader();
488
+ }
489
+
490
+ /**
491
+ * Returns the contract instance for a given address, if it's registered in the PXE.
492
+ * @param address - The contract address.
493
+ * @returns The contract instance if found, undefined otherwise.
494
+ */
433
495
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
434
496
  return this.contractStore.getContractInstance(address);
435
497
  }
@@ -643,11 +705,12 @@ export class PXE {
643
705
  * (where validators prove the public portion).
644
706
  *
645
707
  * @param txRequest - An authenticated tx request ready for proving
708
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
646
709
  * @returns A result containing the proof and public inputs of the tail circuit.
647
710
  * @throws If contract code not found, or public simulation reverts.
648
711
  * Also throws if simulatePublic is true and public simulation reverts.
649
712
  */
650
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
713
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
651
714
  let privateExecutionResult: PrivateExecutionResult;
652
715
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
653
716
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -658,7 +721,7 @@ export class PXE {
658
721
  await this.blockStateSynchronizer.sync();
659
722
  const syncTime = syncTimer.ms();
660
723
  const contractFunctionSimulator = this.#getSimulatorForTx();
661
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
724
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
662
725
 
663
726
  const {
664
727
  publicInputs,
@@ -722,17 +785,13 @@ export class PXE {
722
785
 
723
786
  /**
724
787
  * 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.
788
+ * @param txRequest - An authenticated tx request ready for simulation.
729
789
  * @returns A trace of the program execution with gate counts.
730
790
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
731
791
  */
732
792
  public profileTx(
733
793
  txRequest: TxExecutionRequest,
734
- profileMode: 'full' | 'execution-steps' | 'gates',
735
- skipProofGeneration: boolean = true,
794
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
736
795
  ): Promise<TxProfileResult> {
737
796
  // We disable concurrent profiles for consistency with simulateTx.
738
797
  return this.#putInJobQueue(async jobId => {
@@ -755,12 +814,7 @@ export class PXE {
755
814
  const syncTime = syncTimer.ms();
756
815
 
757
816
  const contractFunctionSimulator = this.#getSimulatorForTx();
758
- const privateExecutionResult = await this.#executePrivate(
759
- contractFunctionSimulator,
760
- txRequest,
761
- undefined,
762
- jobId,
763
- );
817
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
764
818
 
765
819
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
766
820
  txRequest,
@@ -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,8 @@ 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),
930
+ this.node,
885
931
  ));
886
932
  } else {
887
933
  // Kernel logic, plus proving of all private functions and kernels.
@@ -966,18 +1012,12 @@ export class PXE {
966
1012
  }
967
1013
 
968
1014
  /**
969
- * Simulate the execution of a contract utility function.
970
- *
1015
+ * Simulates the execution of a contract utility function.
971
1016
  * @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
1017
  */
977
1018
  public simulateUtility(
978
1019
  call: FunctionCall,
979
- authwits?: AuthWitness[],
980
- scopes?: AztecAddress[],
1020
+ { authwits, scopes }: SimulateUtilityOpts = {},
981
1021
  ): Promise<UtilitySimulationResult> {
982
1022
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
983
1023
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -995,9 +1035,11 @@ export class PXE {
995
1035
  await this.contractSyncService.ensureContractSynced(
996
1036
  call.to,
997
1037
  call.selector,
998
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1038
+ (privateSyncCall, execScopes) =>
1039
+ this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
999
1040
  anchorBlockHeader,
1000
1041
  jobId,
1042
+ scopes,
1001
1043
  );
1002
1044
 
1003
1045
  const executionResult = await this.#simulateUtility(
@@ -1064,10 +1106,11 @@ export class PXE {
1064
1106
  await this.contractSyncService.ensureContractSynced(
1065
1107
  filter.contractAddress,
1066
1108
  null,
1067
- async privateSyncCall =>
1068
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1109
+ async (privateSyncCall, execScopes) =>
1110
+ await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1069
1111
  anchorBlockHeader,
1070
1112
  jobId,
1113
+ filter.scopes,
1071
1114
  );
1072
1115
  });
1073
1116
 
@@ -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
  }
@@ -103,11 +103,10 @@ export class NoteStore implements StagedStore {
103
103
  * @params jobId - the job context to read from.
104
104
  * @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
105
105
  * returned once if this is the case)
106
- * @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
107
106
  */
108
107
  getNotes(filter: NotesFilter, jobId: string): Promise<NoteDao[]> {
109
108
  if (filter.scopes !== undefined && filter.scopes.length === 0) {
110
- return Promise.reject(new Error('Trying to get notes with an empty scopes array'));
109
+ return Promise.resolve([]);
111
110
  }
112
111
 
113
112
  return this.#store.transactionAsync(async () => {
@@ -220,6 +219,10 @@ export class NoteStore implements StagedStore {
220
219
  return Promise.resolve([]);
221
220
  }
222
221
 
222
+ if (nullifiers.some(n => n.l2BlockNumber === 0)) {
223
+ return Promise.reject(new Error('applyNullifiers: nullifiers cannot have been emitted at block 0'));
224
+ }
225
+
223
226
  return this.#withJobLock(jobId, () =>
224
227
  this.#store.transactionAsync(async () => {
225
228
  const notesToNullify = await Promise.all(