Skip to content

@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

@crypto:merkle.verify(root leaf proof index?)
NameTypeDescription
rootbytes32Merkle root
leafbytes32Leaf to prove
proofarrayArray of bytes32 sibling hashes, leaf to root
[index]numberZero-based leaf position for positional (unsorted) verification; omit for sorted-pair trees
# Check a sorted-pair inclusion proof before submitting a claim
set $root 0x87fbd8dad686d9536b2ef65757c3415df1b7a4664deb34eda3d91234936eb5fe
set $proof [0x2222222222222222222222222222222222222222222222222222222222222222 0x3333333333333333333333333333333333333333333333333333333333333333]
print "Included:" @crypto:merkle.verify($root 0x1111111111111111111111111111111111111111111111111111111111111111 $proof)
# Verify a positional (unsorted) proof by passing the leaf index
set $root 0x6145e58f72ce6b641069ee7bd2b6af681fcbdd723a4f795f7d2939d00eb2d91d
print "Included:" @crypto:merkle.verify($root 0x3333333333333333333333333333333333333333333333333333333333333333 [0x3333333333333333333333333333333333333333333333333333333333333333 0x3e92e0db88d6afea9edc4eedf62fffa4d92bcdfc310dccbe943747fe8302e871] 2)
  • Without index, each proof step hashes the pair in ascending order — exactly OpenZeppelin's MerkleProof.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/Hop Lib_MerkleTree.verify.
  • An empty proof is valid exactly when leaf equals root (single-leaf tree).