Skip to main content

Crate stealth_lib

Crate stealth_lib 

Source
Expand description

§stealth-lib

ZK-friendly cryptographic primitives for Rust.

This library provides cryptographic primitives designed for use in zero-knowledge proof systems like Tornado Cash, Semaphore, and similar applications.

§Features

  • MiMC Hash: Efficient hash function designed for ZK circuits
  • Merkle Tree: MiMC-based tree with proof generation and verification
  • No unsafe code: #![deny(unsafe_code)]
  • no_std support: Optional, for WASM/embedded targets

§Quick Start

use stealth_lib::{MerkleTree, MerkleProof};

// Create a Merkle tree with 20 levels (can hold ~1M leaves)
let mut tree = MerkleTree::new(20).unwrap();

// Insert some leaves
let idx = tree.insert(12345).unwrap();

// Generate and verify a proof
let proof = tree.prove(idx).unwrap();
let root = tree.root().unwrap();
assert!(proof.verify(root, &tree.hasher()));

§Security Model

Designed for: Zero-knowledge proof circuits (Tornado Cash, Semaphore, etc.)

Guarantees:

  • Collision resistance of MiMC (computational)
  • Correct Merkle proofs for membership verification

Non-Goals / Explicit Exclusions:

  • ❌ Constant-time execution (vulnerable to timing side-channels)
  • ❌ General-purpose cryptographic primitives
  • ❌ Professional security audit (pending)

For general-purpose cryptography, use established crates like ring, sha2, ed25519-dalek, etc.

§Feature Flags

FeatureDefaultDescription
stdEnable standard library support
serdeEnable serde serialization
borshEnable borsh serialization
experimental⚠️ Educational code only, NOT for production

Re-exports§

pub use error::Error;
pub use error::Result;
pub use hash::MimcHasher;
pub use merkle::MerkleProof;
pub use merkle::MerkleTree;

Modules§

encoding
Encoding utilities.
error
Error types for stealth-lib operations.
hash
Hash functions for stealth-lib.
hasherDeprecated
Legacy hasher module for backwards compatibility.
merkle
Merkle tree implementation with MiMC hash.
merkle_treeDeprecated
Legacy Merkle tree module for backwards compatibility.
utilsDeprecated
Legacy utilities module for backwards compatibility.

Type Aliases§

SolanaErrorDeprecated