Overview
Thesnark module implements zero-knowledge Succinct Non-interactive Arguments of Knowledge (zkSNARKs). The primary implementation is Varuna, a universal preprocessing zkSNARK that supports batch proving and verification.
Varuna zkSNARK
VarunaSNARK Struct
The main Varuna proof system implementation.PairingEngine
The pairing-friendly elliptic curve (typically BLS12-377)
AlgebraicSponge
The Fiat-Shamir sponge (typically PoseidonSponge)
SNARKMode
The SNARK mode (Recursive or Default)
Type Aliases
SNARK Trait Implementation
Varuna implements theSNARK trait, providing the full proof system interface.
Associated Types
Setup Phase
universal_setup
Generates universal structured reference string (SRS).usize
Maximum polynomial degree supported by the SRS
Result<UniversalSRS<E>>
Universal parameters supporting all circuits up to max_degree
circuit_setup
Generates circuit-specific proving and verifying keys.&UniversalSRS<E>
Universal structured reference string
&C
The circuit to generate keys for
Result<(CircuitProvingKey, CircuitVerifyingKey)>
Proving key for the prover and verifying key for the verifier
batch_circuit_setup
Generates keys for multiple circuits simultaneously.&[&C]
Slice of circuits to generate keys for
Result<Vec<(ProvingKey, VerifyingKey)>>
Vector of proving and verifying key pairs
Proving Phase
prove
Generates a zero-knowledge proof for a single circuit.&UniversalProver<E>
Universal prover parameters
&FS::Parameters
Fiat-Shamir sponge parameters
&CircuitProvingKey<E, SM>
Circuit-specific proving key
VarunaVersion
Protocol version (V1 or V2)
&C
The circuit constraints to prove
&mut R
Cryptographically secure random number generator
Result<Proof<E>>
Zero-knowledge proof
prove_batch
Generates a batch proof for multiple circuit instances.&BTreeMap<&ProvingKey, &[C]>
Map from proving keys to constraint instances
Result<Proof<E>>
Batch proof covering all instances
Verification Phase
verify
Verifies a zero-knowledge proof.&UniversalVerifier<E>
Universal verifier parameters
&CircuitVerifyingKey<E>
Circuit-specific verifying key
B
Public input to the circuit
&Proof<E>
The proof to verify
Result<bool>
True if the proof is valid, false otherwise
verify_batch
Verifies a batch proof covering multiple instances.&BTreeMap<&VerifyingKey, &[B]>
Map from verifying keys to public inputs
Result<bool>
True if the batch proof is valid
Key Structures
CircuitProvingKey
Contains all information needed to generate proofs.CircuitVerifyingKey
Contains information needed to verify proofs.Proof
The zero-knowledge proof structure.Certificate
Proof that indexing was performed correctly.Algebraic Holographic Proof (AHP)
AHPForR1CS
The AHP compiler that reduces R1CS to polynomial protocols.Key Methods
index
Indexes a circuit for proving.prover_rounds
Executes prover rounds of the AHP protocol.verifier_rounds
Executes verifier rounds of the AHP protocol.Protocol Versions
VarunaVersion Enum
- V1: Original Varuna protocol
- V2: Optimized version with improved batch verification
SNARKMode Trait
DefaultMode
Standard proving mode.RecursiveMode
Mode optimized for recursive proof composition.Complete Example
Performance Considerations
- Batch proving amortizes costs across multiple circuit instances
- Parallel prover utilizes all available CPU cores
- Lazy evaluation defers expensive computations until needed
- Memory efficiency uses streaming where possible
See Also
- Cryptographic Hash Functions - Fiat-Shamir transformation
- Polynomial Commitments - Commitment scheme
- FFT Operations - Polynomial arithmetic