You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/utilities.adoc
+27-2Lines changed: 27 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -157,10 +157,10 @@ Building an on-chain Merkle Tree allow developers to keep track of the history o
157
157
158
158
The Merkle Tree does not keep track of the roots purposely, so that developers can choose their tracking mechanism. Setting up and using an Merkle Tree in Solidity is as simple as follows:
159
159
160
+
NOTE: Functions are exposed without access control for demonstration purposes
161
+
160
162
[source,solidity]
161
163
----
162
-
// NOTE: Functions are exposed without access control for demonstration purposes
163
-
164
164
using MerkleTree for MerkleTree.Bytes32PushTree;
165
165
MerkleTree.Bytes32PushTree private _tree;
166
166
@@ -174,6 +174,31 @@ function push(bytes32 leaf) public /* onlyOwner */ {
174
174
}
175
175
----
176
176
177
+
The library also supports custom hashing functions, which can be passed as an extra parameter to the xref:api:utils.adoc#MerkleTree-push-struct-MerkleTree-Bytes32PushTree-bytes32-[`push`] and xref:api:utils.adoc#MerkleTree-setup-struct-MerkleTree-Bytes32PushTree-uint8-bytes32-[`setup`] functions.
178
+
179
+
Using custom hashing functions is a sensitive operation. After setup, it requires to keep using the same hashing function for every new valued pushed to the tree to avoid corrupting the tree. For this reason, it's a good practice to keep your hashing function static in your implementation contract as follows:
180
+
181
+
[source,solidity]
182
+
----
183
+
using MerkleTree for MerkleTree.Bytes32PushTree;
184
+
MerkleTree.Bytes32PushTree private _tree;
185
+
186
+
function setup(uint8 _depth, bytes32 _zero) public /* onlyOwner */ {
187
+
root = _tree.setup(_depth, _zero, _hashFn);
188
+
}
189
+
190
+
function push(bytes32 leaf) public /* onlyOwner */ {
0 commit comments