Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2.5 KiB
2.5 KiB
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
proofandleavesmust never overflow. - Any non-zero word in the
flagsarray is treated as true. - The memory offset of
proofmust be non-zero
(i.e.proofis 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
flagsarray is treated as true. - The calldata offset of
proofmust be non-zero
(i.e.proofis 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.