Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process and verify merkle proofs (and multiproof) with custom hash function #4887

Merged
Merged
Show file tree
Hide file tree
Changes from 28 commits
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
5 changes: 5 additions & 0 deletions .changeset/spotty-queens-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`MerkleProof`: Add variations of `verify`, `processProof`, `multiProofVerify` and `processMultiProof` (and equivalent calldata version) with support for custom hashing functions.
62 changes: 62 additions & 0 deletions contracts/mocks/MerkleProofCustomHashMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import {MerkleProof} from "../utils/cryptography/MerkleProof.sol";

// this count be a library, but then we would have to add it to the Stateless.sol mock for upgradeable tests
Amxx marked this conversation as resolved.
Show resolved Hide resolved
abstract contract MerkleProofCustomHashMock {
function customHash(bytes32 a, bytes32 b) internal pure returns (bytes32) {
return a < b ? keccak256(abi.encode(bytes32(0), a, b)) : keccak256(abi.encode(bytes32(0), b, a));
}

function verify(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal view returns (bool) {
return MerkleProof.verify(proof, root, leaf, customHash);
}

function processProof(bytes32[] calldata proof, bytes32 leaf) internal view returns (bytes32) {
return MerkleProof.processProof(proof, leaf, customHash);
}

function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal view returns (bool) {
return MerkleProof.verifyCalldata(proof, root, leaf, customHash);
}

function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal view returns (bytes32) {
return MerkleProof.processProofCalldata(proof, leaf, customHash);
}

function multiProofVerify(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32 root,
bytes32[] calldata leaves
) internal view returns (bool) {
return MerkleProof.multiProofVerify(proof, proofFlags, root, leaves, customHash);
}

function processMultiProof(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] calldata leaves
) internal view returns (bytes32) {
return MerkleProof.processMultiProof(proof, proofFlags, leaves, customHash);
}

function multiProofVerifyCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32 root,
bytes32[] calldata leaves
) internal view returns (bool) {
return MerkleProof.multiProofVerifyCalldata(proof, proofFlags, root, leaves, customHash);
}

function processMultiProofCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] calldata leaves
) internal view returns (bytes32) {
return MerkleProof.processMultiProofCalldata(proof, proofFlags, leaves, customHash);
}
}
Loading
Loading