caelum0x 2b68bde5d5 Predikt: full Polymarket-style prediction market — web + mobile + on-chain + bots
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>
2026-07-06 23:29:50 +03:00

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 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.