MerkleProofCustomHashMock.sol 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. import {MerkleProof} from "../utils/cryptography/MerkleProof.sol";
  4. // This could be a library, but then we would have to add it to the Stateless.sol mock for upgradeable tests
  5. abstract contract MerkleProofCustomHashMock {
  6. function customHash(bytes32 a, bytes32 b) internal pure returns (bytes32) {
  7. return a < b ? sha256(abi.encode(a, b)) : sha256(abi.encode(b, a));
  8. }
  9. function verify(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal view returns (bool) {
  10. return MerkleProof.verify(proof, root, leaf, customHash);
  11. }
  12. function processProof(bytes32[] calldata proof, bytes32 leaf) internal view returns (bytes32) {
  13. return MerkleProof.processProof(proof, leaf, customHash);
  14. }
  15. function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal view returns (bool) {
  16. return MerkleProof.verifyCalldata(proof, root, leaf, customHash);
  17. }
  18. function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal view returns (bytes32) {
  19. return MerkleProof.processProofCalldata(proof, leaf, customHash);
  20. }
  21. function multiProofVerify(
  22. bytes32[] calldata proof,
  23. bool[] calldata proofFlags,
  24. bytes32 root,
  25. bytes32[] calldata leaves
  26. ) internal view returns (bool) {
  27. return MerkleProof.multiProofVerify(proof, proofFlags, root, leaves, customHash);
  28. }
  29. function processMultiProof(
  30. bytes32[] calldata proof,
  31. bool[] calldata proofFlags,
  32. bytes32[] calldata leaves
  33. ) internal view returns (bytes32) {
  34. return MerkleProof.processMultiProof(proof, proofFlags, leaves, customHash);
  35. }
  36. function multiProofVerifyCalldata(
  37. bytes32[] calldata proof,
  38. bool[] calldata proofFlags,
  39. bytes32 root,
  40. bytes32[] calldata leaves
  41. ) internal view returns (bool) {
  42. return MerkleProof.multiProofVerifyCalldata(proof, proofFlags, root, leaves, customHash);
  43. }
  44. function processMultiProofCalldata(
  45. bytes32[] calldata proof,
  46. bool[] calldata proofFlags,
  47. bytes32[] calldata leaves
  48. ) internal view returns (bytes32) {
  49. return MerkleProof.processMultiProofCalldata(proof, proofFlags, leaves, customHash);
  50. }
  51. }