Skip to content

madmecodes/zkp-age-verification-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Zero-Knowledge Proof Voting Demo

A complete, production-ready Zero-Knowledge Proof (ZKP) system using Noir and Barretenberg, implementing age verification for voting eligibility.

Project Goal

Demonstrate how someone can prove they're 18+ years old without revealing their actual age or birth year - using a complete Zero-Knowledge Proof system with cryptographic proof generation and verification.

Project Structure

zkp-voting-demo/
└── age_verification/        # Main ZKP project
    ├── src/main.nr          # The ZKP circuit (Noir code)
    ├── Prover.toml          # Prover inputs (private + public)
    ├── Verifier.toml        # Verifier inputs (public only)
    ├── COMMANDS.md          # Complete command reference
    ├── README.md            # Usage guide
    ├── QUICKSTART.md        # Quick start guide
    ├── ARCHITECTURE.md      # System architecture & concepts
    ├── ACIR_ANALYSIS.md     # Advanced: ACIR format analysis
    └── ZKP_TRUST_MODEL.md   # Understanding security and trust

Quick Start

cd age_verification

# See all available commands
cat COMMANDS.md

# Run the complete workflow
nargo test && nargo compile && nargo execute && \
bb prove --scheme ultra_honk -b ./target/age_verification.json -w ./target/age_verification.gz -o ./target/ && \
bb write_vk -b ./target/age_verification.json -o ./target/ && \
bb verify -k ./target/vk -p ./target/proof

Documentation Structure

Start here to learn:

  • Installation (Noir + Barretenberg)
  • Running the complete workflow
  • Testing the circuit
  • Modifying inputs
  • Understanding the output

Complete command reference:

  • Step-by-step commands
  • File flow diagrams
  • Command summary tables
  • Quick reference

Deep dive into:

  • System architecture diagrams
  • Front-end vs Back-end
  • Key ZKP concepts explained
  • Circuit design principles
  • Data flow visualization
  • Barretenberg integration

4. ACIR Analysis (Advanced)

Understanding the compiled circuit:

  • ACIR file structure
  • How Noir code becomes arithmetic gates
  • Barretenberg's usage of ACIR
  • Circuit complexity analysis

Understanding security and trust:

  • Why proofs cannot be tampered
  • How server trusts client-generated proofs
  • Comparison with biometric authentication
  • Real-world ZKP applications

Learning Path

Beginner

  1. Read the Usage Guide
  2. Review Commands Reference
  3. Experiment with different inputs in Prover.toml

Intermediate

  1. Study the circuit code: src/main.nr
  2. Read Architecture Guide
  3. Modify the circuit to add new constraints
  4. Run nargo test to verify your changes

Advanced

  1. Understand ACIR output: target/age_verification.json (see ACIR_ANALYSIS.md)
  2. Analyze cryptographic proofs and verification keys
  3. Deploy to blockchain platforms with Solidity verifiers
  4. Build your own ZKP circuits

Key Concepts Covered

Concept Description Where to Learn
Circuit Mathematical representation of the problem src/main.nr
Arithmetization Converting logic to math constraints ARCHITECTURE.md
Witness Private + public inputs that satisfy constraints Prover.toml
ACIR Intermediate Representation (backend-agnostic) target/*.json
Front-End Circuit definition (Noir DSL) src/main.nr
Back-End Proof generation & verification (Barretenberg) ARCHITECTURE.md
Proof Cryptographic proof of correct computation target/proof
Verification Key Public key for verifying proofs target/vk

Prerequisites

Required

1. Install Noir (ZKP Circuit Language)

# Install noirup
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash

# Reload your shell
source ~/.zshrc  # or source ~/.bashrc

# Install Noir (stable version)
noirup -v 1.0.0-beta.3

# Verify installation
nargo --version

2. Install Barretenberg (Proving Backend)

# Install bbup
curl -L https://raw.githubusercontent.com/AztecProtocol/aztec-packages/refs/heads/master/barretenberg/bbup/install | bash

# Reload your shell
source ~/.zshrc  # or source ~/.bashrc

# Install Barretenberg (auto-detects compatible version)
bbup

# Verify installation
bb --version

Note: bbup automatically detects your Noir version and installs the compatible Barretenberg version.

Optional (for blockchain integration)

  • Solidity: For blockchain verifiers
  • Web3 tools: For blockchain integration

Example Use Cases

Beyond age verification, this pattern can be used for:

  1. Anonymous Voting

    • Prove eligibility without revealing identity
    • Our example shows age verification
  2. Private Credentials

    • Prove qualifications without revealing details
    • E.g., "I have a degree" without showing which one
  3. Compliance Proofs

    • Prove regulatory compliance
    • Without revealing sensitive business data
  4. Income Verification

    • Prove income range (e.g., $50k-$100k)
    • Without revealing exact salary
  5. Credit Scores

    • Prove score > 700
    • Without revealing exact score

Architecture Overview

┌──────────────────────────────────────────────────┐
│           FRONT-END (Circuit Definition)         │
│                    Noir                          │
│  Noir DSL → Arithmetization → Circuit → ACIR   │
│     ↓            ↓               ↓         ↓     │
│  main.nr    Constraints     main() func   .json  │
└────────────────────┬─────────────────────────────┘
                     │
                     │ ACIR (Intermediate Representation)
                     │
┌────────────────────┴─────────────────────────────┐
│         BACK-END (Proving System)                │
│              Barretenberg                        │
│  Witness → Proof Generation → Verification      │
│     ↓              ↓                 ↓           │
│  Inputs       ZK Proof          Valid/Invalid   │
│              (~14KB)            (< 1 second)     │
└──────────────────────────────────────────────────┘

This is a complete system with:

  • ✅ Circuit definition (Noir)
  • ✅ Cryptographic proof generation (Barretenberg)
  • ✅ Proof verification (Barretenberg)
  • ✅ Production-ready

See ARCHITECTURE.md for detailed diagrams!

Testing

cd age_verification

# Run all tests
nargo test

# Test specific scenarios
# Edit src/main.nr to uncomment failure cases
nargo test

Test cases included:

  • Valid voter (30 years old)
  • Exactly 18 years old
  • Edge case (100 years old)
  • Under 18 (failure test - commented)
  • Future birth year (failure test - commented)

Project Stats

Metric Value
Circuit Complexity Simple (17 ACIR opcodes, 2778 gates)
Constraints 3 main assertions
Test Cases 3 passing + 3 failure examples
Lines of Code ~100 (heavily commented)
Proof Size ~14KB
Verification Key Size ~1.8KB
Proof Generation Time ~15 seconds
Verification Time < 1 second
Learning Time 1-2 hours

What You'll Learn

After working through this project, you'll understand:

  1. ZKP Fundamentals

    • What are Zero-Knowledge Proofs?
    • How do they maintain privacy?
    • When to use them?
  2. Circuit Design

    • How to define constraints
    • Private vs public inputs
    • Arithmetization process
  3. Noir Language

    • Syntax and structure
    • Testing circuits
    • Compilation to ACIR
  4. System Architecture

    • Front-end vs Back-end separation
    • Role of Intermediate Representation
    • Proof generation workflow
    • Barretenberg proving system
  5. Practical Application

    • Complete cryptographic proof lifecycle
    • Real-world use cases
    • Integration patterns
    • Production deployment

Resources

Official Documentation

Community

Related Technologies

  • Circom: Alternative ZKP DSL
  • Cairo: StarkNet's language
  • ZoKrates: Ethereum-focused toolkit

Contributing

This is an educational project. Contributions welcome:

  • Improve documentation
  • Add more examples
  • Create tutorials
  • Fix issues

License

Educational project for learning Zero-Knowledge Proofs.

Acknowledgments

  • Noir Team: For the amazing DSL
  • Aztec: For ZKP infrastructure
  • ZKP Community: For advancing privacy technology

Get Started

cd age_verification

# See available commands
cat COMMANDS.md

# Run complete workflow
nargo test && nargo compile && nargo execute && \
bb prove --scheme ultra_honk -b ./target/age_verification.json -w ./target/age_verification.gz -o ./target/ && \
bb write_vk -b ./target/age_verification.json -o ./target/ && \
bb verify -k ./target/vk -p ./target/proof

Documentation:

About

Learning guide for new users in Zero-Knowledge Proof systems

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages