Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
6b079ee
Add a (complete) MerkleTree structure
Amxx Aug 14, 2022
42c695b
optimize array access & remove depth/length constrains
Amxx Aug 14, 2022
ca83cde
gas optimization
Amxx Aug 14, 2022
f4f46ca
limit tree depth to 255 to avoid issues (255 is enough for any realis…
Amxx Aug 14, 2022
af7cb9c
fix lint
Amxx Aug 14, 2022
45eae37
reason
Amxx Aug 14, 2022
ac648c6
coverage
Amxx Aug 14, 2022
1b184c9
comments
Amxx Aug 14, 2022
4863418
documentation & changelog entry
Amxx Aug 16, 2022
3c19dcf
Merge branch 'master' into structure/merkletree
Amxx Dec 13, 2023
9fc7f31
update
Amxx Dec 13, 2023
652c8a1
add changeset
Amxx Dec 13, 2023
c74ab55
fix lint
Amxx Dec 14, 2023
a9932c9
fix lint
Amxx Dec 14, 2023
d8bdfd0
fix codespell
Amxx Dec 14, 2023
4d0ed52
Merge branch 'master' into structure/merkletree
Amxx Jan 4, 2024
b131354
update @openzeppelin/merkle-tree dependency
Amxx Jan 28, 2024
6422af6
fix lint
Amxx Jan 28, 2024
3ab0d21
Merge branch 'master' into structure/merkletree
Amxx Feb 5, 2024
5639d7c
up
Amxx Feb 5, 2024
24c829a
minimize changes
Amxx Feb 5, 2024
f954a98
Panic with RESOURCE_ERROR when inserting in a full tree
Amxx Feb 5, 2024
acdc6a9
Merge branch 'master' into structure/merkletree
Amxx Feb 6, 2024
cebdc2a
improve coverage
Amxx Feb 6, 2024
d4ced94
test looparound property of memory arrays
Amxx Feb 6, 2024
a3a813c
rename initialize → setUp
Amxx Feb 7, 2024
ec05d19
Update contracts/utils/structs/MerkleTree.sol
Amxx Feb 7, 2024
8ecc790
Merge branch 'master' into structure/merkletree
Amxx Feb 12, 2024
ec3d96b
fix lint
Amxx Feb 12, 2024
bcc0667
cleanup
Amxx Feb 12, 2024
b50ebee
Merge branch 'master' into structure/merkletree
Amxx Feb 16, 2024
5b15205
remove root history from the MerkleTree structure
Amxx Feb 19, 2024
b390790
Add Hashes.sol
Amxx Feb 19, 2024
e331674
fix-lint
Amxx Feb 19, 2024
91f7057
rename to reflect removal of history
Amxx Feb 19, 2024
088fa8c
rename setUp → setup
Amxx Feb 19, 2024
2d869b7
doc
Amxx Feb 20, 2024
567cd3e
Update contracts/utils/structs/MerkleTree.sol
Amxx Feb 20, 2024
a13237a
Update MerkleTree.sol
Amxx Feb 20, 2024
03bea3e
Update changesets and fix some comments
ernestognw Feb 21, 2024
c475bad
Simplify
ernestognw Feb 21, 2024
6a9e873
Add Merkle Tree to the docs
ernestognw Feb 21, 2024
1e59539
Remove merkletree.test.js
ernestognw Feb 21, 2024
051107b
Recover MerkleTree.test.js
ernestognw Feb 21, 2024
a1dd158
prefix variables with underscore to mark them as private (similar do …
Amxx Feb 21, 2024
7a21c4e
test reseting the tree using setup
Amxx Feb 21, 2024
01c2879
rename hashing functions
Amxx Feb 21, 2024
2494680
return index and root when inserting a leaf
Amxx Feb 21, 2024
0a2bfce
rename structure and functions
Amxx Feb 21, 2024
08c9a3c
Apply PR suggestions
ernestognw Mar 5, 2024
31712fb
Update contracts/utils/cryptography/Hashes.sol
Amxx Mar 5, 2024
55853be
rename the standard node hash
Amxx Mar 6, 2024
eca27fc
fix lint
Amxx Mar 6, 2024
eca9085
Fix NatSpec weird error
ernestognw Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix lint
  • Loading branch information
Amxx committed Aug 14, 2022
commit af7cb9c7b67d7ecb24a99d8e303122c91f9f40dc
24 changes: 12 additions & 12 deletions contracts/mocks/MerkleTreeMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,50 @@ import "../utils/structs/MerkleTree.sol";
contract MerkleTreeMock {
using MerkleTree for MerkleTree.TreeWithHistory;

MerkleTree.TreeWithHistory private tree;
MerkleTree.TreeWithHistory private _tree;

constructor(uint256 _depth, uint256 _length) {
tree.initialize(_depth, _length);
_tree.initialize(_depth, _length);
}

function insert(bytes32 leaf) public returns (uint256) {
return tree.insert(leaf);
return _tree.insert(leaf);
}

function getDepth() public view returns (uint256) {
return tree.getDepth();
return _tree.getDepth();
}

function getLength() public view returns (uint256) {
return tree.getLength();
return _tree.getLength();
}

function getLastRoot() public view returns (bytes32) {
return tree.getLastRoot();
return _tree.getLastRoot();
}

function isKnownRoot(bytes32 root) public view returns (bool) {
return tree.isKnownRoot(root);
return _tree.isKnownRoot(root);
}

// internal state
function currentRootIndex() public view returns (uint256) {
return tree.currentRootIndex;
return _tree.currentRootIndex;
}

function nextLeafIndex() public view returns (uint256) {
return tree.nextLeafIndex;
return _tree.nextLeafIndex;
}

function sides(uint256 i) public view returns (bytes32) {
return tree.sides[i];
return _tree.sides[i];
}

function zeros(uint256 i) public view returns (bytes32) {
return tree.zeros[i];
return _tree.zeros[i];
}

function roots(uint256 i) public view returns (bytes32) {
return tree.roots[i];
return _tree.roots[i];
}
}
12 changes: 6 additions & 6 deletions contracts/utils/structs/MerkleTree.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "../StorageSlot.sol";
error Full();

library MerkleTree {
uint256 private constant MAX_DEPTH = 255;
uint256 private constant _MAX_DEPTH = 255;

struct TreeWithHistory {
uint256 currentRootIndex;
Expand All @@ -33,12 +33,12 @@ library MerkleTree {
bytes32 zero,
function(bytes32, bytes32) view returns (bytes32) fnHash
) internal {
require(depth <= MAX_DEPTH);
require(depth <= _MAX_DEPTH);

// Store depth & length in the dynamic array
setLength(self.sides, depth);
setLength(self.zeros, depth);
setLength(self.roots, length);
_unsafeSetLength(self.sides, depth);
_unsafeSetLength(self.zeros, depth);
_unsafeSetLength(self.roots, length);
self.fnHash = fnHash;

// Build the different hashes in a zero-filled complete tree
Expand Down Expand Up @@ -142,7 +142,7 @@ library MerkleTree {
/**
* @dev Helper to set the length of an dynamic array. Directly writting to `.length` is forbiden.
*/
function setLength(bytes32[] storage array, uint256 len) private {
function _unsafeSetLength(bytes32[] storage array, uint256 len) private {
assembly {
sstore(array.slot, len)
}
Expand Down