🚩 Challenge #10 : ZKP - Aadhaar Verifier

⚠️ Important: Please complete Challenge #9 first if you haven't already, as it contains essential instructions related to all upcoming challenges.

🎫 Build Privacy-Preserving Verifiers using Zero-Knowledge Proofs (ZKP) on Arbitrum Stylus:

👷‍♀️ In this challenge, you'll explore a frontend that uses the Anon Aadhaar SDK to verify identity without revealing sensitive information. For advanced users, you can optionally deploy smart contracts to an Arbitrum Stylus dev node for custom verification logic. 🚀

🌟 The final deliverable is a privacy-preserving Aadhaar identity verification application that uses zero-knowledge proofs.

How ZKP Integration Works

This project leverages Zero-Knowledge Proofs (ZKPs) to enable private verification of Aadhaar identity:

  1. Anon Aadhaar SDK: We integrate Anon Aadhaar, a privacy-preserving protocol for proving Aadhaar identity through zero-knowledge proofs.
  2. Frontend Integration: The Next.js frontend uses the Anon Aadhaar SDK for QR code verification and selective disclosure of identity information.
  3. Advanced (Optional): For those wanting to modify the underlying circuits, verification keys can be exported to Solidity contracts that run on Arbitrum Stylus, allowing on-chain verification of zk-proofs.

This integration ensures privacy (inputs remain off-chain) while providing cryptographic proof of identity.

Checkpoint 0: 📦 Environment Setup 📚

Before starting, ensure you have the following installed:

Clone the Repository

git clone -b stylus-zkp-anon-aadhaar https://github.com/abhi152003/speedrun_stylus.git
cd speedrun_stylus

Install Dependencies

Run the following command to install all necessary dependencies:

yarn install

Checkpoint 1: 🚀 Start Your Dev Environment

Start the Frontend Application

Navigate to the nextjs folder and start the development server:

⚠️ Before running the frontend:

Go to the packages/nextjs directory:

cd packages/nextjs
cp .env.example .env

Open the .env file and set:

NEXT_PUBLIC_RPC_URL=http://localhost:8547
NEXT_PUBLIC_PRIVATE_KEY=0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659
cd packages/nextjs
yarn run dev

The app will be available at http://localhost:3000/anon-aadhaar.

Note: The app works out-of-the-box with the Anon Aadhaar SDK. You don't need to run a local Stylus node unless you want to modify the underlying ZK circuits and verifier contracts.

Checkpoint 2: 💫 Explore the Features

Anon Aadhaar Verifier

  • Purpose: Verify identity information from an Aadhaar QR code without revealing all personal data.
  • Implementation: Uses the Anon Aadhaar SDK to verify Aadhaar QR codes and generate zero-knowledge proofs.
  • Privacy-Preserving: Users choose which fields to reveal (age, gender, pincode, state) while keeping other information private.

Key features:

  • Toggle between test mode and production mode for different QR code validation
  • Select specific fields to reveal while keeping others private
  • View detailed proof information, including the Groth16 ZK proof components

Image Visit http://localhost:3000/anon-aadhaar to try the Anon Aadhaar Verifier.

Advanced (Optional): 🛠 Deploying to a Local Arbitrum Stylus Node

If you want to dive deeper into ZKP circuits or deploy custom verification contracts, follow these steps:

Step 1: Start the Nitro Dev Node

  1. Ensure Docker is running on your machine. You can start Docker Desktop if it's not already running.

  2. Navigate to the cargo-stylus folder:

    cd packages/cargo-stylus
    
  3. Run the run-dev-node.sh script:

    bash run-dev-node.sh
    

    This script:

    • Spins up an Arbitrum Stylus Nitro dev node in Docker.
    • Deploys the verifier contracts.
    • Generates the ABI for interacting with the contracts.

The dev node will be accessible at http://localhost:8547.

Step 2: Modify and Deploy Custom Contracts

For the Anon Aadhaar verification, refer to the Anon Aadhaar documentation for customizing its behavior.

To see how the ZK circuits work under the hood, explore the circuits in the Anon Aadhaar repository's circuit folder.

Deploy new contracts by placing them in packages/cargo-stylus/contracts and running:

bash run-dev-node.sh

🛠️ Debugging Tips

Fixing Line Endings for Shell Scripts on Windows (CRLF Issue)

If you encounter errors like Command not found, convert line endings to LF:

sudo apt install dos2unix
dos2unix run-dev-node.sh
chmod +x run-dev-node.sh

Run the script again:

bash run-dev-node.sh

Checkpoint 3: 🚢 Ship your frontend! 🚁

To deploy your app to Vercel:

vercel

Follow Vercel's instructions to get a public URL.

For production deployment:

vercel --prod

🚀 Deploying to Arbitrum Sepolia

If you want to deploy your Balance Checker contract to the Arbitrum Sepolia testnet, follow these steps:

  1. Add private key to the .env file in the cargo-stylus folder

    PRIVATE_KEY=your_private_key_of_your_ethereum_wallet
    
  2. Run the Sepolia Deployment Script

    cd packages/cargo-stylus/zkp_balance_checker
    bash run-sepolia-deploy.sh
    

    This will deploy your contract to Arbitrum Sepolia and output the contract address and transaction hash.

    If you encounter errors like Command not found, convert line endings to LF:

    sudo apt install dos2unix
    dos2unix run-sepolia-deploy.sh
    chmod +x run-sepolia-deploy.sh
    
  3. Configure the Frontend for Sepolia

    • Go to the packages/nextjs directory:
      cd packages/nextjs
      cp .env.example .env
      
    • Open the .env file and set the following variables:
      NEXT_PUBLIC_RPC_URL=https://sepolia-rollup.arbitrum.io/rpc
      NEXT_PUBLIC_PRIVATE_KEY=your_private_key_of_your_ethereum_wallet
      
      Replace your_private_key_of_your_ethereum_wallet with your actual Ethereum wallet private key (never share this key publicly).
  4. Start the Frontend

    yarn run dev
    

    Your frontend will now connect to the Arbitrum Sepolia network and interact with your deployed contract.


🏆 Credits and Acknowledgements

This project uses the following open-source technology:

🏁 Next Steps

  • Explore other zk-proof applications for privacy-preserving verification
  • Add more identity verification options
  • Implement on-chain credential issuance based on successful verifications
  • Integrate with decentralized identity frameworks

Explore more challenges or contribute to this project!

🏃 Head to your next challenge here.