| Crates.io | brine-tree |
| lib.rs | brine-tree |
| version | 0.6.2 |
| created_at | 2025-04-17 05:45:29.124175+00 |
| updated_at | 2025-08-09 22:50:47.775095+00 |
| description | Merkle tree implementation for Solana programs |
| homepage | |
| repository | https://github.com/zfedoran/brine-tree |
| max_upload_size | |
| id | 1637263 |
| size | 104,746 |
A fast, low-overhead, Blake3 Merkle tree library for the Solana programs.
use brine_tree::{MerkleTree, Leaf};
fn main() {
const TREE_DEPTH: usize = 18;
let mut tree = MerkleTree::<{TREE_DEPTH}>::new(&[b"empty_leaf_seed"]);
let data = &[b"hello", b"world"];
let leaf = Leaf::new(data);
tree.try_add_leaf(leaf)?;
// Off-chain proof generation
let db = &[leaf, ...]; // your database of leaves
let leaf_index = 0; // index of the leaf you want to prove
let proof = tree.get_merkle_proof(db, leaf_index)?;
assert!(tree.contains(&proof, data));
Ok(())
}
Returns Ok(()) for successful operations or Err(ProgramError) if invalid.
Q: Why not use an off-chain Merkle tree?
A: Solana programs often need to verify inclusion or manage state on-chain efficiently. Off-chain Merkle trees require additional infrastructure and trust assumptions.
Q: Why not use something else?
A: There definitely are a few other implementations worth looking into, like concurrent merkle tree, but this one is simple and easy to work with.
Contributions are welcome! Please open issues or PRs on the GitHub repo.