1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! # 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
//!
//! | Feature | Default | Description |
//! |---------|---------|-------------|
//! | `std` | ✅ | Enable standard library support |
//! | `serde` | ❌ | Enable serde serialization |
//! | `borsh` | ❌ | Enable borsh serialization |
//! | `experimental` | ❌ | ⚠️ Educational code only, NOT for production |
extern crate alloc;
// Core modules
// Experimental/educational modules (feature-gated)
// Legacy modules (deprecated, will be removed in 2.0)
// Public API re-exports
pub use ;
pub use MimcHasher;
pub use ;
// Backwards compatibility type alias
pub type SolanaError = Error;