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:- Execute a program and generate a proof
- Extract the proof from the transaction
- Verify the proof independently
Complete example
Step by step
1
Create and deploy a program
2
Execute with proof generation
vm.execute, SnarkVM automatically:- Compiles the program to an R1CS constraint system
- Generates a witness (the intermediate values)
- Creates a SNARK proof using Varuna
3
Verify the proof
- 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
What is proven?
The zero-knowledge proof demonstrates:- Correctness: The output was computed correctly from the inputs
- Program execution: The specified program was executed
- Input knowledge: The prover knows private inputs that satisfy the constraints
- 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
Common verification errors
Invalid proof
Invalid proof
The proof doesn’t satisfy the constraints. This usually indicates:
- Tampered proof data
- Incorrect program execution
- Mismatched verifying key
Program not found
Program not found
The program ID in the transaction doesn’t match any deployed program:
Constraint violation
Constraint violation
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