Skip to content

Commit 7b9150c

Browse files
authored
Feat/evoting fixes (#303)
* chore: move blindvote in * chore: stash changes * chore: stash blindvote progress * feat: eVoting works * feat: control panel fixes
1 parent 71d40f2 commit 7b9150c

File tree

83 files changed

+8578
-2549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+8578
-2549
lines changed

control-panel.compose.yml

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,3 @@ services:
99
command: -config.file=/etc/loki/local-config.yaml
1010
networks:
1111
- loki
12-
13-
promtail:
14-
image: grafana/promtail:latest
15-
volumes:
16-
- /var/log:/var/log
17-
command: -config.file=/etc/promtail/config.yml
18-
networks:
19-
- loki
20-
21-
grafana:
22-
environment:
23-
- GF_PATHS_PROVISIONING=/etc/grafana/provisioning
24-
- GF_AUTH_ANONYMOUS_ENABLED=true
25-
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
26-
- GF_FEATURE_TOGGLES_ENABLE=alertingSimplifiedRouting,alertingQueryAndExpressionsStepMode
27-
entrypoint:
28-
- sh
29-
- -euc
30-
- |
31-
mkdir -p /etc/grafana/provisioning/datasources
32-
cat <<EOF > /etc/grafana/provisioning/datasources/ds.yaml
33-
apiVersion: 1
34-
datasources:
35-
- name: Loki
36-
type: loki
37-
access: proxy
38-
orgId: 1
39-
url: http://loki:3100
40-
basicAuth: false
41-
isDefault: true
42-
version: 1
43-
editable: false
44-
EOF
45-
/run.sh
46-
image: grafana/grafana:latest
47-
ports:
48-
- "3000:3000"
49-
networks:
50-
- loki

infrastructure/blindvote/README.md

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
# BlindVote - Decentralized Privacy-Preserving Voting System
2+
3+
A cryptographically secure voting system that uses Pedersen commitments to ensure voter privacy while maintaining public verifiability of election results.
4+
5+
## Key Features
6+
7+
- **Totally Decentralized**: No trusted servers or dealers needed
8+
- **Flexible Voting Options**: Support for any number of vote options (not just binary yes/no)
9+
- **Privacy Preserving**: Individual votes are never revealed
10+
- **Publicly Verifiable**: Anyone can verify the final election results
11+
- **Cryptographically Sound**: Uses ed25519 elliptic curve and proper Pedersen commitments
12+
- **Simple & Clean**: No complex ZK proofs - just the essential crypto operations
13+
14+
## Architecture
15+
16+
The system follows a simple 5-phase process:
17+
18+
1. **Registration**: Voters create public randomness anchors
19+
2. **Voting**: Voters submit encrypted ballots using Pedersen commitments
20+
3. **Aggregation**: All commitments are homomorphically combined
21+
4. **Tally**: Final results are computed from the aggregate commitment
22+
5. **Verification**: Anyone can verify the results are consistent
23+
24+
## Cryptographic Foundation
25+
26+
### Pedersen Commitments
27+
28+
- **Commitment**: `C(m, r) = g^m * h^r`
29+
- `g` = generator point
30+
- `h` = second generator (unknown discrete log relationship)
31+
- `m` = vote value
32+
- `r` = random blinding factor
33+
34+
### Homomorphic Properties
35+
36+
- **Addition**: `C(m1, r1) * C(m2, r2) = C(m1 + m2, r1 + r2)`
37+
- **Aggregation**: `C_agg = ∏ C_i = g^(∑m_i) * h^(∑r_i)`
38+
- **Cancellation**: `X = C_agg * H_S^(-1) = g^(∑m_i)`
39+
40+
## Project Structure
41+
42+
```
43+
src/
44+
├── core/
45+
│ ├── types.ts # Type definitions
46+
│ └── voting-system.ts # Main voting system implementation
47+
├── crypto/
48+
│ └── pedersen.ts # Pedersen commitment implementation
49+
└── examples/
50+
└── example.ts # Presidential election example
51+
```
52+
53+
## Quick Start
54+
55+
### Installation
56+
57+
```bash
58+
# Clone the repository
59+
git clone <repository-url>
60+
cd blindvote
61+
62+
# Install dependencies
63+
pnpm install
64+
65+
# Build the project
66+
pnpm build
67+
```
68+
69+
### Basic Usage
70+
71+
```typescript
72+
import { DecentralizedVotingSystem, ElectionConfig } from "blindvote";
73+
74+
// Create an election configuration
75+
const electionConfig: ElectionConfig = {
76+
id: "demo-election",
77+
title: "Demo Election",
78+
description: "A simple demonstration",
79+
options: [
80+
{ id: "option-a", label: "Option A", value: 1 },
81+
{ id: "option-b", label: "Option B", value: 2 },
82+
{ id: "option-c", label: "Option C", value: 3 },
83+
],
84+
};
85+
86+
// Initialize the voting system
87+
const votingSystem = new DecentralizedVotingSystem(electionConfig);
88+
89+
// Register voters
90+
await votingSystem.registerVoter("alice");
91+
await votingSystem.registerVoter("bob");
92+
93+
// Cast votes
94+
await votingSystem.castBallot("alice", "option-a");
95+
await votingSystem.castBallot("bob", "option-b");
96+
97+
// Aggregate and tally
98+
const result = await votingSystem.tally();
99+
console.log("Election result:", result);
100+
```
101+
102+
### Running Examples
103+
104+
```bash
105+
# Presidential election example
106+
node dist/examples/example.js
107+
```
108+
109+
## API Reference
110+
111+
### ElectionConfig
112+
113+
```typescript
114+
interface ElectionConfig {
115+
id: string; // Unique election identifier
116+
title: string; // Human-readable title
117+
description?: string; // Optional description
118+
options: VoteOption[]; // Available vote options
119+
maxVotes?: number; // Maximum votes per voter (default: 1)
120+
allowAbstain?: boolean; // Allow abstaining (default: false)
121+
}
122+
```
123+
124+
### VoteOption
125+
126+
```typescript
127+
interface VoteOption {
128+
id: string; // Unique option identifier
129+
label: string; // Human-readable label
130+
value: number; // Numeric value for the option
131+
}
132+
```
133+
134+
### DecentralizedVotingSystem
135+
136+
#### Core Methods
137+
138+
- `registerVoter(voterId: string): Promise<Anchor>` - Register a new voter
139+
- `castBallot(voterId: string, optionId: string): Promise<Ballot>` - Cast a vote
140+
- `aggregate(): Promise<AggregatedResults>` - Aggregate all ballots
141+
- `tally(): Promise<ElectionResult>` - Compute final results
142+
- `verifyTally(results, expected): Promise<boolean>` - Verify results
143+
144+
#### Utility Methods
145+
146+
- `getRegisteredVoters(): Anchor[]` - Get all registered voters
147+
- `getSubmittedBallots(): Ballot[]` - Get all submitted ballots
148+
- `isVoterRegistered(voterId): boolean` - Check voter registration
149+
- `hasVoterVoted(voterId): boolean` - Check if voter has voted
150+
151+
## Use Cases
152+
153+
### Multi-Candidate Elections
154+
155+
- Presidential elections
156+
- Board member elections
157+
- Award voting
158+
159+
### Preference Voting
160+
161+
- Ranked choice voting
162+
- Approval voting
163+
- Score voting
164+
165+
### Surveys and Polls
166+
167+
- Customer satisfaction surveys
168+
- Product preference polls
169+
- Team decision making
170+
171+
## Security Properties
172+
173+
1. **Vote Privacy**: Individual votes are never revealed
174+
2. **Vote Integrity**: Votes cannot be modified after submission
175+
3. **Voter Anonymity**: Voter identity is not linked to their vote
176+
4. **Public Verifiability**: Anyone can verify the final results
177+
5. **No Double Voting**: Each voter can only vote once
178+
6. **Decentralized**: No single point of failure or control
179+
180+
## Limitations & Considerations
181+
182+
### Current Implementation
183+
184+
- **Demo Tallying**: The current tally implementation simulates vote counting for demonstration
185+
- **No ZK Proofs**: Simplified version without zero-knowledge proofs
186+
- **Basic Validation**: Simple validation without advanced cryptographic proofs
187+
188+
### Production Considerations
189+
190+
- **Discrete Log Problem**: For large vote counts, discrete log computation becomes expensive
191+
- **Multi-Option Tallying**: Current scheme works best for binary or small-range voting
192+
- **Voter Authentication**: This implementation doesn't handle real-world voter authentication
193+
- **Network Layer**: No built-in networking or bulletin board implementation
194+
195+
## Future Enhancements
196+
197+
1. **Efficient Multi-Option Tallying**: Implement proper schemes for multi-option voting
198+
2. **Voter Authentication**: Add real-world voter identity verification
199+
3. **Network Layer**: Implement decentralized bulletin board
200+
4. **Advanced Privacy**: Add mix networks or other privacy enhancements
201+
5. **Scalability**: Optimize for large-scale elections
202+
203+
## Testing
204+
205+
```bash
206+
# Build the project
207+
pnpm build
208+
209+
# Run examples
210+
node dist/examples/example.js
211+
212+
# Run tests (if available)
213+
pnpm test
214+
```
215+
216+
## Technical Details
217+
218+
### Curve Choice: ed25519
219+
220+
- **Performance**: Faster than secp256k1 for most operations
221+
- **Security**: 128-bit security level
222+
- **Standardization**: Well-established and audited
223+
- **Implementation**: Uses @noble/curves library
224+
225+
### Commitment Scheme
226+
227+
- **Binding**: Computationally infeasible to find different messages with same commitment
228+
- **Hiding**: Commitment reveals no information about the message
229+
- **Homomorphic**: Commitments can be combined algebraically
230+
231+
## Contributing
232+
233+
1. Fork the repository
234+
2. Create a feature branch
235+
3. Make your changes
236+
4. Add tests if applicable
237+
5. Submit a pull request
238+
239+
## License
240+
241+
This project is licensed under the MIT License - see the LICENSE file for details.
242+
243+
## Disclaimer
244+
245+
This is a research and educational implementation. For production use, additional security audits, testing, and hardening would be required.
246+
247+
## References
248+
249+
- [Pedersen Commitments](https://en.wikipedia.org/wiki/Commitment_scheme#Pedersen_commitment)
250+
- [ed25519 Curve](https://ed25519.cr.yp.to/)
251+
- [Homomorphic Encryption](https://en.wikipedia.org/wiki/Homomorphic_encryption)
252+
- [Decentralized Voting](https://en.wikipedia.org/wiki/Electronic_voting#Decentralized_voting)
253+
254+
---
255+
256+
Built with love for transparent, secure, and democratic voting systems.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "blindvote",
3+
"version": "1.0.0",
4+
"description": "Privacy-preserving voting system using Pedersen commitments and zero-knowledge proofs",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"scripts": {
8+
"build": "tsc",
9+
"dev": "ts-node src/index.ts",
10+
"test": "jest",
11+
"example": "ts-node src/examples/example.ts",
12+
"postinstall": "npm run build"
13+
},
14+
"keywords": [
15+
"voting",
16+
"privacy",
17+
"zero-knowledge",
18+
"pedersen",
19+
"commitments"
20+
],
21+
"author": "",
22+
"license": "ISC",
23+
"devDependencies": {
24+
"@types/jest": "^29.0.0",
25+
"@types/node": "^20.0.0",
26+
"jest": "^29.0.0",
27+
"ts-jest": "^29.0.0",
28+
"ts-node": "^10.9.0",
29+
"typescript": "^5.0.0"
30+
},
31+
"dependencies": {
32+
"@noble/curves": "^1.9.7",
33+
"@noble/hashes": "^1.8.0",
34+
"tiny-invariant": "^1.3.3"
35+
}
36+
}

0 commit comments

Comments
 (0)