@aztec/pxe 0.62.0 → 0.63.1

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 (100) hide show
  1. package/dest/config/index.d.ts +2 -3
  2. package/dest/config/index.d.ts.map +1 -1
  3. package/dest/config/index.js +4 -5
  4. package/dest/contract_data_oracle/index.d.ts +1 -0
  5. package/dest/contract_data_oracle/index.d.ts.map +1 -1
  6. package/dest/contract_data_oracle/index.js +5 -1
  7. package/dest/database/incoming_note_dao.d.ts +1 -1
  8. package/dest/database/incoming_note_dao.d.ts.map +1 -1
  9. package/dest/database/kv_pxe_database.d.ts +5 -12
  10. package/dest/database/kv_pxe_database.d.ts.map +1 -1
  11. package/dest/database/kv_pxe_database.js +31 -62
  12. package/dest/database/outgoing_note_dao.d.ts +1 -1
  13. package/dest/database/outgoing_note_dao.d.ts.map +1 -1
  14. package/dest/database/pxe_database.d.ts +17 -25
  15. package/dest/database/pxe_database.d.ts.map +1 -1
  16. package/dest/kernel_oracle/index.d.ts +3 -3
  17. package/dest/kernel_oracle/index.d.ts.map +1 -1
  18. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
  19. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.js +12 -4
  20. package/dest/kernel_prover/kernel_prover.d.ts +3 -1
  21. package/dest/kernel_prover/kernel_prover.d.ts.map +1 -1
  22. package/dest/kernel_prover/kernel_prover.js +39 -7
  23. package/dest/kernel_prover/test/test_circuit_prover.d.ts +1 -0
  24. package/dest/kernel_prover/test/test_circuit_prover.d.ts.map +1 -1
  25. package/dest/kernel_prover/test/test_circuit_prover.js +5 -1
  26. package/dest/{note_processor/utils → note_decryption_utils}/add_public_values_to_payload.d.ts +1 -1
  27. package/dest/note_decryption_utils/add_public_values_to_payload.d.ts.map +1 -0
  28. package/dest/{note_processor/utils → note_decryption_utils}/add_public_values_to_payload.js +1 -1
  29. package/dest/note_decryption_utils/brute_force_note_info.d.ts.map +1 -0
  30. package/dest/{note_processor/utils → note_decryption_utils}/brute_force_note_info.js +1 -1
  31. package/dest/note_decryption_utils/index.d.ts.map +1 -0
  32. package/dest/{note_processor/utils → note_decryption_utils}/index.js +1 -1
  33. package/dest/{note_processor/utils → note_decryption_utils}/produce_note_daos.d.ts +5 -8
  34. package/dest/note_decryption_utils/produce_note_daos.d.ts.map +1 -0
  35. package/dest/note_decryption_utils/produce_note_daos.js +47 -0
  36. package/dest/note_decryption_utils/produce_note_daos_for_key.d.ts +8 -0
  37. package/dest/note_decryption_utils/produce_note_daos_for_key.d.ts.map +1 -0
  38. package/dest/note_decryption_utils/produce_note_daos_for_key.js +17 -0
  39. package/dest/pxe_http/pxe_http_server.d.ts +1 -2
  40. package/dest/pxe_http/pxe_http_server.d.ts.map +1 -1
  41. package/dest/pxe_http/pxe_http_server.js +5 -51
  42. package/dest/pxe_service/create_pxe_service.d.ts.map +1 -1
  43. package/dest/pxe_service/create_pxe_service.js +7 -4
  44. package/dest/pxe_service/error_enriching.d.ts.map +1 -1
  45. package/dest/pxe_service/error_enriching.js +7 -6
  46. package/dest/pxe_service/pxe_service.d.ts +11 -25
  47. package/dest/pxe_service/pxe_service.d.ts.map +1 -1
  48. package/dest/pxe_service/pxe_service.js +45 -48
  49. package/dest/pxe_service/test/pxe_test_suite.d.ts.map +1 -1
  50. package/dest/pxe_service/test/pxe_test_suite.js +4 -3
  51. package/dest/simulator_oracle/index.d.ts +15 -16
  52. package/dest/simulator_oracle/index.d.ts.map +1 -1
  53. package/dest/simulator_oracle/index.js +195 -65
  54. package/dest/synchronizer/synchronizer.d.ts +0 -48
  55. package/dest/synchronizer/synchronizer.d.ts.map +1 -1
  56. package/dest/synchronizer/synchronizer.js +3 -201
  57. package/package.json +14 -14
  58. package/src/config/index.ts +4 -7
  59. package/src/contract_data_oracle/index.ts +5 -0
  60. package/src/database/incoming_note_dao.ts +1 -1
  61. package/src/database/kv_pxe_database.ts +33 -70
  62. package/src/database/outgoing_note_dao.ts +1 -1
  63. package/src/database/pxe_database.ts +19 -28
  64. package/src/kernel_prover/hints/build_private_kernel_reset_private_inputs.ts +13 -3
  65. package/src/kernel_prover/kernel_prover.ts +49 -5
  66. package/src/kernel_prover/test/test_circuit_prover.ts +8 -4
  67. package/src/{note_processor/utils → note_decryption_utils}/add_public_values_to_payload.ts +1 -1
  68. package/src/{note_processor/utils → note_decryption_utils}/produce_note_daos.ts +6 -16
  69. package/src/{note_processor/utils → note_decryption_utils}/produce_note_daos_for_key.ts +6 -15
  70. package/src/pxe_http/pxe_http_server.ts +5 -84
  71. package/src/pxe_service/create_pxe_service.ts +9 -3
  72. package/src/pxe_service/error_enriching.ts +12 -5
  73. package/src/pxe_service/pxe_service.ts +61 -78
  74. package/src/pxe_service/test/pxe_test_suite.ts +6 -2
  75. package/src/simulator_oracle/index.ts +280 -60
  76. package/src/synchronizer/synchronizer.ts +3 -253
  77. package/dest/database/deferred_note_dao.d.ts +0 -40
  78. package/dest/database/deferred_note_dao.d.ts.map +0 -1
  79. package/dest/database/deferred_note_dao.js +0 -38
  80. package/dest/note_processor/index.d.ts +0 -2
  81. package/dest/note_processor/index.d.ts.map +0 -1
  82. package/dest/note_processor/index.js +0 -2
  83. package/dest/note_processor/note_processor.d.ts +0 -83
  84. package/dest/note_processor/note_processor.d.ts.map +0 -1
  85. package/dest/note_processor/note_processor.js +0 -231
  86. package/dest/note_processor/utils/add_public_values_to_payload.d.ts.map +0 -1
  87. package/dest/note_processor/utils/brute_force_note_info.d.ts.map +0 -1
  88. package/dest/note_processor/utils/index.d.ts.map +0 -1
  89. package/dest/note_processor/utils/produce_note_daos.d.ts.map +0 -1
  90. package/dest/note_processor/utils/produce_note_daos.js +0 -51
  91. package/dest/note_processor/utils/produce_note_daos_for_key.d.ts +0 -9
  92. package/dest/note_processor/utils/produce_note_daos_for_key.d.ts.map +0 -1
  93. package/dest/note_processor/utils/produce_note_daos_for_key.js +0 -26
  94. package/src/database/deferred_note_dao.ts +0 -47
  95. package/src/note_processor/index.ts +0 -1
  96. package/src/note_processor/note_processor.ts +0 -358
  97. /package/dest/{note_processor/utils → note_decryption_utils}/brute_force_note_info.d.ts +0 -0
  98. /package/dest/{note_processor/utils → note_decryption_utils}/index.d.ts +0 -0
  99. /package/src/{note_processor/utils → note_decryption_utils}/brute_force_note_info.ts +0 -0
  100. /package/src/{note_processor/utils → note_decryption_utils}/index.ts +0 -0
@@ -2,7 +2,7 @@ import {
2
2
  type AuthWitness,
3
3
  type AztecNode,
4
4
  EventMetadata,
5
- EventType,
5
+ type EventMetadataDefinition,
6
6
  type ExtendedNote,
7
7
  type FunctionCall,
8
8
  type GetUnencryptedLogsResponse,
@@ -31,7 +31,6 @@ import {
31
31
  UniqueNote,
32
32
  getNonNullifiedL1ToL2MessageWitness,
33
33
  } from '@aztec/circuit-types';
34
- import { type NoteProcessorStats } from '@aztec/circuit-types/stats';
35
34
  import {
36
35
  type AztecAddress,
37
36
  type CompleteAddress,
@@ -50,7 +49,6 @@ import {
50
49
  import { computeNoteHashNonce, siloNullifier } from '@aztec/circuits.js/hash';
51
50
  import {
52
51
  type AbiDecoded,
53
- type AbiType,
54
52
  type ContractArtifact,
55
53
  EventSelector,
56
54
  FunctionSelector,
@@ -91,8 +89,6 @@ export class PXEService implements PXE {
91
89
  // ensures that state is not changed while simulating
92
90
  private jobQueue = new SerialQueue();
93
91
 
94
- private fakeProofCreator = new TestPrivateKernelProver();
95
-
96
92
  constructor(
97
93
  private keyStore: KeyStore,
98
94
  private node: AztecNode,
@@ -118,33 +114,11 @@ export class PXEService implements PXE {
118
114
  public async start() {
119
115
  const { l2BlockPollingIntervalMS } = this.config;
120
116
  await this.synchronizer.start(1, l2BlockPollingIntervalMS);
121
- await this.restoreNoteProcessors();
122
117
  await this.#registerProtocolContracts();
123
118
  const info = await this.getNodeInfo();
124
119
  this.log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.protocolVersion}`);
125
120
  }
126
121
 
127
- private async restoreNoteProcessors() {
128
- const accounts = await this.keyStore.getAccounts();
129
- const accountsSet = new Set(accounts.map(k => k.toString()));
130
-
131
- const registeredAddresses = await this.db.getCompleteAddresses();
132
-
133
- let count = 0;
134
- for (const completeAddress of registeredAddresses) {
135
- if (!accountsSet.has(completeAddress.address.toString())) {
136
- continue;
137
- }
138
-
139
- count++;
140
- this.synchronizer.addAccount(completeAddress, this.keyStore, this.config.l2StartingBlock);
141
- }
142
-
143
- if (count > 0) {
144
- this.log.info(`Restored ${count} accounts`);
145
- }
146
- }
147
-
148
122
  /**
149
123
  * Stops the PXE Service, halting processing of new transactions and shutting down the synchronizer.
150
124
  * This function ensures that all ongoing tasks are completed before stopping the server.
@@ -196,7 +170,6 @@ export class PXEService implements PXE {
196
170
  this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`);
197
171
  return accountCompleteAddress;
198
172
  } else {
199
- this.synchronizer.addAccount(accountCompleteAddress, this.keyStore, this.config.l2StartingBlock);
200
173
  this.log.info(`Registered account ${accountCompleteAddress.address.toString()}`);
201
174
  this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
202
175
  }
@@ -296,7 +269,6 @@ export class PXEService implements PXE {
296
269
 
297
270
  this.log.info(`Added contract ${artifact.name} at ${instance.address.toString()}`);
298
271
  await this.db.addContractInstance(instance);
299
- await this.synchronizer.reprocessDeferredNotesForContract(instance.address);
300
272
  }
301
273
 
302
274
  public getContracts(): Promise<AztecAddress[]> {
@@ -393,13 +365,15 @@ export class PXEService implements PXE {
393
365
  note.note,
394
366
  );
395
367
 
396
- const index = await this.node.findLeafIndex('latest', MerkleTreeId.NOTE_HASH_TREE, siloedNoteHash);
368
+ const [index] = await this.node.findLeavesIndexes('latest', MerkleTreeId.NOTE_HASH_TREE, [siloedNoteHash]);
397
369
  if (index === undefined) {
398
370
  throw new Error('Note does not exist.');
399
371
  }
400
372
 
401
373
  const siloedNullifier = siloNullifier(note.contractAddress, innerNullifier!);
402
- const nullifierIndex = await this.node.findLeafIndex('latest', MerkleTreeId.NULLIFIER_TREE, siloedNullifier);
374
+ const [nullifierIndex] = await this.node.findLeavesIndexes('latest', MerkleTreeId.NULLIFIER_TREE, [
375
+ siloedNullifier,
376
+ ]);
403
377
  if (nullifierIndex !== undefined) {
404
378
  throw new Error('The note has been destroyed.');
405
379
  }
@@ -442,7 +416,7 @@ export class PXEService implements PXE {
442
416
  throw new Error('Unexpectedly received non-zero nullifier.');
443
417
  }
444
418
 
445
- const index = await this.node.findLeafIndex('latest', MerkleTreeId.NOTE_HASH_TREE, siloedNoteHash);
419
+ const [index] = await this.node.findLeavesIndexes('latest', MerkleTreeId.NOTE_HASH_TREE, [siloedNoteHash]);
446
420
  if (index === undefined) {
447
421
  throw new Error('Note does not exist.');
448
422
  }
@@ -534,11 +508,24 @@ export class PXEService implements PXE {
534
508
  simulatePublic: boolean,
535
509
  msgSender: AztecAddress | undefined = undefined,
536
510
  skipTxValidation: boolean = false,
511
+ profile: boolean = false,
537
512
  scopes?: AztecAddress[],
538
513
  ): Promise<TxSimulationResult> {
539
514
  return await this.jobQueue.put(async () => {
540
515
  const privateExecutionResult = await this.#executePrivate(txRequest, msgSender, scopes);
541
- const publicInputs = await this.#simulateKernels(txRequest, privateExecutionResult);
516
+
517
+ let publicInputs: PrivateKernelTailCircuitPublicInputs;
518
+ let profileResult;
519
+ if (profile) {
520
+ ({ publicInputs, profileResult } = await this.#profileKernelProver(
521
+ txRequest,
522
+ this.proofCreator,
523
+ privateExecutionResult,
524
+ ));
525
+ } else {
526
+ publicInputs = await this.#simulateKernels(txRequest, privateExecutionResult);
527
+ }
528
+
542
529
  const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
543
530
  const simulatedTx = privateSimulationResult.toSimulatedTx();
544
531
  let publicOutput: PublicSimulationOutput | undefined;
@@ -559,7 +546,11 @@ export class PXEService implements PXE {
559
546
  if (!msgSender) {
560
547
  this.log.info(`Executed local simulation for ${simulatedTx.getTxHash()}`);
561
548
  }
562
- return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput(privateSimulationResult, publicOutput);
549
+ return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput(
550
+ privateSimulationResult,
551
+ publicOutput,
552
+ profileResult,
553
+ );
563
554
  });
564
555
  }
565
556
 
@@ -617,6 +608,15 @@ export class PXEService implements PXE {
617
608
  return this.node.getUnencryptedLogs(filter);
618
609
  }
619
610
 
611
+ /**
612
+ * Gets contract class logs based on the provided filter.
613
+ * @param filter - The filter to apply to the logs.
614
+ * @returns The requested logs.
615
+ */
616
+ public getContractClassLogs(filter: LogFilter): Promise<GetUnencryptedLogsResponse> {
617
+ return this.node.getContractClassLogs(filter);
618
+ }
619
+
620
620
  async #getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall> {
621
621
  const contract = await this.db.getContract(to);
622
622
  if (!contract) {
@@ -681,7 +681,6 @@ export class PXEService implements PXE {
681
681
  const { address, contractClass, instance, artifact } = getCanonicalProtocolContract(name);
682
682
  await this.db.addContractArtifact(contractClass.id, artifact);
683
683
  await this.db.addContractInstance(instance);
684
- await this.synchronizer.reprocessDeferredNotesForContract(address);
685
684
  this.log.info(`Added protocol contract ${name} at ${address.toString()}`);
686
685
  }
687
686
  }
@@ -764,18 +763,36 @@ export class PXEService implements PXE {
764
763
  * @param tx - The transaction to be simulated.
765
764
  */
766
765
  async #simulatePublicCalls(tx: Tx) {
766
+ // Simulating public calls can throw if the TX fails in a phase that doesn't allow reverts (setup)
767
+ // Or return as reverted if it fails in a phase that allows reverts (app logic, teardown)
767
768
  try {
768
- return await this.node.simulatePublicCalls(tx);
769
+ const result = await this.node.simulatePublicCalls(tx);
770
+ if (result.revertReason) {
771
+ throw result.revertReason;
772
+ }
773
+ return result;
769
774
  } catch (err) {
770
- // Try to fill in the noir call stack since the PXE may have access to the debug metadata
771
775
  if (err instanceof SimulationError) {
772
776
  await enrichPublicSimulationError(err, this.contractDataOracle, this.db, this.log);
773
777
  }
774
-
775
778
  throw err;
776
779
  }
777
780
  }
778
781
 
782
+ async #profileKernelProver(
783
+ txExecutionRequest: TxExecutionRequest,
784
+ proofCreator: PrivateKernelProver,
785
+ privateExecutionResult: PrivateExecutionResult,
786
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
787
+ const block = privateExecutionResult.publicInputs.historicalHeader.globalVariables.blockNumber.toNumber();
788
+ const kernelOracle = new KernelOracle(this.contractDataOracle, this.keyStore, this.node, block);
789
+ const kernelProver = new KernelProver(kernelOracle, proofCreator);
790
+
791
+ // Dry run the prover with profiler enabled
792
+ const result = await kernelProver.prove(txExecutionRequest.toTxRequest(), privateExecutionResult, true, true);
793
+ return result;
794
+ }
795
+
779
796
  /**
780
797
  * Simulate a transaction, generate a kernel proof, and create a private transaction object.
781
798
  * The function takes in a transaction request, simulates it, and then generates a kernel proof
@@ -808,18 +825,10 @@ export class PXEService implements PXE {
808
825
  return await this.synchronizer.isGlobalStateSynchronized();
809
826
  }
810
827
 
811
- public async isAccountStateSynchronized(account: AztecAddress) {
812
- return await this.synchronizer.isAccountStateSynchronized(account);
813
- }
814
-
815
828
  public getSyncStatus() {
816
829
  return Promise.resolve(this.synchronizer.getSyncStatus());
817
830
  }
818
831
 
819
- public getSyncStats(): Promise<{ [address: string]: NoteProcessorStats }> {
820
- return Promise.resolve(this.synchronizer.getSyncStats());
821
- }
822
-
823
832
  public async isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
824
833
  return !!(await this.node.getContractClass(id));
825
834
  }
@@ -829,45 +838,18 @@ export class PXEService implements PXE {
829
838
  }
830
839
 
831
840
  public async isContractInitialized(address: AztecAddress): Promise<boolean> {
832
- const initNullifier = siloNullifier(address, address);
841
+ const initNullifier = siloNullifier(address, address.toField());
833
842
  return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
834
843
  }
835
844
 
836
- public getEvents<T>(
837
- type: EventType.Encrypted,
838
- event: { eventSelector: EventSelector; abiType: AbiType; fieldNames: string[] },
839
- from: number,
840
- limit: number,
841
- vpks: Point[],
842
- ): Promise<T[]>;
843
- public getEvents<T>(
844
- type: EventType.Unencrypted,
845
- event: { eventSelector: EventSelector; abiType: AbiType; fieldNames: string[] },
846
- from: number,
847
- limit: number,
848
- ): Promise<T[]>;
849
- public getEvents<T>(
850
- type: EventType,
851
- event: { eventSelector: EventSelector; abiType: AbiType; fieldNames: string[] },
852
- from: number,
853
- limit: number,
854
- vpks: Point[] = [],
855
- ): Promise<T[]> {
856
- const eventMetadata = new EventMetadata<T>(type, event);
857
- if (type.includes(EventType.Encrypted)) {
858
- return this.getEncryptedEvents(from, limit, eventMetadata, vpks);
859
- }
860
-
861
- return this.getUnencryptedEvents(from, limit, eventMetadata);
862
- }
863
-
864
- async getEncryptedEvents<T>(
845
+ public async getEncryptedEvents<T>(
846
+ eventMetadataDef: EventMetadataDefinition,
865
847
  from: number,
866
848
  limit: number,
867
- eventMetadata: EventMetadata<T>,
868
849
  // TODO (#9272): Make this better, we should be able to only pass an address now
869
850
  vpks: Point[],
870
851
  ): Promise<T[]> {
852
+ const eventMetadata = new EventMetadata<T>(eventMetadataDef);
871
853
  if (vpks.length === 0) {
872
854
  throw new Error('Tried to get encrypted events without supplying any viewing public keys');
873
855
  }
@@ -931,7 +913,8 @@ export class PXEService implements PXE {
931
913
  return decodedEvents;
932
914
  }
933
915
 
934
- async getUnencryptedEvents<T>(from: number, limit: number, eventMetadata: EventMetadata<T>): Promise<T[]> {
916
+ async getUnencryptedEvents<T>(eventMetadataDef: EventMetadataDefinition, from: number, limit: number): Promise<T[]> {
917
+ const eventMetadata = new EventMetadata<T>(eventMetadataDef);
935
918
  const { logs: unencryptedLogs } = await this.node.getUnencryptedLogs({
936
919
  fromBlock: from,
937
920
  toBlock: from + limit,
@@ -6,6 +6,8 @@ import {
6
6
  } from '@aztec/circuit-types';
7
7
  import { AztecAddress, Fr, INITIAL_L2_BLOCK_NUM, getContractClassFromArtifact } from '@aztec/circuits.js';
8
8
 
9
+ import omit from 'lodash.omit';
10
+
9
11
  export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) => {
10
12
  describe(testName, () => {
11
13
  let pxe: PXE;
@@ -54,7 +56,9 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
54
56
  const instance = randomContractInstanceWithAddress({ contractClassId });
55
57
 
56
58
  await pxe.registerContractClass(artifact);
57
- expect(await pxe.getContractClass(contractClassId)).toEqual(contractClass);
59
+ expect(await pxe.getContractClass(contractClassId)).toMatchObject(
60
+ omit(contractClass, 'privateFunctionsRoot', 'publicBytecodeCommitment'),
61
+ );
58
62
 
59
63
  await pxe.registerContract({ instance });
60
64
  expect(await pxe.getContractInstance(instance.address)).toEqual(instance);
@@ -69,7 +73,7 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
69
73
  pxe.registerContract({
70
74
  instance: {
71
75
  ...instance,
72
- address: Fr.random(),
76
+ address: AztecAddress.random(),
73
77
  },
74
78
  artifact,
75
79
  }),