-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Process and verify merkle proofs (and multiproof) with custom hash fu…
…nction (#4887) Co-authored-by: ernestognw <ernestognw@gmail.com>
- Loading branch information
1 parent
4b33d32
commit b73bcb2
Showing
10 changed files
with
772 additions
and
262 deletions.
There are no files selected for viewing
This file contains 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 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 could 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 ? sha256(abi.encode(a, b)) : sha256(abi.encode(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.