sigil-state · commitment::tree
Source declarations, signatures and documentation for commitment::tree.
Source: sigil/node/sigil-state/src/commitment/tree.rs. SHA-256: bc6a97df98b4dabd444e6177b791103f6c2b83aa70111b50d0e65d597a0fd3ba.
This reference follows declared source modules, retains conditional attributes, and includes public declarations and implementation methods. Private-module re-exports and trait resolution require the compiler; this is a source reference, not a claim that every listed item is a root import. Function bodies and constant values are omitted.
commitment::tree::CommitmentTree
A BLAKE3-based sparse Merkle tree for state commitments.
Keys are hashed with BLAKE3 to determine their leaf position in a binary tree
of depth 256. Internal nodes store BLAKE3(left || right). Empty subtrees
use a precomputed "default hash" at each level so that the tree is sparse --
only populated paths are stored.
Performance
- Single insert/delete: O(depth) = O(256) hash operations.
- Batch insert: O(k * depth) but with shared-path deduplication, typically much faster than k individual inserts because Merkle paths overlap.
- Proof generation: O(depth).
- Proof verification: O(depth).
#[derive(Debug, Clone)]
pub struct CommitmentTree {
}Source line: 23.
commitment::tree::CommitmentTree::new
Create a new, empty commitment tree.
pub fn new() -> Self;Source line: 50.
commitment::tree::CommitmentTree::insert
Insert or update a key-value pair.
pub fn insert(&mut self, key: &[u8], value: &[u8]);Source line: 60.
commitment::tree::CommitmentTree::batch_insert
Batch insert multiple key-value pairs. Recomputes shared Merkle paths only once, which is faster than individual inserts when paths overlap.
pub fn batch_insert(&mut self, entries: &[(&[u8], &[u8])]);Source line: 87.
commitment::tree::CommitmentTree::delete
Delete a key from the tree.
pub fn delete(&mut self, key: &[u8]);Source line: 120.
commitment::tree::CommitmentTree::root
Get the current root hash. Returns the default root if the tree is empty.
pub fn root(&self) -> [u8; 32];Source line: 141.
commitment::tree::CommitmentTree::prove
Generate an inclusion proof for a key. Returns None if the key is not
present in the tree.
pub fn prove(&self, key: &[u8]) -> Option<InclusionProof>;Source line: 154.
commitment::tree::CommitmentTree::verify_proof
Verify a proof against a known root hash.
pub fn verify_proof(root: &[u8; 32], key: &[u8], value: &[u8], proof: &InclusionProof) -> bool;Source line: 192.
commitment::tree::CommitmentTree::len
Number of leaf entries in the tree.
pub fn len(&self) -> usize;Source line: 214.
commitment::tree::CommitmentTree::is_empty
Whether the tree is empty.
pub fn is_empty(&self) -> bool;Source line: 219.
commitment::tree::CommitmentTree::get
Get the value for a key, if present.
pub fn get(&self, key: &[u8]) -> Option<Vec<u8>>;Source line: 224.