Skip to main content
This example demonstrates how to generate and verify zero-knowledge proofs using SnarkVM’s SNARK implementation.

Overview

When you execute a transaction in SnarkVM, a zero-knowledge proof is automatically generated to prove the computation was performed correctly. This example shows how to:
  1. Execute a program and generate a proof
  2. Extract the proof from the transaction
  3. Verify the proof independently

Complete example

Step by step

1

Create and deploy a program

Deploy a simple program that adds two numbers and squares the result.
2

Execute with proof generation

When you call vm.execute, SnarkVM automatically:
  1. Compiles the program to an R1CS constraint system
  2. Generates a witness (the intermediate values)
  3. Creates a SNARK proof using Varuna
3

Verify the proof

Verification checks that:
  • The proof is valid
  • The program exists and matches the claimed ID
  • All constraints are satisfied
  • The computation was performed correctly
4

Extract proof details

Each transition in the execution contains a proof that can be extracted and inspected.

What is proven?

The zero-knowledge proof demonstrates:
  1. Correctness: The output was computed correctly from the inputs
  2. Program execution: The specified program was executed
  3. Input knowledge: The prover knows private inputs that satisfy the constraints
All without revealing:
  • The private input values (5 and 3)
  • The intermediate computation steps
  • The final output value (64)

Proof properties

Succinctness

Proofs are small (~1-2 KB) regardless of computation complexity

Fast verification

Verification takes milliseconds even for complex computations

Zero-knowledge

No information about private inputs is revealed

Non-interactive

No back-and-forth communication required

Manual proof generation

For advanced use cases, you can generate proofs manually:

Performance characteristics

Typical proving and verification times on modern hardware:
  • Proof generation: 100-500ms for simple programs
  • Proof verification: 10-50ms
  • Proof size: 1-2 KB regardless of computation
Complex programs with many constraints take longer but remain practical.

Common verification errors

The proof doesn’t satisfy the constraints. This usually indicates:
  • Tampered proof data
  • Incorrect program execution
  • Mismatched verifying key
The program ID in the transaction doesn’t match any deployed program:
The witness doesn’t satisfy all constraints. This shouldn’t happen with properly generated proofs but can occur if:
  • The circuit is under-constrained
  • There’s a bug in the program logic

Advanced: Batch verification

Verify multiple proofs efficiently:
SnarkVM’s Varuna SNARK supports native batch verification for improved performance when verifying many proofs.

Next steps

Zero-knowledge proofs

Deep dive into how ZK proofs work in SnarkVM

SNARK algorithms

API reference for Varuna SNARK implementation