Skip to content

aleferu/voting-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Secret Voting System

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.

Overview

The system ensures fairness and secrecy in voting by separating the process into two phases:

  1. Commit Phase: Voters submit a hash of their vote (Salt + Option + Weight). The actual vote remains secret.
  2. 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.

Architecture

  • 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.

Prerequisites

  1. Docker and Docker Compose.
  2. Go (v1.20+).
  3. The voting-network must be running.

Getting Started

Follow these steps to run the complete system.

2. Initialize the Database

The system uses a local MySQL database for managing user logins.

cd ../voting-system/database
./create-db.sh

This 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.

3. Start the Application Backend

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.

4. Use the Application

Open your browser and go to http://localhost:8080.

Phase 1: Initial Setup

  1. On the first visit, you will be prompted to set passwords for the Manager and all Voters.
  2. Provide strong passwords. These are stored securely (hashed) in the local MySQL database.

Phase 2: Manager Workflow

  1. Login as manager_org6 (Role: Manager).
  2. Create Campaign: Define a unique ID, Name, Options, and assign voting weights to Org1-Org5. Total weight must equal 100,000.
  3. Monitor: Watch the "Total Committed Weight".
  4. Phase Change: Once votes are committed, click "Move to Reveal Phase".
  5. Finalize: After the reveal phase is over, click "Close Campaign & Tally" to see the winner.

Phase 3: Voter Workflow

  1. Login as a voter (e.g., voter_org1).
  2. 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-....json file. You cannot reveal your vote without it.
  3. 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.

Project Structure

  • 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).

About

CC code and web utility to interact in a secret voting system using Hyperledger Fabric

Topics

Resources

Stars

Watchers

Forks

Contributors