Skip to content

@circom:tree.root

Compute the Poseidon Merkle root of an array of field-element leaves. A single-leaf lean tree has root = leaf.

⚗️ Experimental — available at next.evmcrispr.com.

Returns: number

@circom:tree.root(leaves lean:<value> depth:<value>)
NameTypeDescription
leavesarrayArray of field-element leaves, in insertion order
lean:boollean:true — Semaphore v4 LeanIMT (the default when depth: is not set)
depth:numberdepth:<n> — zero-padded fixed-depth tree
# Compute the Poseidon Merkle root of a group of members
set $members [1234 5678 9012]
print "Root:" @circom:tree.root($members)
  • lean (default) is a port of zk-kit's LeanIMT, the tree used by Semaphore v4: depth grows with the leaf count, missing right children are propagated up unchanged, and a single-leaf tree has root = leaf.
  • depth:<n> builds a zero-padded incremental tree of static depth (Tornado-style contracts, Semaphore v3): missing children are replaced by the zero chain Z0 = 0, Z(i+1) = poseidon(Zi Zi), and the empty-subtree roots match the widely deployed MerkleTreeWithHistory zeros.
  • Leaves are field elements in insertion order — the tree is positional, never sorted.