smt-circom

Crates.iosmt-circom
lib.rssmt-circom
version0.1.0
created_at2025-12-27 15:09:40.249272+00
updated_at2025-12-27 15:09:40.249272+00
descriptionSparse Merkle Tree, compatible with circom proofs
homepage
repositoryhttps://github.com/lincot/mootvote
max_upload_size
id2007399
size46,126
Timofey (lincot)

documentation

README

smt-circom

This crate provides a Sparse Merkle Tree implementation in Rust using Poseidon hash, compatible with circom zero-knowledge proofs.

It can be used with an in-memory node store, a persistent RocksDB store, or a custom store.

The implementation is inspired by @iden3/js-merkletree.

Example usage

use smt_circom::{store::MemStore, SparseMerkleTree};

let mut tree = SparseMerkleTree::<64, _>::new(MemStore::new())?;
assert_eq!(tree.root()?, [0; 32]);
let (idx, new_value) = ([1; 32], [2; 32]);
let proof = tree.get_proof(idx);
assert!(!proof.membership);
tree.add_or_update(idx, new_value)?;

Benchmark results

Here's the result of running a benchmark on an AMD Ryzen 5 5600H, comparing smt-circom against @iden3/js-merkletree (Node.js), both using trees with depth 64 and an in-memory store. It first adds 10 random leafs, then gets inclusion proofs for these 10 leafs (both benchmarks use the same seeded rng).

Add 10 leafs Get 10 proofs
smt-circom 1.74 ms 0.00174 ms
js-merkletree 13.5 ms 1.05 ms
Commit count: 0

cargo fmt