MerkleTreeWithHistory
A Merkle tree with history for storing and managing commitments in the privacy system.This structure implements a sparse Merkle tree that maintains a history of recent roots to enable privacy-preserving transaction verification while preventing double-spending. # Components - levels
: The depth of the Merkle tree (number of levels) - filled_subtrees
: Intermediate hashes of subtree roots at each level - roots
: Historical Merkle roots for verification - current_root_index
: Index of the current active root - next_index
: Next available index for inserting new leaves - zeros
: Precomputed zero hashes for empty nodes at each level # Privacy Features - Maintains commitment history without revealing individual transactions - Enables zero-knowledge proof verification against recent state - Prevents double-spending through nullifier tracking
Fully qualified path: obscura::structs::MerkleTreeWithHistory
#[starknet::storage_node]
pub struct MerkleTreeWithHistory {
pub levels: u32,
pub filled_subtrees: Vec<u256>,
pub roots: Vec<u256>,
pub current_root_index: u32,
pub next_index: u32,
pub zeros: Vec<u256>,
}
Members
levels
The depth of the Merkle tree (number of levels). Determines the maximum number of commitments that can be stored.
Fully qualified path: obscura::structs::MerkleTreeWithHistory::levels
pub levels: u32
filled_subtrees
Stores intermediate hashes of subtree roots at each level. Used for efficient Merkle tree updates and proof generation.
Fully qualified path: obscura::structs::MerkleTreeWithHistory::filled_subtrees
pub filled_subtrees: Vec<u256>
roots
Stores the historical Merkle roots for transaction verification. Allows verification against recent state while maintaining privacy.
Fully qualified path: obscura::structs::MerkleTreeWithHistory::roots
pub roots: Vec<u256>
current_root_index
Tracks the index of the current Merkle root in the circular buffer. Used for efficient root rotation and history management.
Fully qualified path: obscura::structs::MerkleTreeWithHistory::current_root_index
pub current_root_index: u32
next_index
Tracks the next available index for inserting a new leaf. Ensures sequential insertion and proper tree structure.
Fully qualified path: obscura::structs::MerkleTreeWithHistory::next_index
pub next_index: u32
zeros
Precomputed zero hashes for empty nodes at each level. Optimizes Merkle tree operations by avoiding repeated hash calculations.
Fully qualified path: obscura::structs::MerkleTreeWithHistory::zeros
pub zeros: Vec<u256>