stealth-lib
ZK-friendly cryptographic primitives for Rust.
Features
- MiMC Hash: Efficient hash function designed for ZK circuits (compatible with Tornado Cash / circomlib)
- Merkle Tree: MiMC-based tree with proof generation and verification
- No unsafe code:
#![deny(unsafe_code)] no_stdsupport: Optional, for WASM/embedded targets- Well-documented: Comprehensive API documentation with examples
Installation
Add to your Cargo.toml:
[]
= "1.0"
Feature Flags
| Feature | Default | Description |
|---|---|---|
std |
✅ | Enable standard library support |
serde |
❌ | Enable serde serialization |
borsh |
❌ | Enable borsh serialization (for Solana) |
experimental |
❌ | ⚠️ Educational code only, NOT for production |
Quick Start
Merkle Tree with Proofs
use ;
MiMC Hashing
use MimcHasher;
Security Model
Designed For
- Zero-knowledge proof circuits (Tornado Cash, Semaphore, etc.)
- On-chain verification of Merkle membership proofs
- Privacy-preserving applications using ZK-SNARKs
Guarantees
- ✅ Collision resistance of MiMC (computational security)
- ✅ Correct Merkle proofs for membership verification
- ✅ Deterministic outputs for same inputs
- ✅ Root history buffer for handling concurrent insertions
Non-Goals / Explicit Exclusions
- ❌ NOT constant-time — Vulnerable to timing side-channels
- ❌ NOT a general-purpose crypto library — Use
ring,sha2, etc. - ❌ NOT professionally audited — Use at your own risk
- ❌ NOT suitable for password hashing — Use argon2, bcrypt, scrypt
Do ✅
- Use for building ZK circuits
- Verify proofs on-chain (Solana, Ethereum)
- Use established libraries for non-ZK crypto
Don't ❌
- Use MiMC for password hashing
- Use the
experimentalfeature in production - Assume constant-time execution
- Use for cryptographic signatures
API Overview
Core Types
| Type | Description |
|---|---|
MerkleTree |
Sparse Merkle tree with MiMC hash |
MerkleProof |
Merkle inclusion proof |
MimcHasher |
MiMC-Feistel sponge hasher |
Error |
Typed error enum |
Result<T> |
Result alias with Error |
Error Handling
All fallible operations return Result<T, Error>:
use ;
let tree = new;
assert!;
let mut tree = new.unwrap; // 4 leaves max
for _ in 0..4
let result = tree.insert;
assert!;
Migration from v0.x
Version 1.0 introduces breaking changes for improved safety:
// Old (v0.x)
use MerkleTree;
let tree = new; // Could panic
let root = tree.get_last_root; // Could panic
// New (v1.0)
use MerkleTree;
let tree = new.unwrap; // Returns Result
let root = tree.root.unwrap; // Returns Option
See CHANGELOG.md for full migration guide.
MSRV
Minimum Supported Rust Version: 1.70.0
Benchmarks
Run benchmarks with:
Typical results on modern hardware:
mimc_hash: ~500nsmerkle_insert (depth 20): ~50μsmerkle_prove (depth 20): ~100μsmerkle_verify (depth 20): ~50μs
Contributing
Contributions are welcome! Please open an issue or PR.
License
MIT License - see LICENSE for details.
Security
For security issues, please see SECURITY.md.