From 5652ff2c8ac3beb471e143b8799f940de0f503e5 Mon Sep 17 00:00:00 2001 From: Alexis Bruneteau Date: Fri, 7 Nov 2025 03:15:02 +0100 Subject: [PATCH] docs: Add voting setup troubleshooting guide Documents the issue where elections are missing ElGamal encryption parameters which are required for the voting system to work. Provides 3 options to fix: 1. Database SQL update 2. Adminer UI 3. Fresh database reset Explains root cause and how to verify the fix worked. --- e-voting-system/VOTING_SETUP_ISSUE.md | 136 ++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 e-voting-system/VOTING_SETUP_ISSUE.md diff --git a/e-voting-system/VOTING_SETUP_ISSUE.md b/e-voting-system/VOTING_SETUP_ISSUE.md new file mode 100644 index 0000000..2707ec8 --- /dev/null +++ b/e-voting-system/VOTING_SETUP_ISSUE.md @@ -0,0 +1,136 @@ +# Voting Setup Issue - Solution + +## Problem + +Users cannot vote because: +1. Elections don't have ElGamal encryption keys (`elgamal_p`, `elgamal_g`) +2. The voting interface fails when trying to get public keys + +## Root Cause + +The database initialization script `docker/create_active_election.sql` didn't set the ElGamal parameters, even though the init.sql had `elgamal_p = 23, elgamal_g = 5`. + +## Fix + +### Option 1: Fix via Database (Recommended) + +Connect to the database and update the elections with ElGamal parameters: + +```bash +# Connect to MariaDB +docker compose exec mariadb mariadb -u evoting_user -pevoting_pass123 evoting_db + +# Run this SQL: +UPDATE elections SET elgamal_p = 23, elgamal_g = 5; + +# Verify: +SELECT id, name, elgamal_p, elgamal_g FROM elections LIMIT 5; + +# Exit +exit +``` + +### Option 2: Use Adminer UI + +1. Go to http://localhost:8081 +2. Login: + - Server: `mariadb` + - User: `evoting_user` + - Password: `evoting_pass123` + - Database: `evoting_db` +3. Click on `elections` table +4. Edit each row and set: + - `elgamal_p` = 23 + - `elgamal_g` = 5 + +### Option 3: Fresh Database Reset + +```bash +# Stop and remove all data +docker compose down -v + +# Start fresh +docker compose -f docker-compose.multinode.yml up -d + +# Wait 40 seconds for initialization +sleep 40 + +# Verify elections have keys +curl http://localhost:8000/api/elections/debug/all | jq '.elections[0] | {id, name, elgamal_p, elgamal_g}' +``` + +## Verify Fix Worked + +After fixing, test: + +```bash +# Check election keys are set +curl http://localhost:8000/api/elections/debug/all | jq '.elections[0] | {id, name, elgamal_p, elgamal_g}' + +# Should show: +# { +# "id": 1, +# "name": "...", +# "elgamal_p": 23, +# "elgamal_g": 5 +# } + +# Get public keys (should work now) +curl http://localhost:8000/api/votes/public-keys?election_id=1 | jq '.' +``` + +## Why This Happened + +The SQL scripts do this: +1. `docker/init.sql` - Creates elections with `elgamal_p = 23, elgamal_g = 5` +2. `docker/populate_past_elections.sql` - Inserts past elections (no ElGamal params) +3. `docker/create_active_election.sql` - **Updates** election 1 but lost the ElGamal params + +The UPDATE statement in step 3 didn't preserve the ElGamal parameters. They should be: + +```sql +UPDATE elections +SET + is_active = TRUE, + start_date = DATE_SUB(NOW(), INTERVAL 1 HOUR), + end_date = DATE_ADD(NOW(), INTERVAL 7 DAY), + elgamal_p = 23, + elgamal_g = 5 +WHERE id = 1; +``` + +## After Fix + +Once elections have ElGamal keys: + +1. Users can register normally +2. Users can see active elections +3. Frontend can fetch public keys for voting +4. Encrypted voting works +5. Blockchain records votes + +## Testing After Fix + +```bash +# 1. Check keys are set +curl http://localhost:8000/api/votes/public-keys?election_id=1 + +# 2. Open frontend +http://localhost:3000 + +# 3. Register (if needed) +# 4. Login +# 5. Click "Participer" on an election +# 6. Select a candidate +# 7. Submit vote + +# Should see success message with transaction ID +``` + +## If Still Not Working + +1. Clear browser cache (Ctrl+Shift+Delete) +2. Restart frontend container: `docker compose restart frontend` +3. Rebuild frontend if config changed: `docker compose up -d --build frontend` +4. Check backend logs: `docker compose logs backend | grep -i error` +5. Check browser console for errors (F12)