Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ffe08a4
add custm-hash versions of the MerkleProof functions
Amxx Feb 8, 2024
a45abe8
remove cache that causes stack too deep
Amxx Feb 8, 2024
9bc06ea
fix lint
Amxx Feb 8, 2024
2977574
more tests
Amxx Feb 9, 2024
92399a3
natspec comments
Amxx Feb 9, 2024
f449987
procedurally generate MerkleProof
Amxx Feb 9, 2024
725a75f
add changeset
Amxx Feb 12, 2024
d56dad6
Merge branch 'master' into feature/cryptography/merkle-proof-custom-hash
Amxx Feb 12, 2024
408271a
codespell
Amxx Feb 12, 2024
d11d7f5
Merge branch 'master' into feature/cryptography/merkle-proof-custom-hash
ernestognw Mar 25, 2024
a7abb27
Fix procedural generation
ernestognw Mar 25, 2024
e49c0ac
Nits
ernestognw Apr 22, 2024
55b390e
Merge branch 'master' into feature/cryptography/merkle-proof-custom-hash
ernestognw Apr 23, 2024
2d87005
Merge branch 'master' into feature/cryptography/merkle-proof-custom-hash
Amxx Jun 27, 2024
9c7ab66
linted generation
Amxx Jun 27, 2024
b32a118
up
Amxx Jun 27, 2024
ec01f3d
Fix tests
ernestognw Jun 27, 2024
c2ca934
remove one local variable to avoid stack too depth when calldata + cu…
Amxx Jun 28, 2024
0b19ff7
remove one local variable to avoid stack too depth when calldata + cu…
Amxx Jun 28, 2024
4ca51e9
add note about the use of non communative hashing functions
Amxx Jun 28, 2024
cc8d816
add note about the use of non communative hashing functions
Amxx Jun 28, 2024
c38e1aa
Merge branch 'master' into feature/cryptography/merkle-proof-custom-hash
ernestognw Jul 15, 2024
d437555
Improve coverage and address review comments
ernestognw Jul 15, 2024
a939a13
Nit
ernestognw Jul 15, 2024
50f1ccb
update merkle-tree to @1.0.7
Amxx Jul 15, 2024
640e2da
Merge branch 'feature/cryptography/merkle-proof-custom-hash-tests' in…
Amxx Jul 15, 2024
e3554ae
refactor tests
Amxx Jul 15, 2024
75703a6
up
Amxx Jul 15, 2024
0ea8d75
Apply suggestions from code review
Amxx Jul 15, 2024
f388e69
Update MerkleTree.sol
Amxx Jul 15, 2024
b7d56bb
Use sha256 for the MerkleProof custom hash tests
Amxx Jul 15, 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 Feb 8, 2024
commit 9bc06eaadbe19b60f1c5adc2034f6861b6c77814
34 changes: 26 additions & 8 deletions contracts/utils/cryptography/MerkleProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ library MerkleProof {
}

/// @dev Version of {verify} with support for custom internal hashing function
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf, function (bytes32, bytes32) pure returns (bytes32) hasher) internal pure returns (bool) {
function verify(
bytes32[] memory proof,
bytes32 root,
bytes32 leaf,
function(bytes32, bytes32) pure returns (bytes32) hasher
) internal pure returns (bool) {
return processProof(proof, leaf, hasher) == root;
}

Expand All @@ -46,7 +51,12 @@ library MerkleProof {
}

/// @dev Calldata version of {verify} with support for custom internal hashing function
function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf, function (bytes32, bytes32) pure returns (bytes32) hasher) internal pure returns (bool) {
function verifyCalldata(
bytes32[] calldata proof,
bytes32 root,
bytes32 leaf,
function(bytes32, bytes32) pure returns (bytes32) hasher
) internal pure returns (bool) {
return processProofCalldata(proof, leaf, hasher) == root;
}

Expand All @@ -61,7 +71,11 @@ library MerkleProof {
}

/// @dev Version of {processProof} with support for custom internal hashing function
function processProof(bytes32[] memory proof, bytes32 leaf, function (bytes32, bytes32) pure returns (bytes32) hasher) internal pure returns (bytes32) {
function processProof(
bytes32[] memory proof,
bytes32 leaf,
function(bytes32, bytes32) pure returns (bytes32) hasher
) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = hasher(computedHash, proof[i]);
Expand All @@ -77,7 +91,11 @@ library MerkleProof {
}

/// @dev Calldata version of {processProof} with support for custom internal hashing function
function processProofCalldata(bytes32[] calldata proof, bytes32 leaf, function (bytes32, bytes32) pure returns (bytes32) hasher) internal pure returns (bytes32) {
function processProofCalldata(
bytes32[] calldata proof,
bytes32 leaf,
function(bytes32, bytes32) pure returns (bytes32) hasher
) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = hasher(computedHash, proof[i]);
Expand Down Expand Up @@ -106,7 +124,7 @@ library MerkleProof {
bool[] memory proofFlags,
bytes32 root,
bytes32[] memory leaves,
function (bytes32, bytes32) pure returns (bytes32) hasher
function(bytes32, bytes32) pure returns (bytes32) hasher
) internal pure returns (bool) {
return processMultiProof(proof, proofFlags, leaves, hasher) == root;
}
Expand All @@ -131,7 +149,7 @@ library MerkleProof {
bool[] calldata proofFlags,
bytes32 root,
bytes32[] memory leaves,
function (bytes32, bytes32) pure returns (bytes32) hasher
function(bytes32, bytes32) pure returns (bytes32) hasher
) internal pure returns (bool) {
return processMultiProofCalldata(proof, proofFlags, leaves, hasher) == root;
}
Expand Down Expand Up @@ -159,7 +177,7 @@ library MerkleProof {
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32[] memory leaves,
function (bytes32, bytes32) pure returns (bytes32) hasher
function(bytes32, bytes32) pure returns (bytes32) hasher
) internal pure returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
Expand Down Expand Up @@ -225,7 +243,7 @@ library MerkleProof {
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] memory leaves,
function (bytes32, bytes32) pure returns (bytes32) hasher
function(bytes32, bytes32) pure returns (bytes32) hasher
) internal pure returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
Expand Down