Cryptographically verifiable elections using immudb and Golang
Valentin, one of our engineers started a nice side project to show the possibilities of immudb. His goal is to showcase a website that provides a secure way for elections.
Powered by immudb
The main feature is that the voting platform built on immudb is automatically verified by everyone who visits the website! So immudb could run on an untrusted system, but the amount of users visiting the website makes it impossible to manipulate the data unnoticed.
- Electronic voting system allowing anyone to act as an auditor and (cryptographically) verify that the election data has not been tampered.
- The cryptographic verification, a.k.a the consistency proof, is achieved by leveraging the core features of immudb. It is based on multiple Merkle Trees.
If you just want to go ahead and visit the GitHub project: https://github.com/padurean/immuvoting
Continue reading to get some more information about how it works.
The verification Go code
The code gets compiled to WASM and resides in the VerifyConsistency function.
In it’s definition the code is split in 5 steps (there are comments in the code, marking each step):
- Get the local state which was persisted to local storage during a previous run
- Get the current server (immudb) state by sending a GET /state request to the immuvoting REST server. NOTE: when interracting with immudb directly, through an SDK, the CurrentState method must be used instead
- Get a verifiable transaction between the local and current states by sending a GET /verifiable-tx to the immuvoting REST server. NOTE:when interracting with immudb directly, through an SDK, the VerifiableTXByID method must be used instead
- Use the verifiable transaction to do the actual verification. This will run only in the client browser, with no other interraction with the server. Show the result of the verification in the UI; OK or Tampered
- If the verification passed, persist the fresh state from the server (obtained at step 2.) to local storage (overwrite the previous one), otherwise do nothing (keep the last non-tampered state in local storage)
To compile the verification code to WebAssembly
- Compile as WASM, outputing to the client folder:
GOOS=js GOARCH=wasm go build -o ../client/verifier.wasm ./verifier/verifier.go*
- Make sure wasm_exec.js is present in the client folder. If it’s not there, copy it from your Go distribution:
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" ./client/
Short demo video
How to run it
A modern browser (the web interface uses relatively new HTML and ES6 features - e.g. the
Fire it up!
NOTE: immuvoting will try to connect to it using default config:
defaultdb and default credentials (have a look in server/main.go for more details)
from immuvoting's server folder run:
go get ./...
go run .to start the HTTP API server (backend)
a separate HTTP server needs to be started to serve the frontend (in the client folder) - e.g. if using VSCode, you can just use it's Go Live feature; or you can use any other solution, like
python -m SimpleHTTPServer.
That's all. You can now access the fronted at http://localhost:<xxx>.
NOTE: Port number depends on the HTTP server you used: default port for VSCode's Go Live it's
5500, for python's
- The cryptographic verification of the election data (a.k.a. the consistency proof or tampering proof) is written in Go and it's code resides in server/verifier/verifier.go.
How it works: Consistency proofs and Merkle Trees
- The cryptographic verification, a.k.a the consistency proof, is achieved by leveraging the core features of immudb.
It is based on Merkle Trees.