Submissions
The **Decentralized Voting System** built on **Sui** is designed to facilitate secure, transparent, and efficient on-chain elections. It handles everything from voter registration to election management, candidate management, vote casting, and result tallying. Here’s a breakdown of the key aspects: ### Key Errors - **ENotAdmin**: Only the admin can perform certain actions. - **EVoterAlreadyRegistered**: Ensures voters cannot register twice. - **ENotAuthorized**: Ensures actions like updating voter details are only performed by the correct user. - **EVoteAlreadyCasted**: Prevents double voting. - **ECandidateNotExists**: Ensures that only valid candidates can receive votes. - **EInvalidElectionState**: Validates the state of an election before certain operations. - **ENoVotesToRevoke**: Prevents revoking a vote if none were cast. ### Key Structs 1. **VotingSystem**: The core of the system, tracking voters, elections, and the admin in charge. 2. **Voter**: Represents voters with fields for their address, voting status, and history of elections they’ve voted in. 3. **Election**: Stores election data such as candidates, vote counts, start/end times, and the state (upcoming, ongoing, or ended). 4. **Candidate**: Represents candidates with a unique ID and name. 5. **VoteCount**: Tracks the vote count for each candidate in an election. 6. **VoteCastedEvent**: Event that is emitted whenever a vote is cast, providing transparency and traceability. ### Voting Process 1. **Voter Registration**: Admin registers voters using their unique address. This ensures only registered users can vote. 2. **Create Election**: Admin creates a new election with a name, start time, and end time. 3. **Add Candidates**: Admin can add multiple candidates to an election. Each candidate has a unique ID and name. 4. **Vote Casting**: During the election period, registered voters can cast their votes. A voter can only vote once, and their vote is stored in their history. 5. **Tally Votes**: Once the election ends, the votes are tallied automatically by counting how many votes each candidate received. 6. **End Election**: Admin can end the election, preventing further votes from being cast and allowing tallying to proceed. ### Other Functions - **Revoke Vote**: Voters can revoke their vote before the election ends, reducing the candidate's vote count. - **Verify Voter**: A helper function to check if an address is a registered voter. - **Election Details**: Retrieves details of an election, including the list of candidates, their names, and the current state of the election. - **Get Election Results**: After an election ends, results can be retrieved showing the vote count for each candidate. ### Transparency and Security - The system is designed to be **admin-driven** for managing elections, but voters have autonomy over casting and revoking their votes. - The **VoteCastedEvent** ensures transparency, as every vote action is logged and can be traced on-chain. - The voting history and election state management ensure that elections follow a strict lifecycle (upcoming, ongoing, ended) with appropriate checks in place to prevent unauthorized actions at any stage. This system is robust and ensures secure and verifiable elections for organizations or DAOs using the Sui blockchain.
Dacade is an open-sourced platform and is created in collaboration with multiple contributors. Go to the repository to start contributing.