This is a full-stack decentralized application implementing a Secret Voting System using a Commit-Reveal scheme on Hyperledger Fabric.
Note: Network is located in github.com/aleferu/voting-network.
The system ensures fairness and secrecy in voting by separating the process into two phases:
- Commit Phase: Voters submit a hash of their vote (Salt + Option + Weight). The actual vote remains secret.
- Reveal Phase: Once the campaign target weight is reached, the Manager moves the campaign to the Reveal phase. Voters then submit their actual option and secret salt to verify their committed hash.
- Blockchain Network (
../voting-network): A 6-Org Fabric network. Org1-5 are Voters, Org6 is the Election Manager. link. - Smart Contract (
chaincode-go): Implements the business logic for Campaigns, Votes, Status transitions, and Results tallying. - Backend (
application-go): A Go REST API that interacts with the Fabric Gateway to submit/evaluate transactions and connects to MySQL for user authentication. - Database (
database): A MySQL container storing user credentials (usernames and bcrypt password hashes) and roles. - Frontend (
frontend): A simple HTML/JS web interface for Managers and Voters.
- Docker and Docker Compose.
- Go (v1.20+).
- The
voting-networkmust be running.
Follow these steps to run the complete system.
The system uses a local MySQL database for managing user logins.
cd ../voting-system/database
./create-db.shThis starts a MySQL container and initializes the schema with default users:
- Manager:
manager_org6 - Voters:
voter_org1,voter_org2,voter_org3,voter_org4,voter_org5
Note: Initial passwords are unset. You will set them on first launch.
The backend connects to both the Fabric network (using certificates generated while setting up the network) and the MySQL database.
cd ../application-go
go mod tidy
go run .The server will start on http://localhost:8080.
Open your browser and go to http://localhost:8080.
- On the first visit, you will be prompted to set passwords for the Manager and all Voters.
- Provide strong passwords. These are stored securely (hashed) in the local MySQL database.
- Login as
manager_org6(Role: Manager). - Create Campaign: Define a unique ID, Name, Options, and assign voting weights to Org1-Org5. Total weight must equal 100,000.
- Monitor: Watch the "Total Committed Weight".
- Phase Change: Once votes are committed, click "Move to Reveal Phase".
- Finalize: After the reveal phase is over, click "Close Campaign & Tally" to see the winner.
- Login as a voter (e.g.,
voter_org1). - Commit Vote:
- Select an active campaign (Status: OPEN).
- Choose an option.
- The system generates a random Secret Key (Salt).
- Download the Receipt! You MUST keep the
vote-receipt-....jsonfile. You cannot reveal your vote without it.
- Reveal Vote:
- Wait for the Manager to move the campaign to the REVEAL phase.
- Select the campaign.
- Select the option you voted for.
- Upload your Secret Key Receipt.
- Submit to reveal your vote on the ledger.
application-go/: Backend logic.main.go: HTTP handlers and DB logic.fabric.go: Fabric Gateway connection logic.
chaincode-go/: Smart contract.voting.go: Main chaincode logic.
database/: Docker Compose for MySQL, the schema, and some utility bash scripts.frontend/: Static web assets (index.html,manager.html,voter.html).clean.sh: Script to remove docker containers for the chaincode. Useful when developing changes.erase.sh: Deep clean script (Network, DB, Images).