Skip to content

Latest commit

Β 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 

Repository files navigation

ZK-ID-Verifier

A zero-knowledge proof-based identity verification system built with Circom and Solana. This project enables privacy-preserving identity verification where users can prove they know their credentials without revealing the actual ID or password.

πŸ” Overview

ZK-ID-Verifier uses zero-knowledge proofs (ZKP) to verify user identities on the Solana blockchain. The system leverages the Poseidon hash function within a Circom circuit to create cryptographic proofs that validate user credentials without exposing sensitive information.

Key Features

  • Privacy-Preserving: Verify identity without revealing credentials
  • Zero-Knowledge Proofs: Built using Circom circuits and Groth16 proving system
  • Solana Integration: On-chain verification using a custom Solana program
  • Poseidon Hashing: Efficient cryptographic hashing optimized for ZK circuits
  • Verifiable Credentials: Generate and verify cryptographic proofs of identity

πŸ—οΈ Architecture

The project consists of three main components:

  1. Circom Circuit (id-verifier.circom)

    • Implements the identity verification logic
    • Uses Poseidon hash function for efficient ZK-friendly hashing
    • Takes user ID and password as private inputs
    • Verifies against an expected hash
  2. Input Generator (generate_input.js)

    • JavaScript utility to generate test inputs
    • Creates Poseidon hash of ID and password
    • Outputs formatted JSON for circuit witness generation
  3. Solana Program (Zkp.rs)

    • On-chain verification program written in Rust
    • Validates ZK proofs on Solana blockchain
    • Manages verification records using PDAs (Program Derived Addresses)
    • Prevents double verification

πŸ“‹ Prerequisites

  • Node.js (v14 or higher)
  • Rust (latest stable version)
  • Circom (v2.2.2 or higher)
  • SnarkJS (for proof generation and verification)
  • Solana CLI (for deploying the on-chain program)

πŸš€ Installation

  1. Clone the repository

    git clone https://github.com/yourusername/zk-id-verifier.git
    cd zk-id-verifier
  2. Install Node.js dependencies

    cd circom
    npm install circomlibjs ethers
  3. Install Circom compiler

    # Follow instructions at https://docs.circom.io/getting-started/installation/
  4. Install Rust and Solana CLI

    # Install Rust
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
    # Install Solana CLI
    sh -c "$(curl -sSfL https://release.solana.com/stable/install)"

πŸ”§ Usage

1. Generate Test Inputs

cd circom
node generate_input.js

This creates input/input.json with sample ID, password, and expected hash.

2. Compile the Circuit

circom id-verifier.circom --r1cs --wasm --sym

This generates:

  • id-verifier.r1cs - Rank-1 Constraint System
  • id-verifier.wasm - WebAssembly witness generator
  • id-verifier.sym - Symbol file for debugging

3. Generate Witness

cd id-verifier_js
node generate_witness.js id-verifier.wasm ../input/input.json ../witness.wtns

4. Trusted Setup (Powers of Tau)

# Download or generate powers of tau
snarkjs powersoftau new bn128 12 pot12_0000.ptau -v
snarkjs powersoftau contribute pot12_0000.ptau pot12_0001.ptau --name="First contribution" -v
snarkjs powersoftau prepare phase2 pot12_0001.ptau pot12_final.ptau -v

5. Generate Proving and Verification Keys

snarkjs groth16 setup id-verifier.r1cs pot12_final.ptau id-verifier_0000.zkey
snarkjs zkey contribute id-verifier_0000.zkey id-verifier_final.zkey --name="Contribution" -v
snarkjs zkey export verificationkey id-verifier_final.zkey verifier_key.json

6. Generate Proof

snarkjs groth16 prove id-verifier_final.zkey witness.wtns proof.json public.json

7. Verify Proof (Off-chain)

snarkjs groth16 verify verifier_key.json public.json proof.json

8. Deploy Solana Program

# Build the Solana program
cargo build-bpf

# Deploy to devnet
solana program deploy target/deploy/zkp.so --url devnet

πŸ“ Project Structure

zk-id-verifier/
β”œβ”€β”€ circom/
β”‚   β”œβ”€β”€ id-verifier.circom          # Main circuit definition
β”‚   β”œβ”€β”€ generate_input.js           # Input generation script
β”‚   β”œβ”€β”€ Zkp.rs                      # Solana verification program
β”‚   β”œβ”€β”€ circuits/
β”‚   β”‚   └── circomlib/              # Circom library (Poseidon, etc.)
β”‚   β”œβ”€β”€ input/
β”‚   β”‚   └── input.json              # Generated test inputs
β”‚   β”œβ”€β”€ id-verifier_js/             # Compiled WASM witness generator
β”‚   β”œβ”€β”€ proof.json                  # Generated ZK proof
β”‚   β”œβ”€β”€ public.json                 # Public inputs
β”‚   β”œβ”€β”€ verifier_key.json           # Verification key
β”‚   └── Cargo.toml                  # Rust workspace configuration
└── README.md

πŸ”¬ How It Works

Circuit Logic

The IDVerifier circuit performs the following steps:

  1. Takes three inputs:

    • id (private): User's identifier
    • password (private): User's password
    • expectedHash (public): Expected Poseidon hash
  2. Computes Poseidon([id, password])

  3. Verifies that the computed hash matches the expected hash

  4. Generates a zero-knowledge proof that the verification succeeded

Solana Program

The on-chain program:

  1. Receives a ZK proof and verification key
  2. Validates the proof using Groth16 verification
  3. Creates a verification record PDA for the user
  4. Stores verification status and timestamp
  5. Prevents duplicate verifications

πŸ”‘ Security Considerations

  • Private Inputs: ID and password never leave the client
  • Zero-Knowledge: Proofs reveal nothing about the actual credentials
  • Immutable Records: Verification records are stored on-chain
  • Replay Protection: Each user can only verify once
  • Trusted Setup: Requires a secure multi-party computation ceremony

πŸ› οΈ Development

Running Tests

# Test Rust program
cd circom
cargo test

Modifying the Circuit

  1. Edit id-verifier.circom
  2. Recompile the circuit
  3. Regenerate proving/verification keys
  4. Update the Solana program if needed

πŸ“ License

This project uses the Circom compiler which is licensed under GPL-3.0. See the circom/COPYING file for details.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“š Resources

⚠️ Disclaimer

This is a demonstration project. For production use, ensure proper security audits and use production-grade trusted setup ceremonies.

πŸ“§ Contact

For questions or support, please open an issue on GitHub.


Built with ❀️ using Circom, Solana, and Zero-Knowledge Proofs

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages