@aztec/world-state 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.
- package/dest/merkle-tree/merkle_tree_operations_facade.d.ts +4 -5
- package/dest/merkle-tree/merkle_tree_operations_facade.d.ts.map +1 -1
- package/dest/merkle-tree/merkle_tree_operations_facade.js +6 -7
- package/dest/merkle-tree/merkle_tree_snapshot_operations_facade.d.ts +2 -2
- package/dest/merkle-tree/merkle_tree_snapshot_operations_facade.d.ts.map +1 -1
- package/dest/merkle-tree/merkle_tree_snapshot_operations_facade.js +5 -5
- package/dest/world-state-db/merkle_tree_db.d.ts +4 -4
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/dest/world-state-db/merkle_trees.d.ts +2 -2
- package/dest/world-state-db/merkle_trees.d.ts.map +1 -1
- package/dest/world-state-db/merkle_trees.js +13 -13
- package/package.json +5 -5
- package/src/index.ts +0 -3
- package/src/merkle-tree/merkle_tree_operations_facade.ts +0 -190
- package/src/merkle-tree/merkle_tree_snapshot_operations_facade.ts +0 -143
- package/src/synchronizer/config.ts +0 -27
- package/src/synchronizer/index.ts +0 -2
- package/src/synchronizer/server_world_state_synchronizer.ts +0 -248
- package/src/synchronizer/world_state_synchronizer.ts +0 -73
- package/src/world-state-db/index.ts +0 -2
- package/src/world-state-db/merkle_tree_db.ts +0 -252
- package/src/world-state-db/merkle_trees.ts +0 -619
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import { MAX_NEW_NULLIFIERS_PER_TX, NullifierLeafPreimage } from '@aztec/circuits.js';
|
|
2
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { createDebugLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
|
|
5
|
-
import { BatchInsertionResult, IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
|
|
6
|
-
import { L2Block, MerkleTreeId, SiblingPath } from '@aztec/types';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Type alias for the nullifier tree ID.
|
|
10
|
-
*/
|
|
11
|
-
export type IndexedTreeId = MerkleTreeId.NULLIFIER_TREE;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Type alias for the public data tree ID.
|
|
15
|
-
*/
|
|
16
|
-
export type PublicTreeId = MerkleTreeId.PUBLIC_DATA_TREE;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @remarks Short explanation:
|
|
21
|
-
* The nullifier tree must be initially padded as the pre-populated 0 index prevents efficient subtree insertion.
|
|
22
|
-
* Padding with some values solves this issue.
|
|
23
|
-
*
|
|
24
|
-
* @remarks Thorough explanation:
|
|
25
|
-
* There needs to be an initial (0,0,0) leaf in the tree, so that when we insert the first 'proper' leaf, we can
|
|
26
|
-
* prove that any value greater than 0 doesn't exist in the tree yet. We prefill/pad the tree with "the number of
|
|
27
|
-
* leaves that are added by one block" so that the first 'proper' block can insert a full subtree.
|
|
28
|
-
*
|
|
29
|
-
* Without this padding, there would be a leaf (0,0,0) at leaf index 0, making it really difficult to insert e.g.
|
|
30
|
-
* 1024 leaves for the first block, because there's only neat space for 1023 leaves after 0. By padding with 1023
|
|
31
|
-
* more leaves, we can then insert the first block of 1024 leaves into indices 1024:2047.
|
|
32
|
-
*/
|
|
33
|
-
export const INITIAL_NULLIFIER_TREE_SIZE = 2 * MAX_NEW_NULLIFIERS_PER_TX;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Defines tree information.
|
|
37
|
-
*/
|
|
38
|
-
export interface TreeInfo {
|
|
39
|
-
/**
|
|
40
|
-
* The tree ID.
|
|
41
|
-
*/
|
|
42
|
-
treeId: MerkleTreeId;
|
|
43
|
-
/**
|
|
44
|
-
* The tree root.
|
|
45
|
-
*/
|
|
46
|
-
root: Buffer;
|
|
47
|
-
/**
|
|
48
|
-
* The number of leaves in the tree.
|
|
49
|
-
*/
|
|
50
|
-
size: bigint;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* The depth of the tree.
|
|
54
|
-
*/
|
|
55
|
-
depth: number;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Adds a last boolean flag in each function on the type.
|
|
60
|
-
*/
|
|
61
|
-
type WithIncludeUncommitted<F> = F extends (...args: [...infer Rest]) => infer Return
|
|
62
|
-
? (...args: [...Rest, boolean]) => Return
|
|
63
|
-
: F;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* The current roots of the commitment trees
|
|
67
|
-
*/
|
|
68
|
-
export type CurrentTreeRoots = {
|
|
69
|
-
/** Note Hash Tree root. */
|
|
70
|
-
noteHashTreeRoot: Buffer;
|
|
71
|
-
/** Contract data tree root. */
|
|
72
|
-
contractDataTreeRoot: Buffer;
|
|
73
|
-
/** L1 to L2 Messages data tree root. */
|
|
74
|
-
l1Tol2MessagesTreeRoot: Buffer;
|
|
75
|
-
/** Nullifier data tree root. */
|
|
76
|
-
nullifierTreeRoot: Buffer;
|
|
77
|
-
/** Blocks tree root. */
|
|
78
|
-
blocksTreeRoot: Buffer;
|
|
79
|
-
/** Public data tree root */
|
|
80
|
-
publicDataTreeRoot: Buffer;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Defines the names of the setters on Merkle Trees.
|
|
85
|
-
*/
|
|
86
|
-
type MerkleTreeSetters = 'appendLeaves' | 'updateLeaf' | 'commit' | 'rollback' | 'handleL2Block' | 'batchInsert';
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Defines the interface for operations on a set of Merkle Trees configuring whether to return committed or uncommitted data.
|
|
90
|
-
*/
|
|
91
|
-
export type MerkleTreeDb = {
|
|
92
|
-
[Property in keyof MerkleTreeOperations as Exclude<Property, MerkleTreeSetters>]: WithIncludeUncommitted<
|
|
93
|
-
MerkleTreeOperations[Property]
|
|
94
|
-
>;
|
|
95
|
-
} & Pick<MerkleTreeOperations, MerkleTreeSetters> & {
|
|
96
|
-
/**
|
|
97
|
-
* Returns a snapshot of the current state of the trees.
|
|
98
|
-
* @param block - The block number to take the snapshot at.
|
|
99
|
-
*/
|
|
100
|
-
getSnapshot(block: number): Promise<ReadonlyArray<TreeSnapshot | IndexedTreeSnapshot>>;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Defines the interface for operations on a set of Merkle Trees.
|
|
105
|
-
*/
|
|
106
|
-
export interface MerkleTreeOperations {
|
|
107
|
-
/**
|
|
108
|
-
* Appends leaves to a given tree.
|
|
109
|
-
* @param treeId - The tree to be updated.
|
|
110
|
-
* @param leaves - The set of leaves to be appended.
|
|
111
|
-
*/
|
|
112
|
-
appendLeaves(treeId: MerkleTreeId, leaves: Buffer[]): Promise<void>;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Returns information about the given tree.
|
|
116
|
-
* @param treeId - The tree to be queried.
|
|
117
|
-
*/
|
|
118
|
-
getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo>;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Gets the current roots of the commitment trees.
|
|
122
|
-
*/
|
|
123
|
-
getTreeRoots(): Promise<CurrentTreeRoots>;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Gets sibling path for a leaf.
|
|
127
|
-
* @param treeId - The tree to be queried for a sibling path.
|
|
128
|
-
* @param index - The index of the leaf for which a sibling path should be returned.
|
|
129
|
-
*/
|
|
130
|
-
getSiblingPath<N extends number>(treeId: MerkleTreeId, index: bigint): Promise<SiblingPath<N>>;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Returns the previous index for a given value in an indexed tree.
|
|
134
|
-
* @param treeId - The tree for which the previous value index is required.
|
|
135
|
-
* @param value - The value to be queried.
|
|
136
|
-
*/
|
|
137
|
-
getPreviousValueIndex(
|
|
138
|
-
treeId: IndexedTreeId,
|
|
139
|
-
value: bigint,
|
|
140
|
-
): Promise<
|
|
141
|
-
| {
|
|
142
|
-
/**
|
|
143
|
-
* The index of the found leaf.
|
|
144
|
-
*/
|
|
145
|
-
index: bigint;
|
|
146
|
-
/**
|
|
147
|
-
* A flag indicating if the corresponding leaf's value is equal to `newValue`.
|
|
148
|
-
*/
|
|
149
|
-
alreadyPresent: boolean;
|
|
150
|
-
}
|
|
151
|
-
| undefined
|
|
152
|
-
>;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Returns the data at a specific leaf.
|
|
156
|
-
* @param treeId - The tree for which leaf data should be returned.
|
|
157
|
-
* @param index - The index of the leaf required.
|
|
158
|
-
*/
|
|
159
|
-
getLeafPreimage(treeId: IndexedTreeId, index: bigint): Promise<IndexedTreeLeafPreimage | undefined>;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Update the leaf data at the given index.
|
|
163
|
-
* @param treeId - The tree for which leaf data should be edited.
|
|
164
|
-
* @param leaf - The updated leaf value.
|
|
165
|
-
* @param index - The index of the leaf to be updated.
|
|
166
|
-
*/
|
|
167
|
-
updateLeaf(treeId: IndexedTreeId | PublicTreeId, leaf: NullifierLeafPreimage | Buffer, index: bigint): Promise<void>;
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Returns the index containing a leaf value.
|
|
171
|
-
* @param treeId - The tree for which the index should be returned.
|
|
172
|
-
* @param value - The value to search for in the tree.
|
|
173
|
-
*/
|
|
174
|
-
findLeafIndex(treeId: MerkleTreeId, value: Buffer): Promise<bigint | undefined>;
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Gets the value for a leaf in the tree.
|
|
178
|
-
* @param treeId - The tree for which the index should be returned.
|
|
179
|
-
* @param index - The index of the leaf.
|
|
180
|
-
*/
|
|
181
|
-
getLeafValue(treeId: MerkleTreeId, index: bigint): Promise<Buffer | undefined>;
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Inserts the new block hash into the new block hashes tree.
|
|
185
|
-
* This includes all of the current roots of all of the data trees and the current blocks global vars.
|
|
186
|
-
* @param globalVariablesHash - The global variables hash to insert into the block hash.
|
|
187
|
-
*/
|
|
188
|
-
updateBlocksTree(globalVariablesHash: Fr): Promise<void>;
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Updates the latest global variables hash
|
|
192
|
-
* @param globalVariablesHash - The latest global variables hash
|
|
193
|
-
*/
|
|
194
|
-
updateLatestGlobalVariablesHash(globalVariablesHash: Fr): Promise<void>;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Gets the global variables hash from the previous block
|
|
198
|
-
*/
|
|
199
|
-
getLatestGlobalVariablesHash(): Promise<Fr>;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Batch insert multiple leaves into the tree.
|
|
203
|
-
* @param leaves - Leaves to insert into the tree.
|
|
204
|
-
* @param treeId - The tree on which to insert.
|
|
205
|
-
* @param subtreeHeight - Height of the subtree.
|
|
206
|
-
* @returns The witness data for the leaves to be updated when inserting the new ones.
|
|
207
|
-
*/
|
|
208
|
-
batchInsert<TreeHeight extends number, SubtreeSiblingPathHeight extends number>(
|
|
209
|
-
treeId: MerkleTreeId,
|
|
210
|
-
leaves: Buffer[],
|
|
211
|
-
subtreeHeight: number,
|
|
212
|
-
): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>>;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Handles a single L2 block (i.e. Inserts the new commitments into the merkle tree).
|
|
216
|
-
* @param block - The L2 block to handle.
|
|
217
|
-
*/
|
|
218
|
-
handleL2Block(block: L2Block): Promise<HandleL2BlockResult>;
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Commits pending changes to the underlying store.
|
|
222
|
-
*/
|
|
223
|
-
commit(): Promise<void>;
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Rolls back pending changes.
|
|
227
|
-
*/
|
|
228
|
-
rollback(): Promise<void>;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/** Return type for handleL2Block */
|
|
232
|
-
export type HandleL2BlockResult = {
|
|
233
|
-
/** Whether the block processed was emitted by our sequencer */ isBlockOurs: boolean;
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Outputs a tree leaves using for debugging purposes.
|
|
238
|
-
*/
|
|
239
|
-
export async function inspectTree(
|
|
240
|
-
db: MerkleTreeOperations,
|
|
241
|
-
treeId: MerkleTreeId,
|
|
242
|
-
log = createDebugLogger('aztec:inspect-tree'),
|
|
243
|
-
) {
|
|
244
|
-
const info = await db.getTreeInfo(treeId);
|
|
245
|
-
const output = [`Tree id=${treeId} size=${info.size} root=0x${info.root.toString('hex')}`];
|
|
246
|
-
for (let i = 0; i < info.size; i++) {
|
|
247
|
-
output.push(
|
|
248
|
-
` Leaf ${i}: ${await db.getLeafValue(treeId, BigInt(i)).then(x => x?.toString('hex') ?? '[undefined]')}`,
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
log(output.join('\n'));
|
|
252
|
-
}
|