Expand description
Binary Merkle Tree (BMT) implementation
This module provides an optimized implementation of a Binary Merkle Tree for hashing data in parallel and generating proofs of inclusion.
§Key Components
- Hasher: Core BMT hashing functionality with span support
- Proof: Inclusion proofs for efficient verification
- Prover: Interface for generating and verifying proofs
§Example Usage
use nectar_primitives::bmt::{Hasher, Prover};
// Create a hasher and update with data
let data = b"hello world";
let mut hasher = Hasher::new();
hasher.set_span(data.len() as u64);
hasher.update(data);
// Get the hash
let hash = hasher.sum();
// Generate a proof for the first segment
let proof = hasher.generate_proof(data, 0).unwrap();
// Verify the proof
assert!(Hasher::verify_proof(&proof, hash.as_slice()).unwrap());Re-exports§
pub use crate::error::PrimitivesError;pub use crate::error::Result;
Structs§
- Hasher
- BMT hasher with configurable body size.
- Hasher
Factory - Factory for creating BMT hashers.
- Proof
- Represents a proof for a specific segment in a Binary Merkle Tree
Constants§
- BRANCHES
- Number of branches in the Binary Merkle Tree.
- DEFAULT_
BODY_ SIZE - Default body size for chunks (128 branches * 32 byte segments = 4096).
- HASH_
SIZE - Hash size in bytes (keccak256).
- SPAN_
SIZE - Span header size in bytes (u64).
Traits§
- Prover
- Extension trait to add proof-related functionality to BMTHasher