Building a Cryptographically Verifiable Referendum System

A binary referendum (such as a Leave/Remain or Yes/No vote) presents a fundamental cryptographic paradox: voter privacy requires that nobody can see how an individual voted, while public verifiability requires that everyone can independently verify that the final tally is accurate. How can we achieve both? It turns out that three well-understood building blocks do the heavy lifting: Partially Homomorphic Encryption (PHE), Zero-Knowledge Proofs (ZKPs), and Threshold Decryption. In this post, we’ll explore how to build a secure, verifiable referendum system using LightPHE—a multi-language library that supports robust PHE schemes including EC ElGamal, Exponential ElGamal, Paillier, and Damgard-Jurik with Python, Golang, Java and TypeScript languages.

European Union flag with a missing star, illustrating a Leave/Remain referendum
European Union flag with missing stars representing Brexit concept by pexels

The Cryptographic Blueprint

A secure e-voting workflow requires four essential phases:


🙋‍♂️ You may consider to enroll my top-rated cryptography course on Udemy

Cryptography Basiscs From Scratch In Python

  1. Setup & Threshold Key Generation: A dealer generates a key pair, publishes the public key, and splits the private key into shares for independent trustees using a threshold scheme (e.g., any 2 out of 3 trustees must cooperate to decrypt). The dealer then forgets the private key—LightPHE drops it right after the split. Note that the dealer does know the whole key while splitting it, so the dealer must be trusted during setup. After that, no single party holds the key, which removes the single point of failure or corruption.
  2. Encrypted Ballots with ZKPs: Voters cast binary votes ($1$ for Leave, $0$ for Remain). Along with the ciphertext, each voter attaches a Zero-Knowledge Proof that is bound to their voter ID. Ballots and proofs are published on a public bulletin board. This ensures:
    • Validity: Ballots must strictly be $0$ or $1$ (preventing malformed votes such as $5$, which would count as five votes), and anyone can check this without decrypting a single ballot.
    • Replay Protection: If an adversary (like Mallory) copies Alice’s valid ballot and submits it as their own, the proof fails verification, because it is bound to Alice’s ID, not Mallory’s.
  3. Homomorphic Tallying: Anyone can aggregate the valid encrypted ballots from the bulletin board using the homomorphic property of the cryptosystem—adding ciphertexts together without ever decrypting individual votes. Since everyone can recompute the encrypted tally, nobody has to trust the counting server.
  4. Threshold Decryption: Any 2 trustees decrypt the final tally partially, each with their own share, and attach a proof that their partial decryption is honest. Anyone can combine the partial decryptions and verify the proofs. The result is the number of Leave votes; Remain votes are the rest of the valid ballots.

Multi-Language Implementation

LightPHE provides the same cryptosystems and the same API shape across Python, Go, Java, and TypeScript, so a voter app, a bulletin board and the trustees can each run on a different stack and still interoperate. Below is the whole referendum pipeline in all four languages.

  • Python – LightPHE – is the reference implementation, ideal for prototyping, research and data pipelines.
  • Go – lightphe-go – fits backend services such as a bulletin board that verifies thousands of ballots, with explicit error handling on every step.
  • Java – lightphe4j – is available on Maven Central for JVM-based enterprise systems (Java 17+).
  • TypeScript – lightphe-ts – runs in Node.js and in the browser, so ballots can be encrypted on the voter’s own device before they ever leave it.

Notice that the dealer’s cryptosystem is never used to decrypt anything. After generate_threshold_keys, it no longer has the private key, and a single trustee cannot decrypt the tally either—LightPHE refuses to combine fewer than 2 valid partial decryptions. Java snippets use assert for brevity, so run them with -ea to enable assertions.

What If a Trustee Cheats?

Threshold decryption spreads the trust, but it doesn’t make trustees honest. Suppose the three trustees are nominated by competing campaigns. Without proofs, a trustee can send a tampered partial decryption and shift the final result by any amount it chooses—for example, quietly add 50 votes to its own side—because the Lagrange coefficients of the other trustees are public. The forged tally would be accepted silently.

That’s why each trustee calls partial_decrypt(tally, prove = True), and the combiner calls combine_partial_decryptions(tally, partials, verify = True). The proof shows that the partial decryption was computed with the trustee’s own share. A tampered partial decryption fails verification and is discarded, so the cheater is caught and outvoted by the honest trustees. Anyone can also check a single trustee’s work with verify_partial_decryption to find out exactly who cheated.

Why This Architecture Matters

  1. Protection Against Copied Ballots: The Zero-Knowledge Proof is bound to a context, the voter’s ID. When Mallory submits a copy of Alice’s ballot under her own ID, verification fails. Keep in mind that the context is just a public string: this only works if the bulletin board authenticates voters, accepts a ballot only for the ID of the authenticated voter, and accepts at most one ballot per ID. The proof stops copying; authentication stops impersonation.
  2. Decentralized Trust: Once the dealer forgets the key, no single rogue administrator, trustee or compromised server can decrypt individual ballots or peek at the outcome early. The guarantee holds as long as fewer than the threshold number of trustees collude: any 2 of the 3 trustees together could decrypt a single ballot, so choose trustees with competing interests.
  3. A Publicly Verifiable Tally: Every ballot proof, every partial decryption proof and the encrypted tally itself can be checked by anyone with the public key. Nobody has to take the election authority’s word for the result.
  4. Cross-Language Parity: Whether your core infrastructure runs on Python data scripts, Go microservices, Java enterprise apps, or TypeScript web services, LightPHE implements the same underlying math with the same API shape across all four languages.

What This Design Does Not Cover

Cryptography solves the tallying part of an election, not the whole election. To be honest about the limits:

  • Voter Authentication: Deciding who is eligible to vote, and making sure each person votes once, is outside of the cryptosystem. The bulletin board must handle it.
  • Trusted Dealer: The dealer knows the private key during setup. If that is not acceptable, the trustees need to generate the key together with a distributed key generation protocol, so the full key never exists in one place.
  • Coercion and Vote Selling: A voter can reveal the randomness used to encrypt their ballot and prove to a third party how they voted. Preventing this (receipt-freeness) requires additional techniques beyond this design.
  • Compromised Voter Devices: The proof shows that a ballot is 0 or 1, not that it is the choice the voter intended. Malware on the voter’s device could encrypt the opposite vote.

Conclusion & Key Takeaways

By combining Partially Homomorphic Encryption, Zero-Knowledge Proofs, and Threshold Decryption, we resolved the core voting paradox: individual ballots stay private, while the tally is publicly verifiable by anyone, and no single party—not even a trustee—can decrypt a ballot or forge the result alone.

Choosing the Right PHE Cryptosystem

LightPHE supports multiple PHE schemes that offer both threshold decryption and the proofs above, allowing you to tailor your voting infrastructure based on performance and payload requirements:

  • Exponential ElGamal: Ideal for small-range tallies (like binary referendums) with low bandwidth overhead and efficient ZKP generation. Keys must be generated with prime_order = True for threshold decryption and proofs.
  • EC ElGamal: Best for resource-constrained client environments (e.g., mobile apps) requiring small key sizes and fast performance. No extra key parameters are needed.
  • Paillier & Damgard-Jurik: Superior choice when working with large scalar arithmetic or multi-candidate additive aggregation without discrete logarithm limitations during decryption. Keys must be generated with safe_primes = True so that trustees can prove their partial decryptions.

Other additive algorithms in LightPHE—like Okamoto-Uchiyama, Benaloh, and Naccache-Stern—can also sum encrypted votes. However, they lack two critical features for a secure election:

  1. No Ballot Proofs: LightPHE cannot generate 0/1 membership proofs for these algorithms. This means a dishonest voter could encrypt a value like 5 instead of 1, effectively casting five votes undetected.
  2. No Threshold Decryption: These schemes do not support threshold keys, meaning a single private key holder could decrypt any individual ballot and destroy voter privacy.

Without ballot proofs and threshold decryption, you cannot run a secure election.

What’s Next?

A binary referendum is the simplest form of homomorphic aggregation (0 vs 1). However, real-world elections often have more than two options. In our next post, we will expand this architecture from binary referendums to Multi-Party Elections—demonstrating how to encode a vote for one of many parties so that a single encrypted tally counts every party at once, and how one-hot ballot vectors remove the limit on the number of parties.


Support this blog financially if you do like!

Buy me a coffee      Buy me a coffee


Leave a Reply