Skip to main content

Module bmt

Module bmt 

Source
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.
HasherFactory
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