@aztec/pxe 0.76.4 → 0.77.0-testnet-ignition.21

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 (113) hide show
  1. package/dest/bin/index.js +4 -6
  2. package/dest/config/index.d.ts +2 -2
  3. package/dest/config/index.d.ts.map +1 -1
  4. package/dest/config/index.js +20 -23
  5. package/dest/config/package_info.js +4 -2
  6. package/dest/contract_data_oracle/index.d.ts +10 -10
  7. package/dest/contract_data_oracle/index.d.ts.map +1 -1
  8. package/dest/contract_data_oracle/index.js +74 -89
  9. package/dest/contract_data_oracle/private_functions_tree.d.ts +5 -4
  10. package/dest/contract_data_oracle/private_functions_tree.d.ts.map +1 -1
  11. package/dest/contract_data_oracle/private_functions_tree.js +47 -51
  12. package/dest/database/contracts/contract_artifact_db.d.ts +2 -2
  13. package/dest/database/contracts/contract_artifact_db.d.ts.map +1 -1
  14. package/dest/database/contracts/contract_artifact_db.js +3 -2
  15. package/dest/database/contracts/contract_instance_db.d.ts +2 -1
  16. package/dest/database/contracts/contract_instance_db.d.ts.map +1 -1
  17. package/dest/database/contracts/contract_instance_db.js +3 -2
  18. package/dest/database/index.js +0 -1
  19. package/dest/database/kv_pxe_database.d.ts +9 -5
  20. package/dest/database/kv_pxe_database.d.ts.map +1 -1
  21. package/dest/database/kv_pxe_database.js +244 -257
  22. package/dest/database/note_dao.d.ts +13 -10
  23. package/dest/database/note_dao.d.ts.map +1 -1
  24. package/dest/database/note_dao.js +35 -48
  25. package/dest/database/outgoing_note_dao.d.ts +6 -3
  26. package/dest/database/outgoing_note_dao.d.ts.map +1 -1
  27. package/dest/database/outgoing_note_dao.js +25 -37
  28. package/dest/database/pxe_database.d.ts +12 -8
  29. package/dest/database/pxe_database.d.ts.map +1 -1
  30. package/dest/database/pxe_database.js +4 -2
  31. package/dest/database/pxe_database_test_suite.d.ts +1 -1
  32. package/dest/database/pxe_database_test_suite.d.ts.map +1 -1
  33. package/dest/database/pxe_database_test_suite.js +286 -147
  34. package/dest/index.d.ts +1 -6
  35. package/dest/index.d.ts.map +1 -1
  36. package/dest/index.js +1 -7
  37. package/dest/kernel_oracle/index.d.ts +20 -10
  38. package/dest/kernel_oracle/index.d.ts.map +1 -1
  39. package/dest/kernel_oracle/index.js +32 -9
  40. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts +3 -3
  41. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
  42. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.js +71 -67
  43. package/dest/kernel_prover/hints/index.js +0 -1
  44. package/dest/kernel_prover/index.js +0 -1
  45. package/dest/kernel_prover/kernel_prover.d.ts +6 -6
  46. package/dest/kernel_prover/kernel_prover.d.ts.map +1 -1
  47. package/dest/kernel_prover/kernel_prover.js +98 -81
  48. package/dest/kernel_prover/proving_data_oracle.d.ts +15 -7
  49. package/dest/kernel_prover/proving_data_oracle.d.ts.map +1 -1
  50. package/dest/kernel_prover/proving_data_oracle.js +4 -2
  51. package/dest/note_decryption_utils/add_public_values_to_payload.d.ts +3 -2
  52. package/dest/note_decryption_utils/add_public_values_to_payload.d.ts.map +1 -1
  53. package/dest/note_decryption_utils/add_public_values_to_payload.js +11 -12
  54. package/dest/pxe_http/index.js +0 -1
  55. package/dest/pxe_http/pxe_http_server.d.ts +1 -1
  56. package/dest/pxe_http/pxe_http_server.d.ts.map +1 -1
  57. package/dest/pxe_http/pxe_http_server.js +9 -7
  58. package/dest/pxe_service/error_enriching.d.ts +3 -3
  59. package/dest/pxe_service/error_enriching.d.ts.map +1 -1
  60. package/dest/pxe_service/error_enriching.js +14 -17
  61. package/dest/pxe_service/index.d.ts +0 -1
  62. package/dest/pxe_service/index.d.ts.map +1 -1
  63. package/dest/pxe_service/index.js +0 -2
  64. package/dest/pxe_service/pxe_service.d.ts +21 -12
  65. package/dest/pxe_service/pxe_service.d.ts.map +1 -1
  66. package/dest/pxe_service/pxe_service.js +279 -333
  67. package/dest/pxe_service/test/pxe_test_suite.d.ts +1 -1
  68. package/dest/pxe_service/test/pxe_test_suite.d.ts.map +1 -1
  69. package/dest/pxe_service/test/pxe_test_suite.js +44 -28
  70. package/dest/simulator/index.d.ts +3 -3
  71. package/dest/simulator/index.d.ts.map +1 -1
  72. package/dest/simulator/index.js +1 -3
  73. package/dest/simulator_oracle/index.d.ts +18 -6
  74. package/dest/simulator_oracle/index.d.ts.map +1 -1
  75. package/dest/simulator_oracle/index.js +307 -235
  76. package/dest/simulator_oracle/tagging_utils.d.ts +2 -1
  77. package/dest/simulator_oracle/tagging_utils.d.ts.map +1 -1
  78. package/dest/simulator_oracle/tagging_utils.js +5 -7
  79. package/dest/synchronizer/index.js +0 -1
  80. package/dest/synchronizer/synchronizer.d.ts +7 -4
  81. package/dest/synchronizer/synchronizer.d.ts.map +1 -1
  82. package/dest/synchronizer/synchronizer.js +64 -43
  83. package/dest/utils/create_pxe_service.d.ts +2 -2
  84. package/dest/utils/create_pxe_service.d.ts.map +1 -1
  85. package/dest/utils/create_pxe_service.js +13 -11
  86. package/package.json +18 -19
  87. package/src/bin/index.ts +1 -1
  88. package/src/config/index.ts +3 -3
  89. package/src/contract_data_oracle/index.ts +20 -20
  90. package/src/contract_data_oracle/private_functions_tree.ts +6 -7
  91. package/src/database/contracts/contract_artifact_db.ts +2 -2
  92. package/src/database/contracts/contract_instance_db.ts +2 -1
  93. package/src/database/kv_pxe_database.ts +33 -32
  94. package/src/database/note_dao.ts +11 -8
  95. package/src/database/outgoing_note_dao.ts +7 -4
  96. package/src/database/pxe_database.ts +13 -15
  97. package/src/database/pxe_database_test_suite.ts +8 -11
  98. package/src/index.ts +1 -7
  99. package/src/kernel_oracle/index.ts +55 -22
  100. package/src/kernel_prover/hints/build_private_kernel_reset_private_inputs.ts +14 -11
  101. package/src/kernel_prover/kernel_prover.ts +89 -69
  102. package/src/kernel_prover/proving_data_oracle.ts +20 -20
  103. package/src/note_decryption_utils/add_public_values_to_payload.ts +5 -4
  104. package/src/pxe_http/pxe_http_server.ts +1 -1
  105. package/src/pxe_service/error_enriching.ts +6 -6
  106. package/src/pxe_service/index.ts +0 -1
  107. package/src/pxe_service/pxe_service.ts +121 -224
  108. package/src/pxe_service/test/pxe_test_suite.ts +6 -3
  109. package/src/simulator/index.ts +3 -3
  110. package/src/simulator_oracle/index.ts +77 -47
  111. package/src/simulator_oracle/tagging_utils.ts +2 -1
  112. package/src/synchronizer/synchronizer.ts +31 -12
  113. package/src/utils/create_pxe_service.ts +16 -4
@@ -1,57 +1,49 @@
1
1
  import {
2
- type AztecNode,
3
- type FunctionCall,
4
- type InBlock,
5
- L1NotePayload,
6
- type L2Block,
7
- type L2BlockNumber,
8
- MerkleTreeId,
9
- Note,
10
- type NoteStatus,
11
- type NullifierMembershipWitness,
12
- type PublicDataWitness,
13
- TxHash,
14
- type TxScopedL2Log,
15
- getNonNullifiedL1ToL2MessageWitness,
16
- } from '@aztec/circuit-types';
17
- import {
18
- type AztecAddress,
19
- type BlockHeader,
20
- type CompleteAddress,
21
- type ContractInstance,
22
- Fr,
23
- FunctionSelector,
24
- IndexedTaggingSecret,
25
- type KeyValidationRequest,
26
2
  type L1_TO_L2_MSG_TREE_HEIGHT,
27
3
  MAX_NOTE_HASHES_PER_TX,
28
4
  PRIVATE_LOG_SIZE_IN_FIELDS,
29
- PrivateLog,
30
- PublicLog,
31
- computeAddressSecret,
32
- computeTaggingSecretPoint,
33
- } from '@aztec/circuits.js';
34
- import { computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/circuits.js/hash';
5
+ PUBLIC_LOG_DATA_SIZE_IN_FIELDS,
6
+ } from '@aztec/constants';
7
+ import { timesParallel } from '@aztec/foundation/collection';
8
+ import { poseidon2Hash } from '@aztec/foundation/crypto';
9
+ import { Fr } from '@aztec/foundation/fields';
10
+ import { createLogger } from '@aztec/foundation/log';
11
+ import { BufferReader } from '@aztec/foundation/serialize';
12
+ import type { KeyStore } from '@aztec/key-store';
13
+ import type { AcirSimulator, DBOracle, SimulationProvider } from '@aztec/simulator/client';
14
+ import { MessageLoadOracleInputs } from '@aztec/simulator/client';
35
15
  import {
36
16
  type FunctionArtifact,
17
+ FunctionCall,
18
+ FunctionSelector,
37
19
  FunctionType,
38
20
  NoteSelector,
39
21
  encodeArguments,
40
22
  getFunctionArtifact,
41
- } from '@aztec/foundation/abi';
42
- import { timesParallel } from '@aztec/foundation/collection';
43
- import { poseidon2Hash } from '@aztec/foundation/crypto';
44
- import { createLogger } from '@aztec/foundation/log';
45
- import { type KeyStore } from '@aztec/key-store';
23
+ } from '@aztec/stdlib/abi';
24
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
25
+ import type { InBlock, L2Block, L2BlockNumber } from '@aztec/stdlib/block';
26
+ import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
27
+ import { computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
28
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
29
+ import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
30
+ import { computeAddressSecret, computeTaggingSecretPoint } from '@aztec/stdlib/keys';
46
31
  import {
47
- type AcirSimulator,
48
- type DBOracle,
49
- MessageLoadOracleInputs,
50
- type SimulationProvider,
51
- } from '@aztec/simulator/client';
32
+ IndexedTaggingSecret,
33
+ L1NotePayload,
34
+ LogWithTxData,
35
+ PrivateLog,
36
+ PublicLog,
37
+ TxScopedL2Log,
38
+ } from '@aztec/stdlib/logs';
39
+ import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
40
+ import { Note, type NoteStatus } from '@aztec/stdlib/note';
41
+ import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
42
+ import type { BlockHeader } from '@aztec/stdlib/tx';
43
+ import { TxHash } from '@aztec/stdlib/tx';
52
44
 
53
45
  import { ContractDataOracle } from '../contract_data_oracle/index.js';
54
- import { type PxeDatabase } from '../database/index.js';
46
+ import type { PxeDatabase } from '../database/index.js';
55
47
  import { NoteDao } from '../database/note_dao.js';
56
48
  import { getOrderedNoteItems } from '../note_decryption_utils/add_public_values_to_payload.js';
57
49
  import { getAcirSimulator } from '../simulator/index.js';
@@ -79,7 +71,7 @@ export class SimulatorOracle implements DBOracle {
79
71
  if (!completeAddress) {
80
72
  throw new Error(
81
73
  `No public key registered for address ${account}.
82
- Register it by calling pxe.registerAccount(...).\nSee docs for context: https://docs.aztec.network/reference/common_errors/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`,
74
+ Register it by calling pxe.registerAccount(...).\nSee docs for context: https://docs.aztec.network/developers/reference/debugging/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`,
83
75
  );
84
76
  }
85
77
  return completeAddress;
@@ -134,7 +126,7 @@ export class SimulatorOracle implements DBOracle {
134
126
  functionName: string,
135
127
  ): Promise<FunctionArtifact | undefined> {
136
128
  const instance = await this.contractDataOracle.getContractInstance(contractAddress);
137
- const artifact = await this.contractDataOracle.getContractArtifact(instance.contractClassId);
129
+ const artifact = await this.contractDataOracle.getContractArtifact(instance.currentContractClassId);
138
130
  return artifact && getFunctionArtifact(artifact, functionName);
139
131
  }
140
132
 
@@ -699,8 +691,45 @@ export class SimulatorOracle implements DBOracle {
699
691
  });
700
692
  }
701
693
 
694
+ public async getLogByTag(tag: Fr): Promise<LogWithTxData | null> {
695
+ const logs = await this.aztecNode.getLogsByTags([tag]);
696
+ const logsForTag = logs[0];
697
+
698
+ this.log.debug(`Got ${logsForTag.length} logs for tag ${tag}`);
699
+
700
+ if (logsForTag.length == 0) {
701
+ return null;
702
+ } else if (logsForTag.length > 1) {
703
+ // TODO(#11627): handle this case
704
+ throw new Error(
705
+ `Got ${logsForTag.length} logs for tag ${tag}. getLogByTag currently only supports a single log per tag`,
706
+ );
707
+ }
708
+
709
+ const log = logsForTag[0];
710
+
711
+ // getLogsByTag doesn't have all of the information that we need (notably note hashes and the first nullifier), so
712
+ // we need to make a second call to the node for `getTxEffect`.
713
+ // TODO(#9789): bundle this information in the `getLogsByTag` call.
714
+ const txEffect = await this.aztecNode.getTxEffect(log.txHash);
715
+ if (txEffect == undefined) {
716
+ throw new Error(`Unexpected: failed to retrieve tx effects for tx ${log.txHash} which is known to exist`);
717
+ }
718
+
719
+ const reader = BufferReader.asReader(log.logData);
720
+ const logArray = reader.readArray(PUBLIC_LOG_DATA_SIZE_IN_FIELDS, Fr);
721
+
722
+ // Public logs always take up all available fields by padding with zeroes, and the length of the originally emitted
723
+ // log is lost. Until this is improved, we simply remove all of the zero elements (which are expected to be at the
724
+ // end).
725
+ // TODO(#11636): use the actual log length.
726
+ const trimmedLog = logArray.filter(x => !x.isZero());
727
+
728
+ return new LogWithTxData(trimmedLog, log.txHash.hash, txEffect.data.noteHashes, txEffect.data.nullifiers[0]);
729
+ }
730
+
702
731
  public async removeNullifiedNotes(contractAddress: AztecAddress) {
703
- this.log.verbose('Removing nullified notes', { contract: contractAddress });
732
+ this.log.verbose('Searching for nullifiers of known notes', { contract: contractAddress });
704
733
 
705
734
  for (const recipient of await this.keyStore.getAccounts()) {
706
735
  const currentNotesForRecipient = await this.db.getNotes({ contractAddress, owner: recipient });
@@ -775,7 +804,7 @@ export class SimulatorOracle implements DBOracle {
775
804
  receipt.blockHash!.toString(),
776
805
  uniqueNoteHashTreeIndex,
777
806
  await recipient.toAddressPoint(),
778
- NoteSelector.empty(), // todo: remove
807
+ NoteSelector.empty(), // TODO(#12013): remove
779
808
  );
780
809
  }
781
810
 
@@ -798,10 +827,11 @@ export class SimulatorOracle implements DBOracle {
798
827
  );
799
828
  }
800
829
 
830
+ const selector = await FunctionSelector.fromNameAndParameters(artifact);
801
831
  const execRequest: FunctionCall = {
802
832
  name: artifact.name,
803
833
  to: contractAddress,
804
- selector: await FunctionSelector.fromNameAndParameters(artifact),
834
+ selector,
805
835
  type: FunctionType.UNCONSTRAINED,
806
836
  isStatic: artifact.isStatic,
807
837
  args: encodeArguments(artifact, [
@@ -819,8 +849,8 @@ export class SimulatorOracle implements DBOracle {
819
849
  getAcirSimulator(this.db, this.aztecNode, this.keyStore, this.simulationProvider, this.contractDataOracle)
820
850
  ).runUnconstrained(
821
851
  execRequest,
822
- artifact,
823
852
  contractAddress,
853
+ selector,
824
854
  [], // empty scope as this call should not require access to private information
825
855
  );
826
856
  }
@@ -1,4 +1,5 @@
1
- import { type Fr, IndexedTaggingSecret } from '@aztec/circuits.js';
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import { IndexedTaggingSecret } from '@aztec/stdlib/logs';
2
3
 
3
4
  // Half the size of the window we slide over the tagging secret indexes.
4
5
  export const WINDOW_HALF_SIZE = 10;
@@ -1,15 +1,11 @@
1
- import {
2
- type AztecNode,
3
- L2BlockStream,
4
- type L2BlockStreamEvent,
5
- type L2BlockStreamEventHandler,
6
- } from '@aztec/circuit-types';
7
- import { INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js';
1
+ import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
8
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
9
- import { type L2TipsStore } from '@aztec/kv-store/stores';
3
+ import type { L2TipsStore } from '@aztec/kv-store/stores';
4
+ import { L2BlockStream, type L2BlockStreamEvent, type L2BlockStreamEventHandler } from '@aztec/stdlib/block';
5
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
10
6
 
11
- import { type PXEConfig } from '../config/index.js';
12
- import { type PxeDatabase } from '../database/index.js';
7
+ import type { PXEConfig } from '../config/index.js';
8
+ import type { PxeDatabase } from '../database/index.js';
13
9
 
14
10
  /**
15
11
  * The Synchronizer class manages the synchronization with the aztec node, allowing PXE to retrieve the
@@ -20,6 +16,7 @@ import { type PxeDatabase } from '../database/index.js';
20
16
  export class Synchronizer implements L2BlockStreamEventHandler {
21
17
  private initialSyncBlockNumber = INITIAL_L2_BLOCK_NUM - 1;
22
18
  private log: Logger;
19
+ private isSyncing: Promise<void> | undefined;
23
20
  protected readonly blockStream: L2BlockStream;
24
21
 
25
22
  constructor(
@@ -66,7 +63,12 @@ export class Synchronizer implements L2BlockStreamEventHandler {
66
63
  // block number in which each index is used it's all we can do.
67
64
  await this.db.resetNoteSyncData();
68
65
  // Update the header to the last block.
69
- await this.db.setHeader(await this.node.getBlockHeader(event.blockNumber));
66
+ const newHeader = await this.node.getBlockHeader(event.blockNumber);
67
+ if (!newHeader) {
68
+ this.log.error(`Block header not found for block number ${event.blockNumber} during chain prune`);
69
+ } else {
70
+ await this.db.setHeader(newHeader);
71
+ }
70
72
  break;
71
73
  }
72
74
  }
@@ -77,6 +79,23 @@ export class Synchronizer implements L2BlockStreamEventHandler {
77
79
  * recent data (e.g. notes), and handling any reorgs that might have occurred.
78
80
  */
79
81
  public async sync() {
82
+ if (this.isSyncing !== undefined) {
83
+ this.log.debug(`Waiting for the ongoing sync to finish`);
84
+ await this.isSyncing;
85
+ return;
86
+ }
87
+
88
+ this.log.debug(`Syncing PXE with the node`);
89
+ const isSyncing = this.doSync();
90
+ this.isSyncing = isSyncing;
91
+ try {
92
+ await isSyncing;
93
+ } finally {
94
+ this.isSyncing = undefined;
95
+ }
96
+ }
97
+
98
+ private async doSync() {
80
99
  let currentHeader;
81
100
 
82
101
  try {
@@ -86,7 +105,7 @@ export class Synchronizer implements L2BlockStreamEventHandler {
86
105
  }
87
106
  if (!currentHeader) {
88
107
  // REFACTOR: We should know the header of the genesis block without having to request it from the node.
89
- await this.db.setHeader(await this.node.getBlockHeader(0));
108
+ await this.db.setHeader((await this.node.getBlockHeader(0))!);
90
109
  }
91
110
  await this.blockStream.sync();
92
111
  }
@@ -1,14 +1,15 @@
1
1
  import { BBNativePrivateKernelProver } from '@aztec/bb-prover';
2
2
  import { BBWASMBundlePrivateKernelProver } from '@aztec/bb-prover/wasm/bundle';
3
- import { type AztecNode, type PrivateKernelProver } from '@aztec/circuit-types';
4
3
  import { randomBytes } from '@aztec/foundation/crypto';
5
4
  import { createLogger } from '@aztec/foundation/log';
6
5
  import { KeyStore } from '@aztec/key-store';
7
- import { createStore } from '@aztec/kv-store/lmdb';
6
+ import { createStore } from '@aztec/kv-store/lmdb-v2';
8
7
  import { L2TipsStore } from '@aztec/kv-store/stores';
8
+ import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
9
9
  import { type SimulationProvider, WASMSimulator } from '@aztec/simulator/client';
10
+ import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
10
11
 
11
- import { type PXEServiceConfig } from '../config/index.js';
12
+ import type { PXEServiceConfig } from '../config/index.js';
12
13
  import { KVPxeDatabase } from '../database/kv_pxe_database.js';
13
14
  import { PXEService } from '../pxe_service/pxe_service.js';
14
15
 
@@ -48,7 +49,18 @@ export async function createPXEService(
48
49
  const tips = new L2TipsStore(store, 'pxe');
49
50
  const simulationProvider = new WASMSimulator();
50
51
  const prover = proofCreator ?? (await createProver(config, simulationProvider, logSuffix));
51
- const pxe = new PXEService(keyStore, aztecNode, db, tips, prover, simulationProvider, config, logSuffix);
52
+ const protocolContractsProvider = new BundledProtocolContractsProvider();
53
+ const pxe = new PXEService(
54
+ keyStore,
55
+ aztecNode,
56
+ db,
57
+ tips,
58
+ prover,
59
+ simulationProvider,
60
+ protocolContractsProvider,
61
+ config,
62
+ logSuffix,
63
+ );
52
64
  await pxe.init();
53
65
  return pxe;
54
66
  }