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.
3.2 KiB
3.2 KiB
Voting Setup Issue - Solution
Problem
Users cannot vote because:
- Elections don't have ElGamal encryption keys (
elgamal_p,elgamal_g) - 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:
# 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
- Go to http://localhost:8081
- Login:
- Server:
mariadb - User:
evoting_user - Password:
evoting_pass123 - Database:
evoting_db
- Server:
- Click on
electionstable - Edit each row and set:
elgamal_p= 23elgamal_g= 5
Option 3: Fresh Database Reset
# 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:
# 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:
docker/init.sql- Creates elections withelgamal_p = 23, elgamal_g = 5docker/populate_past_elections.sql- Inserts past elections (no ElGamal params)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:
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:
- Users can register normally
- Users can see active elections
- Frontend can fetch public keys for voting
- Encrypted voting works
- Blockchain records votes
Testing After Fix
# 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
- Clear browser cache (Ctrl+Shift+Delete)
- Restart frontend container:
docker compose restart frontend - Rebuild frontend if config changed:
docker compose up -d --build frontend - Check backend logs:
docker compose logs backend | grep -i error - Check browser console for errors (F12)