@crypto:merkle.verify
Verify a Merkle inclusion proof against a root. Without an index the proof is checked with the sorted-pair convention (OpenZeppelin MerkleProof); with an index it is checked positionally (unsorted trees).
Returns: bool
Syntax
Section titled “Syntax”@crypto:merkle.verify(root leaf proof index?)Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
root | bytes32 | Merkle root |
leaf | bytes32 | Leaf to prove |
proof | array | Array of bytes32 sibling hashes, leaf to root |
[index] | number | Zero-based leaf position for positional (unsorted) verification; omit for sorted-pair trees |
Examples
Section titled “Examples”# Check a sorted-pair inclusion proof before submitting a claimset $root 0x87fbd8dad686d9536b2ef65757c3415df1b7a4664deb34eda3d91234936eb5feset $proof [0x2222222222222222222222222222222222222222222222222222222222222222 0x3333333333333333333333333333333333333333333333333333333333333333]print "Included:" @crypto:merkle.verify($root 0x1111111111111111111111111111111111111111111111111111111111111111 $proof)
# Verify a positional (unsorted) proof by passing the leaf indexset $root 0x6145e58f72ce6b641069ee7bd2b6af681fcbdd723a4f795f7d2939d00eb2d91dprint "Included:" @crypto:merkle.verify($root 0x3333333333333333333333333333333333333333333333333333333333333333 [0x3333333333333333333333333333333333333333333333333333333333333333 0x3e92e0db88d6afea9edc4eedf62fffa4d92bcdfc310dccbe943747fe8302e871] 2)- Without
index, each proof step hashes the pair in ascending order — exactly OpenZeppelin'sMerkleProof.verify. - With
index, each proof step places the computed hash on the left when the current index bit is even and on the right when it is odd, then shifts the index — the semantics of Optimism/HopLib_MerkleTree.verify. - An empty proof is valid exactly when
leafequalsroot(single-leaf tree).