INNER CODE UNIT · Rust
merkle_root
risc0/risc0-ethereum · crates/aggregation/src/lib.rs:371
pub fn merkle_root(leaves: &[Digest]) -> Digest {
match leaves {
[] => panic!("digest list is empty, cannot compute Merkle root"),
_ => MerkleMountainRange::from_iter(leaves)
.finalized_root()
.unwrap(),
}
}
// TODO(victor) Should this be assembled into under a struct and impl rather than as discrete
// functions?
/// Calculate the Merkle path proving inclusion of the leaf at the given index in a tree
/// constructed from the given leaves. The leaf and root are not included.
///
/// Panics if the given index is out of bounds.
pub fn merkle_path(leaves: &[Digest], index: usize) -> Vec<Digest> {
assert!(
index < leaves.len(),