@aztec/pxe 1.2.1 → 2.0.0-nightly.20250813

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 (88) hide show
  1. package/dest/config/package_info.js +1 -1
  2. package/dest/contract_function_simulator/contract_function_simulator.d.ts +5 -2
  3. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  4. package/dest/contract_function_simulator/contract_function_simulator.js +48 -29
  5. package/dest/contract_function_simulator/index.d.ts +1 -0
  6. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  7. package/dest/contract_function_simulator/index.js +1 -0
  8. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
  9. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  10. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  11. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
  12. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  13. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -1
  14. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
  15. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  16. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +22 -0
  17. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -0
  18. package/dest/contract_function_simulator/oracle/note_packing_utils.js +49 -0
  19. package/dest/contract_function_simulator/oracle/oracle.d.ts +44 -43
  20. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  21. package/dest/contract_function_simulator/oracle/oracle.js +127 -106
  22. package/dest/contract_function_simulator/oracle/private_execution.d.ts +7 -2
  23. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  24. package/dest/contract_function_simulator/oracle/private_execution.js +16 -11
  25. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +41 -17
  26. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +51 -23
  28. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +48 -47
  29. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/oracle/typed_oracle.js +89 -87
  31. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +31 -30
  32. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +33 -30
  34. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/pxe_oracle_interface.js +6 -7
  36. package/dest/entrypoints/server/utils.d.ts +4 -2
  37. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  38. package/dest/entrypoints/server/utils.js +4 -2
  39. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +4 -4
  40. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
  41. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +58 -59
  42. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +4 -0
  43. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +1 -0
  44. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +41 -0
  45. package/dest/private_kernel/hints/index.d.ts +1 -0
  46. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  47. package/dest/private_kernel/hints/index.js +1 -0
  48. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  49. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  50. package/dest/private_kernel/private_kernel_execution_prover.js +13 -4
  51. package/dest/private_kernel/private_kernel_oracle.d.ts +1 -1
  52. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  53. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
  54. package/dest/private_kernel/private_kernel_oracle_impl.js +6 -6
  55. package/dest/pxe_service/error_enriching.d.ts.map +1 -1
  56. package/dest/pxe_service/error_enriching.js +1 -0
  57. package/dest/pxe_service/pxe_service.d.ts +3 -2
  58. package/dest/pxe_service/pxe_service.d.ts.map +1 -1
  59. package/dest/pxe_service/pxe_service.js +28 -19
  60. package/dest/storage/capsule_data_provider/capsule_data_provider.js +1 -1
  61. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
  62. package/dest/storage/note_data_provider/note_data_provider.js +16 -4
  63. package/package.json +16 -16
  64. package/src/config/package_info.ts +1 -1
  65. package/src/contract_function_simulator/contract_function_simulator.ts +67 -37
  66. package/src/contract_function_simulator/index.ts +1 -0
  67. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  68. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  69. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
  70. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  71. package/src/contract_function_simulator/oracle/note_packing_utils.ts +52 -0
  72. package/src/contract_function_simulator/oracle/oracle.ts +149 -111
  73. package/src/contract_function_simulator/oracle/private_execution.ts +17 -12
  74. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +60 -24
  75. package/src/contract_function_simulator/oracle/typed_oracle.ts +108 -92
  76. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +34 -30
  77. package/src/contract_function_simulator/pxe_oracle_interface.ts +6 -8
  78. package/src/entrypoints/server/utils.ts +17 -6
  79. package/src/private_kernel/hints/build_private_kernel_reset_private_inputs.ts +106 -104
  80. package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +58 -0
  81. package/src/private_kernel/hints/index.ts +1 -0
  82. package/src/private_kernel/private_kernel_execution_prover.ts +21 -4
  83. package/src/private_kernel/private_kernel_oracle.ts +1 -1
  84. package/src/private_kernel/private_kernel_oracle_impl.ts +12 -9
  85. package/src/pxe_service/error_enriching.ts +1 -0
  86. package/src/pxe_service/pxe_service.ts +30 -32
  87. package/src/storage/capsule_data_provider/capsule_data_provider.ts +1 -1
  88. package/src/storage/note_data_provider/note_data_provider.ts +27 -16
@@ -214,7 +214,7 @@ export class PXEService implements PXE {
214
214
  if (!result) {
215
215
  throw new Error(`L2 to L1 message not found in block ${blockNumber}`);
216
216
  }
217
- return [result.l2MessageIndex, result.siblingPath];
217
+ return [result.leafIndex, result.siblingPath];
218
218
  }
219
219
 
220
220
  public getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
@@ -318,7 +318,7 @@ export class PXEService implements PXE {
318
318
  return !!(await this.node.getContractClass(id));
319
319
  }
320
320
 
321
- async #isContractPubliclyDeployed(address: AztecAddress): Promise<boolean> {
321
+ async #isContractPublished(address: AztecAddress): Promise<boolean> {
322
322
  return !!(await this.node.getContract(address));
323
323
  }
324
324
 
@@ -351,10 +351,11 @@ export class PXEService implements PXE {
351
351
  };
352
352
  }
353
353
 
354
+ // Executes the entrypoint private function, as well as all nested private
355
+ // functions that might arise.
354
356
  async #executePrivate(
355
357
  contractFunctionSimulator: ContractFunctionSimulator,
356
358
  txRequest: TxExecutionRequest,
357
- msgSender?: AztecAddress,
358
359
  scopes?: AztecAddress[],
359
360
  ): Promise<PrivateExecutionResult> {
360
361
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -364,7 +365,10 @@ export class PXEService implements PXE {
364
365
  txRequest,
365
366
  contractAddress,
366
367
  functionSelector,
367
- msgSender,
368
+ undefined,
369
+ // The sender for tags is set by contracts, typically by an account
370
+ // contract entrypoint
371
+ undefined, // senderForTags
368
372
  scopes,
369
373
  );
370
374
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
@@ -496,7 +500,7 @@ export class PXEService implements PXE {
496
500
  public async getContractMetadata(address: AztecAddress): Promise<{
497
501
  contractInstance: ContractInstanceWithAddress | undefined;
498
502
  isContractInitialized: boolean;
499
- isContractPubliclyDeployed: boolean;
503
+ isContractPublished: boolean;
500
504
  }> {
501
505
  let instance;
502
506
  try {
@@ -507,7 +511,7 @@ export class PXEService implements PXE {
507
511
  return {
508
512
  contractInstance: instance,
509
513
  isContractInitialized: await this.#isContractInitialized(address),
510
- isContractPubliclyDeployed: await this.#isContractPubliclyDeployed(address),
514
+ isContractPublished: await this.#isContractPublished(address),
511
515
  };
512
516
  }
513
517
 
@@ -656,6 +660,9 @@ export class PXEService implements PXE {
656
660
  }
657
661
 
658
662
  public async getNotes(filter: NotesFilter): Promise<UniqueNote[]> {
663
+ // We need to manually trigger private state sync to have a guarantee that all the events are available.
664
+ await this.simulateUtility('sync_private_state', [], filter.contractAddress);
665
+
659
666
  const noteDaos = await this.noteDataProvider.getNotes(filter);
660
667
 
661
668
  const extendedNotes = noteDaos.map(async dao => {
@@ -734,9 +741,7 @@ export class PXEService implements PXE {
734
741
  totalTime - ((syncTime ?? 0) + (proving ?? 0) + perFunction.reduce((acc, { time }) => acc + time, 0)),
735
742
  };
736
743
 
737
- this.log.info(`Proving completed in ${totalTime}ms`, {
738
- timings,
739
- });
744
+ this.log.debug(`Proving completed in ${totalTime}ms`, { timings });
740
745
  return new TxProvingResult(privateExecutionResult, publicInputs, clientIvcProof!, {
741
746
  timings,
742
747
  nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls,
@@ -751,7 +756,6 @@ export class PXEService implements PXE {
751
756
  txRequest: TxExecutionRequest,
752
757
  profileMode: 'full' | 'execution-steps' | 'gates',
753
758
  skipProofGeneration: boolean = true,
754
- msgSender?: AztecAddress,
755
759
  ): Promise<TxProfileResult> {
756
760
  // We disable concurrent profiles for consistency with simulateTx.
757
761
  return this.#putInJobQueue(async () => {
@@ -761,7 +765,6 @@ export class PXEService implements PXE {
761
765
  origin: txRequest.origin,
762
766
  functionSelector: txRequest.functionSelector,
763
767
  simulatePublic: false,
764
- msgSender,
765
768
  chainId: txRequest.txContext.chainId,
766
769
  version: txRequest.txContext.version,
767
770
  authWitnesses: txRequest.authWitnesses.map(w => w.requestHash),
@@ -775,7 +778,7 @@ export class PXEService implements PXE {
775
778
  const syncTime = syncTimer.ms();
776
779
 
777
780
  const contractFunctionSimulator = this.#getSimulatorForTx();
778
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, msgSender);
781
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
779
782
 
780
783
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
781
784
  txRequest,
@@ -816,12 +819,7 @@ export class PXEService implements PXE {
816
819
  const simulatorStats = contractFunctionSimulator.getStats();
817
820
  return new TxProfileResult(executionSteps, { timings, nodeRPCCalls: simulatorStats.nodeRPCCalls });
818
821
  } catch (err: any) {
819
- throw this.#contextualizeError(
820
- err,
821
- inspect(txRequest),
822
- `profileMode=${profileMode}`,
823
- `msgSender=${msgSender?.toString() ?? 'undefined'}`,
824
- );
822
+ throw this.#contextualizeError(err, inspect(txRequest), `profileMode=${profileMode}`);
825
823
  }
826
824
  });
827
825
  }
@@ -845,7 +843,6 @@ export class PXEService implements PXE {
845
843
  origin: txRequest.origin,
846
844
  functionSelector: txRequest.functionSelector,
847
845
  simulatePublic,
848
- msgSender: overrides?.msgSender,
849
846
  chainId: txRequest.txContext.chainId,
850
847
  version: txRequest.txContext.version,
851
848
  authWitnesses: txRequest.authWitnesses.map(w => w.requestHash),
@@ -863,12 +860,9 @@ export class PXEService implements PXE {
863
860
  // will fail. Consider handing control to the user/wallet on whether they want to run them
864
861
  // or not.
865
862
  const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
866
- const privateExecutionResult = await this.#executePrivate(
867
- contractFunctionSimulator,
868
- txRequest,
869
- overrides?.msgSender,
870
- scopes,
871
- );
863
+
864
+ // Execution of private functions only; no proving, and no kernel logic.
865
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes);
872
866
 
873
867
  let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
874
868
  let executionSteps: PrivateExecutionStep[] = [];
@@ -886,6 +880,7 @@ export class PXEService implements PXE {
886
880
  this.contractDataProvider,
887
881
  ));
888
882
  } else {
883
+ // Kernel logic, plus proving of all private functions and kernels.
889
884
  ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
890
885
  simulate: true,
891
886
  skipFeeEnforcement,
@@ -894,7 +889,7 @@ export class PXEService implements PXE {
894
889
  }
895
890
 
896
891
  const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
897
- const simulatedTx = privateSimulationResult.toSimulatedTx();
892
+ const simulatedTx = await privateSimulationResult.toSimulatedTx();
898
893
  let publicSimulationTime: number | undefined;
899
894
  let publicOutput: PublicSimulationOutput | undefined;
900
895
  if (simulatePublic && publicInputs.forPublic) {
@@ -904,7 +899,7 @@ export class PXEService implements PXE {
904
899
  }
905
900
 
906
901
  let validationTime: number | undefined;
907
- if (!skipTxValidation && !skipKernels) {
902
+ if (!skipTxValidation) {
908
903
  const validationTimer = new Timer();
909
904
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
910
905
  validationTime = validationTimer.ms();
@@ -913,7 +908,7 @@ export class PXEService implements PXE {
913
908
  }
914
909
  }
915
910
 
916
- const txHash = await simulatedTx.getTxHash();
911
+ const txHash = simulatedTx.getTxHash();
917
912
 
918
913
  const totalTime = totalTimer.ms();
919
914
 
@@ -959,7 +954,6 @@ export class PXEService implements PXE {
959
954
  err,
960
955
  inspect(txRequest),
961
956
  `simulatePublic=${simulatePublic}`,
962
- `msgSender=${overrides?.msgSender?.toString() ?? 'undefined'}`,
963
957
  `skipTxValidation=${skipTxValidation}`,
964
958
  `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
965
959
  );
@@ -968,7 +962,7 @@ export class PXEService implements PXE {
968
962
  }
969
963
 
970
964
  public async sendTx(tx: Tx): Promise<TxHash> {
971
- const txHash = await tx.getTxHash();
965
+ const txHash = tx.getTxHash();
972
966
  if (await this.node.getTxEffect(txHash)) {
973
967
  throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
974
968
  }
@@ -1065,9 +1059,9 @@ export class PXEService implements PXE {
1065
1059
  return Promise.resolve({
1066
1060
  pxeVersion: this.packageVersion,
1067
1061
  protocolContractAddresses: {
1068
- classRegisterer: ProtocolContractAddress.ContractClassRegisterer,
1062
+ classRegistry: ProtocolContractAddress.ContractClassRegistry,
1069
1063
  feeJuice: ProtocolContractAddress.FeeJuice,
1070
- instanceDeployer: ProtocolContractAddress.ContractInstanceDeployer,
1064
+ instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
1071
1065
  multiCallEntrypoint: ProtocolContractAddress.MultiCallEntrypoint,
1072
1066
  },
1073
1067
  });
@@ -1134,4 +1128,8 @@ export class PXEService implements PXE {
1134
1128
  async resetNoteSyncData() {
1135
1129
  return await this.taggingDataProvider.resetNoteSyncData();
1136
1130
  }
1131
+
1132
+ public stop(): Promise<void> {
1133
+ return this.jobQueue.end();
1134
+ }
1137
1135
  }
@@ -29,7 +29,7 @@ export class CapsuleDataProvider implements DataProvider {
29
29
  async loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
30
30
  const dataBuffer = await this.#capsules.getAsync(dbSlotToKey(contractAddress, slot));
31
31
  if (!dataBuffer) {
32
- this.logger.debug(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
32
+ this.logger.trace(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
33
33
  return null;
34
34
  }
35
35
  const capsule: Fr[] = [];
@@ -202,19 +202,17 @@ export class NoteDataProvider implements DataProvider {
202
202
  ? await toArray(
203
203
  this.#notesByTxHashAndScope.get(formattedScopeString)!.getValuesAsync(filter.txHash.toString()),
204
204
  )
205
- : filter.contractAddress
205
+ : filter.storageSlot
206
206
  ? await toArray(
207
+ this.#notesByStorageSlotAndScope
208
+ .get(formattedScopeString)!
209
+ .getValuesAsync(filter.storageSlot.toString()),
210
+ )
211
+ : await toArray(
207
212
  this.#notesByContractAndScope
208
213
  .get(formattedScopeString)!
209
214
  .getValuesAsync(filter.contractAddress.toString()),
210
- )
211
- : filter.storageSlot
212
- ? await toArray(
213
- this.#notesByStorageSlotAndScope
214
- .get(formattedScopeString)!
215
- .getValuesAsync(filter.storageSlot.toString()),
216
- )
217
- : await toArray(this.#notesByRecipientAndScope.get(formattedScopeString)!.valuesAsync()),
215
+ ),
218
216
  );
219
217
  }
220
218
 
@@ -229,11 +227,9 @@ export class NoteDataProvider implements DataProvider {
229
227
  ? await toArray(this.#nullifiedNotesByRecipient.getValuesAsync(filter.recipient.toString()))
230
228
  : filter.txHash
231
229
  ? await toArray(this.#nullifiedNotesByTxHash.getValuesAsync(filter.txHash.toString()))
232
- : filter.contractAddress
233
- ? await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString()))
234
- : filter.storageSlot
235
- ? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString()))
236
- : await toArray(this.#nullifiedNotes.keysAsync()),
230
+ : filter.storageSlot
231
+ ? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString()))
232
+ : await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString())),
237
233
  notes: this.#nullifiedNotes,
238
234
  });
239
235
  }
@@ -247,7 +243,7 @@ export class NoteDataProvider implements DataProvider {
247
243
  }
248
244
 
249
245
  const note = NoteDao.fromBuffer(serializedNote);
250
- if (filter.contractAddress && !note.contractAddress.equals(filter.contractAddress)) {
246
+ if (!note.contractAddress.equals(filter.contractAddress)) {
251
247
  continue;
252
248
  }
253
249
 
@@ -334,6 +330,21 @@ export class NoteDataProvider implements DataProvider {
334
330
  }
335
331
 
336
332
  async getSize() {
337
- return (await this.getNotes({})).reduce((sum, note) => sum + note.getSize(), 0);
333
+ const scopes = await toArray(this.#scopes.keysAsync());
334
+ const contractAddresses = new Set<string>();
335
+
336
+ // Collect all unique contract addresses across all scopes
337
+ for (const scope of scopes) {
338
+ const addresses = await toArray(this.#notesByContractAndScope.get(scope)!.keysAsync());
339
+ addresses.forEach(addr => contractAddresses.add(addr));
340
+ }
341
+
342
+ // Get all notes for each contract address
343
+ const allNotes = await Promise.all(
344
+ Array.from(contractAddresses).map(addr => this.getNotes({ contractAddress: AztecAddress.fromString(addr) })),
345
+ );
346
+
347
+ // Reduce all notes to get total size
348
+ return allNotes.flat().reduce((sum, note) => sum + note.getSize(), 0);
338
349
  }
339
350
  }