@aztec/pxe 0.16.4 → 0.16.6

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 (35) hide show
  1. package/dest/bin/index.js +3 -1
  2. package/dest/database/memory_db.js +3 -3
  3. package/dest/pxe_http/pxe_http_server.d.ts.map +1 -1
  4. package/dest/pxe_http/pxe_http_server.js +2 -2
  5. package/dest/simulator_oracle/index.js +3 -3
  6. package/dest/synchronizer/synchronizer.js +2 -2
  7. package/package.json +9 -9
  8. package/src/bin/index.ts +0 -39
  9. package/src/config/index.ts +0 -37
  10. package/src/contract_data_oracle/index.ts +0 -163
  11. package/src/contract_database/index.ts +0 -1
  12. package/src/contract_database/memory_contract_database.ts +0 -58
  13. package/src/contract_tree/index.ts +0 -241
  14. package/src/database/database.ts +0 -140
  15. package/src/database/index.ts +0 -2
  16. package/src/database/memory_db.ts +0 -181
  17. package/src/database/note_dao.ts +0 -90
  18. package/src/index.ts +0 -11
  19. package/src/kernel_oracle/index.ts +0 -39
  20. package/src/kernel_prover/index.ts +0 -2
  21. package/src/kernel_prover/kernel_prover.ts +0 -325
  22. package/src/kernel_prover/proof_creator.ts +0 -155
  23. package/src/kernel_prover/proving_data_oracle.ts +0 -69
  24. package/src/note_processor/index.ts +0 -1
  25. package/src/note_processor/note_processor.ts +0 -286
  26. package/src/pxe_http/index.ts +0 -1
  27. package/src/pxe_http/pxe_http_server.ts +0 -78
  28. package/src/pxe_service/create_pxe_service.ts +0 -52
  29. package/src/pxe_service/index.ts +0 -3
  30. package/src/pxe_service/pxe_service.ts +0 -679
  31. package/src/pxe_service/test/pxe_test_suite.ts +0 -132
  32. package/src/simulator/index.ts +0 -24
  33. package/src/simulator_oracle/index.ts +0 -186
  34. package/src/synchronizer/index.ts +0 -1
  35. package/src/synchronizer/synchronizer.ts +0 -296
@@ -1,241 +0,0 @@
1
- import {
2
- CONTRACT_TREE_HEIGHT,
3
- EthAddress,
4
- FUNCTION_TREE_HEIGHT,
5
- Fr,
6
- FunctionData,
7
- MembershipWitness,
8
- NewContractConstructor,
9
- NewContractData,
10
- computeFunctionTreeData,
11
- generateFunctionLeaves,
12
- hashVKStr,
13
- isConstrained,
14
- isConstructor,
15
- } from '@aztec/circuits.js';
16
- import {
17
- computeCompleteAddress,
18
- computeContractLeaf,
19
- computeFunctionTree,
20
- computeFunctionTreeRoot,
21
- computeVarArgsHash,
22
- hashConstructor,
23
- } from '@aztec/circuits.js/abis';
24
- import { ContractArtifact, FunctionSelector } from '@aztec/foundation/abi';
25
- import { assertLength } from '@aztec/foundation/serialize';
26
- import { AztecNode, ContractDao, MerkleTreeId, PublicKey, StateInfoProvider } from '@aztec/types';
27
-
28
- /**
29
- * The ContractTree class represents a Merkle tree of functions for a particular contract.
30
- * It manages the construction of the function tree, computes its root, and generates membership witnesses
31
- * for constrained functions. This class also enables lookup of specific function artifact using selectors.
32
- * It is used in combination with the AztecNode to compute various data for executing private transactions.
33
- */
34
- export class ContractTree {
35
- private functionLeaves?: Fr[];
36
- private functionTree?: Fr[];
37
- private functionTreeRoot?: Fr;
38
- private contractIndex?: bigint;
39
-
40
- constructor(
41
- /**
42
- * The contract data object containing the artifact and contract address.
43
- */
44
- public readonly contract: ContractDao,
45
- private stateInfoProvider: StateInfoProvider,
46
- /**
47
- * Data associated with the contract constructor for a new contract.
48
- */
49
- public readonly newContractConstructor?: NewContractConstructor,
50
- ) {}
51
-
52
- /**
53
- * Create a new ContractTree instance from the provided contract artifact, constructor arguments, and related data.
54
- * The function generates function leaves for constrained functions, computes the function tree root,
55
- * and hashes the constructor's verification key. It then computes the contract address using the contract
56
- * and portal contract addresses, contract address salt, and generated data. Finally, it returns a new
57
- * ContractTree instance containing the contract data and computed values.
58
- *
59
- * @param artifact - The contract's build artifact containing the functions and their metadata.
60
- * @param args - An array of Fr elements representing the constructor's arguments.
61
- * @param portalContract - The Ethereum address of the portal smart contract.
62
- * @param contractAddressSalt - An Fr element representing the salt used to compute the contract address.
63
- * @param from - The public key of the contract deployer.
64
- * @param node - An instance of the AztecNode class representing the current node.
65
- * @returns A new ContractTree instance containing the contract data and computed values.
66
- */
67
- public static new(
68
- artifact: ContractArtifact,
69
- args: Fr[],
70
- portalContract: EthAddress,
71
- contractAddressSalt: Fr,
72
- from: PublicKey,
73
- node: AztecNode,
74
- ) {
75
- const constructorArtifact = artifact.functions.find(isConstructor);
76
- if (!constructorArtifact) {
77
- throw new Error('Constructor not found.');
78
- }
79
- if (!constructorArtifact.verificationKey) {
80
- throw new Error('Missing verification key for the constructor.');
81
- }
82
-
83
- const functions = artifact.functions.map(f => ({
84
- ...f,
85
- selector: FunctionSelector.fromNameAndParameters(f.name, f.parameters),
86
- }));
87
- const leaves = generateFunctionLeaves(functions);
88
- const root = computeFunctionTreeRoot(leaves);
89
- const functionData = FunctionData.fromAbi(constructorArtifact);
90
- const vkHash = hashVKStr(constructorArtifact.verificationKey);
91
- const argsHash = computeVarArgsHash(args);
92
- const constructorHash = hashConstructor(functionData, argsHash, vkHash);
93
-
94
- const completeAddress = computeCompleteAddress(from, contractAddressSalt, root, constructorHash);
95
-
96
- const contractDao: ContractDao = {
97
- ...artifact,
98
- completeAddress,
99
- functions,
100
- portalContract,
101
- };
102
- const NewContractConstructor = {
103
- functionData,
104
- vkHash,
105
- };
106
- return new ContractTree(contractDao, node, NewContractConstructor);
107
- }
108
-
109
- /**
110
- * Retrieve the artifact of a given function.
111
- * The function is identified by its selector, which represents a unique identifier for the function's signature.
112
- * Throws an error if the function with the provided selector is not found in the contract.
113
- *
114
- * @param selector - The function selector.
115
- * @returns The artifact object containing relevant information about the targeted function.
116
- */
117
- public getFunctionArtifact(selector: FunctionSelector) {
118
- const artifact = this.contract.functions.find(f => f.selector.equals(selector));
119
- if (!artifact) {
120
- throw new Error(
121
- `Unknown function. Selector ${selector.toString()} not found in the artifact of contract ${this.contract.completeAddress.address.toString()}. Expected one of: ${this.contract.functions
122
- .map(f => f.selector.toString())
123
- .join(', ')}`,
124
- );
125
- }
126
- return artifact;
127
- }
128
-
129
- /**
130
- * Retrieve the bytecode of a function in the contract by its function selector.
131
- * The function selector is a unique identifier for each function in a contract.
132
- * Throws an error if the function with the given selector is not found in the contract.
133
- *
134
- * @param selector - The selector of a function to get bytecode for.
135
- * @returns The bytecode of the function as a string.
136
- */
137
- public getBytecode(selector: FunctionSelector) {
138
- return this.getFunctionArtifact(selector).bytecode;
139
- }
140
-
141
- /**
142
- * Retrieves the contract membership witness for the current contract tree instance.
143
- * The contract membership witness is a proof that demonstrates the existence of the contract
144
- * in the global contract merkle tree. This proof contains the index of the contract's leaf
145
- * in the tree and the sibling path needed to construct the root of the merkle tree.
146
- * If the witness hasn't been previously computed, this function will request the contract node
147
- * to find the contract's index and path in order to create the membership witness.
148
- *
149
- * @param blockNumber - The block number at which to get the data.
150
- *
151
- * @returns A Promise that resolves to the MembershipWitness object for the given contract tree.
152
- */
153
- public async getContractMembershipWitness(blockNumber: number | 'latest' = 'latest') {
154
- const index = await this.getContractIndex();
155
-
156
- const siblingPath = await this.stateInfoProvider.getContractSiblingPath(blockNumber, index);
157
- return new MembershipWitness<typeof CONTRACT_TREE_HEIGHT>(
158
- CONTRACT_TREE_HEIGHT,
159
- index,
160
- assertLength(siblingPath.toFieldArray(), CONTRACT_TREE_HEIGHT),
161
- );
162
- }
163
-
164
- /**
165
- * Calculate and return the root of the function tree for the current contract.
166
- * This root is a cryptographic commitment to the set of constrained functions within the contract,
167
- * which is used in the Aztec node's proof system. The root will be cached after the first call.
168
- *
169
- * @returns A promise that resolves to the Fr (finite field element) representation of the function tree root.
170
- */
171
- public getFunctionTreeRoot() {
172
- if (!this.functionTreeRoot) {
173
- const leaves = this.getFunctionLeaves();
174
- this.functionTreeRoot = computeFunctionTreeRoot(leaves);
175
- }
176
- return Promise.resolve(this.functionTreeRoot);
177
- }
178
-
179
- /**
180
- * Retrieve the membership witness of a function within a contract's function tree.
181
- * A membership witness represents the position and authentication path of a target function
182
- * in the Merkle tree of constrained functions. It is required to prove the existence of the
183
- * function within the contract during execution.
184
- *
185
- * @param selector - The function selector.
186
- * @returns A MembershipWitness instance representing the position and authentication path of the function in the function tree.
187
- */
188
- public getFunctionMembershipWitness(
189
- selector: FunctionSelector,
190
- ): Promise<MembershipWitness<typeof FUNCTION_TREE_HEIGHT>> {
191
- const targetFunctions = this.contract.functions.filter(isConstrained);
192
- const functionIndex = targetFunctions.findIndex(f => f.selector.equals(selector));
193
- if (functionIndex < 0) {
194
- return Promise.resolve(MembershipWitness.empty(FUNCTION_TREE_HEIGHT, 0n));
195
- }
196
-
197
- if (!this.functionTree) {
198
- const leaves = this.getFunctionLeaves();
199
- this.functionTree = computeFunctionTree(leaves);
200
- }
201
- const functionTreeData = computeFunctionTreeData(this.functionTree, functionIndex);
202
- return Promise.resolve(
203
- new MembershipWitness<typeof FUNCTION_TREE_HEIGHT>(
204
- FUNCTION_TREE_HEIGHT,
205
- BigInt(functionIndex),
206
- assertLength(functionTreeData.siblingPath, FUNCTION_TREE_HEIGHT),
207
- ),
208
- );
209
- }
210
-
211
- /**
212
- * Retrieve the function leaves for the contract tree.
213
- * Function leaves are computed based on constrained functions present in the contract.
214
- * It caches the computed function leaves and returns them if already calculated.
215
- *
216
- * @returns An array of Fr representing the function leaves.
217
- */
218
- private getFunctionLeaves() {
219
- if (!this.functionLeaves) {
220
- this.functionLeaves = generateFunctionLeaves(this.contract.functions);
221
- }
222
- return this.functionLeaves;
223
- }
224
-
225
- private async getContractIndex() {
226
- if (this.contractIndex === undefined) {
227
- const { completeAddress, portalContract } = this.contract;
228
- const root = await this.getFunctionTreeRoot();
229
- const newContractData = new NewContractData(completeAddress.address, portalContract, root);
230
- const commitment = computeContractLeaf(newContractData);
231
- this.contractIndex = await this.stateInfoProvider.findLeafIndex('latest', MerkleTreeId.CONTRACT_TREE, commitment);
232
- if (this.contractIndex === undefined) {
233
- throw new Error(
234
- `Failed to find contract at ${completeAddress.address} with portal ${portalContract} resulting in commitment ${commitment}.`,
235
- );
236
- }
237
- return this.contractIndex;
238
- }
239
- return this.contractIndex;
240
- }
241
- }
@@ -1,140 +0,0 @@
1
- import { BlockHeader, CompleteAddress, PublicKey } from '@aztec/circuits.js';
2
- import { AztecAddress } from '@aztec/foundation/aztec-address';
3
- import { Fr } from '@aztec/foundation/fields';
4
- import { ContractDatabase, MerkleTreeId, NoteFilter } from '@aztec/types';
5
-
6
- import { NoteDao } from './note_dao.js';
7
-
8
- /**
9
- * A database interface that provides methods for retrieving, adding, and removing transactional data related to Aztec
10
- * addresses, storage slots, and nullifiers.
11
- */
12
- export interface Database extends ContractDatabase {
13
- /**
14
- * Add a auth witness to the database.
15
- * @param messageHash - The message hash.
16
- * @param witness - An array of field elements representing the auth witness.
17
- */
18
- addAuthWitness(messageHash: Fr, witness: Fr[]): Promise<void>;
19
-
20
- /**
21
- * Fetching the auth witness for a given message hash.
22
- * @param messageHash - The message hash.
23
- * @returns A Promise that resolves to an array of field elements representing the auth witness.
24
- */
25
- getAuthWitness(messageHash: Fr): Promise<Fr[]>;
26
-
27
- /**
28
- * Adding a capsule to the capsule dispenser.
29
- * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle.
30
- * @param capsule - An array of field elements representing the capsule.
31
- */
32
- addCapsule(capsule: Fr[]): Promise<void>;
33
-
34
- /**
35
- * Get the next capsule from the capsule dispenser.
36
- * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle.
37
- * @returns A promise that resolves to an array of field elements representing the capsule.
38
- */
39
- popCapsule(): Promise<Fr[] | undefined>;
40
-
41
- /**
42
- * Gets notes based on the provided filter.
43
- * @param filter - The filter to apply to the notes.
44
- * @returns The requested notes.
45
- */
46
- getNotes(filter: NoteFilter): Promise<NoteDao[]>;
47
-
48
- /**
49
- * Adds a note to DB.
50
- * @param note - The note to add.
51
- */
52
- addNote(note: NoteDao): Promise<void>;
53
-
54
- /**
55
- * Adds an array of notes to DB.
56
- * This function is used to insert multiple notes to the database at once,
57
- * which can improve performance when dealing with large numbers of transactions.
58
- *
59
- * @param notes - An array of notes.
60
- */
61
- addNotes(notes: NoteDao[]): Promise<void>;
62
-
63
- /**
64
- * Remove nullified notes associated with the given account and nullifiers.
65
- *
66
- * @param nullifiers - An array of Fr instances representing nullifiers to be matched.
67
- * @param account - A PublicKey instance representing the account for which the records are being removed.
68
- * @returns Removed notes.
69
- */
70
- removeNullifiedNotes(nullifiers: Fr[], account: PublicKey): Promise<NoteDao[]>;
71
-
72
- /**
73
- * Retrieve the stored Merkle tree roots from the database.
74
- * The function returns a Promise that resolves to an object containing the MerkleTreeId as keys
75
- * and their corresponding Fr values as roots. Throws an error if the tree roots are not set in the
76
- * memory database.
77
- *
78
- * @returns An object containing the Merkle tree roots for each merkle tree id.
79
- */
80
- getTreeRoots(): Record<MerkleTreeId, Fr>;
81
-
82
- /**
83
- * Set the tree roots for the Merkle trees in the database.
84
- * This function updates the 'treeRoots' property of the instance
85
- * with the provided 'roots' object containing MerkleTreeId and Fr pairs.
86
- * Note that this will overwrite any existing tree roots in the database.
87
- *
88
- * @param roots - A Record object mapping MerkleTreeIds to their corresponding Fr root values.
89
- * @returns A Promise that resolves when the tree roots have been successfully updated in the database.
90
- */
91
- setTreeRoots(roots: Record<MerkleTreeId, Fr>): Promise<void>;
92
-
93
- /**
94
- * Retrieve the stored Block Header from the database.
95
- * The function returns a Promise that resolves to the Block Header.
96
- * This data is required to reproduce block attestations.
97
- * Throws an error if the block header is not available within the database.
98
- *
99
- * note: this data is a combination of the tree roots and the global variables hash.
100
- */
101
- getBlockHeader(): BlockHeader;
102
-
103
- /**
104
- * Set the latest Block Header.
105
- * This function updates the 'global variables hash' and `tree roots` property of the instance
106
- * Note that this will overwrite any existing hash or roots in the database.
107
- *
108
- * @param blockHeader - An object containing the most recent block header.
109
- * @returns A Promise that resolves when the hash has been successfully updated in the database.
110
- */
111
- setBlockHeader(blockHeader: BlockHeader): Promise<void>;
112
-
113
- /**
114
- * Adds complete address to the database.
115
- * @param address - The complete address to add.
116
- * @returns A promise resolving to true if the address was added, false if it already exists.
117
- * @throws If we try to add a CompleteAddress with the same AztecAddress but different public key or partial
118
- * address.
119
- */
120
- addCompleteAddress(address: CompleteAddress): Promise<boolean>;
121
-
122
- /**
123
- * Retrieves the complete address corresponding to the provided aztec address.
124
- * @param address - The aztec address of the complete address contract.
125
- * @returns A promise that resolves to a CompleteAddress instance if the address is found, or undefined if not found.
126
- */
127
- getCompleteAddress(address: AztecAddress): Promise<CompleteAddress | undefined>;
128
-
129
- /**
130
- * Retrieves the list of complete address added to this database
131
- * @returns A promise that resolves to an array of AztecAddress instances.
132
- */
133
- getCompleteAddresses(): Promise<CompleteAddress[]>;
134
-
135
- /**
136
- * Returns the estimated size in bytes of this db.
137
- * @returns The estimated size in bytes of this db.
138
- */
139
- estimateSize(): number;
140
- }
@@ -1,2 +0,0 @@
1
- export * from './database.js';
2
- export * from './memory_db.js';
@@ -1,181 +0,0 @@
1
- import { BlockHeader, CompleteAddress, PublicKey } from '@aztec/circuits.js';
2
- import { AztecAddress } from '@aztec/foundation/aztec-address';
3
- import { Fr } from '@aztec/foundation/fields';
4
- import { createDebugLogger } from '@aztec/foundation/log';
5
- import { MerkleTreeId, NoteFilter } from '@aztec/types';
6
-
7
- import { MemoryContractDatabase } from '../contract_database/index.js';
8
- import { Database } from './database.js';
9
- import { NoteDao } from './note_dao.js';
10
-
11
- /**
12
- * The MemoryDB class provides an in-memory implementation of a database to manage transactions and auxiliary data.
13
- * It extends the MemoryContractDatabase, allowing it to store contract-related data as well.
14
- * The class offers methods to add, fetch, and remove transaction records and auxiliary data based on various filters such as transaction hash, address, and storage slot.
15
- * As an in-memory database, the stored data will not persist beyond the life of the application instance.
16
- */
17
- export class MemoryDB extends MemoryContractDatabase implements Database {
18
- private notesTable: NoteDao[] = [];
19
- private treeRoots: Record<MerkleTreeId, Fr> | undefined;
20
- private globalVariablesHash: Fr | undefined;
21
- private addresses: CompleteAddress[] = [];
22
- private authWitnesses: Record<string, Fr[]> = {};
23
- // A capsule is a "blob" of data that is passed to the contract through an oracle.
24
- // We are using a stack to keep track of the capsules that are passed to the contract.
25
- private capsuleStack: Fr[][] = [];
26
-
27
- constructor(logSuffix?: string) {
28
- super(createDebugLogger(logSuffix ? 'aztec:memory_db_' + logSuffix : 'aztec:memory_db'));
29
- }
30
-
31
- /**
32
- * Add a auth witness to the database.
33
- * @param messageHash - The message hash.
34
- * @param witness - An array of field elements representing the auth witness.
35
- */
36
- public addAuthWitness(messageHash: Fr, witness: Fr[]): Promise<void> {
37
- this.authWitnesses[messageHash.toString()] = witness;
38
- return Promise.resolve();
39
- }
40
-
41
- /**
42
- * Fetching the auth witness for a given message hash.
43
- * @param messageHash - The message hash.
44
- * @returns A Promise that resolves to an array of field elements representing the auth witness.
45
- */
46
- public getAuthWitness(messageHash: Fr): Promise<Fr[]> {
47
- return Promise.resolve(this.authWitnesses[messageHash.toString()]);
48
- }
49
-
50
- public addNote(note: NoteDao): Promise<void> {
51
- this.notesTable.push(note);
52
- return Promise.resolve();
53
- }
54
-
55
- public addCapsule(capsule: Fr[]): Promise<void> {
56
- this.capsuleStack.push(capsule);
57
- return Promise.resolve();
58
- }
59
-
60
- public popCapsule(): Promise<Fr[] | undefined> {
61
- return Promise.resolve(this.capsuleStack.pop());
62
- }
63
-
64
- public addNotes(notes: NoteDao[]) {
65
- this.notesTable.push(...notes);
66
- return Promise.resolve();
67
- }
68
-
69
- public async getNotes(filter: NoteFilter): Promise<NoteDao[]> {
70
- let ownerPublicKey: PublicKey | undefined;
71
- if (filter.owner !== undefined) {
72
- const ownerCompleteAddress = await this.getCompleteAddress(filter.owner);
73
- if (ownerCompleteAddress === undefined) {
74
- throw new Error(`Owner ${filter.owner.toString()} not found in memory database`);
75
- }
76
- ownerPublicKey = ownerCompleteAddress.publicKey;
77
- }
78
-
79
- return this.notesTable.filter(
80
- note =>
81
- (filter.contractAddress == undefined || note.contractAddress.equals(filter.contractAddress)) &&
82
- (filter.txHash == undefined || note.txHash.equals(filter.txHash)) &&
83
- (filter.storageSlot == undefined || note.storageSlot.equals(filter.storageSlot!)) &&
84
- (ownerPublicKey == undefined || note.publicKey.equals(ownerPublicKey!)),
85
- );
86
- }
87
-
88
- public removeNullifiedNotes(nullifiers: Fr[], account: PublicKey) {
89
- const nullifierSet = new Set(nullifiers.map(nullifier => nullifier.toString()));
90
- const [remaining, removed] = this.notesTable.reduce(
91
- (acc: [NoteDao[], NoteDao[]], note) => {
92
- const nullifier = note.siloedNullifier.toString();
93
- if (note.publicKey.equals(account) && nullifierSet.has(nullifier)) {
94
- acc[1].push(note);
95
- } else {
96
- acc[0].push(note);
97
- }
98
- return acc;
99
- },
100
- [[], []],
101
- );
102
-
103
- this.notesTable = remaining;
104
-
105
- return Promise.resolve(removed);
106
- }
107
-
108
- public getTreeRoots(): Record<MerkleTreeId, Fr> {
109
- const roots = this.treeRoots;
110
- if (!roots) {
111
- throw new Error(`Tree roots not set in memory database`);
112
- }
113
- return roots;
114
- }
115
-
116
- public setTreeRoots(roots: Record<MerkleTreeId, Fr>) {
117
- this.treeRoots = roots;
118
- return Promise.resolve();
119
- }
120
-
121
- public getBlockHeader(): BlockHeader {
122
- const roots = this.getTreeRoots();
123
- if (!this.globalVariablesHash) {
124
- throw new Error(`Global variables hash not set in memory database`);
125
- }
126
- return new BlockHeader(
127
- roots[MerkleTreeId.NOTE_HASH_TREE],
128
- roots[MerkleTreeId.NULLIFIER_TREE],
129
- roots[MerkleTreeId.CONTRACT_TREE],
130
- roots[MerkleTreeId.L1_TO_L2_MESSAGES_TREE],
131
- roots[MerkleTreeId.BLOCKS_TREE],
132
- Fr.ZERO, // todo: private kernel vk tree root
133
- roots[MerkleTreeId.PUBLIC_DATA_TREE],
134
- this.globalVariablesHash,
135
- );
136
- }
137
-
138
- public async setBlockHeader(blockHeader: BlockHeader): Promise<void> {
139
- this.globalVariablesHash = blockHeader.globalVariablesHash;
140
- await this.setTreeRoots({
141
- [MerkleTreeId.NOTE_HASH_TREE]: blockHeader.noteHashTreeRoot,
142
- [MerkleTreeId.NULLIFIER_TREE]: blockHeader.nullifierTreeRoot,
143
- [MerkleTreeId.CONTRACT_TREE]: blockHeader.contractTreeRoot,
144
- [MerkleTreeId.L1_TO_L2_MESSAGES_TREE]: blockHeader.l1ToL2MessagesTreeRoot,
145
- [MerkleTreeId.BLOCKS_TREE]: blockHeader.blocksTreeRoot,
146
- [MerkleTreeId.PUBLIC_DATA_TREE]: blockHeader.publicDataTreeRoot,
147
- });
148
- }
149
-
150
- public addCompleteAddress(completeAddress: CompleteAddress): Promise<boolean> {
151
- const accountIndex = this.addresses.findIndex(r => r.address.equals(completeAddress.address));
152
- if (accountIndex !== -1) {
153
- if (this.addresses[accountIndex].equals(completeAddress)) {
154
- return Promise.resolve(false);
155
- }
156
-
157
- throw new Error(
158
- `Complete address with aztec address ${completeAddress.address.toString()} but different public key or partial key already exists in memory database`,
159
- );
160
- }
161
- this.addresses.push(completeAddress);
162
- return Promise.resolve(true);
163
- }
164
-
165
- public getCompleteAddress(address: AztecAddress): Promise<CompleteAddress | undefined> {
166
- const recipient = this.addresses.find(r => r.address.equals(address));
167
- return Promise.resolve(recipient);
168
- }
169
-
170
- public getCompleteAddresses(): Promise<CompleteAddress[]> {
171
- return Promise.resolve(this.addresses);
172
- }
173
-
174
- public estimateSize() {
175
- const notesSize = this.notesTable.reduce((sum, note) => sum + note.getSize(), 0);
176
- const treeRootsSize = this.treeRoots ? Object.entries(this.treeRoots).length * Fr.SIZE_IN_BYTES : 0;
177
- const authWits = Object.entries(this.authWitnesses);
178
- const authWitsSize = authWits.reduce((sum, [key, value]) => sum + key.length + value.length * Fr.SIZE_IN_BYTES, 0);
179
- return notesSize + treeRootsSize + authWitsSize + this.addresses.length * CompleteAddress.SIZE_IN_BYTES;
180
- }
181
- }
@@ -1,90 +0,0 @@
1
- import { AztecAddress, Fr, Point, PublicKey } from '@aztec/circuits.js';
2
- import { toBigIntBE, toBufferBE } from '@aztec/foundation/bigint-buffer';
3
- import { BufferReader, Note, TxHash } from '@aztec/types';
4
-
5
- /**
6
- * A note with contextual data.
7
- */
8
- export class NoteDao {
9
- constructor(
10
- /** The note as emitted from the Noir contract. */
11
- public note: Note,
12
- /** The contract address this note is created in. */
13
- public contractAddress: AztecAddress,
14
- /** The specific storage location of the note on the contract. */
15
- public storageSlot: Fr,
16
- /** The hash of the tx the note was created in. */
17
- public txHash: TxHash,
18
- /** The nonce of the note. */
19
- public nonce: Fr,
20
- /**
21
- * Inner note hash of the note. This is customizable by the app circuit.
22
- * We can use this value to compute siloedNoteHash and uniqueSiloedNoteHash.
23
- */
24
- public innerNoteHash: Fr,
25
- /** The nullifier of the note (siloed by contract address). */
26
- public siloedNullifier: Fr,
27
- /** The location of the relevant note in the note hash tree. */
28
- public index: bigint,
29
- /** The public key with which the note was encrypted. */
30
- public publicKey: PublicKey,
31
- ) {}
32
-
33
- toBuffer(): Buffer {
34
- return Buffer.concat([
35
- this.note.toBuffer(),
36
- this.contractAddress.toBuffer(),
37
- this.storageSlot.toBuffer(),
38
- this.txHash.buffer,
39
- this.nonce.toBuffer(),
40
- this.innerNoteHash.toBuffer(),
41
- this.siloedNullifier.toBuffer(),
42
- toBufferBE(this.index, 32),
43
- this.publicKey.toBuffer(),
44
- ]);
45
- }
46
- static fromBuffer(buffer: Buffer | BufferReader) {
47
- const reader = BufferReader.asReader(buffer);
48
-
49
- const note = Note.fromBuffer(reader);
50
- const contractAddress = AztecAddress.fromBuffer(reader);
51
- const storageSlot = Fr.fromBuffer(reader);
52
- const txHash = new TxHash(reader.readBytes(TxHash.SIZE));
53
- const nonce = Fr.fromBuffer(reader);
54
- const innerNoteHash = Fr.fromBuffer(reader);
55
- const siloedNullifier = Fr.fromBuffer(reader);
56
- const index = toBigIntBE(reader.readBytes(32));
57
- const publicKey = Point.fromBuffer(reader);
58
-
59
- return new NoteDao(
60
- note,
61
- contractAddress,
62
- storageSlot,
63
- txHash,
64
- nonce,
65
- innerNoteHash,
66
- siloedNullifier,
67
- index,
68
- publicKey,
69
- );
70
- }
71
-
72
- toString() {
73
- return '0x' + this.toBuffer().toString('hex');
74
- }
75
-
76
- static fromString(str: string) {
77
- const hex = str.replace(/^0x/, '');
78
- return NoteDao.fromBuffer(Buffer.from(hex, 'hex'));
79
- }
80
-
81
- /**
82
- * Returns the size in bytes of the Note Dao.
83
- * @returns - Its size in bytes.
84
- */
85
- public getSize() {
86
- const indexSize = Math.ceil(Math.log2(Number(this.index)));
87
- const noteSize = 4 + this.note.items.length * Fr.SIZE_IN_BYTES;
88
- return noteSize + AztecAddress.SIZE_IN_BYTES + Fr.SIZE_IN_BYTES * 4 + TxHash.SIZE + Point.SIZE_IN_BYTES + indexSize;
89
- }
90
- }
package/src/index.ts DELETED
@@ -1,11 +0,0 @@
1
- export * from './pxe_service/index.js';
2
- export * from './pxe_http/index.js';
3
- export * from './config/index.js';
4
-
5
- export { Tx, TxHash } from '@aztec/types';
6
-
7
- export { TxRequest, PartialAddress } from '@aztec/circuits.js';
8
- export * from '@aztec/foundation/fields';
9
- export * from '@aztec/foundation/eth-address';
10
- export * from '@aztec/foundation/aztec-address';
11
- export * from '@aztec/key-store';