ZeroKnowledgeVoting is a demo application showcasing a zero-knowledge voting system using zk-SNARKs. It allows voters to cast votes anonymously while ensuring the integrity of the voting process. Results are displayed in real-time. This project leverages zkVerify's public, permissionless ZK-proof verification blockchain to enhance trust and transparency.
This project aligns with the zkVerify Hackathon’s objectives by:
- Leveraging zkVerify: It uses zkVerify’s Groth16 verifier on the BN-254 curve to validate zero-knowledge proofs.
- Promoting Decentralization: Demonstrates a real-world use case of decentralized proof verification for secure and anonymous voting.
- Innovative Application: Showcases how ZKPs can enhance trust, privacy, and transparency in democratic processes.
- Ensure Node.js is installed. The demo has been tested with Node.js v23.3.0.
- You need wallets funded with:
- ACME tokens for zkVerify operations.
- Sepolia ETH for Ethereum transactions.
-
Clone the repository:
git clone [email protected]:zkPikachu/ZeroKnowledgeVoting.git
-
Navigate to the project directory:
cd ZeroKnowledgeVoting
-
Move to the
contracts
folder:
cd contracts
-
Set up environment variables:
- Create a
.env
file usingenv.template
as an example:cp env.template .env
- Create a
-
Navigate to the
src
folder and find thezkVote.sol
smart contract. This contains the Solidity code for your voting Smart Contract. -
Visit Remix Ethereum IDE and ensure your wallet is connected to the Sepolia Testnet.
-
Copy
zkVote.sol
code and paste it into a new file in Remix. -
Set Constructor Parameters:
- In
zkVote.sol
, the constructor requires:_zkvContract
: The address of the zkVerify contract._vkHash
: The verification key hash for your circuit.
- These parameters are stored in your
.env
file in your project foldercontracts
.
-
Deploy the Contract to Sepolia and copy the deployed contract address. Ensure the Ethereum address used to deploy the contract is the one you’re using for the app (
ETH_SECRET_KEY
should be the private key for that address). -
Paste the contract address into the
.env.template
file in your app folder asETH_APP_CONTRACT_ADDRESS
-
Move to the
app
folder:
cd ../../app
- Set up environment variables:
- Create a
.env
file usingenv.template
as an example:cp env.template .env
- Create a
.env.secrets
file usingenv.secrets.template
as an example:cp env.secrets.template .env.secrets
- In
.env.secrets
:ZKV_SEED_PHRASE
: The seed phrase of a wallet with sufficient ACME tokens.ETH_SECRET_KEY
: The secret key of an Ethereum wallet with sufficient Sepolia ETH.
- In
- Install dependencies:
npm install
- Initialize the voting poll:
npm run init-poll
- This command registers voters from
voterRegistry.json
and generates thevoterMapping.json
file. You can vote using one of the account addresses listed invoterRegistry.json
.
- Start the application:
npm start
- Open the application in your browser:
- To cast a vote, go to: http://localhost:3000
- To view voting results, go to: http://localhost:3001
This process submits a transaction to the App Contract, including the necessary attestation details obtained from ZKVerify (such as the attestation ID and Merkle path). Upon successful submission and validation, the App Contract confirms and acknowledges that your vote has been casted.
- Voting: Enter your account address (from
voterRegistry.json
) and choose a candidate to cast your vote. - Results: View the real-time voting results on the results page.
ZKV_RPC_URL="wss://testnet-rpc.zkverify.io"
ETH_RPC_URL="https://ethereum-sepolia-rpc.publicnode.com"
ETH_ZKVERIFY_CONTRACT_ADDRESS=0x209f82A06172a8d96CF2c95aD8c42316E80695c1
ETH_APP_CONTRACT_ADDRESS=0x2719FB1f292C434305cefe52d82e2A53CecDcF85
ZKV_SEED_PHRASE="your wallet seed phrase with ACME tokens"
ETH_SECRET_KEY=your ethereum wallet private key starting with 0x
- Ensure your wallets are sufficiently funded before running the application.
- For more information, refer to the source code or contact the repository owner.
-
App:
- The Node.js backend handles proof generation, verification, and interaction with the blockchain.
- Provides APIs for vote submission and results display.
-
Frontend:
- Web-based UI built using HTML and JavaScript for casting votes and viewing results.
-
zk-SNARK Circuit:
- Written in
circom
, the circuit enforces rules such as verifying Merkle paths, vote commitments, and nullifiers. - Uses
groth16
as the proving system.
- Written in
-
zkVote Smart Contract:
- A Solidity contract deployed on the Ethereum blockchain.
- Integrates with the zkVerify platform for off-chain proof verification and ensures rules like no double voting.
This project is licensed under the MIT License.