-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Process and verify merkle proofs (and multiproof) with custom hash function #4887
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
Merged
Amxx
merged 31 commits into
OpenZeppelin:master
from
Amxx:feature/cryptography/merkle-proof-custom-hash
Jul 15, 2024
Merged
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 a45abe8
remove cache that causes stack too deep
Amxx 9bc06ea
fix lint
Amxx 2977574
more tests
Amxx 92399a3
natspec comments
Amxx f449987
procedurally generate MerkleProof
Amxx 725a75f
add changeset
Amxx d56dad6
Merge branch 'master' into feature/cryptography/merkle-proof-custom-hash
Amxx 408271a
codespell
Amxx d11d7f5
Merge branch 'master' into feature/cryptography/merkle-proof-custom-hash
ernestognw a7abb27
Fix procedural generation
ernestognw e49c0ac
Nits
ernestognw 55b390e
Merge branch 'master' into feature/cryptography/merkle-proof-custom-hash
ernestognw 2d87005
Merge branch 'master' into feature/cryptography/merkle-proof-custom-hash
Amxx 9c7ab66
linted generation
Amxx b32a118
up
Amxx ec01f3d
Fix tests
ernestognw c2ca934
remove one local variable to avoid stack too depth when calldata + cu…
Amxx 0b19ff7
remove one local variable to avoid stack too depth when calldata + cu…
Amxx 4ca51e9
add note about the use of non communative hashing functions
Amxx cc8d816
add note about the use of non communative hashing functions
Amxx c38e1aa
Merge branch 'master' into feature/cryptography/merkle-proof-custom-hash
ernestognw d437555
Improve coverage and address review comments
ernestognw a939a13
Nit
ernestognw 50f1ccb
update merkle-tree to @1.0.7
Amxx 640e2da
Merge branch 'feature/cryptography/merkle-proof-custom-hash-tests' in…
Amxx e3554ae
refactor tests
Amxx 75703a6
up
Amxx 0ea8d75
Apply suggestions from code review
Amxx f388e69
Update MerkleTree.sol
Amxx b7d56bb
Use sha256 for the MerkleProof custom hash tests
Amxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.