mirror of
https://github.com/privacy-scaling-explorations/zk-kit.git
synced 2026-04-22 03:00:15 -04:00
feat(incremental-merkle-tree.sol): return root on insert
This commit is contained in:
@@ -132,7 +132,7 @@ library IncrementalBinaryTree {
|
||||
/// @dev Inserts a leaf in the tree.
|
||||
/// @param self: Tree data.
|
||||
/// @param leaf: Leaf to be inserted.
|
||||
function insert(IncrementalTreeData storage self, uint256 leaf) public {
|
||||
function insert(IncrementalTreeData storage self, uint256 leaf) public returns (uint256) {
|
||||
uint256 depth = self.depth;
|
||||
|
||||
require(leaf < SNARK_SCALAR_FIELD, "IncrementalBinaryTree: leaf must be < SNARK_SCALAR_FIELD");
|
||||
@@ -159,6 +159,7 @@ library IncrementalBinaryTree {
|
||||
|
||||
self.root = hash;
|
||||
self.numberOfLeaves += 1;
|
||||
return hash;
|
||||
}
|
||||
|
||||
/// @dev Updates a leaf in the tree.
|
||||
|
||||
@@ -33,9 +33,11 @@ contract IncrementalBinaryTreeTest {
|
||||
function insertLeaf(bytes32 _treeId, uint256 _leaf) external {
|
||||
require(trees[_treeId].depth != 0, "IncrementalBinaryTreeTest: tree does not exist");
|
||||
|
||||
trees[_treeId].insert(_leaf);
|
||||
uint256 root = trees[_treeId].insert(_leaf);
|
||||
|
||||
emit LeafInserted(_treeId, _leaf, trees[_treeId].root);
|
||||
require(root == trees[_treeId].root, "root mismatch");
|
||||
|
||||
emit LeafInserted(_treeId, _leaf, root);
|
||||
}
|
||||
|
||||
function updateLeaf(
|
||||
|
||||
Reference in New Issue
Block a user