@aztec/merkle-tree 0.16.1 → 0.16.3
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/index.d.ts +5 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +6 -2
- package/dest/interfaces/append_only_tree.d.ts +2 -1
- package/dest/interfaces/append_only_tree.d.ts.map +1 -1
- package/dest/interfaces/indexed_tree.d.ts +38 -17
- package/dest/interfaces/indexed_tree.d.ts.map +1 -1
- package/dest/interfaces/merkle_tree.d.ts +7 -0
- package/dest/interfaces/merkle_tree.d.ts.map +1 -1
- package/dest/interfaces/update_only_tree.d.ts +3 -3
- package/dest/interfaces/update_only_tree.d.ts.map +1 -1
- package/dest/load_tree.d.ts +2 -1
- package/dest/load_tree.d.ts.map +1 -1
- package/dest/load_tree.js +1 -2
- package/dest/new_tree.d.ts +1 -1
- package/dest/new_tree.d.ts.map +1 -1
- package/dest/new_tree.js +2 -2
- package/dest/snapshots/append_only_snapshot.d.ts +30 -0
- package/dest/snapshots/append_only_snapshot.d.ts.map +1 -0
- package/dest/snapshots/append_only_snapshot.js +200 -0
- package/dest/snapshots/base_full_snapshot.d.ts +50 -0
- package/dest/snapshots/base_full_snapshot.d.ts.map +1 -0
- package/dest/snapshots/base_full_snapshot.js +179 -0
- package/dest/snapshots/full_snapshot.d.ts +22 -0
- package/dest/snapshots/full_snapshot.d.ts.map +1 -0
- package/dest/snapshots/full_snapshot.js +21 -0
- package/dest/snapshots/indexed_tree_snapshot.d.ts +15 -0
- package/dest/snapshots/indexed_tree_snapshot.d.ts.map +1 -0
- package/dest/snapshots/indexed_tree_snapshot.js +75 -0
- package/dest/snapshots/snapshot_builder.d.ts +76 -0
- package/dest/snapshots/snapshot_builder.d.ts.map +1 -0
- package/dest/snapshots/snapshot_builder.js +2 -0
- package/dest/snapshots/snapshot_builder_test_suite.d.ts +5 -0
- package/dest/snapshots/snapshot_builder_test_suite.d.ts.map +1 -0
- package/dest/snapshots/snapshot_builder_test_suite.js +163 -0
- package/dest/sparse_tree/sparse_tree.d.ts +5 -0
- package/dest/sparse_tree/sparse_tree.d.ts.map +1 -1
- package/dest/sparse_tree/sparse_tree.js +18 -1
- package/dest/standard_indexed_tree/standard_indexed_tree.d.ts +111 -81
- package/dest/standard_indexed_tree/standard_indexed_tree.d.ts.map +1 -1
- package/dest/standard_indexed_tree/standard_indexed_tree.js +225 -259
- package/dest/standard_indexed_tree/test/standard_indexed_tree_with_append.d.ts.map +1 -1
- package/dest/standard_indexed_tree/test/standard_indexed_tree_with_append.js +13 -19
- package/dest/standard_tree/standard_tree.d.ts +5 -0
- package/dest/standard_tree/standard_tree.d.ts.map +1 -1
- package/dest/standard_tree/standard_tree.js +24 -1
- package/dest/tree_base.d.ts +9 -4
- package/dest/tree_base.d.ts.map +1 -1
- package/dest/tree_base.js +16 -7
- package/package.json +4 -3
- package/src/index.ts +5 -1
- package/src/interfaces/append_only_tree.ts +2 -1
- package/src/interfaces/indexed_tree.ts +50 -28
- package/src/interfaces/merkle_tree.ts +8 -0
- package/src/interfaces/update_only_tree.ts +3 -4
- package/src/load_tree.ts +2 -2
- package/src/new_tree.ts +2 -2
- package/src/snapshots/append_only_snapshot.ts +243 -0
- package/src/snapshots/base_full_snapshot.ts +232 -0
- package/src/snapshots/full_snapshot.ts +26 -0
- package/src/snapshots/indexed_tree_snapshot.ts +108 -0
- package/src/snapshots/snapshot_builder.ts +84 -0
- package/src/snapshots/snapshot_builder_test_suite.ts +218 -0
- package/src/sparse_tree/sparse_tree.ts +16 -0
- package/src/standard_indexed_tree/standard_indexed_tree.ts +325 -304
- package/src/standard_indexed_tree/test/standard_indexed_tree_with_append.ts +23 -21
- package/src/standard_tree/standard_tree.ts +21 -0
- package/src/tree_base.ts +28 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sparse_tree.d.ts","sourceRoot":"","sources":["../../src/sparse_tree/sparse_tree.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"sparse_tree.d.ts","sourceRoot":"","sources":["../../src/sparse_tree/sparse_tree.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAgB,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEzD;;GAEG;AACH,qBAAa,UAAW,SAAQ,QAAS,YAAW,cAAc;;IAGhE;;;;OAIG;IACU,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB5D,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAI9C,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAIjD,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CAGhG"}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
var _SparseTree_snapshotBuilder;
|
|
2
|
+
import { __classPrivateFieldGet } from "tslib";
|
|
3
|
+
import { FullTreeSnapshotBuilder } from '../snapshots/full_snapshot.js';
|
|
1
4
|
import { INITIAL_LEAF, TreeBase } from '../tree_base.js';
|
|
2
5
|
/**
|
|
3
6
|
* A Merkle tree implementation that uses a LevelDB database to store the tree.
|
|
4
7
|
*/
|
|
5
8
|
export class SparseTree extends TreeBase {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
_SparseTree_snapshotBuilder.set(this, new FullTreeSnapshotBuilder(this.db, this));
|
|
12
|
+
}
|
|
6
13
|
/**
|
|
7
14
|
* Updates a leaf in the tree.
|
|
8
15
|
* @param leaf - New contents of the leaf.
|
|
@@ -27,5 +34,15 @@ export class SparseTree extends TreeBase {
|
|
|
27
34
|
this.cachedSize = (this.cachedSize ?? this.size) + 1n;
|
|
28
35
|
}
|
|
29
36
|
}
|
|
37
|
+
snapshot(block) {
|
|
38
|
+
return __classPrivateFieldGet(this, _SparseTree_snapshotBuilder, "f").snapshot(block);
|
|
39
|
+
}
|
|
40
|
+
getSnapshot(block) {
|
|
41
|
+
return __classPrivateFieldGet(this, _SparseTree_snapshotBuilder, "f").getSnapshot(block);
|
|
42
|
+
}
|
|
43
|
+
findLeafIndex(_value, _includeUncommitted) {
|
|
44
|
+
throw new Error('Finding leaf index is not supported for sparse trees');
|
|
45
|
+
}
|
|
30
46
|
}
|
|
31
|
-
|
|
47
|
+
_SparseTree_snapshotBuilder = new WeakMap();
|
|
48
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3BhcnNlX3RyZWUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3BhcnNlX3RyZWUvc3BhcnNlX3RyZWUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFDQSxPQUFPLEVBQUUsdUJBQXVCLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUV4RSxPQUFPLEVBQUUsWUFBWSxFQUFFLFFBQVEsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBRXpEOztHQUVHO0FBQ0gsTUFBTSxPQUFPLFVBQVcsU0FBUSxRQUFRO0lBQXhDOztRQUNFLHNDQUFtQixJQUFJLHVCQUF1QixDQUFDLElBQUksQ0FBQyxFQUFFLEVBQUUsSUFBSSxDQUFDLEVBQUM7SUFzQ2hFLENBQUM7SUFwQ0M7Ozs7T0FJRztJQUNJLEtBQUssQ0FBQyxVQUFVLENBQUMsSUFBWSxFQUFFLEtBQWE7UUFDakQsSUFBSSxLQUFLLEdBQUcsSUFBSSxDQUFDLFFBQVEsRUFBRTtZQUN6QixNQUFNLEtBQUssQ0FB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BYSxDQUFDLE1BQWMsRUFBRSxtQkFBNEI7UUFDL0QsTUFBTSxJQUFJLEtBQUssQ0FBQyxzREFBc0QsQ0FBQyxDQUFDO0lBQzFFLENBQUM7Q0FDRiJ9
|
|
@@ -1,32 +1,63 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { IndexedTreeLeaf, IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
|
|
3
|
+
import { Hasher, SiblingPath } from '@aztec/types';
|
|
4
|
+
import { LevelUp } from 'levelup';
|
|
5
|
+
import { BatchInsertionResult, IndexedTree, IndexedTreeSnapshot } from '../index.js';
|
|
4
6
|
import { TreeBase } from '../tree_base.js';
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
8
|
+
* Factory for creating leaf preimages.
|
|
7
9
|
*/
|
|
8
|
-
export interface
|
|
10
|
+
export interface PreimageFactory {
|
|
9
11
|
/**
|
|
10
|
-
*
|
|
12
|
+
* Creates a new preimage from a leaf.
|
|
13
|
+
* @param leaf - Leaf to create a preimage from.
|
|
14
|
+
* @param nextKey - Next key of the leaf.
|
|
15
|
+
* @param nextIndex - Next index of the leaf.
|
|
11
16
|
*/
|
|
12
|
-
|
|
17
|
+
fromLeaf(leaf: IndexedTreeLeaf, nextKey: bigint, nextIndex: bigint): IndexedTreeLeafPreimage;
|
|
13
18
|
/**
|
|
14
|
-
*
|
|
19
|
+
* Creates a new preimage from a buffer.
|
|
20
|
+
* @param buffer - Buffer to create a preimage from.
|
|
15
21
|
*/
|
|
16
|
-
|
|
22
|
+
fromBuffer(buffer: Buffer): IndexedTreeLeafPreimage;
|
|
17
23
|
/**
|
|
18
|
-
*
|
|
24
|
+
* Creates an empty preimage.
|
|
19
25
|
*/
|
|
20
|
-
|
|
26
|
+
empty(): IndexedTreeLeafPreimage;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a copy of a preimage.
|
|
29
|
+
* @param preimage - Preimage to be cloned.
|
|
30
|
+
*/
|
|
31
|
+
clone(preimage: IndexedTreeLeafPreimage): IndexedTreeLeafPreimage;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Factory for creating leaves.
|
|
35
|
+
*/
|
|
36
|
+
export interface LeafFactory {
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new leaf from a buffer.
|
|
39
|
+
* @param key - Key of the leaf.
|
|
40
|
+
*/
|
|
41
|
+
buildDummy(key: bigint): IndexedTreeLeaf;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new leaf from a buffer.
|
|
44
|
+
* @param buffer - Buffer to create a leaf from.
|
|
45
|
+
*/
|
|
46
|
+
fromBuffer(buffer: Buffer): IndexedTreeLeaf;
|
|
21
47
|
}
|
|
48
|
+
export declare const buildDbKeyForPreimage: (name: string, index: bigint) => string;
|
|
49
|
+
export declare const buildDbKeyForLeafIndex: (name: string, key: bigint) => string;
|
|
22
50
|
/**
|
|
23
|
-
*
|
|
51
|
+
* Standard implementation of an indexed tree.
|
|
24
52
|
*/
|
|
25
53
|
export declare class StandardIndexedTree extends TreeBase implements IndexedTree {
|
|
26
|
-
|
|
27
|
-
protected
|
|
28
|
-
|
|
54
|
+
#private;
|
|
55
|
+
protected leafPreimageFactory: PreimageFactory;
|
|
56
|
+
protected leafFactory: LeafFactory;
|
|
57
|
+
protected cachedLeafPreimages: {
|
|
58
|
+
[key: string]: IndexedTreeLeafPreimage;
|
|
29
59
|
};
|
|
60
|
+
constructor(db: LevelUp, hasher: Hasher, name: string, depth: number, size: bigint | undefined, leafPreimageFactory: PreimageFactory, leafFactory: LeafFactory, root?: Buffer);
|
|
30
61
|
/**
|
|
31
62
|
* Appends the given leaves to the tree.
|
|
32
63
|
* @param _leaves - The leaves to append.
|
|
@@ -53,33 +84,39 @@ export declare class StandardIndexedTree extends TreeBase implements IndexedTree
|
|
|
53
84
|
getLeafValue(index: bigint, includeUncommitted: boolean): Promise<Buffer | undefined>;
|
|
54
85
|
/**
|
|
55
86
|
* Finds the index of the largest leaf whose value is less than or equal to the provided value.
|
|
56
|
-
* @param
|
|
87
|
+
* @param newKey - The new key to be inserted into the tree.
|
|
57
88
|
* @param includeUncommitted - If true, the uncommitted changes are included in the search.
|
|
58
89
|
* @returns The found leaf index and a flag indicating if the corresponding leaf's value is equal to `newValue`.
|
|
59
90
|
*/
|
|
60
|
-
|
|
91
|
+
findIndexOfPreviousKey(newKey: bigint, includeUncommitted: boolean): Promise<{
|
|
61
92
|
/**
|
|
62
93
|
* The index of the found leaf.
|
|
63
94
|
*/
|
|
64
|
-
index:
|
|
95
|
+
index: bigint;
|
|
65
96
|
/**
|
|
66
97
|
* A flag indicating if the corresponding leaf's value is equal to `newValue`.
|
|
67
98
|
*/
|
|
68
99
|
alreadyPresent: boolean;
|
|
69
|
-
}
|
|
100
|
+
} | undefined>;
|
|
101
|
+
private getCachedLowLeafIndex;
|
|
102
|
+
private getCachedLeafIndex;
|
|
103
|
+
private getDbLowLeafIndex;
|
|
104
|
+
private getDbPreimage;
|
|
105
|
+
private getCachedPreimage;
|
|
70
106
|
/**
|
|
71
|
-
* Gets the latest
|
|
72
|
-
* @param index - Index of the leaf of which to obtain the
|
|
107
|
+
* Gets the latest LeafPreimage copy.
|
|
108
|
+
* @param index - Index of the leaf of which to obtain the LeafPreimage copy.
|
|
73
109
|
* @param includeUncommitted - If true, the uncommitted changes are included in the search.
|
|
74
|
-
* @returns A copy of the leaf
|
|
110
|
+
* @returns A copy of the leaf preimage at the given index or undefined if the leaf was not found.
|
|
75
111
|
*/
|
|
76
|
-
|
|
112
|
+
getLatestLeafPreimageCopy(index: bigint, includeUncommitted: boolean): Promise<IndexedTreeLeafPreimage | undefined>;
|
|
77
113
|
/**
|
|
78
|
-
*
|
|
79
|
-
* @param
|
|
80
|
-
* @
|
|
114
|
+
* Returns the index of a leaf given its value, or undefined if no leaf with that value is found.
|
|
115
|
+
* @param value - The leaf value to look for.
|
|
116
|
+
* @param includeUncommitted - Indicates whether to include uncommitted data.
|
|
117
|
+
* @returns The index of the first leaf found with a given value (undefined if not found).
|
|
81
118
|
*/
|
|
82
|
-
|
|
119
|
+
findLeafIndex(value: Buffer, includeUncommitted: boolean): Promise<bigint | undefined>;
|
|
83
120
|
/**
|
|
84
121
|
* Initializes the tree.
|
|
85
122
|
* @param prefilledSize - A number of leaves that are prefilled with values.
|
|
@@ -95,10 +132,6 @@ export declare class StandardIndexedTree extends TreeBase implements IndexedTree
|
|
|
95
132
|
* more leaves, we can then insert the first block of 1024 leaves into indices 1024:2047.
|
|
96
133
|
*/
|
|
97
134
|
init(prefilledSize: number): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Loads Merkle tree data from a database and assigns them to this object.
|
|
100
|
-
*/
|
|
101
|
-
initFromDb(): Promise<void>;
|
|
102
135
|
/**
|
|
103
136
|
* Commits all the leaves to the database and removes them from a cache.
|
|
104
137
|
*/
|
|
@@ -109,10 +142,10 @@ export declare class StandardIndexedTree extends TreeBase implements IndexedTree
|
|
|
109
142
|
private clearCachedLeaves;
|
|
110
143
|
/**
|
|
111
144
|
* Updates a leaf in the tree.
|
|
112
|
-
* @param
|
|
145
|
+
* @param preimage - New contents of the leaf.
|
|
113
146
|
* @param index - Index of the leaf to be updated.
|
|
114
147
|
*/
|
|
115
|
-
protected updateLeaf(
|
|
148
|
+
protected updateLeaf(preimage: IndexedTreeLeafPreimage, index: bigint): Promise<void>;
|
|
116
149
|
/**
|
|
117
150
|
*
|
|
118
151
|
* Each base rollup needs to provide non membership / inclusion proofs for each of the nullifier.
|
|
@@ -121,8 +154,6 @@ export declare class StandardIndexedTree extends TreeBase implements IndexedTree
|
|
|
121
154
|
*
|
|
122
155
|
* This offers massive circuit performance savings over doing incremental insertions.
|
|
123
156
|
*
|
|
124
|
-
* A description of the algorithm can be found here: https://colab.research.google.com/drive/1A0gizduSi4FIiIJZ8OylwIpO9-OTqV-R
|
|
125
|
-
*
|
|
126
157
|
* WARNING: This function has side effects, it will insert values into the tree.
|
|
127
158
|
*
|
|
128
159
|
* Assumptions:
|
|
@@ -142,92 +173,91 @@ export declare class StandardIndexedTree extends TreeBase implements IndexedTree
|
|
|
142
173
|
* roots.
|
|
143
174
|
*
|
|
144
175
|
* This become tricky when two items that are being batch inserted need to update the same low nullifier, or need to use
|
|
145
|
-
* a value that is part of the same batch insertion as their low nullifier.
|
|
146
|
-
*
|
|
176
|
+
* a value that is part of the same batch insertion as their low nullifier. What we do to avoid this case is to
|
|
177
|
+
* update the existing leaves in the tree with the nullifiers in high to low order, ensuring that this case never occurs.
|
|
178
|
+
* The circuit has to sort the nullifiers (or take a hint of the sorted nullifiers and prove that it's a valid permutation).
|
|
179
|
+
* Then we just batch insert the new nullifiers in the original order.
|
|
147
180
|
*
|
|
148
181
|
* The following example will illustrate attempting to insert 2,3,20,19 into a tree already containing 0,5,10,15
|
|
149
182
|
*
|
|
150
183
|
* The example will explore two cases. In each case the values low nullifier will exist within the batch insertion,
|
|
151
184
|
* One where the low nullifier comes before the item in the set (2,3), and one where it comes after (20,19).
|
|
152
185
|
*
|
|
186
|
+
* First, we sort the nullifiers high to low, that's 20,19,3,2
|
|
187
|
+
*
|
|
153
188
|
* The original tree: Pending insertion subtree
|
|
154
189
|
*
|
|
155
|
-
* index 0 2 3
|
|
190
|
+
* index 0 1 2 3 - - - -
|
|
156
191
|
* ------------------------------------- ----------------------------
|
|
157
192
|
* val 0 5 10 15 - - - -
|
|
158
193
|
* nextIdx 1 2 3 0 - - - -
|
|
159
194
|
* nextVal 5 10 15 0 - - - -
|
|
160
195
|
*
|
|
161
196
|
*
|
|
162
|
-
* Inserting
|
|
163
|
-
* 1. Find the low nullifier (
|
|
197
|
+
* Inserting 20:
|
|
198
|
+
* 1. Find the low nullifier (3) - provide inclusion proof
|
|
164
199
|
* 2. Update its pointers
|
|
165
|
-
* 3. Insert
|
|
200
|
+
* 3. Insert 20 into the pending subtree
|
|
166
201
|
*
|
|
167
|
-
* index 0 2 3
|
|
202
|
+
* index 0 1 2 3 - - 6 -
|
|
168
203
|
* ------------------------------------- ----------------------------
|
|
169
|
-
* val 0 5 10 15
|
|
170
|
-
* nextIdx
|
|
171
|
-
* nextVal
|
|
172
|
-
*
|
|
173
|
-
* Inserting
|
|
174
|
-
* 1.
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* We do not provide a non inclusion proof to out circuit, but prompt it to look within the insertion subtree.
|
|
180
|
-
* 2. Update pending insertion subtree
|
|
181
|
-
* 3. Insert 3 into pending subtree
|
|
182
|
-
*
|
|
183
|
-
* (no inclusion proof provided)
|
|
184
|
-
* index 0 2 3 4 5 6 - -
|
|
204
|
+
* val 0 5 10 15 - - 20 -
|
|
205
|
+
* nextIdx 1 2 3 6 - - 0 -
|
|
206
|
+
* nextVal 5 10 15 20 - - 0 -
|
|
207
|
+
*
|
|
208
|
+
* Inserting 19:
|
|
209
|
+
* 1. Find the low nullifier (3) - provide inclusion proof
|
|
210
|
+
* 2. Update its pointers
|
|
211
|
+
* 3. Insert 19 into the pending subtree
|
|
212
|
+
*
|
|
213
|
+
* index 0 1 2 3 - - 6 7
|
|
185
214
|
* ------------------------------------- ----------------------------
|
|
186
|
-
* val 0 5 10 15
|
|
187
|
-
* nextIdx
|
|
188
|
-
* nextVal
|
|
215
|
+
* val 0 5 10 15 - - 20 19
|
|
216
|
+
* nextIdx 1 2 3 7 - - 0 6
|
|
217
|
+
* nextVal 5 10 15 19 - - 0 20
|
|
189
218
|
*
|
|
190
|
-
* Inserting
|
|
191
|
-
* 1. Find the low nullifier (
|
|
219
|
+
* Inserting 3:
|
|
220
|
+
* 1. Find the low nullifier (0) - provide inclusion proof
|
|
192
221
|
* 2. Update its pointers
|
|
193
|
-
* 3. Insert
|
|
222
|
+
* 3. Insert 3 into the pending subtree
|
|
194
223
|
*
|
|
195
|
-
* index 0 2 3
|
|
224
|
+
* index 0 1 2 3 - 5 6 7
|
|
196
225
|
* ------------------------------------- ----------------------------
|
|
197
|
-
* val 0 5 10 15
|
|
198
|
-
* nextIdx 5 2 3 7
|
|
199
|
-
* nextVal
|
|
226
|
+
* val 0 5 10 15 - 3 20 19
|
|
227
|
+
* nextIdx 5 2 3 7 - 1 0 6
|
|
228
|
+
* nextVal 3 10 15 19 - 5 0 20
|
|
200
229
|
*
|
|
201
|
-
* Inserting
|
|
202
|
-
* 1.
|
|
203
|
-
* We can provide an inclusion proof of this intermediate tree state.
|
|
230
|
+
* Inserting 2:
|
|
231
|
+
* 1. Find the low nullifier (0) - provide inclusion proof
|
|
204
232
|
* 2. Update its pointers
|
|
205
|
-
* 3. Insert
|
|
233
|
+
* 3. Insert 2 into the pending subtree
|
|
206
234
|
*
|
|
207
|
-
* index 0 2 3
|
|
235
|
+
* index 0 1 2 3 4 5 6 7
|
|
208
236
|
* ------------------------------------- ----------------------------
|
|
209
|
-
* val 0 5 10 15 2 3 20
|
|
210
|
-
* nextIdx
|
|
211
|
-
* nextVal 2 10 15 19 3 5 0
|
|
237
|
+
* val 0 5 10 15 2 3 20 19
|
|
238
|
+
* nextIdx 4 2 3 7 5 1 0 6
|
|
239
|
+
* nextVal 2 10 15 19 3 5 0 20
|
|
212
240
|
*
|
|
213
241
|
* Perform subtree insertion
|
|
214
242
|
*
|
|
215
|
-
* index 0 2 3 4 5 6 7
|
|
243
|
+
* index 0 1 2 3 4 5 6 7
|
|
216
244
|
* ---------------------------------------------------------------------
|
|
217
|
-
* val 0 5 10 15 2 3 20
|
|
218
|
-
* nextIdx
|
|
219
|
-
* nextVal 2 10 15 19 3 5 0
|
|
245
|
+
* val 0 5 10 15 2 3 20 19
|
|
246
|
+
* nextIdx 4 2 3 7 5 1 0 6
|
|
247
|
+
* nextVal 2 10 15 19 3 5 0 20
|
|
220
248
|
*
|
|
221
249
|
* TODO: this implementation will change once the zero value is changed from h(0,0,0). Changes incoming over the next sprint
|
|
222
250
|
* @param leaves - Values to insert into the tree.
|
|
223
251
|
* @param subtreeHeight - Height of the subtree.
|
|
224
252
|
* @returns The data for the leaves to be updated when inserting the new ones.
|
|
225
253
|
*/
|
|
226
|
-
batchInsert<TreeHeight extends number, SubtreeHeight extends number, SubtreeSiblingPathHeight extends number>(leaves: Buffer[], subtreeHeight: SubtreeHeight): Promise<
|
|
254
|
+
batchInsert<TreeHeight extends number, SubtreeHeight extends number, SubtreeSiblingPathHeight extends number>(leaves: Buffer[], subtreeHeight: SubtreeHeight): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>>;
|
|
227
255
|
getSubtreeSiblingPath<SubtreeHeight extends number, SubtreeSiblingPathHeight extends number>(subtreeHeight: SubtreeHeight, includeUncommitted: boolean): Promise<SiblingPath<SubtreeSiblingPathHeight>>;
|
|
256
|
+
snapshot(blockNumber: number): Promise<IndexedTreeSnapshot>;
|
|
257
|
+
getSnapshot(block: number): Promise<IndexedTreeSnapshot>;
|
|
228
258
|
/**
|
|
229
259
|
* Encodes leaves and appends them to a tree.
|
|
230
|
-
* @param
|
|
260
|
+
* @param preimages - Leaves to encode.
|
|
231
261
|
* @param hash0Leaf - Indicates whether 0 value leaf should be hashed. See {@link encodeLeaf}.
|
|
232
262
|
* @returns Empty promise
|
|
233
263
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard_indexed_tree.d.ts","sourceRoot":"","sources":["../../src/standard_indexed_tree/standard_indexed_tree.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"standard_indexed_tree.d.ts","sourceRoot":"","sources":["../../src/standard_indexed_tree/standard_indexed_tree.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,mBAAmB,EAGpB,MAAM,aAAa,CAA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