Skip to content

Private voting

View Markdown

DAOs, community treasuries and project councils increasingly vote on-chain, and on a public ledger every ballot is tied to an address. That invites vote buying (“show me your transaction and I’ll pay you”), social pressure from peers and employers, and whales watching the count before they decide. What you want is a vote where eligibility and one-person-one-vote can be checked by anyone, but nobody can tell who voted for what, and only the final result is ever revealed.

Private voting · step 1 / 5
Organizerbuilds the voter list
pk1pk2pk3pk4pk5you
voterRootPUBLIC0x4500…8fbe
electionIdPUBLICZeroJ DAO Proposal #1
election key PK (3 trustees)PUBLIC0x8a53…ff7f

5 voters registered. The demo's tree has depth 10 (1,024 slots).

Your deviceA votervoter3identity hidden
secretKeySECRETHIDDEN0xd018…806e████████
Merkle pathSECRETHIDDEN10 sibling hashes████████
voteSECRETHIDDEN████████
randomness k (fresh)SECRETHIDDEN0xb2f4…1085████████
nullifier = Poseidon(secretKey, electionId)PUBLIC0x19e2…d741
ballot (A, B) = Enc(PK, vote)PUBLICA 0xc6e8…066e B 0x9762…4f0d
πGroth16 proof192 bytes

Second ballot, No: same key, so the same nullifier.

CardanoPlutus V3 scripts
VoteZkMintingPolicyGroth16 proof validbefore the voting deadlinemints 1 token named nullifier
VoteListValidator · nullifier → ballot
  1. 0x19e2…d741inserted
  2. 0x1e82…e9c6
  3. 0x7c51…fb29
2 ballots so far (voter1, voter2)insert fails: already in the list
Tally · after the deadlineanyone adds the 3 ballots, still encryptedthe 3 trustees decrypt only the total, once
2 Yes1 No

Which voter cast which ballot, and how each one voted: unknown.

1. Register

The organizer collects each voter's public key, Poseidon(secretKey, 0), builds a Merkle tree and publishes only the root and the election ID. Three trustees publish the election key that ballots are encrypted to. Your secret key stays on your device.

2. Prove

Your device computes your nullifier, encrypts your vote to the election key with fresh randomness, and proves three things at once: your key is on the list, the nullifier is yours, and the ballot holds a 0 or a 1. Switch to Public view: the vote never leaves the device in the clear.

3. Submit

The transaction carries the 192-byte proof and a new list node holding your nullifier and ballot. The minting policy takes the election ID, voter root and election key from its own parameters, the ballot from that node, verifies the proof before the deadline, and mints one token named after the nullifier. The list validator inserts the node between its sorted neighbours.

4. Vote again

A second ballot from the same key, even with a different choice, has the same nullifier. It's already in the list, so the insert fails and the transaction is rejected. A different key would give a new nullifier, but that key isn't in the tree.

5. Tally

After the deadline anyone adds the encrypted ballots, and the trustees decrypt only that total, once, with proofs that they did it honestly. Nobody learns who cast which ballot or how any one voter voted. The encrypted tally walkthrough below shows the count step by step.

SECRET never leaves the voter's devicePUBLIC visible to anyone on CardanoHash and ballot values are illustrative.

The voter proves “I’m on the eligible-voter list, this is my one nullifier for this election, and this encrypted ballot holds a 0 or a 1”, without revealing who they are or how they voted.

Four pieces make this work:

  • Voter list. Each voter’s public key is Poseidon(secretKey, 0). The organizer puts all public keys into a Merkle tree and publishes only the root.
  • Nullifier. Poseidon(secretKey, electionId). It’s deterministic, so the same voter in the same election always produces the same value, and a second vote is caught. A different electionId gives an unrelated nullifier, so a voter’s ballots can’t be linked across elections.
  • Encrypted ballot. The vote, encrypted with exponential ElGamal to an election key that three trustees hold together. Nobody can open a single ballot, but ballots can be added up while still encrypted.
  • Tally. After voting closes, the trustees decrypt only the total, once, and prove they did it honestly.

The circuit ties the first three to one secret key. A voter who switches keys to get a fresh nullifier isn’t in the tree, and a voter who keeps their key gets the same nullifier again.

If ElGamal is new to you, Commitments & encryption, explained introduces it with an interactive lockbox.

A hash looks like a natural way to hide a vote: publish Poseidon(vote, nullifier) and nobody can undo the hash. The first version of this demo did exactly that, and it doesn’t work. The nullifier is public and a vote is only 0 or 1, so anyone can hash both choices and see which one matches. Hiding a value with a hash only works when there are far too many possible values to try. A yes/no vote, an age or a small amount can always be guessed this way.

Can anyone read the vote? · step 1 / 3
voter3casts a ballot
voteSECRET
salt (random)SECRET0x9f29…64cf
randomness k (fresh, 252 bits)SECRET0x9eb6…4d6e

Pick a vote, then see what the observer can do with the public ballot.

On-chainanyone can read it
nullifier NPUBLIC0x6eba…7255
ballot = Poseidon(vote, N)PUBLIC0x77ef…2dce
ballot = Poseidon(vote, N, salt)PUBLIC0x6bf9…f98d
ballot A = [k]·GPUBLIC0xc185…5d4c
ballot B = [vote]·G + [k]·PKPUBLIC0xc182…9f1b
Observera vote buyer, an employer, anyone
Guess the vote
Poseidon(0, N) = 0xee8b…a80bPoseidon(1, N) = 0x77ef…2dce
Poseidon(0, N, ?) — the salt is secretPoseidon(1, N, ?) — the salt is secret
encrypt 0 myself: B = 0x8187…ffe7 — no matchencrypt 1 myself: B = 0xef6d…0033 — no match

Match found: voter3 voted Yes.

Count the votesanyone can, by guessing every ballot: that's the problemnobody can, until every voter reveals their salt, and with it their voteciphertexts add up; the trustees decrypt only the total

1. Hash the vote

The first version of the demo stored Poseidon(vote, N). The hash can't be undone, but it doesn't need to be: N is public and a vote is only 0 or 1, so an observer hashes both and compares. One always matches. Flip the vote and try again. A hash hides a value only when there are too many possible values to try.

2. Add a salt

Mixing in a secret random salt stops the guessing, because the observer can't compute the hash without it. But now nobody can count either. To tally, every voter has to come back and reveal their salt, which reveals their vote at the end, and anyone who doesn't come back isn't counted.

3. Encrypt it

The demo encrypts the vote with exponential ElGamal to a key the trustees hold together. Each ballot uses fresh randomness k, so encrypting 0 or 1 yourself never reproduces it. Press Encrypt again: same vote, a completely different ballot. And ElGamal ciphertexts add up, so the chain can total the ballots and the trustees decrypt only the sum.

SECRET only the voter knows itPUBLIC anyone can see itHash and point values are illustrative.

A secret random salt stops the guessing, but then nobody can count the votes without every voter coming back to reveal their salt, which reveals their vote at the end. Encryption solves both problems at once: each ballot uses fresh randomness, so it can’t be matched by guessing, and ElGamal ciphertexts can be added, so the total can be decrypted without opening any ballot. The hash version was reported as issue #7 and replaced with the encrypted ballot described on this page (ADR-0005).

InputVisibilityWhy
secretKeySecretThe voter’s identity; it derives both the public key and the nullifier
Merkle path (siblings, pathBits)SecretThe path would reveal the voter’s position in the list
voteSecretInside the ciphertext; the proof limits it to 0 or 1
randomness (252 bits)SecretFresh for every ballot; it’s what makes two ballots for the same choice look unrelated
electionId, voterRootPublicThe election and its list of eligible voters, fixed in the on-chain script
Election key PK (PK.u, PK.v)PublicThe trustees’ combined key, also fixed in the script
nullifierPublicRecorded on-chain to block a second vote
Ballot (A, B) (A.u, A.v, B.u, B.v)PublicThe encrypted vote; it reveals nothing without the trustees
  1. Trustee keys. Each of the three trustees generates a key pair and publishes its public key with a zero-knowledge proof of possession (a DLEQ proof that it knows the matching secret). Without that proof, a dishonest trustee could choose its key to cancel the others’ and read every ballot alone. The election key is the sum of the three public keys.
  2. Register. The organizer collects each voter’s public key Poseidon(secretKey, 0), builds the Merkle tree and publishes voterRoot. The election ID, the root, the election key and the voting deadline become parameters of the on-chain scripts.
  3. Encrypt and prove. The voter encrypts their vote v with fresh randomness k: A = [k]·G, B = [v]·G + [k]·PK. A Groth16 proof, made with ZeroJ’s pure-Java prover, shows that the voter is on the list, that the nullifier is theirs, and that (A, B) encrypts a 0 or a 1 under PK. A ballot that tries to count twice (v = 2) has no valid proof. In a real deployment this runs on the voter’s own device; the demo proves server-side for convenience.
  4. Submit. A transaction mints one token whose name is the nullifier and creates a list node that holds the ballot. The minting policy verifies the proof on-chain before the deadline, and the nullifier is inserted into an on-chain sorted list.
  5. Reject repeats. A second vote from the same key has the same nullifier. The list already contains it, so the insert fails.
  6. Add up. Anyone can add the ballots: (ΣA, ΣB) is an encryption of the number of YES votes.
  7. Decryption shares. After the deadline, each trustee publishes D_j = [sk_j]·ΣA together with a DLEQ proof that it used the same secret as its registered key. A wrong share fails its proof.
  8. Count. ΣB − (D₁ + D₂ + D₃) = [YES]·G. The number of YES votes is small, so a short search recovers it. Anyone can repeat every check from chain data and the published election manifest.
voter (off-chain) Cardano
───────────────── ───────
secretKey, Merkle path, tx: redeemer = proof; new list node = (nullifier, A, B)
vote, randomness ──encrypt + prove──▶ ├─ minting policy: Groth16 check, deadline, mint 1 token named <nullifier>
└─ list validator: insert <nullifier> between sorted neighbours
after the deadline: anyone adds the ballots ─▶ trustees post verified shares ─▶ YES count

The trustees decrypt the total exactly once, after the deadline. Decrypting a running total twice would let anyone subtract the two results and learn the votes cast in between.

Step through the tally. Switch to Public view to see what an observer gets: encrypted ballots, nullifiers, the trustees’ shares, and the total.

Encrypted tally · step 1 / 6
Voterseach knows only their own voteidentities and choices hidden

Each voter holds an eligibility secret. Its key is a leaf in the voter tree.

voter1SECRETHIDDENYES████
voter2SECRETHIDDENNO████
voter3SECRETHIDDENYES████
πeligible · my nullifier · encrypts 0 or 1one per ballot
voter1 votes again: same secret, same nullifier
Cardanoballot policy + vote list
election key PK = PK₁ + PK₂ + PK₃PUBLIC0x8a53…ff7f
Vote list (one node per nullifier)
  • N = 0x1bff…b202(A, B) = 0x4619…4d18
  • N = 0x1b85…ab73(A, B) = 0xe56c…eaea
  • N = 0xcc63…8910(A, B) = 0xffde…bc02
each proof verified on-chain, before the deadlinenullifier already in the list: second ballot refused
encrypted sum (ΣA, ΣB)PUBLIC0x9fde…e79f

Adding the ciphertexts adds the votes inside them. Nobody has decrypted anything yet.

ResultYES 2 · NO 1 · total 3ΣB − (D₁ + D₂ + D₃) = [YES]·G, found by a short searchanyone re-checks the shares, the ballots and the count
Trusteesn-of-n in the demo
Trustee 1
sk1SECRETHIDDEN0xbf9f…cce4████
publishes PK1 with a proof it knows sk1absent: no share
Trustee 2
sk2SECRETHIDDEN0xbe9f…6aa9████
publishes PK2 with a proof it knows sk2absent: no share
Trustee 3
sk3SECRETHIDDEN0xbd9f…086e████
publishes PK3 with a proof it knows sk3absent: no share

1. Election key

Three trustees each make a key pair and publish the public half, with a proof that they know the secret behind it (this stops a trustee choosing a key that cancels the others). The election key is the sum of the three. Nobody holds its secret key.

2. Encrypted votes

Each voter encrypts 0 or 1 to the election key and proves, in zero knowledge, that they are on the voter list, that the nullifier is theirs, and that the ciphertext holds a 0 or a 1, nothing else. The chain sees only ciphertexts. Flip a vote in the voters' view: its ciphertext changes, and the public view stays unreadable.

3. Vote twice?

voter1 tries again. The same secret gives the same nullifier, which is already in the on-chain list, so the second ballot is refused, whatever it encrypts.

4. Add them up

Anyone can add the ciphertexts. The result is one ciphertext of the number of YES votes. No single ballot is ever decrypted, and the running total isn't decrypted before the deadline either.

5. Decryption shares

After the deadline, each trustee applies its secret to the sum, once, and posts the result with a proof that it used the same secret as its registered key. A wrong share fails its proof. In the demo every trustee must take part; tick the box to see what happens when one doesn't.

6. Result

Removing the three shares leaves the YES count as a small curve multiple, found by a quick search. Anyone can redo every check from chain data. Only the total is revealed, never who voted what.

SECRET known only to its ownerPUBLIC on-chainKey and ciphertext values are illustrative.

Lightly simplified from the demo’s PrivateBallotProof: constructor validation is trimmed. ZkElGamal.encrypt is ZeroJ’s elgamal-jubjub-v1 encryption relation, so the demo doesn’t implement any ElGamal itself.

PrivateBallotProof.java
import org.zeroj.circuit.annotation.*;
import org.zeroj.circuit.lib.poseidon.PoseidonParams;
import org.zeroj.circuit.lib.poseidon.PoseidonParamsBLS12_381T3;
import org.zeroj.circuit.lib.zk.ZkElGamal;
import org.zeroj.circuit.lib.zk.ZkElGamalPublicKey;
import org.zeroj.circuit.lib.zk.ZkMerkle;
import org.zeroj.circuit.lib.zk.ZkPoseidon;
@ZKCircuit(name = "private-ballot",
nameTemplate = "private-ballot-d{treeDepth}-jubjub-elgamal", version = 3)
public class PrivateBallotProof {
private static final PoseidonParams POSEIDON = PoseidonParamsBLS12_381T3.INSTANCE;
public PrivateBallotProof(@CircuitParam("treeDepth") int treeDepth) {}
@Prove
void prove(ZkContext zk,
@Public ZkField electionId,
@Public ZkField voterRoot,
@Public ZkField electionKeyU, @Public ZkField electionKeyV, // PK
@Public ZkField nullifier,
@Public ZkField handleU, @Public ZkField handleV, // A
@Public ZkField ballotU, @Public ZkField ballotV, // B
@Secret @UInt(bits = 1) ZkUInt vote, // 0 or 1
@Secret @UInt(bits = 252) ZkUInt randomness,
@Secret ZkField secretKey,
@Secret @FixedSize(param = "treeDepth") ZkArray<ZkField> siblings,
@Secret @FixedSize(param = "treeDepth") ZkArray<ZkBool> pathBits) {
// Eligibility, and one nullifier per voter and election.
ZkPoseidon.hash(zk, POSEIDON, secretKey, electionId).assertEqual(nullifier);
var voterKey = ZkPoseidon.hash(zk, POSEIDON, secretKey, zk.constant(0));
ZkMerkle.verifyProofPoseidon(zk, POSEIDON, voterKey, voterRoot, siblings, pathBits);
// The ballot: an encryption of a 1-bit vote under the election key.
var electionKey = ZkElGamalPublicKey.fromVerifierFixedPublic(zk, electionKeyU, electionKeyV);
ZkElGamal.encrypt(zk, vote, randomness, electionKey)
.assertAffineEquals(zk, handleU, handleV, ballotU, ballotV);
}
}

The @UInt(bits = 1) on vote is what limits a ballot to 0 or 1. The circuit has 9,477 constraints at tree depth 10. The annotation processor generates a PrivateBallotProofCircuit companion that you compile to R1CS and prove with Groth16. Before you trust a circuit like this, test it with invalid witnesses: a key that isn’t in the tree, a nullifier from another election, a vote of 2, a ballot encrypted to another key. It should reject every one. See Testing circuits.

The demo uses two Plutus V3 scripts written in Java with JuLC:

  • VoteZkMintingPolicy verifies the ballot proof with Groth16BLS12381Lib.verify(...) from zeroj-onchain-julc. The redeemer carries only the proof. Every one of the nine public inputs comes from the script’s parameters (electionId, voterRoot, the election key, and the verification key) or from the ledger: the nullifier is the name of the single token minted, and the ballot is read from the inline datum of the list node that receives it. The transaction must also be valid only up to the voting deadline.
  • VoteListValidator keeps nullifiers in a sorted linked list, one UTxO per nullifier, each holding its ballot. Inserting between two neighbours proves the new nullifier wasn’t there before. Votes that land in different parts of the list touch different UTxOs, so they don’t contend. Each node locks about 2 ADA.

A valid proof is not authorization, which is why the election’s values are script parameters and not redeemer fields: otherwise a voter could prove membership in a tree they built themselves, or encrypt to a key they hold. See On-chain verification.

Off-chain, the tally uses ZeroJ’s ElGamal API. Simplified from the demo’s TallyService, with one trustee’s secret shown for brevity (each trustee computes its own share on its own machine):

Tally (simplified)
import org.zeroj.circuit.lib.jubjub.ElGamal;
import org.zeroj.circuit.lib.jubjub.ElGamalCiphertext;
import org.zeroj.circuit.lib.jubjub.ElGamalPublicKey;
import org.zeroj.circuit.lib.jubjub.VerifiedDecryptionShare;
import java.util.List;
// `ballots`: every ballot in the vote list, admitted under the election's key context
ElGamalCiphertext total = ElGamalCiphertext.sum(ballots);
// Trustee j, on its own machine: its share of the decryption, D_j = [sk_j]·ΣA
VerifiedDecryptionShare own = ElGamal.decryptionShare(trusteeSecret, total);
byte[] published1 = own.encode(); // posted with a DLEQ proof of own.statement()
// Anyone: accept each published share only if its proof verifies (repeat for every trustee)
VerifiedDecryptionShare share1 = VerifiedDecryptionShare.verify(total, trusteeKey1, published1,
statement -> verifyDleqProof(proof1, statement.publicInputs()));
// ... share2 and share3 the same way, then decrypt the total
long yes = ElGamal.decrypt(total, List.of(share1, share2, share3), total.bound().longValueExact());

ElGamal.decrypt accepts only shares that went through VerifiedDecryptionShare.verify, and the total’s bound is the number of ballots, so the final search is tiny. See the ElGamal guide for the full API.

  • Every trustee is needed, and all of them together could read any ballot. The demo’s key is n-of-n: if one trustee disappears, nothing can be decrypted, and the three together could decrypt a single ballot instead of the total. ZeroJ’s threshold ElGamal with a distributed key generation is the t-of-n alternative: any t + 1 trustees can decrypt, and fewer learn nothing. The demo doesn’t use it yet.
  • The demo server knows every vote. For convenience it holds every voter’s and trustee’s secret and proves on their behalf. In a real election each voter proves on their own device and each trustee keeps its own key.
  • Demo voter keys are random and kept. The test voters’ secret keys come from SecureRandom and are stored, owner-only, in the demo’s data directory. Earlier versions used small fixed numbers (10000 + i), so anyone could compute each voter’s nullifier, match ballots to voters, or vote for a voter who hadn’t voted yet. Voting “as Alice” by label in the demo is the operator acting for that voter, not the voter signing in.
  • Small or unanimous results reveal votes. If all three ballots are YES, everyone knows how each voter voted. The total is always public.
  • The vote list is public. Anyone can see how many ballots were cast and when.
  • The voter list is a trust point. Whoever builds the tree decides who can vote. Publish the leaves so members can check their inclusion and spot keys that shouldn’t be there.
  • Check the trustees’ key proofs. The election key is only as good as the possession proofs behind it; the manifest publishes every key with its proof so anyone can rebuild it.
  • Watch transaction-level metadata. In the demo a service wallet submits and pays for every vote. If voters pay fees from their own wallets, the fee input links them to their ballot. Use a relayer and be mindful of timing.
  • No receipt-freeness or coercion resistance. A voter can prove to a vote buyer how they voted by handing over the randomness k, or hand over their secret key entirely. Anti-collusion designs such as MACI address this. This demo doesn’t.
  • Key theft is vote theft. Anyone who learns a voter’s secret key can vote in their place.
  • Trusted setup. The demo uses a single-party development setup for both its circuits. A real election needs keys from a multi-party ceremony (Trusted setup, explained).

The demo lives in private-voting. With Yaci DevKit running (see Run the demos):

Terminal window
./demo.sh voting --run

At startup the app creates an election with five funded test voters and three trustees, and opens voting for 10 minutes. With --run, voter1 votes yes and voter2 votes no. Each ballot is encrypted and proven in pure Java and verified on-chain. To see double-vote protection, vote again as voter1 from the UI, or run:

Terminal window
curl -X POST http://localhost:8086/api/vote \
-H "Content-Type: application/json" -d '{"voterLabel":"voter1","vote":0}'

The second vote is rejected because voter1’s nullifier is already in the on-chain list. Cast a third vote (voter3 yes) and fetch the tally:

Terminal window
curl http://localhost:8086/api/results

Before the deadline it shows only the encrypted sum. After it, the trustees’ shares are posted and checked, and the result is yes: 2, no: 1, total: 3, verified: true, with the list of checks performed. GET /api/election/manifest returns everything needed to re-check the scripts and the tally yourself.

Design notes: Private voting — detailed design (nullifier registries compared, batch rollups, Hydra, MACI).