Skip to content

smilewithkhushi/simple-circuit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Simple Circuit: My First Zero Knowledge Proof Project

Welcome to my first project using Noir for generating zero knowledge proofs!


πŸ“‹ Project Overview

This project demonstrates a complete workflow for building, compiling, and verifying zero knowledge circuits using Noir. It serves as both a learning resource and a practical example for beginners.

Key Technologies

  • Language: Noir (.nr file extension)
  • Proving Backend: Barretenberg
  • Proving Scheme: ultra_honk
  • Project Type: Binary crate
  • Creator: Aztec Network

🎯 Your First Simple Circuit

Basic Circuit Example

fn main(x: Field, y: pub Field) {
    assert(x != y);
}

#[test]
fn test_circuit() {
    main(1, 2);
}

This circuit proves that you know a private value (x) that is not equal to a public value (y), without revealing x.

How It Works

  1. Private Input x: Only known to the prover
  2. Public Input y: Known to both prover and verifier
  3. Assertion: assert(x != y) creates a constraint
  4. Proof: Generates a zero knowledge proof that the constraint is satisfied

πŸ“ Repository Structure

simple_circuit/
β”œβ”€β”€ README.MD                      # This file - Project overview
β”œβ”€β”€ Basics.MD                      # Detailed guide to Noir basics & concepts
β”œβ”€β”€ NOIR_GUIDE.md                  # Complete guide to Noir language
β”œβ”€β”€ Nargo.toml                     # Project manifest
β”œβ”€β”€ Prover.toml                    # Input values for testing
β”œβ”€β”€ src/
β”‚   └── main.nr                    # Main circuit entry point
β”œβ”€β”€ 0. Installation/
β”‚   └── README.MD                  # Installation & setup guide for macOS/Windows
└── target/
    β”œβ”€β”€ simple_circuit.json        # Compiled circuit bytecode
    β”œβ”€β”€ simple_circuit.gz          # Witness file
    β”œβ”€β”€ vk                         # Verification key
    β”œβ”€β”€ proof                      # Generated proof
    └── public_inputs              # Public inputs

πŸš€ Quick Start

1. Install Dependencies

Follow the Installation Guide for:

  • macOS or Windows setup
  • Rust, Nargo, and Barretenberg installation
  • Verification of all tools

2. Understand the Basics

Read Basics.MD to learn:

  • Variable types in Noir
  • Input visibility (private vs public)
  • Testing functions
  • Complete workflow (check β†’ compile β†’ execute β†’ prove β†’ verify)

3. Learn the Language

Check NOIR_GUIDE.md for:

  • Language features and syntax
  • Common patterns
  • Best practices
  • Resources and documentation

4. Run Your First Proof

# 1. Check circuit structure
nargo check

# 2. Compile to ACIR
nargo compile

# 3. Execute to generate witness
nargo execute

# 4. Generate verification key
bb write_vk -b ./target/simple_circuit.json -o ./target

# 5. Generate proof
bb prove -b ./target/simple_circuit.json -w ./target/simple_circuit.gz -o ./target

# 6. Verify proof
bb verify -k ./target/vk -p ./target/proof

πŸ“– Documentation Files

File Purpose
README.MD (this file) Project overview and quick start
Basics.MD Detailed Noir basics, types, and workflow
NOIR_GUIDE.md Comprehensive Noir language guide
0. Installation/README.MD Step-by-step installation for macOS & Windows

πŸ” Understanding the Workflow

1. Nargo Check βœ“

  • Validates circuit structure
  • Creates Prover.toml for inputs

2. Nargo Compile πŸ“¦

  • Compiles Noir to ACIR (Arithmetic Circuit IR)
  • Creates circuit bytecode

3. Nargo Execute βš™οΈ

  • Executes circuit with test inputs
  • Generates witness file (simple_circuit.gz)
  • Stores witness in /target

4. BB Write VK πŸ”‘

  • Generates verification key from circuit
  • Creates vk file for proof verification

5. BB Prove 🎯

  • Uses Barretenberg to create proof
  • Combines circuit + witness
  • Outputs proof and public_inputs

6. BB Verify βœ…

  • Verifies proof off-chain
  • Uses verification key
  • Confirms proof validity without executing circuit

πŸ’‘ Key Learnings

About Noir

  • DSL for ZKPs: Designed specifically for zero knowledge proofs
  • Rust-like Syntax: Familiar to modern programmers
  • Type-Safe: Strong type system prevents errors
  • Backend Agnostic: Can compile to different proving systems

About Circuits

  • Private vs Public: Control input visibility
  • Assertions: Create constraints that must be satisfied
  • Witness: The satisfying assignment that proves the constraint
  • Proof: Cryptographic evidence without revealing witness

About Barretenberg

  • Ultra-Honk Scheme: Modern proving system
  • High Performance: Optimized for production use
  • Multi-threaded: Uses parallel processing for efficiency
  • Aztec-Built: Developed by Aztec for their privacy network

πŸ”§ Project Files Explained

Nargo.toml - Project Manifest

[package]
name = "simple_circuit"
type = "bin"
authors = ["Your Name"]
compiler_version = "0.21.0"
  • Type: bin means binary crate (executable)
  • Dependencies: Add libraries here as needed

Prover.toml - Test Inputs

x = "1"
y = "2"
  • Private Inputs: Values for x, z, etc.
  • Public Inputs: Values for pub parameters
  • Updated after each nargo execute

src/main.nr - Circuit Code

fn main(x: Field, y: pub Field) {
    assert(x != y);
}
  • Entry Point: Main circuit logic
  • Functions: Define circuit behavior
  • Tests: Validate circuit logic

πŸ“š Additional Resources

Official Documentation

Community


πŸŽ“ Next Steps

Beginner

  • βœ… Understand basic circuit structure
  • βœ… Learn input visibility (private vs public)
  • βœ… Generate your first proof
  • πŸ”² Write custom constraints

Intermediate

  • πŸ”² Build more complex circuits
  • πŸ”² Use cryptographic functions (SHA256, ECDSA)
  • πŸ”² Create reusable code patterns
  • πŸ”² Optimize circuit size

Advanced

  • πŸ”² Build library crates
  • πŸ”² Integrate with smart contracts
  • πŸ”² Create proving backends
  • πŸ”² Contribute to Noir ecosystem

πŸ’« About This Repository

This is a learning project for exploring:

  • Zero knowledge proof fundamentals
  • Noir programming language
  • Barretenberg proving system
  • ZK circuit development workflow

Feel free to fork, modify, and learn!


πŸ“ Notes

  • All examples use the BN254 elliptic curve (Barretenberg default)
  • Proofs are verified using ultra_honk scheme
  • Generated proofs are non-interactive and publicly verifiable
  • This project uses test inputs for demonstration

Last Updated: October 2025

For detailed guides, see:

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages