For the complete documentation index, see llms.txt.
aztec-nr - protocol_types::merkle_tree::merkle_tree

Function compute_merkle_tree_nodes

pub fn compute_merkle_tree_nodes<let N: u32>(
    leaves: [Field; N],
    hasher: fn(Field, Field) -> Field,
) -> [Field; N - 1]

Computes the N - 1 internal nodes of a balanced Merkle tree from its N leaves (root last); N must be a power of 2 greater than 1.

Leaves are consumed as-is: this helper does not hash leaf preimages, it only hashes pairs upward. The same hasher is applied at every layer (the leaf/base layer and all internal-node layers alike), so there is NO domain separation between the leaf hashing and the internal-node hashing. An internal node is therefore just hasher(left, right), indistinguishable in form from a leaf.

WARNING: because of this, callers MUST pass leaves that are already domain-separated from this helper's internal-node hashes (i.e. produced by a hash whose domain differs from hasher), so that an internal-node value can never be a valid leaf. (Per-tree domain separation of the node hashing itself is likewise the caller's choice: pass the tree-specific hasher, e.g. nullifier_merkle_hash.)