@aztec/world-state 0.1.0-alpha11

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 (45) hide show
  1. package/.eslintrc.cjs +1 -0
  2. package/.tsbuildinfo +1 -0
  3. package/README.md +40 -0
  4. package/dest/index.d.ts +4 -0
  5. package/dest/index.d.ts.map +1 -0
  6. package/dest/index.js +4 -0
  7. package/dest/merkle-tree/merkle_tree_operations_facade.d.ts +117 -0
  8. package/dest/merkle-tree/merkle_tree_operations_facade.d.ts.map +1 -0
  9. package/dest/merkle-tree/merkle_tree_operations_facade.js +133 -0
  10. package/dest/synchroniser/config.d.ts +19 -0
  11. package/dest/synchroniser/config.d.ts.map +1 -0
  12. package/dest/synchroniser/config.js +13 -0
  13. package/dest/synchroniser/index.d.ts +3 -0
  14. package/dest/synchroniser/index.d.ts.map +1 -0
  15. package/dest/synchroniser/index.js +3 -0
  16. package/dest/synchroniser/server_world_state_synchroniser.d.ts +62 -0
  17. package/dest/synchroniser/server_world_state_synchroniser.d.ts.map +1 -0
  18. package/dest/synchroniser/server_world_state_synchroniser.js +134 -0
  19. package/dest/synchroniser/server_world_state_synchroniser.test.d.ts +2 -0
  20. package/dest/synchroniser/server_world_state_synchroniser.test.d.ts.map +1 -0
  21. package/dest/synchroniser/server_world_state_synchroniser.test.js +215 -0
  22. package/dest/synchroniser/world_state_synchroniser.d.ts +34 -0
  23. package/dest/synchroniser/world_state_synchroniser.d.ts.map +1 -0
  24. package/dest/synchroniser/world_state_synchroniser.js +11 -0
  25. package/dest/utils.d.ts +12 -0
  26. package/dest/utils.d.ts.map +1 -0
  27. package/dest/utils.js +14 -0
  28. package/dest/world-state-db/index.d.ts +165 -0
  29. package/dest/world-state-db/index.d.ts.map +1 -0
  30. package/dest/world-state-db/index.js +21 -0
  31. package/dest/world-state-db/merkle_trees.d.ts +200 -0
  32. package/dest/world-state-db/merkle_trees.d.ts.map +1 -0
  33. package/dest/world-state-db/merkle_trees.js +373 -0
  34. package/package.json +15 -0
  35. package/src/index.ts +3 -0
  36. package/src/merkle-tree/merkle_tree_operations_facade.ts +164 -0
  37. package/src/synchroniser/config.ts +27 -0
  38. package/src/synchroniser/index.ts +2 -0
  39. package/src/synchroniser/server_world_state_synchroniser.test.ts +281 -0
  40. package/src/synchroniser/server_world_state_synchroniser.ts +151 -0
  41. package/src/synchroniser/world_state_synchroniser.ts +36 -0
  42. package/src/utils.ts +24 -0
  43. package/src/world-state-db/index.ts +215 -0
  44. package/src/world-state-db/merkle_trees.ts +547 -0
  45. package/tsconfig.json +23 -0
@@ -0,0 +1,165 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { LeafData, SiblingPath, LowLeafWitnessData } from '@aztec/merkle-tree';
3
+ import { L2Block, MerkleTreeId } from '@aztec/types';
4
+ export * from './merkle_trees.js';
5
+ export { LeafData } from '@aztec/merkle-tree';
6
+ /**
7
+ * Type alias for the nullifier tree ID.
8
+ */
9
+ export type IndexedTreeId = MerkleTreeId.NULLIFIER_TREE;
10
+ /**
11
+ * Type alias for the public data tree ID.
12
+ */
13
+ export type PublicTreeId = MerkleTreeId.PUBLIC_DATA_TREE;
14
+ /**
15
+ * The nullifier tree must be pre filled with the number of leaves that are added by one rollup.
16
+ * The tree must be initially padded as the pre-populated 0 index prevents efficient subtree insertion.
17
+ * Padding with some values solves this issue.
18
+ */
19
+ export declare const INITIAL_NULLIFIER_TREE_SIZE: number;
20
+ /**
21
+ * Defines tree information.
22
+ */
23
+ export interface TreeInfo {
24
+ /**
25
+ * The tree ID.
26
+ */
27
+ treeId: MerkleTreeId;
28
+ /**
29
+ * The tree root.
30
+ */
31
+ root: Buffer;
32
+ /**
33
+ * The number of leaves in the tree.
34
+ */
35
+ size: bigint;
36
+ /**
37
+ * The depth of the tree.
38
+ */
39
+ depth: number;
40
+ }
41
+ /**
42
+ * Adds a last boolean flag in each function on the type.
43
+ */
44
+ type WithIncludeUncommitted<F> = F extends (...args: [...infer Rest]) => infer Return ? (...args: [...Rest, boolean]) => Return : F;
45
+ /**
46
+ * The current roots of the commitment trees
47
+ */
48
+ export type CurrentCommitmentTreeRoots = {
49
+ /** Private data tree root. */
50
+ privateDataTreeRoot: Buffer;
51
+ /** Contract data tree root. */
52
+ contractDataTreeRoot: Buffer;
53
+ /** L1 to L2 Messages data tree root. */
54
+ l1Tol2MessagesTreeRoot: Buffer;
55
+ /** Nullifier data tree root. */
56
+ nullifierTreeRoot: Buffer;
57
+ };
58
+ /**
59
+ * Defines the names of the setters on Merkle Trees.
60
+ */
61
+ type MerkleTreeSetters = 'appendLeaves' | 'updateLeaf' | 'commit' | 'rollback' | 'handleL2Block' | 'batchInsert';
62
+ /**
63
+ * Defines the interface for operations on a set of Merkle Trees configuring whether to return committed or uncommitted data.
64
+ */
65
+ export type MerkleTreeDb = {
66
+ [Property in keyof MerkleTreeOperations as Exclude<Property, MerkleTreeSetters>]: WithIncludeUncommitted<MerkleTreeOperations[Property]>;
67
+ } & Pick<MerkleTreeOperations, MerkleTreeSetters>;
68
+ /**
69
+ * Defines the interface for operations on a set of Merkle Trees.
70
+ */
71
+ export interface MerkleTreeOperations {
72
+ /**
73
+ * Appends leaves to a given tree.
74
+ * @param treeId - The tree to be updated.
75
+ * @param leaves - The set of leaves to be appended.
76
+ */
77
+ appendLeaves(treeId: MerkleTreeId, leaves: Buffer[]): Promise<void>;
78
+ /**
79
+ * Returns information about the given tree.
80
+ * @param treeId - The tree to be queried.
81
+ */
82
+ getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo>;
83
+ /**
84
+ * Gets the current roots of the commitment trees.
85
+ */
86
+ getCommitmentTreeRoots(): CurrentCommitmentTreeRoots;
87
+ /**
88
+ * Gets sibling path for a leaf.
89
+ * @param treeId - The tree to be queried for a sibling path.
90
+ * @param index - The index of the leaf for which a sibling path should be returned.
91
+ */
92
+ getSiblingPath(treeId: MerkleTreeId, index: bigint): Promise<SiblingPath<number>>;
93
+ /**
94
+ * Returns the previous index for a given value in an indexed tree.
95
+ * @param treeId - The tree for which the previous value index is required.
96
+ * @param value - The value to be queried.
97
+ */
98
+ getPreviousValueIndex(treeId: IndexedTreeId, value: bigint): Promise<{
99
+ /**
100
+ * The index of the found leaf.
101
+ */
102
+ index: number;
103
+ /**
104
+ * A flag indicating if the corresponding leaf's value is equal to `newValue`.
105
+ */
106
+ alreadyPresent: boolean;
107
+ }>;
108
+ /**
109
+ * Returns the data at a specific leaf.
110
+ * @param treeId - The tree for which leaf data should be returned.
111
+ * @param index - The index of the leaf required.
112
+ */
113
+ getLeafData(treeId: IndexedTreeId, index: number): Promise<LeafData | undefined>;
114
+ /**
115
+ * Update the leaf data at the given index.
116
+ * @param treeId - The tree for which leaf data should be edited.
117
+ * @param leaf - The updated leaf value.
118
+ * @param index - The index of the leaf to be updated.
119
+ */
120
+ updateLeaf(treeId: IndexedTreeId | PublicTreeId, leaf: LeafData | Buffer, index: bigint): Promise<void>;
121
+ /**
122
+ * Returns the index containing a leaf value.
123
+ * @param treeId - The tree for which the index should be returned.
124
+ * @param value - The value to search for in the tree.
125
+ */
126
+ findLeafIndex(treeId: MerkleTreeId, value: Buffer): Promise<bigint | undefined>;
127
+ /**
128
+ * Gets the value for a leaf in the tree.
129
+ * @param treeId - The tree for which the index should be returned.
130
+ * @param index - The index of the leaf.
131
+ */
132
+ getLeafValue(treeId: MerkleTreeId, index: bigint): Promise<Buffer | undefined>;
133
+ /**
134
+ * Inserts into the roots trees (CONTRACT_TREE_ROOTS_TREE, PRIVATE_DATA_TREE_ROOTS_TREE, L1_TO_L2_MESSAGES_TREE_ROOTS_TREE)
135
+ * the current roots of the corresponding trees (CONTRACT_TREE, PRIVATE_DATA_TREE, L1_TO_L2_MESSAGES_TREE).
136
+ */
137
+ updateHistoricRootsTrees(): Promise<void>;
138
+ /**
139
+ * Batch insert multiple leaves into the tree.
140
+ * @param leaves - Leaves to insert into the tree.
141
+ * @param treeId - The tree on which to insert.
142
+ * @param treeHeight - Height of the tree.
143
+ * @param subtreeHeight - Height of the subtree.
144
+ * @returns The witness data for the leaves to be updated when inserting the new ones.
145
+ */
146
+ batchInsert(treeId: MerkleTreeId, leaves: Buffer[], treeHeight: number, subtreeHeight: number): Promise<[LowLeafWitnessData<number>[], SiblingPath<number>] | [undefined, SiblingPath<number>]>;
147
+ /**
148
+ * Handles a single L2 block (i.e. Inserts the new commitments into the merkle tree).
149
+ * @param block - The L2 block to handle.
150
+ */
151
+ handleL2Block(block: L2Block): Promise<void>;
152
+ /**
153
+ * Commits pending changes to the underlying store.
154
+ */
155
+ commit(): Promise<void>;
156
+ /**
157
+ * Rolls back pending changes.
158
+ */
159
+ rollback(): Promise<void>;
160
+ }
161
+ /**
162
+ * Outputs a tree leaves using for debugging purposes.
163
+ */
164
+ export declare function inspectTree(db: MerkleTreeOperations, treeId: MerkleTreeId, log?: import("@aztec/foundation/log").DebugLogger): Promise<void>;
165
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/world-state-db/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAIrD,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC,cAAc,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,YAAY,CAAC,gBAAgB,CAAC;AAEzD;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,QAAmC,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,MAAM,EAAE,YAAY,CAAC;IACrB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,EAA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AI,CAAC,CAAC;IAE7C;;OAEG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAExB;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC/B,EAAE,EAAE,oBAAoB,EACxB,MAAM,EAAE,YAAY,EACpB,GAAG,8CAA0C,iBAU9C"}
@@ -0,0 +1,21 @@
1
+ import { createDebugLogger } from '@aztec/foundation/log';
2
+ import { KERNEL_NEW_NULLIFIERS_LENGTH } from '@aztec/circuits.js';
3
+ export * from './merkle_trees.js';
4
+ /**
5
+ * The nullifier tree must be pre filled with the number of leaves that are added by one rollup.
6
+ * The tree must be initially padded as the pre-populated 0 index prevents efficient subtree insertion.
7
+ * Padding with some values solves this issue.
8
+ */
9
+ export const INITIAL_NULLIFIER_TREE_SIZE = 2 * KERNEL_NEW_NULLIFIERS_LENGTH;
10
+ /**
11
+ * Outputs a tree leaves using for debugging purposes.
12
+ */
13
+ export async function inspectTree(db, treeId, log = createDebugLogger('aztec:inspect-tree')) {
14
+ const info = await db.getTreeInfo(treeId);
15
+ const output = [`Tree id=${treeId} size=${info.size} root=0x${info.root.toString('hex')}`];
16
+ for (let i = 0; i < info.size; i++) {
17
+ output.push(` Leaf ${i}: ${await db.getLeafValue(treeId, BigInt(i)).then(x => x?.toString('hex') ?? '[undefined]')}`);
18
+ }
19
+ log(output.join('\n'));
20
+ }
21
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvd29ybGQtc3RhdGUtZGIvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLGlCQUFpQixFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDMUQsT0FBTyxFQUFFLDRCQUE0QixFQUFFLE1BQU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nessData, SiblingPath } from '@aztec/merkle-tree';
3
+ import { default as levelup } from 'levelup';
4
+ import { CurrentCommitmentTreeRoots, IndexedTreeId, MerkleTreeDb, MerkleTreeOperations, PublicTreeId, TreeInfo } from './index.js';
5
+ import { L2Block, MerkleTreeId } from '@aztec/types';
6
+ import { IWasmModule } from '@aztec/foundation/wasm';
7
+ /**
8
+ * A convenience class for managing multiple merkle trees.
9
+ */
10
+ export declare class MerkleTrees implements MerkleTreeDb {
11
+ private db;
12
+ private log;
13
+ private trees;
14
+ private jobQueue;
15
+ constructor(db: levelup.LevelUp, log?: import("@aztec/foundation/log").DebugLogger);
16
+ /**
17
+ * Initialises the collection of Merkle Trees.
18
+ * @param optionalWasm - WASM instance to use for hashing (if not provided PrimitivesWasm will be used).
19
+ */
20
+ init(optionalWasm?: IWasmModule): Promise<void>;
21
+ /**
22
+ * Method to asynchronously create and initialise a MerkleTrees instance.
23
+ * @param db - The db instance to use for data persistance.
24
+ * @param wasm - WASM instance to use for hashing (if not provided PrimitivesWasm will be used).
25
+ * @returns - A fully initialised MerkleTrees instance.
26
+ */
27
+ static new(db: levelup.LevelUp, wasm?: IWasmModule): Promise<MerkleTrees>;
28
+ /**
29
+ * Stops the job queue (waits for all jobs to finish).
30
+ */
31
+ stop(): Promise<void>;
32
+ /**
33
+ * Gets a view of this db that returns uncommitted data.
34
+ * @returns - A facade for this instance.
35
+ */
36
+ asLatest(): MerkleTreeOperations;
37
+ /**
38
+ * Gets a view of this db that returns committed data only.
39
+ * @returns - A facade for this instance.
40
+ */
41
+ asCommitted(): MerkleTreeOperations;
42
+ /**
43
+ * Inserts into the roots trees (CONTRACT_TREE_ROOTS_TREE, PRIVATE_DATA_TREE_ROOTS_TREE, L1_TO_L2_MESSAGES_TREE_ROOTS_TREE)
44
+ * the current roots of the corresponding trees (CONTRACT_TREE, PRIVATE_DATA_TREE, L1_TO_L2_MESSAGES_TREE).
45
+ * @param includeUncommitted - Indicates whether to include uncommitted data.
46
+ */
47
+ updateHistoricRootsTrees(includeUncommitted: boolean): Promise<void>;
48
+ /**
49
+ * Gets the tree info for the specified tree.
50
+ * @param treeId - Id of the tree to get information from.
51
+ * @param includeUncommitted - Indicates whether to include uncommitted data.
52
+ * @returns The tree info for the specified tree.
53
+ */
54
+ getTreeInfo(treeId: MerkleTreeId, includeUncommitted: boolean): Promise<TreeInfo>;
55
+ /**
56
+ * Get the current roots of the commitment trees.
57
+ * @param includeUncommitted - Indicates whether to include uncommitted data.
58
+ * @returns The current roots of the trees.
59
+ */
60
+ getCommitmentTreeRoots(includeUncommitted: boolean): CurrentCommitmentTreeRoots;
61
+ /**
62
+ * Gets the value at the given index.
63
+ * @param treeId - The ID of the tree to get the leaf value from.
64
+ * @param index - The index of the leaf.
65
+ * @param includeUncommitted - Indicates whether to include uncommitted changes.
66
+ * @returns Leaf value at the given index (undefined if not found).
67
+ */
68
+ getLeafValue(treeId: MerkleTreeId, index: bigint, includeUncommitted: boolean): Promise<Buffer | undefined>;
69
+ /**
70
+ * Gets the sibling path for a leaf in a tree.
71
+ * @param treeId - The ID of the tree.
72
+ * @param index - The index of the leaf.
73
+ * @param includeUncommitted - Indicates whether the sibling path should incro include uncommitted data.
74
+ * @returns The sibling path for the leaf.
75
+ */
76
+ getSiblingPath<N extends number>(treeId: MerkleTreeId, index: bigint, includeUncommitted: boolean): Promise<SiblingPath<N>>;
77
+ /**
78
+ * Appends leaves to a tree.
79
+ * @param treeId - The ID of the tree.
80
+ * @param leaves - The leaves to append.
81
+ * @returns Empty promise.
82
+ */
83
+ appendLeaves(treeId: MerkleTreeId, leaves: Buffer[]): Promise<void>;
84
+ /**
85
+ * Commits all pending updates.
86
+ * @returns Empty promise.
87
+ */
88
+ commit(): Promise<void>;
89
+ /**
90
+ * Rolls back all pending updates.
91
+ * @returns Empty promise.
92
+ */
93
+ rollback(): Promise<void>;
94
+ /**
95
+ * Finds the index of the largest leaf whose value is less than or equal to the provided value.
96
+ * @param treeId - The ID of the tree to search.
97
+ * @param value - The value to be inserted into the tree.
98
+ * @param includeUncommitted - If true, the uncommitted changes are included in the search.
99
+ * @returns The found leaf index and a flag indicating if the corresponding leaf's value is equal to `newValue`.
100
+ */
101
+ getPreviousValueIndex(treeId: IndexedTreeId, value: bigint, includeUncommitted: boolean): Promise<{
102
+ /**
103
+ * The index of the found leaf.
104
+ */
105
+ index: number;
106
+ /**
107
+ * A flag indicating if the corresponding leaf's value is equal to `newValue`.
108
+ */
109
+ alreadyPresent: boolean;
110
+ }>;
111
+ /**
112
+ * Gets the leaf data at a given index and tree.
113
+ * @param treeId - The ID of the tree get the leaf from.
114
+ * @param index - The index of the leaf to get.
115
+ * @param includeUncommitted - Indicates whether to include uncommitted data.
116
+ * @returns Leaf data.
117
+ */
118
+ getLeafData(treeId: IndexedTreeId, index: number, includeUncommitted: boolean): Promise<LeafData | undefined>;
119
+ /**
120
+ * Returns the index of a leaf given its value, or undefined if no leaf with that value is found.
121
+ * @param treeId - The ID of the tree.
122
+ * @param value - The leaf value to look for.
123
+ * @param includeUncommitted - Indicates whether to include uncommitted data.
124
+ * @returns The index of the first leaf found with a given value (undefined if not found).
125
+ */
126
+ findLeafIndex(treeId: MerkleTreeId, value: Buffer, includeUncommitted: boolean): Promise<bigint | undefined>;
127
+ /**
128
+ * Updates a leaf in a tree at a given index.
129
+ * @param treeId - The ID of the tree.
130
+ * @param leaf - The new leaf value.
131
+ * @param index - The index to insert into.
132
+ * @returns Empty promise.
133
+ */
134
+ updateLeaf(treeId: IndexedTreeId | PublicTreeId, leaf: LeafData | Buffer, index: bigint): Promise<void>;
135
+ /**
136
+ * Handles a single L2 block (i.e. Inserts the new commitments into the merkle tree).
137
+ * @param block - The L2 block to handle.
138
+ */
139
+ handleL2Block(block: L2Block): Promise<void>;
140
+ /**
141
+ * Batch insert multiple leaves into the tree.
142
+ * @param treeId - The ID of the tree.
143
+ * @param leaves - Leaves to insert into the tree.
144
+ * @param treeHeight - Height of the tree.
145
+ * @param subtreeHeight - Height of the subtree.
146
+ * @returns The data for the leaves to be updated when inserting the new ones.
147
+ */
148
+ batchInsert<TreeHeight extends number, SubtreeHeight extends number, SubtreeSiblingPathHeight extends number>(treeId: MerkleTreeId, leaves: Buffer[], treeHeight: TreeHeight, subtreeHeight: SubtreeHeight): Promise<[LowLeafWitnessData<TreeHeight>[], SiblingPath<SubtreeSiblingPathHeight>] | [undefined, SiblingPath<SubtreeSiblingPathHeight>]>;
149
+ /**
150
+ * Waits for all jobs to finish before executing the given function.
151
+ * @param fn - The function to execute.
152
+ * @returns Promise containing the result of the function.
153
+ */
154
+ private synchronise;
155
+ /**
156
+ * Returns the tree info for the specified tree id.
157
+ * @param treeId - Id of the tree to get information from.
158
+ * @param includeUncommitted - Indicates whether to include uncommitted data.
159
+ * @returns The tree info for the specified tree.
160
+ */
161
+ private _getTreeInfo;
162
+ /**
163
+ * Returns an instance of an indexed tree.
164
+ * @param treeId - Id of the tree to get an instance of.
165
+ * @returns The indexed tree for the specified tree id.
166
+ */
167
+ private _getIndexedTree;
168
+ /**
169
+ * Returns the sibling path for a leaf in a tree.
170
+ * @param treeId - Id of the tree to get the sibling path from.
171
+ * @param index - Index of the leaf to get the sibling path for.
172
+ * @param includeUncommitted - Indicates whether to include uncommitted updates in the sibling path.
173
+ * @returns Promise containing the sibling path for the leaf.
174
+ */
175
+ private _getSiblingPath;
176
+ /**
177
+ * Appends leaves to a tree.
178
+ * @param treeId - Id of the tree to append leaves to.
179
+ * @param leaves - Leaves to append.
180
+ * @returns Empty promise.
181
+ */
182
+ private _appendLeaves;
183
+ private _updateLeaf;
184
+ /**
185
+ * Commits all pending updates.
186
+ * @returns Empty promise.
187
+ */
188
+ private _commit;
189
+ /**
190
+ * Rolls back all pending updates.
191
+ * @returns Empty promise.
192
+ */
193
+ private _rollback;
194
+ /**
195
+ * Handles a single L2 block (i.e. Inserts the new commitments into the merkle tree).
196
+ * @param l2Block - The L2 block to handle.
197
+ */
198
+ private _handleL2Block;
199
+ }
200
+ //# sourceMappingURL=merkle_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