Skip to content

BigRishi/bt03

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” ZK Credential Verification System

A privacy-preserving credential verification platform built on Ethereum using Zero-Knowledge Proofs. Issuers can issue digital credentials on-chain, holders can prove ownership without revealing sensitive data, and verifiers can validate credentials trustlessly.

Solidity React Hardhat License


๐Ÿš€ Features

  • Issuer Dashboard โ€” Register as a trusted authority and issue credentials on-chain
  • Holder Dashboard โ€” View credentials and generate zero-knowledge proofs
  • Verifier Dashboard โ€” Verify proofs on-chain without accessing personal data
  • ZK Proof Generation โ€” Prove credential ownership without revealing private data
  • On-Chain Verification โ€” Smart contract validates proofs cryptographically
  • MetaMask Integration โ€” Auto-connects to the correct blockchain network
  • Immutable Audit Trail โ€” Every verification is recorded on the blockchain

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚        React Frontend            โ”‚
โ”‚  (Issuer / Holder / Verifier)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚ ethers.js + MetaMask
               โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     Ethereum Blockchain          โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  CredentialRegistry.sol    โ”‚  โ”‚
โ”‚  โ”‚  (Issue, Revoke, Verify)   โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                โ”‚ calls            โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  Groth16Verifier.sol       โ”‚  โ”‚
โ”‚  โ”‚  (ZK Proof Verification)   โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“‚ Project Structure

blockchain/
โ”œโ”€โ”€ contracts/
โ”‚   โ”œโ”€โ”€ CredentialRegistry.sol    # Credential management + ZK verification
โ”‚   โ””โ”€โ”€ Groth16Verifier.sol       # ZK-SNARK proof verifier
โ”œโ”€โ”€ circuits/
โ”‚   โ””โ”€โ”€ credential.circom         # Circom ZK circuit (Poseidon hash)
โ”œโ”€โ”€ scripts/
โ”‚   โ””โ”€โ”€ deploy.js                 # Contract deployment + ABI export
โ”œโ”€โ”€ test/
โ”‚   โ””โ”€โ”€ CredentialRegistry.test.js
โ”œโ”€โ”€ frontend/
โ”‚   โ””โ”€โ”€ src/
โ”‚       โ”œโ”€โ”€ components/           # Issuer, Holder, Verifier dashboards
โ”‚       โ”œโ”€โ”€ utils/                # WalletContext, zkUtils
โ”‚       โ””โ”€โ”€ App.js                # Router + contract loading
โ”œโ”€โ”€ hardhat.config.js
โ””โ”€โ”€ package.json

โšก Quick Start

Prerequisites

1. Install Dependencies

cd blockchain
npm install
cd frontend
npm install
cd ..

2. Start Local Blockchain (Terminal 1)

npx hardhat node

3. Deploy Contracts (Terminal 2)

npx hardhat run scripts/deploy.js --network localhost

4. Start Frontend (Terminal 3)

cd frontend
npm start

5. Configure MetaMask

The app auto-switches MetaMask to the Hardhat network. Just click Connect and approve.

  • Network: Hardhat Local
  • RPC URL: http://127.0.0.1:8545
  • Chain ID: 31337

๐ŸŽฎ Usage Flow

1. ISSUER    โ†’  Register  โ†’  Issue credential (hash stored on-chain)
2. HOLDER    โ†’  Enter secret + data  โ†’  Generate ZK Proof  โ†’  Copy/Download
3. VERIFIER  โ†’  Paste proof JSON  โ†’  Verify on-chain  โ†’  Valid โœ“ / Invalid โœ—

Key Concept: The verifier confirms the credential is authentic without ever seeing the credential data. Only a cryptographic proof is verified.


๐Ÿ”’ How Zero-Knowledge Proofs Work Here

Holder knows: secret + credentialData
              โ†“
Computes:     hash = Poseidon(secret, credentialData)
              โ†“
Generates:    ZK Proof โ†’ "I know the preimage of this hash"
              โ†“
Verifier:     Checks proof on-chain โ†’ Valid/Invalid
              (never learns secret or credentialData)

๐Ÿงช Smart Contracts

CredentialRegistry.sol

Function Description
selfRegisterIssuer(name) Register as a credential issuer
issueCredential(hash, holder, type, uri) Issue a credential on-chain
revokeCredential(hash) Revoke a credential
verifyCredentialProof(hash, a, b, c, input) Verify a ZK proof on-chain
getHolderCredentials(address) Get all credentials for a holder

Groth16Verifier.sol

Verifies that ZK proof elements are cryptographically linked, ensuring forged proofs are rejected.


๐Ÿงช Running Tests

npx hardhat test
  CredentialRegistry
    โœ“ should auto-register deployer as issuer
    โœ“ should allow self-registration as issuer
    โœ“ should prevent duplicate issuer registration
    โœ“ should issue a credential
    โœ“ should prevent non-issuers from issuing
    โœ“ should prevent duplicate credentials
    โœ“ should track holder credentials
    โœ“ should allow issuer to revoke
    โœ“ should prevent non-issuer from revoking

  9 passing

๐Ÿ› ๏ธ Tech Stack

Technology Purpose
Solidity 0.8.19 Smart contracts
Circom 2.0 ZK circuit definition
Hardhat Ethereum dev framework
React 18 Frontend UI
Ethers.js v6 Blockchain interaction
MetaMask Wallet & transaction signing
SnarkJS ZK proof generation

๐Ÿ“„ License

MIT


Built with โค๏ธ using Ethereum, Zero-Knowledge Proofs, and React