Skip to main content

compute_root

Function compute_root 

Source
pub fn compute_root(leaves: &[MerkleHash]) -> MerkleHash
Expand description

Compute the Merkle root of a list of leaf hashes per RFC 6962 Section 2.1.

Recursively splits at the largest power of 2 less than n: MTH(D[0:n]) = SHA-256(0x01 || MTH(D[0:k]) || MTH(D[k:n])) where k = 2^(floor(log2(n-1))).

Args:

  • leaves — Slice of leaf hashes. Empty input returns MerkleHash::EMPTY.

Usage:

let root = compute_root(&leaf_hashes);