Module tree

Source
Expand description

This module contains the MerkleTree, an implementation of a perfect binary Merkle tree.

§Examples

use alloy_merkle_tree::tree::MerkleTree;
use alloy_primitives::{B256, U256};

let mut tree = MerkleTree::new();
// Number of leaves should be a power of 2 for a perfect binary tree
let num_leaves = 16;
for i in 0..num_leaves {
    tree.insert(B256::from(U256::from(i)));
}
tree.finish();

for i in 0..num_leaves {
    let proof = tree.create_proof(&B256::from(U256::from(i))).unwrap();
    assert!(MerkleTree::verify_proof(&proof));
}

Structs§

MerkleProof
Represents a Merkle proof for a specific leaf in the Merkle tree.
MerkleTree
A Merkle tree implementation supporting insertion of leaves, tree construction, proof generation, and proof verification.