The idea behind this project was to build a very simple interactive cli-application, to test what I'm currently learning in rust.
Quadratic voting is a collective decision-making procedure that allows participants to express not just their preferences, but also the intensity of those preferences. Unlike traditional voting where each person gets one vote per issue, quadratic voting allows voters to allocate multiple "credits" to issues they care about most.
Key Principle: The cost of votes increases quadratically, but the voting power increases linearly.
- 1 vote costs 1 credit
- 2 votes cost 4 credits
- 3 votes cost 9 credits
- And so on...
This system ensures that while people can express strong preferences on issues they care deeply about, they cannot simply "buy" elections due to the increasing marginal cost.
- 🗳️ Quadratic Voting Logic: Implements the mathematical foundation of quadratic voting
- 👥 Voter Registration: Register multiple participants in a voting session
- 📋 Proposal Management: Add and manage voting proposals
- 💰 Credit System: Each voter gets allocated credits to spend on proposals
- 📊 Results Tracking: View detailed voting results and individual vote breakdowns
- 🖥️ Interactive CLI: User-friendly command-line interface for easy interaction
- ✅ Session Management: Control when voting sessions start and end
- Rust (1.70.0 or later)
- Cargo package manager
- Clone or download this repository
- Navigate to the project directory:
cd quadratic-voting-rs- Build the project:
cargo build --releasecargo runThe application provides a simple menu-driven interface:
-
Register as a Voter (Option 1)
- Enter your name to register
- You'll be assigned a voter ID and receive the default credits (100)
-
Vote on Proposals (Option 2)
- Enter your voter ID
- Select a proposal ID (0, 1, or 2 for the default proposals)
- Specify how many credits you want to spend
- Your vote power will be calculated as the square root of credits spent
-
View Results (Option 3)
- See all proposals with their total vote counts
- View individual voter contributions to each proposal
-
Exit (Option 4)
- Quit the application
The application comes with three pre-configured proposals:
- Scroll meetup - Organise a scroll meetup
- Aztec dev workshop - Organise an aztec zk workshop for developers
- Ethereum Layer 2 Discussion - Host a discussion about Ethereum Layer 2 scaling solutions
cargo testsrc/lib.rs- Core quadratic voting logic and data structuressrc/main.rs- Interactive CLI applicationtests/unit_tests.rs- Unit tests for core functionality
- Session: Manages the overall voting session and coordinates all components
- Proposal: Represents voting proposals with titles, descriptions, and vote tallies
- Voter: Represents registered voters with allocated credits
- Vote: Records individual vote transactions and credit expenditure
The quadratic voting formula ensures fair representation:
- Vote Power = √(Credits Spent)
- Total Cost = (Desired Votes)²
This creates a natural balance where intense preferences can be expressed, but at increasing cost, preventing vote buying while allowing meaningful preference expression.
- Allow users to update/modify votes after casting
- Add data persistence (save/load sessions)
- Improve input validation and error messages
- Add more comprehensive tests (include un-happy paths)
- Add Gherkin style comments in tests
- No Role Authorisation
- No Data Persistence: All data is lost when the application exits
- Fixed Proposals: Proposals are hard-coded and cannot be changed during runtime
- No Vote Updates: Voters cannot modify their votes once cast
- Basic Input Validation: Limited error checking for user inputs