Sitelet https://github.com/Vectorized/solady/blob/main/docs/utils/merkleprooflib.md
Skip to content

Latest commit

 

History

History
106 lines (72 loc) · 2.52 KB

File metadata and controls

106 lines (72 loc) · 2.52 KB

MerkleProofLib

Gas optimized verification of proof of inclusion for a leaf in a Merkle tree.

Merkle Proof Verification Operations

verify(bytes32[],bytes32,bytes32)

function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf)
    internal
    pure
    returns (bool isValid)

Returns whether leaf exists in the Merkle tree with root, given proof.

verifyCalldata(bytes32[],bytes32,bytes32)

function verifyCalldata(
    bytes32[] calldata proof,
    bytes32 root,
    bytes32 leaf
) internal pure returns (bool isValid)

Returns whether leaf exists in the Merkle tree with root, given proof.

verifyMultiProof(bytes32[],bytes32,bytes32[],bool[])

function verifyMultiProof(
    bytes32[] memory proof,
    bytes32 root,
    bytes32[] memory leaves,
    bool[] memory flags
) internal pure returns (bool isValid)

Returns whether all leaves exist in the Merkle tree with root,
given proof and flags.

Note:

  • Breaking the invariant flags.length == (leaves.length - 1) + proof.length
    will always return false.
  • The sum of the lengths of proof and leaves must never overflow.
  • Any non-zero word in the flags array is treated as true.
  • The memory offset of proof must be non-zero
    (i.e. proof is not pointing to the scratch space).

verifyMultiProofCalldata(bytes32[],bytes32,bytes32[],bool[])

function verifyMultiProofCalldata(
    bytes32[] calldata proof,
    bytes32 root,
    bytes32[] calldata leaves,
    bool[] calldata flags
) internal pure returns (bool isValid)

Returns whether all leaves exist in the Merkle tree with root,
given proof and flags.

Note:

  • Breaking the invariant flags.length == (leaves.length - 1) + proof.length
    will always return false.
  • Any non-zero word in the flags array is treated as true.
  • The calldata offset of proof must be non-zero
    (i.e. proof is from a regular Solidity function with a 4-byte selector).

Empty Calldata Helpers

emptyProof()

function emptyProof() internal pure returns (bytes32[] calldata proof)

Returns an empty calldata bytes32 array.

emptyLeaves()

function emptyLeaves() internal pure returns (bytes32[] calldata leaves)

Returns an empty calldata bytes32 array.

emptyFlags()

function emptyFlags() internal pure returns (bool[] calldata flags)

Returns an empty calldata bool array.