Skip to main content

Overview

The snark 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 the SNARK 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
Note: In production, the SRS is loaded from trusted setup parameters, not generated. Example:

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
Example:

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
Example:

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
Example:

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
Example:

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