A secure and anonymous governance voting system leveraging Zero-Knowledge (ZK) proofs on the Cosmos blockchain.
Cosmos ZK Voting is a governance voting system designed to ensure voter anonymity while maintaining the integrity and security of the voting process. Utilizing Zero-Knowledge proofs, this system allows voters to participate in governance without revealing their identities, fostering a more private and secure voting environment.
- Anonymous Voting: Protects voter identities using Zero-Knowledge proofs.
- Decentralized: Built on the Cosmos blockchain for enhanced security and scalability.
- Secure Key Management: Ensures the safety of prover and verifier keys.
- dispatcher Support: Facilitates seamless vote transactions through a dedicated dispatcher service.
- Flexible Proposal Management: Create and manage governance proposals with ease.
Follow the steps below to set up and run Cosmos ZK Voting locally.
git clone https://github.com/vitwit/cosmos-zk-gov
git fetch
git checkout main
Build and install the zkappd
binary required to run the Cosmos ZK Voting chain.
make install
Initialize and start a local testnet.
- Initialize and Start the Chain:
Modify thescripts/init-zkgovapp.sh
script according to your requirements.
make init-zkgovapp
will the run chain.
make init-zkgovapp
Before setting up the chain, generate the ZK prover and verifier keys.
Create Keys Directory:
mkdir keys
- Generate ZK Keys:
make generate-zk-keys
- This command runs the
groth16.setup()
function defined in/x/zkgov/client/zk/main.go
.
Note: Multiple prover and verifier key pairs are generated (e.g.,verifier-2
,verifier-3
,verifier-4
, etc.) to accommodate varying Merkle proof sizes. Use the appropriate key pair dynamically as needed.
- Optimize Merkle Implementation: Aim for a constant Merkle tree size of 2^31 and improve update operations from O(n) to O(log n).
The Dispatcher is an HTTP server that listens for vote transactions, signs them with a valid chain address, and broadcasts them on-chain.
Vote transactions must be sent from a different, unlinkable address than the registered address. Since most users may not have multiple unlinkable addresses, the dispatcher serves as an intermediary to handle this securely.
Security Assurance: The Dispatcher cannot manipulate transactions because the ZK proof guarantees transaction validity without exposing user secrets.
1.Start the dispatcher:
zkappd tx zk-gov run-dispatcher --from {key} --keyring-backend test --chain-id {chain-id} -y
Alternatively, you can run a predefined dispatcher (e.g., alice):
make run-alice-dispatcher
- This command starts an HTTP server on port
8080
by default. You can change the port using the--dispatcherPort {port}
flag.
Create a new governance proposal that can be voted on with a YES or NO.
Note: This implementation is basic and intended for testing. A more robust system is recommended for production use.
Proposal ID: Starts at 1 and increments sequentially.
zkappd tx zk-gov create-proposal [proposal-title] [proposal-description] --from [address] --keyring-backend test --chain-id [chain-id]
Or use a make command for convenience:
make create-proposal-a
Create Commitments Directory:
mkdir commitments
Register a vote commitment, which will be used later to anonymize the actual vote.
zkappd tx zk-gov register-vote [proposal-id] {"YES"/"NO"} --from [actual-voter-address] --keyring-backend test --chain-id [chain-id]
Alternatively, use predefined make commands:
make register-alice-vote
make register-bob-vote
make register-charlie-vote
make register-david-vote
After registering a vote commitment, generate a ZK proof to cast the actual vote. This proof verifies that you know the valid commitment without revealing your identity.
Important: The vote transaction must be signed by a different, unlinkable address from the one used to register the vote commitment. Use the dispatcher to facilitate this process.
zkappd tx zk-gov vote [proposal-id] [register-vote-address] --from [different-unlinkable-address] --keyring-backend test --chain-id [chain-id]
Or use make commands:
make broadcast-alice-vote
make broadcast-bob-vote
zkappd tx zk-gov vote [proposal-id] [register-vote-address] --dispatcher [dispatcher-address]
Or use make commands:
make broadcast-charlie-vote-via-dispatcher
make broadcast-david-vote-via-dispatcher
View the state of a proposal, including commitments and votes.
zkappd q zk-gov get-proposal-info [proposal-id]
Contributions are welcome! Please fork the repository and submit a pull request for any enhancements or bug fixes.
This project is licensed under the MIT License.
For questions or support, please open an issue on the GitHub repository or reach out to [email protected].