arnaucube
arnaucube/davinci-paperPublic Self-hosted repository
davinci-paper/v3-pq/spec.md
v3-pq/spec.mdRaw
  1# DAVINCI v3-PQ — Post-Quantum Protocol Specification
  2
  3**Status:** draft v1.0 · 2026-10-20 · v2 remains the deployed protocol. Reviewed: three
  4adversarial soundness rounds (protocol reviewer) + audience-representative sign-off; a final
  5consolidated review gates implementation (Phase 0 of the migration plan).
  6**Audience:** engineers who already know [DAVINCI v2](https://spec.davinci.vote). This document only
  7specifies what *changes*. Everything not mentioned here (settlement flow, grace window, blob
  8verification via the point-evaluation precompile, census origins, sequencer lifecycle, process
  9registry mechanics) works exactly as in v2 [DAV2].
 10
 11---
 12
 13## 1. Why v3, in one paragraph
 14
 15Every ballot DAVINCI v2 publishes in Ethereum blobs [EIP4844] is an ElGamal ciphertext over
 16BabyJubjub. Published blob data can be archived by anyone indefinitely, and ElGamal falls to
 17Shor's algorithm — so a future quantum computer decrypts **past elections retroactively**
 18("harvest now, decrypt later"). Integrity is less urgent (a settled chain cannot be rewritten
 19under Ethereum's finality assumptions), but **ballot privacy must be post-quantum today**.
 20v3-PQ removes the quantum-vulnerable primitives from the ballot *confidentiality* path: no
 21shared-key homomorphic encryption, no pairings, no DKG, no Groth16. Ballot secrecy rests on
 22polynomial secret sharing, hashes, STARKs, and one NIST-standardized KEM (a post-quantum
 23"public-key lockbox" — all such terms are defined plainly in §2.4). The KEM is never
 24proven inside the voter's circuit (the batch guest performs encapsulations, and rare complaint
 25proofs perform decapsulations; see §8.5, §9.2). During the hybrid period voter authentication
 26still *also* uses ECDSA (§11), and the settlement wrapper and KZG blob commitments remain
 27inherited non-PQ dependencies (§12.5).
 28
 29### Changes at a glance
 30
 31| Component | v2 | v3-PQ |
 32|---|---|---|
 33| Ballot confidentiality | ElGamal over BabyJubjub (threshold key) | Shamir shares + PRF masks over KEM transport (§3) |
 34| Ballot proof | Groth16 over BN254 (circom, trusted setup) | Plonky3 STARK over Goldilocks, browser WASM (§6) |
 35| Election key | DKG / council ceremony (BabyJubjub) | **None.** Wardens register ML-KEM keys (§4) |
 36| Tally | Threshold decryption + BSGS search | Lagrange interpolation of θ proven warden sums (§10) |
 37| Running tally | Homomorphic ciphertext accumulator | Padded plain-sum accumulator over Goldilocks (§8.4) |
 38| Silent revoting | Re-encryption of stored ciphertexts | Hash-chained opaque slot leaves (§7) + padded accumulator |
 39| Revotes | Slot overwrite + ciphertext subtraction | One-live-chain packages + revocation nullifiers (§5.3) |
 40| Voter authentication | ECDSA (secp256k1) | Hash-preimage proof in-STARK; `hybrid` verifies **both**; `hybrid-legacy` admits unenrolled voters on ECDSA (§11) |
 41| CSP credentials | ECDSA | SLH-DSA (SPHINCS+) [FIPS 205] |
 42| Batch proof | ZisK, verifies Groth16 (BN254 precompiles) | ZisK [ZISK], verifies ballot STARKs (Poseidon2 precompile) |
 43| Tally bound | maxValue·maxVoters ≤ 10^12 (BSGS limit) | ≤ 2^61 (field headroom; no search) |
 44
 45![What changes from v2 to v3-PQ](figures/architecture-delta.svg)
 46
 47---
 48
 49## Protocol intuition — read this first
 50
 51*A plain-English walkthrough of a v3 election, phase by phase, mapped onto the v2 flow you
 52already know. Every term used loosely here gets a precise definition from §2 onward; the
 53jargon cheat-sheet is §2.4.*
 54
 55**Setup.** The organizer creates the election exactly as in v2 — census, ballot rules,
 56duration. One thing changed: instead of waiting for a key ceremony, the organizer points at a
 57committee of ν key wardens (say 5, or 16), each of which has already published a post-quantum
 58"lockbox" public key: anyone can lock a small secret so that only that warden can open it.
 59There is **no election encryption key** — nothing is generated jointly, and v2's whole DKG
 60phase is simply gone.
 61
 62**Casting.** The voter's browser takes each ballot value and splits it into ν puzzle pieces,
 63one per warden, using the Shamir trick: any θ pieces (the *threshold* — e.g. 3 of 5) fit
 64together to reconstruct the value, while θ−1 or fewer are pure noise that says nothing at
 65all. The browser then hides each piece under a one-time mask (a random-looking number added
 66to it), locks each mask key into the matching warden's lockbox, and attaches a STARK proof —
 67generated right there in the browser — that the whole construction is consistent: the pieces
 68encode one valid ballot that follows the election rules, the masks match their commitments,
 69and the voter is who they claim to be. The published vote (a *package*) is just masked
 70pieces + locked boxes + commitments. Everything visible is noise; nothing about the choice
 71can be read from it, now or ever, by anything short of θ wardens cooperating.
 72
 73**Voting period.** Sequencers collect packages and settle batches with a zkVM proof, as in
 74v2. The chain maintains one new object: a public **running total** — for each warden, the sum
 75of all masked pieces addressed to it. Adding masked numbers keeps them masked, so the running
 76total is public yet unreadable. A revote cancels the voter's previous package through an
 77unlinkable **nullifier** (same idea as Tornado/Semaphore nullifiers), and the batch proof
 78subtracts the old package's pieces from the running total. Meanwhile, refreshes keep
 79re-hashing slot entries so an outside observer still cannot tell who revoted — v2's "silent
 80revoting", achieved by different means.
 81
 82**End of election.** After the grace window come two short new phases: first a
 83**complaint window**, where any warden that finds a broken package — a lockbox that doesn't
 84open to what was promised — can prove that on-chain and have the package excluded; then the
 85exclusion list freezes.
 86
 87![Election timeline: the two new phases before results](figures/timeline.svg)
 88
 89**Results.** Any θ wardens now each do one job: open all their lockboxes, strip their own
 90masks off their column of the frozen running total, and publish the resulting **partial
 91sum** — with a proof that they did exactly that and nothing else. The punchline: those θ
 92partial sums are θ points on a single polynomial, and that polynomial's value at zero *is*
 93the exact election result. The smart contract draws the unique curve through the θ points and
 94reads it at zero — ordinary integer math, done on-chain. No decryption ever happens, because
 95there is nothing to decrypt.
 96
 97![How the tally emerges from θ partial sums](figures/tally-algebra.svg)
 98
 99What this buys you:
100- **There is no decryption key.** Not distributed, not threshold-shared — it does not exist,
101  and neither does the ceremony machinery that managed it in v2.
102- **Harvest-now-decrypt-later is dead below θ wardens.** The published pieces are
103  information-theoretic noise; the only cryptography protecting them is the lockboxes
104  (ML-KEM) and hashes — both post-quantum.
105- **Every step is proof-checked** — browser proof, batch proof, warden proofs — so voters,
106  sequencers and wardens are checked, not trusted, for correctness.
107- **The tally is exact integer arithmetic.** No decryption failures, no noise budgets, no
108  brute-force search at the end.
109
110---
111
112## 2. Notation, parameters and encodings
113
114- $\mathbb{F}$ — the **Goldilocks field**, $p = 2^{64} - 2^{32} + 1$ (the Plonky3 [P3] and ZisK
115  native field). All shares, masks and tally arithmetic live here. Canonical encoding of an
116  element: 8 bytes little-endian, value < $p$.
117- $\nu$ — number of **key wardens**; $\theta$ — tally threshold ($1 \le \theta \le \nu \le 16$;
118  the cap matches v2 committee/council sizes, and data availability cost is linear in ν).
119- `nf` — active ballot fields, 1..16, as in v2. A ballot is a vector $b_1..b_{16}$; fields
120  beyond `nf` are **inactive and MUST be 0** (enforced by the ballot proof; their shares are
121  shares of 0).
122- **KEM** — ML-KEM-768 [FIPS 203] (ct 1088 B) by default; ML-KEM-512 (ct 768 B) is an allowed
123  profile for DA-sensitive deployments. One *encapsulation* yields `(ct, K)` with a 32-byte
124  shared secret `K`; arbitrary payloads are carried KEM-DEM style (encapsulate, derive a
125  wrapping key from `K`, then DEM-encrypt — §2.1).
126- **Poseidon2** — Poseidon2 over Goldilocks, width 16, ZisK-precompile-compatible constants
127  [POS2]. Used for all in-circuit hashing (commitments, PRFs, binding hashes). A Poseidon2
128  digest is 4 field elements, serialized as 4×8 B LE (32 bytes).
129- **SHA-256** — unchanged: the state SMT, package digests, and everything contracts check.
130- **256-bit values in circuits** (DEM keys, SHA-256 digests crossing into Goldilocks
131  arithmetic): encoded as **eight 32-bit limbs**, each range-checked < 2^32. Never as four
132  64-bit limbs (not injective: $p^4 < 2^{256}$), and never reduced mod $p$.
133
134### 2.1 DEM (authenticated encryption for warden payloads)
135
136Hash-based, precompile-friendly, normative for **every protocol payload** (voter→warden is
137pure KEM+PRF and needs no DEM; this DEM covers batch payloads, batch-key share wrapping, and
138ceremony deliveries):
139`keystream block j = HMAC-SHA-256(k, nonce ‖ LE64(j))` (HMAC, not raw hashing — the needed
140assumption is that HMAC-SHA-256 is a PRF (§2.4), a conservative standard one); ciphertext =
141plaintext ⊕ keystream; `tag = HMAC-SHA-256(k_mac, nonce ‖ AAD ‖ ciphertext)`;
142`(k, k_mac) = HKDF-SHA-256(K, "enc"/"mac")` from the KEM/batch secret. `nonce = SHA-256(AAD)`.
143The AAD is the canonical serialization of a **DEM context** that always includes a purpose
144tag, the election context, the **batch number or ceremony (session, attempt) identifier**,
145sender and recipient — unique per encryption *including retries* (a ceremony restart is a new
146attempt id ⇒ fresh masks, keys and nonces; the same derived key and nonce never encrypt two
147different plaintexts). Payloads are bounded below 2^32 blocks; receivers verify the full tag
148before releasing any plaintext. AES-256-GCM may be used by clients for unrelated local
149storage/transport, never as a substitute encoding of protocol payloads.
150
151### 2.2 Domain-separated contexts
152
153Every derived value uses a purpose-tagged context; nothing is derived without one.
154
155| Purpose | Context contents |
156|---|---|
157| `pkgCtx` — the package context tuple | `(protocolVersion, chainID, registry, processID, wardenEpoch, voteID)` — the common prefix below |
158| `maskCtx(i, f)` — PRF pad for masked shares | `("v3/mask", pkgCtx, recipient i, field f)` |
159| `hCtx(i)` — share/pad commitment | `("v3/hcommit", pkgCtx, recipient i)` |
160| `commitCtx` — package commitment | `("v3/pkgcommit", pkgCtx)` — the `ctx` argument of `pkgCommit` (§5.1) |
161| `nullCtx` — revocation nullifier | `("v3/null", protocolVersion, chainID, registry, processID)` — **predecessor-only**: `NULL = Poseidon2(nullCtx, sk, prevPkgDigest)` with `sk` the voter's census-bound secret or `sk_pkg` (§11). Never depends on the successor package, batch, or recipients. |
162| `slotCtx` / `refreshCtx` — slot leaves | `"davinci-slot-v3"` / `"davinci-refresh-v3"` (§7) |
163
164The package's mask nonce is its **voteID** — public, unique per package, authenticated, and
165independent of the masked values (it derives from the secret `k`, §5.2, before any masking),
166so wardens can recompute every `maskCtx` from public data with no circularity.
167
168### 2.3 Protocol parameters
169
170| Parameter | Value | Why |
171|---|---|---|
172| Share/tally field | Goldilocks $p$ | native in the ballot AIR and ~native u64 in ZisK guests |
173| Registry tally cap | `maxValue · maxVoters ≤ 2^61` | per-field tally stays below $p$ with headroom (weights don't change this: each field is individually bounded by `maxValue`) |
174| **Integer-cost profile (enforced)** | `nf · maxValue^costExponent < 2^61`, checked by the registry at creation **and** recomputed overflow-safe in the ballot proof | the cost sum must not wrap mod $p$ (e.g. `costExponent=192` would give $2^{192} \equiv 1$); v2 only *advised* this profile — v3 enforces it |
175| Warden evaluation points | $x_i = i$, $i \in 1..\nu$ | Shamir positions, pairwise distinct, nonzero |
176| Max votes per batch | profile-dependent (§8.6) | in-guest verification cost + the 32-blob batch cap inherited from v2's batch program (see §8.6) |
177| Max refreshed slots per batch | 2048, rule as v2 | unchanged |
178| Nullifier tree | SHA-256 SMT, depth 256 | full-width nullifiers (no truncation into the 64-bit key space) |
179| Ballot STARK profile | Goldilocks, blowup 8, 34 FRI queries, hiding PCS | ≈102-bit conjectured FRI soundness (§12.4) |
180
181### 2.4 Terminology for software engineers
182
183Plain definitions, anchored in things an Ethereum engineer already knows. Skim once; the rest
184of the document assumes them.
185
186- **KEM** (Key Encapsulation Mechanism; here **ML-KEM**, the standardized Kyber) — a
187  public-key *lockbox*: anyone can "encapsulate" against your public key and obtain a fresh
188  32-byte shared secret plus a ciphertext; only you (with the private key) can recover that
189  secret from the ciphertext. Think of it as the post-quantum replacement for ECDH key
190  exchange — except there is no shared-curve math and the two parties never need to be online
191  together.
192- **PRF** (pseudorandom function) — a keyed hash used as a deterministic random-number
193  generator: same key + input ⇒ same output, and without the key the outputs are
194  indistinguishable from random. Mentally: `keccak256(key, input)` used the way you'd use a
195  seeded RNG. Here PRFs expand a KEM secret into the masks that hide shares.
196- **Shamir secret sharing** — split a value into ν pieces by choosing a random polynomial of
197  degree θ−1 whose value at x=0 is the secret, and handing out its values at x=1..ν. Any θ
198  pieces determine the polynomial (and hence the secret); any θ−1 pieces are statistically
199  independent of it — noise, not "hard to crack".
200- **Threshold θ-of-ν** — ν parties hold pieces; any θ of them suffice to act (here: tally);
201  fewer than θ learn nothing and can block nothing except by being too few.
202- **Lagrange interpolation** — given θ points, there is exactly one polynomial of degree
203  ≤ θ−1 through them; evaluating it at x=0 recovers a Shamir secret. "Draw the unique curve
204  through the points, read it at zero." A few multiplications and additions — cheap even in
205  Solidity.
206- **STARK** — a zero-knowledge proof system built only from hashes (no trusted setup, no
207  elliptic curves, post-quantum). Bigger proofs than Groth16 (hundreds of KB), but
208  browser-provable and cheap to verify.
209- **AIR** — the constraint system of a STARK: its "circuit".
210- **FRI** — the polynomial-checking engine inside a STARK; the reason STARK verification is
211  mostly hashing.
212- **Hiding PCS** — the polynomial commitment inside the STARK is randomized so the proof
213  leaks nothing about private inputs; this is what makes the proof *zero-knowledge* rather
214  than merely succinct.
215- **Witness** — the prover's private inputs (the ballot, the shares, the keys). Never leaves
216  the prover.
217- **Nullifier** — a one-way tag published to mark something as spent without revealing what;
218  exactly the Tornado Cash / Semaphore pattern. Here: marks a vote package as replaced.
219- **Accumulator** (as used here) — just a running sum vector of field elements maintained by
220  the batch program. *Not* an RSA or Merkle accumulator.
221- **DEM / AEAD** — symmetric authenticated encryption (ciphertext + tamper-proof tag), the
222  AES-GCM role; v3 instantiates it from SHA-256/HMAC so zk-proofs about it stay cheap (§2.1).
223- **Domain separation** — namespacing every hash/PRF input with a purpose tag and context so
224  a value from one context can never be replayed in another — the same reason EIP-712 typed
225  signing exists (§2.2).
226- **Dealer** — a party that generates a secret and distributes shares of it (used in the
227  tally ceremony, §10.3).
228- **CSPRNG** — a cryptographically secure random generator (`crypto.getRandomValues`,
229  `/dev/urandom`); "fresh CSPRNG randomness" means sampled from this, never derived.
230
231---
232
233## 3. The core idea: tally without a decryption key
234
235v2 hides a ballot inside a ciphertext and adds ciphertexts homomorphically. v3 hides a ballot
236inside **polynomials** and adds polynomials. If you know Lagrange interpolation, you know the
237whole trick:
238
2391. For each ballot field value $b$, the voter picks a random polynomial $f$ of degree
240   $\theta-1$ with $f(0) = b$, and computes one **share** per warden: $s_i = f(i)$. Any
241   $\theta$ shares reconstruct $b$; any $\theta-1$ shares are statistically independent of
242   $b$. Plain Shamir [Sha79]: no curves, just polynomial evaluation in $\mathbb{F}$.
2432. Shares are never published in the clear. The voter publishes **masked shares**
244   $e_i = s_i + \mathrm{PRF}(K_i, \mathrm{maskCtx})$, where the pad key $K_i$ travels to
245   warden $i$ inside an ML-KEM ciphertext. To everyone except warden $i$, $e_i$ is a
246   uniformly random field element.
2473. Polynomials add: the per-field sum of every active voter's polynomial is itself a
248   degree-$(\theta-1)$ polynomial whose value at 0 is the **tally**. So the protocol only
249   ever needs to add public field elements. The batch program maintains a public
250   **accumulator** $A \in \mathbb{F}^{\nu \times 16}$: coordinate $(i, f)$ is the running
251   sum of the masked shares addressed to warden $i$ for field $f$ (plus batch pads, §8.4).
2524. At the end, each participating warden decapsulates its KEM ciphertexts, subtracts its pads
253   from its row, and publishes its **sum-share** $S_i$ — with a ZisK proof that it did exactly
254   that against on-chain-committed data. Lagrange interpolation of any $\theta$ published
255   sum-shares at $x=0$ **is** the tally. Exact field arithmetic: no decryption of any
256   aggregate, no noise, no discrete-log search.
257
258![How the tally emerges without a decryption key](figures/tally-algebra.svg)
259
260(*This section is the intuition; the full computation also handles the exclusion set, batch
261pads, and a blinding term — §9–§10.*)
262
263The ballot STARK (§6) makes steps 1–2 trustworthy, the batch proof (§8) step 3, the warden
264proofs (§10) step 4. **The zkVM proof chain replaces the homomorphic algebra** — the
265structural difference from academic PQ voting designs ([TEV], [PQK]), which obtain the same
266guarantee from lattice commitments. (Some public-key encryption is unavoidable for ballots
267addressed to offline wardens [IR89]; v3 confines it to KEM transport. Threshold *lattice*
268decryption — the known hard part of lattice voting [NOAH] — is avoided entirely: the
269threshold lives at the plaintext layer.)
270
271Privacy in one sentence: below $\theta$ colluding wardens, shares are information-theoretically
272useless in isolation, and the computational assumptions protecting ballots are ML-KEM, the
273PRF/hash, and the zero-knowledge of the STARKs — all post-quantum (full leakage model: §12).
274
275---
276
277## 4. Roles: what changed
278
279- **Organizer, sequencers, provers, observers** — unchanged from v2.
280- **Key wardens** no longer run a DKG or hold shares of a secret key. Per *epoch*, each warden
281  generates an ML-KEM keypair and calls the **WardenRegistry** contract with: `H(pk)`, a URI
282  where the full public key is served (IPFS or HTTPS), and a ZisK **well-formedness proof**
283  (the key pair derives from a committed seed and passes an encaps/decaps self-test). The
284  registry verifies the proof on-chain. An election pins its committee in `wardenSetHash`
285  (config leaf `0x3`, §7): `(ν, θ, epoch, the ν registered H(pk) values)`. A voter's client
286  fetches the ν public keys (from their URIs or any sequencer), recomputes each `H(pk)` and
287  the set hash, and verifies it against the on-chain value before casting; it refuses to cast
288  otherwise. The registry refuses to create an election whose warden set is not fully
289  registered. During the election wardens do nothing; at the end they run one archive scan,
290  optional complaints, and one tally ceremony (§9–§10).
291- **Key modes.** *Committee* (lottery over registered operators) and *council*
292  (organizer-invited set) map 1:1 from v2 — they only select *which* registered warden keys
293  form the set. *Sequencer mode* is the degenerate $\nu = \theta = 1$ case (the sequencer is
294  the only warden; ~1 KB per ballot — cheaper than v2). **Locked mode is deferred**: it
295  requires an organizer-side share column and a separately reviewed extension of the tally
296  equations; it is not part of v3.0.
297
298---
299
300## 5. The ballot package
301
302A vote is one **package**. Its public part goes into blobs; its private part exists only in
303the voter's browser — except the *revote metadata* the chosen sequencer needs (§5.4).
304
305![Building a ballot package in the browser](figures/ballot-package.svg)
306
307### 5.1 Public package contents and CanonicalPackage
308
309| # | Field | Size (ν=16, ML-KEM-768) | Description |
310|---|---|---|---|
311| 1 | `version` | 1 B (`0x03`) | package format version |
312| 2 | `processID` | 31 B | as v2 |
313| 3 | `voteID` | 8 B LE | §5.2; also the package's mask nonce (§2.2) |
314| 4 | `E` | ν·16·8 B = 2,048 B | masked shares, row-major (warden-major, field-minor), canonical LE |
315| 5 | `cts` | ν·1,088 B = 17,408 B | ML-KEM ciphertexts, warden order 1..ν |
316| 6 | `h` | ν·32 B = 512 B | commitments $h_i = \mathrm{Poseidon2}(hCtx(i), s_{i,1..16}, K_i)$ ($K_i$ as 8×32-bit limbs) |
317| 7 | `pkgCommit` | 32 B | $\mathrm{Poseidon2}(slot, pk_{\text{voter}}, \mathrm{prevPkgDigest}, \mathrm{sharesDigest}, \mathrm{salt}, \mathrm{commitCtx})$ — hiding comes from `salt`, an independent **256-bit CSPRNG commitment salt** kept in the package opening (share entropy alone is NOT enough: given θ−1 shares and a candidate ballot, the whole polynomial is determined); `prevPkgDigest = 0^{32}` for a first vote |
318| 8 | `hybridSig` | 65 B or absent | hybrid mode only: ECDSA over `pkgDigest`, Ethereum personal-message format (§11) |
319
320`CanonicalPackage` = the concatenation of fields 1–7 exactly as listed (fixed order, fixed
321sizes, no framing). **`pkgDigest = SHA-256(CanonicalPackage)`** is the package's chain
322identity: it is the value stored at the vote-ID leaf, the input to revocation nullifiers, and
323what complaints reference. `sharesDigest = Poseidon2` sponge over all $s_{i,f}$ in the same
324row-major order. The ballot STARK (~400 KB) accompanies the package to the sequencer but is
325**not** published in blobs.
326
327### 5.2 Construction (browser, pseudocode)
328
329```text
330k         = fresh random scalar (or PRF(sk, "v3/k", processID, counter) in recovery mode)
331voteID    = N + trunc63(Poseidon2(processID, address, k))        # trunc63 = lowest 63 bits;
332                                                                 # N = 2^63 (v2's namespace offset)
333for f in 1..nf:
334    poly_f = random polynomial, degree θ-1, poly_f(0) = ballot[f]
335for f in nf+1..16:  poly_f = random polynomial with poly_f(0) = 0  # inactive fields: shares of 0
336s[i][f]   = poly_f(i)                                            # ν shares per field
337for i in 1..ν:
338    (ct[i], K[i]) = MLKEM.Encaps(pk_warden[i])                   # fresh randomness per package, NEVER reused
339    for f in 1..16: e[i][f] = s[i][f] + PRF(K[i], maskCtx(i, f)) mod p
340    h[i]  = Poseidon2(hCtx(i), s[i][1..16], K[i])
341salt      = fresh 256-bit CSPRNG value                           # hiding salt, kept in the opening
342pkgCommit = Poseidon2(slot, pk_voter, prevPkgDigest, sharesDigest, salt, commitCtx)
343ctsDigest = SHA-256(ct[1] || .. || ct[ν])                        # binds the ciphertext bytes (§6)
344proof     = BallotSTARK.prove(...)                               # §6
345```
346
347ML-KEM encapsulation costs ~1–2 ms per warden in browser WASM [KEMB]; the dominant client
348cost is the STARK (§6). **Pad-reuse warning:** reusing KEM randomness across two packages
349would publish the *difference* of two sharings, which interpolates to the difference of the
350ballots — encapsulations are fresh per package, enforced by convention and by the fresh
351`voteID` in every `maskCtx`.
352
353**Client state.** Default: `k`, the polynomials and the KEM randomness are **independent
354CSPRNG randomness**, and the client stores the package opening — including the commitment
355salt — (needed to revote). Optional *recovery mode* derives them **and the salt** as
356`PRF(sk_voter, purpose, processID, counter)` with distinct purpose tags (salt included:
357`"v3/salt"`). Any device holding `sk` can then reconstruct past packages. The documented
358trade-off: whoever later obtains `sk` can also reconstruct that voter's own historical
359ballots. Counter recovery: the
360client trial-derives counters 0,1,2…, computes each candidate `pkgDigest`, and checks which
361are admitted (vote-ID leaves) and which are consumed (nullifier tree) to find its live
362package; gaps from collision-resamples (§14) are skipped naturally.
363
364### 5.3 Revoting: the one-live-chain rule
365
366v2 overwrote the voter's slot and subtracted the stored ciphertext. v3 has no stored
367ciphertext, so the *voter's proof* identifies what to remove:
368
369![Revote lifecycle: the one-live-chain rule](figures/revote-lifecycle.svg)
370
371- Each voter has, per election, a chain of packages $P_0 \to P_1 \to \dots$; exactly one is
372  **live**. A revote package $P_{t+1}$ consumes $P_t$: the STARK proves knowledge of $P_t$'s
373  opening (same slot, same key) and the nullifier derivation
374  $\mathrm{NULL}_t = \mathrm{Poseidon2}(\mathrm{nullCtx}, sk, \mathrm{pkgDigest}_t)$, where
375  `sk` is the voter's census-bound secret (or the self-chosen `sk_pkg` for unenrolled hybrid
376  voters — §11).
377- The batch program checks $P_t$ **was admitted and is settled**: an inclusion proof of
378  `voteID_t → pkgDigest_t` under the current root (consequently, a predecessor cast in the
379  *same* batch cannot be consumed yet — §14). It inserts $\mathrm{NULL}_t$ into the nullifier
380  tree (insert-once: double consumption is impossible), subtracts $P_t$'s public `E` from the
381  accumulator, and adds $P_{t+1}$'s.
382- Invariants enforced by the batch program: an **empty slot admits exactly one initial
383  package**; a package for an **occupied slot must consume exactly one admitted, unconsumed
384  predecessor of the same owner and slot**; refreshes never create occupancy.
385
386Nullifiers are unlinkable to packages for third parties (they depend on `sk`). The coercion
387consequences are stated in §12.3.
388
389### 5.4 Submission interface (voter → sequencer)
390
391The voter submits to one sequencer, over an encrypted channel as in v2:
392`{CanonicalPackage, hybridSig?, ballotProof, censusProof?, and — for a revote — the
393predecessor reference (voteID_t, pkgDigest_t) with its inclusion path}`. The sequencer (and
394its prover) therefore **learns revote events and predecessor linkage for the votes it seals —
395the same boundary as v2**, where the sealing sequencer learns which updates are overwrites.
396It never learns ballots, shares, pads, or `sk`: those stay inside the STARK witness. The
397batch program receives the predecessor's public data as ordinary host input; the STARK is
398what makes it *authorized* (nullifier + ownership), and the chain is what makes it
399*authentic* (vote-ID leaf).
400
401---
402
403## 6. The ballot proof (Plonky3 STARK)
404
405The Groth16 circuit is replaced by a STARK over Goldilocks, proven in the browser via WASM —
406the production descendant of the davinci-stark prototype [DST], minus its elliptic-curve
407section. No trusted setup.
408
409**Public inputs** (all as Goldilocks elements/limbs):
410`inputsHash` (4 limbs) · `voteID` · `slot` · `authMode` flag · `isRevote` flag ·
411`prevPkgDigest` (8×32-bit limbs; zero when `isRevote=0`) · `NULL` (4 limbs; zero when
412`isRevote=0`).
413
414In words, the proof pins down every public byte of the package plus the election context, so
415the batch program can check "this proof authorizes exactly these bytes".
416**`inputsHash`** is the Poseidon2 binding of the **complete CanonicalPackage plus election
417context**, computed exactly as:
418`Poseidon2(version, processID, packedBallotMode, wardenSetHash, censusRoot, voteID, slot,
419authMode, weight, H2(E), ctsDigest, H2(h_1..h_ν), pkgCommit)` where `H2` is the Poseidon2
420sponge over the listed values in package order and **`ctsDigest = SHA-256(cts)`** enters as
4218×32-bit limbs. The voter computes `ctsDigest` *outside* the circuit (the circuit treats it
422as opaque limbs — this **binds** the ciphertext bytes without proving anything about ML-KEM);
423the batch program recomputes `SHA-256(cts)` and the full `inputsHash` from the package body
424and rejects on any mismatch. Nothing in the admitted package — including the ciphertexts —
425can differ from what the voter authorized. The `slot` public input (derived from the census
426identity per the census-origin rule, proven against the in-circuit census membership path)
427is what the batch program uses for the state transition, and `authMode` pins which §11
428authentication branch the proof took.
429
430**The proof shows:**
4311. **Ballot validity** — v2's ballot protocol (ranges, uniqueness, cost sum vs
432   `maxValueSum`/weight, `ballotMode` unpacking), with three normative strengthenings over
433   the v2-era prototype: the weight bound is enforced when `maxValueSum = 0`; all comparisons
434   use sound borrow-checked integer gadgets (no Goldilocks wraparound); and the cost sum is
435   computed overflow-safe under the enforced integer-cost profile (§2.3).
4362. **Share consistency** — for every field (including inactive ones, with constant term 0),
437   the ν shares lie on one polynomial of degree ≤ θ−1 whose constant term is the ballot
438   value. Cost: ν·16·(θ−1) ≈ 1.8k multiplications at ν=16, θ=8 — trivial for the AIR.
4393. **Mask consistency** — $e_{i,f} = s_{i,f} + \mathrm{PRF}(K_i, \mathrm{maskCtx}(i,f))$ with
440   the same $(s_i, K_i)$ committed in $h_i$.
4414. **voteID derivation** from `(processID, address, k)` and the `inputsHash` binding above.
4425. **Authentication** (§11): knowledge of `sk` with `H(sk)` bound in the census leaf — or,
443   for an unenrolled hybrid voter (`pk_PQ = 0`), knowledge of the self-chosen `sk_pkg` bound
444   in the chain's first `pkgCommit` (§11), with identity resting on `hybridSig`. For a
445   revote, additionally the predecessor opening (same slot, same key) and the `NULL`
446   derivation of §5.3.
447
448What the proof deliberately does **not** show: that `ct_i` decapsulates to the committed
449$K_i$. Proving ML-KEM in-circuit would drag SHAKE through the AIR. Instead, mismatched
450transport is *harmless to integrity* (no tally proof ever runs Decaps — §10.2) and *publicly
451excludable* (complaints — §9.2). A STARK-friendly verifiable encryption removing this
452trade-off is the main tracked upgrade (§15).
453
454**Indicative numbers** (estimates until the v3 circuit is benchmarked; the prototype [DST]
455measured 3.2 s native proving and ~12 ms verification for a *larger* trace): trace ≤ 2048 ×
456~200 columns, ~10–20 s desktop-browser proving (mobile will be slower — to be benchmarked;
457the ~400 KB proof uploads once to one sequencer and is never stored on-chain).
458
459---
460
461## 7. State tree changes
462
463Same SHA-256 sparse Merkle tree, depth 64, same namespaces as v2, three changes:
464
465![State tree v3 layout](figures/state-tree-v3.svg)
466
4671. **Vote-ID leaves carry the package digest**: `voteID → pkgDigest` (v2 stored 0). This lets
468   revotes and complaints authenticate a package *body* against the chain.
4692. **Slot leaves are chained opaque digests** (no ballot data):
470   - first vote / overwrite: `leaf = SHA-256("davinci-slot-v3" ‖ pkgDigest ‖ s_batch)`
471   - refresh: `leaf' = SHA-256("davinci-refresh-v3" ‖ leaf ‖ s_batch)`
472   with `s_batch` the sequencer's secret batch seed (proven in-guest, never published — the
473   same trust class as v2's re-encryption seed). A refresh needs only the **public current
474   leaf** plus the refresher's own secret, so **any sequencer can refresh any occupied slot**
475   — permissionless sequencing is preserved and a vanished sequencer blocks nothing. Both
476   update types produce fresh-looking 32-byte values; this plus the padded accumulator is
477   what replaced re-encryption-based silent revoting.
4783. **Config namespace**: `0x3` = `wardenSetHash` (§4) instead of an encryption key; `0x4` =
479   `SHA-256(A)` (the accumulator value itself is published in every batch's blobs); `0x5`
480   (reserved in v2) = the root of the **nullifier tree**, a dedicated SHA-256 SMT of depth
481   256. A nullifier is a Poseidon2 digest serialized to 32 bytes (4×8 B LE), used directly
482   as the 256-bit key; leaf value = 1.
483
484---
485
486## 8. The batch program (ZisK guest)
487
488In one line: the batch program is the referee — it re-checks every vote package, applies the
489state updates, and maintains the masked running total.
490
491Same role, same settlement flow, same public-output pattern (`ok`/`failMask`, old/new roots,
492counters, census root, blobs digest) as v2. The constraint groups change as follows.
493
494![Batch program v3 dataflow](figures/batch-flow.svg)
495
496### 8.1 Ballot proof verification
497Verifies the n ballot STARKs **in-guest**. FRI verification is hash-dominated and ZisK
498exposes a Poseidon2-Goldilocks precompile; the measured count on the prototype verifier is
499**7,515 permutations per proof**, giving a *modeled* in-guest cost of roughly 1M steps per
500ballot (to be benchmarked). The ballot verifier configuration (AIR identity, FRI profile,
501Poseidon2 constants) is pinned via `ballotVKHash` at config leaf `0x7`, as in v2.
502
503### 8.2 Census, authentication, binding
504As v2 for census membership and slot derivation. Authentication follows the election's
505**auth policy** (§11): `pq-only` relies on the in-STARK preimage proof alone; `hybrid`
506*additionally* verifies `hybridSig` (ECDSA over `pkgDigest`, secp256k1 precompile, recovered
507address = census address) for every package; `hybrid-legacy` dispatches per census leaf as
508specified in §11. The program recomputes `ctsDigest`, `inputsHash` and `pkgDigest` from the
509package body and matches them against the proof's public inputs and the inserted leaf value
510— so an admitted package is byte-for-byte the one the voter's proof authorized (§6).
511
512### 8.3 State transitions
513In fixed order, each proven against the previous root, as v2: (1) insert
514`voteID → pkgDigest`; (2) insert revocation nullifiers with the one-live-chain checks of
515§5.3 (predecessors must be settled under the starting root); (3) write slot leaves (votes +
516overwrites), then refresh the sample $\mathcal{R}$ (§7.2; sample-size rule as v2); (4) update
517`0x4` with the new accumulator digest and `0x5` with the new nullifier root.
518
519### 8.4 Accumulator update and the batch pad
520$$A' = A + \sum_{\text{new pkgs}} E \; - \sum_{\text{consumed pkgs}} E \; + \; B$$
521
522In words: the new accumulator is the old one, plus the masked shares of every package this
523batch adds, minus the masked shares of every package it revokes, plus a fresh secret pad $B$
524whose only job is to hide *which* rows were subtracted.
525
526Here $B \in \mathbb{F}^{\nu \times 16}$ is a fresh **uniform** batch pad derived in-guest
527from the secret batch seed. Without $B$, the public batch delta minus the (public) new-package
528sums would equal $-\sum_{\text{consumed}} E$, letting anyone identify revoked packages by
529matching public `E` rows. $B$ is deliberately *unstructured* — a Shamir-codeword-shaped pad
530would vanish under the code's public parity checks and leak the same information.
531
532### 8.5 The warden payload (KEM-DEM, proven)
533Per batch, the guest: derives a 256-bit batch key $k_b$ and the ML-KEM encapsulation
534randomness from the secret batch seed (guest-internal derivation under the pinned program, so
535it is as trustworthy as the proof itself); DEM-encrypts (§2.1)
536`payload = (B ‖ consumed pkgDigests ‖ context)` under $k_b$; Shamir-shares $k_b$
537**coordinate-wise over its 32-bit limbs** θ-of-ν; and for each warden $i$: one in-guest
538ML-KEM encapsulation to $pk_i$ → wrapping secret → DEM-encrypts share $i$. The proof binds
539$B$ to the accumulator update, the consumed list to the nullifier insertions, and every
540ciphertext to its registered recipient key and context. **Unlike voter transport, a malformed
541batch payload is unprovable, not merely complainable** — it would hide an accepted
542transition's revocations and pads from the tally. All of it is published in the batch's blobs.
543
544### 8.6 Blob layout v3 and honest DA numbers
545Blob cells carry 31 payload bytes each (a v3 codec choice — v2 packed typed values; v3 packs
546an opaque byte stream per section), 4096 cells per blob ⇒ 126,976 B per blob. Sections, in
547order: header · new packages (CanonicalPackage bytes) · slot-update list
548(slot index 8 B + new leaf 32 B — so a refresh costs 40 B framed, vs ~1–2 KB in v2) ·
549nullifiers (32 B each) · accumulator value $A'$ (ν·16·8 B) · warden payload (§8.5).
550Byte-exact cell maps live in the davinci-zkvm normative docs, as in v2.
551
552Per-package size: `72 + ν·(160 + ct_len)` bytes (72 B fixed fields; per warden: 128 B of
553masked shares + 32 B commitment + one ciphertext) ⇒ **20,040 B** at ν=16/ML-KEM-768;
55414,920 B at ν=16/ML-KEM-512; 6,312 B at ν=5/768; 1,320 B at ν=1.
555
556| Profile (256 votes + 256 refreshes) | batch bytes | blobs (126,976 B each) | vs v2 (~5 blobs) |
557|---|---|---|---|
558| ν=16, ML-KEM-768 | ≈ 5.2 MB | **≈ 41 — exceeds the 32-blob batch cap** ⇒ max ~195 votes/batch, or use ML-KEM-512 | ~8× |
559| ν=16, ML-KEM-512 | ≈ 3.9 MB | ≈ 31 | ~6× |
560| ν=5, ML-KEM-768 | ≈ 1.7 MB | ≈ 14 | ~2.7× |
561| ν=1 (sequencer mode) | ≈ 0.35 MB | ≈ 3 | ~0.7× — *cheaper than v2* |
562
563DA is v3's main cost regression and is linear in ν: size committees to the election's
564stakes. Classic McEliece transport (96–128 B ciphertexts ⇒ 4.2–4.7 KB/package at ν=16 by the
565same formula) is the tracked reduction path for large committees [MCE].
566
567---
568
569## 9. End of election: freeze, complaints, exclusions
570
571The v2 timeline (end → grace window) gains two phases before results:
572
573![Election timeline v3](figures/timeline.svg)
574
575### 9.1 Casting freeze
576When the grace window closes the registry stops accepting transitions (as v2) and the
577accumulator freezes as $A_{\text{cast}}$, bound to the frozen final root.
578
579### 9.2 Complaint window and the exclusion set X
580During a scheduled window (an election parameter, like the grace bounds), **registered
581wardens of the election** may submit complaints: `submitComplaint(processID, pkgDigest,
582publicValues, proof)` where the ZisK proof shows `Decaps(sk_i, ct_i)` yields a key
583inconsistent with the package's admitted $h_i$ (witness: the warden's registered key seed;
584statement bound to the admitted `pkgDigest` and the frozen root). The registry verifies the
585proof and appends the package to an **idempotent, append-only exclusion set $X$**. Complaints
586**never touch the accumulator** — so no complaint needs to know whether its package was
587already consumed, and ordering cannot matter. Submission is allow-listed to the election's ν
588wardens; the submitter pays gas. **Capacity is sized to the workload, not an arbitrary cap**:
589the registry bounds total admitted casts (`maxVoters × maxRevotes`, a new creation
590parameter), and the complaint window length and the wardens' proving/fee budget must cover
591that bound in the worst case (an adversary can make the complaint path linear in admitted
592casts — this is an explicit liveness assumption, §9.3, not an exceptional path). At the
593deadline $X$ freezes on-chain; every tally proof binds the frozen
594$(\text{root}, A_{\text{cast}}, X)$ snapshot.
595
596Semantics, stated plainly: a voter whose *live* package ends up in $X$ is not counted (their
597earlier packages stay consumed) — a deliberately malformed revote is a provable
598self-abstention, and a voter+warden coalition gains a bounded post-close withdrawal option
599for that voter's own ballot. A package malformed toward warden $i$ that is *not* excluded
600still tallies correctly from wardens that can open it (§10.2); warden $i$ either complains in
601the window or sits out.
602
603### 9.3 Liveness
604The tally needs at least θ wardens (the tally threshold) that complete the archive scan (and any complaints) inside the
605window, complete the ceremony (§10.3), and publish proven contributions — plus, as in v2,
606timely inclusion of their transactions, **plus complaint capacity (proving + fees + window
607length) provisioned for the election's admitted-cast bound in the worst case (§9.2)**.
608Fewer ⇒ results are lost, exactly as v2's "θ of ν wardens take part in decryption".
609
610---
611
612## 10. Tally: warden sums and Lagrange
613
614In one line: this is where the masked running total becomes the election result — in public,
615with proofs, and without any decryption key.
616
617### 10.1 What each participating warden computes
618After the exclusion freeze, each participating warden $i$:
6191. downloads the complete blob archive (same DA story as any v2 observer; work is linear in
620   *total casts*, not final voters);
6212. decapsulates its per-package ciphertexts, recovers shares
622   $s_{v,i,f} = e_{v,i,f} - \mathrm{PRF}(K_{v,i}, \mathrm{maskCtx})$, and checks each against
623   the admitted $h_{v,i}$;
6243. joins the **tally ceremony** (§10.3): the participants reconstruct the per-batch payload
625   keys (θ shares each), decrypt the payloads — obtaining every batch pad $B$ and the full
626   consumed set $R$, verified against the batch proofs that committed them — and run the
627   zero-blinding round producing $G_f$;
6284. computes, over $\mathrm{Active} = \mathrm{Admitted} \setminus (R \cup X)$:
629
630$$S_{i,f} = A_{\text{cast},i,f} - \sum_{v \in X \setminus R} e_{v,i,f} - \sum_{v \in \mathrm{Active}} \mathrm{PRF}(K_{v,i}, \mathrm{maskCtx}) - \sum_{b} B_{b,i,f} + G_f(i)$$
631
632In words: start from the frozen running total; remove the rows of excluded-but-never-revoked
633packages; strip your own masks for every counted package; strip the batch pads; add your
634blinding share.
635
636One-line sanity check: $A_{\text{cast}}$ = (masked shares of all admitted-minus-consumed
637packages) + (all batch pads); removing the still-present excluded rows, all pads, and all
638batch pads leaves exactly $\sum_{\mathrm{Active}} s_{v,i,f}$; adding $G_f(i)$ with
639$G_f(0)=0$ doesn't change the interpolation at 0.
640
6415. publishes $S_i$ with a **ZisK proof** whose statement binds: the election, the frozen
642   $(\text{root}, A_{\text{cast}}, X)$ snapshot, the complete archive commitment, its
643   recipient index, and the accepted ceremony transcript (§10.3) — and whose witness contains
644   its KEM key seed (authenticating it as warden $i$ against the registered commitment), the
645   per-package $(s, K)$ openings **for every counted active package** (each checked against
646   its admitted $h_{v,i}$), the reconstructed payload keys and payload openings, and its
647   blinding evaluations. The program enforces **complete, exactly-once processing** of every
648   admitted package in the archive (counted, consumed, or excluded — nothing skipped) and
649   that $R$ and $B$ are the values authenticated by the accepted batch payloads.
6506. `submitTallyShare(processID, i, S_i, publicValues, proof)`; after θ verified shares,
651   anyone calls `finalizeResults(processID)`: **the registry performs the Lagrange
652   interpolation on-chain** (θ ≤ 16 points over Goldilocks — a few u64 mulmods per field),
653   records the per-field results, and emits `ProcessResultsSet`.
654
655Wardens run their **own provers**: the witness contains their secrets, and a shared proving
656service used by θ wardens would itself hold reconstruction capability. Proving cost scales
657with total casts (a few Poseidon2 permutations per package; as an **unvalidated projection**
658— archive, payload and ceremony checks included — on the order of 10^8 guest steps for a
659million-cast election, to be benchmarked with the v3 implementation before warden hardware
660guidance is given).
661
662### 10.2 Why malformed voter transport cannot corrupt anything
663**Decapsulation never appears in any tally proof** — contributions open the admitted
664commitments $h$ instead, and under commitment binding every accepted $S_i$ lies on the same
665aggregate polynomial. A voter publishing a bad `ct_i` only deprives warden $i$ of its opening
666witness (warden $i$ complains or sits out; the voter could even re-supply the opening
667out-of-band, which is safe — correctness is tied to $h$, not to the transport). Every clean
668θ-subset interpolates the same tally, because the ballot STARK proved all ν shares lie on one
669valid polynomial. Malformed transport is an availability lever against one warden, never an
670integrity lever against the election.
671
672### 10.3 The zero-blinding ceremony
673In plain terms: before publishing their partial sums, the participating wardens jointly add
674noise that cancels out exactly at the finish line (x = 0), so the published sums reveal the
675result and nothing else. Why it's needed: published raw, θ sum-shares determine the aggregate
676polynomial $F$; any single warden — participant or not — could evaluate it at its own index,
677compare with the sum of its decoded per-package shares, and fingerprint the revoked set. The
678ceremony prevents that:
679
6801. A `tallySession` is recorded on-chain: session id = `H(processID ‖ root ‖ X ‖ roster)`,
681   with the participant roster and dealer set fixed (dealers = the participants).
6822. Each dealer $k$ samples a seed and derives, per field, blinding coefficients
683   $c_{k,f,1..\theta-1}$, defining $g_{k,f}(x) = \sum_j c_{k,f,j} x^j$ — **the constant term
684   is structurally absent, so $g_{k,f}(0) = 0$ by construction** (this is the
685   "zero-certificate": the committed coefficient vector simply has no degree-0 entry).
6863. Dealer $k$ publishes (in a session blob): a hiding Poseidon2 commitment to its
687   coefficients; **per-recipient hiding evaluation commitments**
688   $cm_{k,i} = \mathrm{Poseidon2}(g_{k,1..16}(i), r_{k,i})$; the KEM-DEM ciphertexts to each
689   co-participant $i$ encrypting $(g_{k,1..16}(i), r_{k,i})$; and a **ZisK dealer proof**
690   that the committed coefficients, the evaluation commitments, and the ciphertexts are all
691   consistent, under the recipients' registered keys and this session's context.
6924. Contributions use $G_f(i) = \sum_{k \in D} g_{k,f}(i)$ over the **accepted dealer set
693   $D$** — fixed on-chain after the dealer deadline; every contribution proof binds the same
694   $D$ and session id, and **opens the evaluation commitments $cm_{k,i}$** (the recipient
695   learned the opening by decapsulating off-circuit — decapsulation still never enters any
696   tally proof). A dealer whose proof is missing or invalid is excluded and the session
697   restarts with fresh masks (roster must stay ≥ θ).
698
699As long as one accepted dealer is honest, no one outside the ceremony — and no
700non-participating warden — learns anything about $F$ beyond what the public tally
701$F(0)$ itself reveals. Participants do jointly learn the
702revoked set $R$; that is the documented θ-gated metadata leakage (§12.2).
703
704---
705
706## 11. Census and authentication
707
708- **Census trees** migrate from Poseidon-BN254 to Poseidon2-Goldilocks (a breaking format
709  change; same lean-IMT structure). Leaf encoding:
710  `leaf = Poseidon2(address, weight, pk_PQ)` with `pk_PQ = H(sk)` for a CSPRNG-generated
711  secret, or `pk_PQ = 0` for a not-yet-enrolled voter (hybrid censuses only).
712- **PQ-key enrollment.** The Ethereum wallet signs an enrollment message binding
713  `address ↔ pk_PQ`; the signature *authorizes* the binding and is never key entropy (a
714  future ECDSA break must not reveal PQ secrets). Enrollment paths per census origin:
715  off-chain censuses collect `pk_PQ` at census construction; on-chain/token censuses read a
716  global **PQKeyRegistry** contract where voters register once (one transaction, reusable
717  across all elections); CSP censuses include `pk_PQ` in the credential.
718- **Election auth policy** (immutable registry parameter, fixed at creation):
719  - `pq-only`: every leaf must carry `pk_PQ`; authentication is the in-STARK preimage proof
720    alone; no ECDSA anywhere in the ballot path.
721  - `hybrid`: every leaf must carry `pk_PQ`, and every package is verified on **both**
722    authenticators — the in-STARK preimage proof *and* `hybridSig` (ECDSA over `pkgDigest`,
723    verified by the batch program). No OR-downgrade exists in this mode.
724  - `hybrid-legacy`: like `hybrid`, but leaves with `pk_PQ = 0` are admitted with identity
725    resting on ECDSA alone; the STARK's auth clause (§6.5) switches to a **self-chosen
726    package key**: the voter generates `sk_pkg` (CSPRNG; kept with the package opening). The
727    first package binds `H(sk_pkg)` inside `pkgCommit`. Every later package in the chain
728    proves knowledge of the *same* `sk_pkg` (predecessor opening) and derives its nullifier
729    as `NULL = Poseidon2(nullCtx, sk_pkg, prevPkgDigest)`. The batch program dispatches per
730    leaf: `pk_PQ ≠ 0` ⇒ both authenticators against the census key; `pk_PQ = 0` ⇒ mandatory
731    `hybridSig` + the `sk_pkg` clause. Anyone can count the legacy-status census members
732    (leaf contents are public census data) — though not, of course, which *final* packages
733    are theirs beyond what slot-participation already reveals. Ballot *privacy* is fully PQ
734    for these voters; the election's **integrity assumptions include ECDSA security for its
735    legacy voters** (§12.1). This mode is what makes existing token censuses usable before
736    universal enrollment.
737- **Enrollment snapshot rule.** A voter's authentication status and key for an election are
738  pinned at the election's **creation snapshot**: for on-chain/token censuses the registry
739  records the PQKeyRegistry root at the creation block, and membership proofs must present
740  the enrollment status under that snapshot regardless of which (newer) eligibility root the
741  census contract later accepts. Enrolling *after* an election was created affects
742  subsequent elections only — an existing package chain never changes keys mid-election.
743- **CSP censuses**: credentials become SLH-DSA signatures [FIPS 205] over the v2 message
744  format extended with `pk_PQ`; verification is pure hashing via the SHA-256 precompile.
745- Slot derivation, participation visibility, census origins 1–4 mechanics: as v2, with the
746  enrollment additions above. The v2 census invariants (slot uniqueness across the census;
747  stable distinct CSP indexes) remain assumptions of integrity.
748
749---
750
751## 12. Security properties, stated plainly
752
753### 12.1 What holds, under what
754
755| Property | Holds if |
756|---|---|
757| **Tally integrity** | STARK/zkVM soundness (FRI + hashes), binding commitments, correct pinned programs, the settlement chain executes the registry, and the v2 census invariants (unique slots / stable CSP indexes). Then no coalition of voters, sequencers, provers or wardens can shift a tally — including via malformed KEM transport (§10.2). |
758| **Ballot privacy** | fewer than θ warden keys compromised **over their whole lifetime** (not just the active epoch), ML-KEM IND-CCA, PRF/hash security, hiding STARKs, and honest voter devices. Below θ, shares in isolation are information-theoretically independent of the ballot. **Post-quantum computational privacy — not "everlasting"**: an unbounded adversary could attack archived KEM transcripts. |
759| **Revote hiding (public data)** | hash security + the sealing sequencer/prover draws the batch seed *and the refresh set* from fresh randomness and keeps them secret (v2's exact trust statement). Public data reveals participation per slot, update counts/timing, `numOverwrites` — v2's leakage surface. |
760| **Exact tally** | unconditional arithmetic (mod-$p$ sums, Lagrange). ML-KEM's residual decapsulation-failure probability (≈2^-139 per pair at ML-KEM-512, ≈2^-164 at -768; election-wide union bound over *all* encapsulations: per-ballot, batch shares, ceremony deliveries) is not zero even for proven-correct encapsulations. Each failure degrades gracefully: a per-ballot failure becomes a complaint; a batch-key *share* failure is tolerated provided at least θ valid shares remain available (with ν=θ, or only θ responsive wardens, one failed share means that payload cannot be reconstructed and the tally cannot complete — size ν above θ accordingly); a ceremony delivery failure excludes the dealer and restarts the session. Deliberately malformed batch transport is a different thing entirely — it is unprovable (§8.5), so it cannot appear in an accepted batch. |
761| **Liveness** | ≥1 honest sequencer with proving capacity and timely inclusion (as v2), plus ≥θ wardens through the scan window and ceremony (§9.3). |
762
763### 12.2 What wardens and insiders learn
764θ colluding wardens can reconstruct **every package's ballot** — exactly v2's boundary, where
765θ wardens can decrypt every ballot. New, and narrower: the **tally participants** (a θ-sized
766set) jointly learn the revoked-package set $R$ — metadata, not contents — and any one of them
767can leak it onward; non-participating wardens and the public learn nothing about $R$ (batch
768pads §8.4 + blinding §10.3 close those channels, given ≥1 honest accepted dealer). The
769sequencer/prover that seals a vote learns its revote linkage (§5.4) — as in v2.
770
771### 12.3 The honest coercion statement
772v3 keeps v2's informal posture (no formal receipt-freeness; revotes hidden among refreshes)
773with **one new residual, stated openly**: a coercer who obtains a package's *revocation
774token* — by extracting the voter's identity key, **or** by demanding a ZK proof of the
775token's derivation, **or** a valid unsubmitted revote authorization — can watch the public
776nullifier tree and detect whether that package was later consumed. v2's re-encryption resists
777even that (testing re-encryptions is a DDH-type problem). This is the main new
778coercion-relevant difference from v2 (alongside the §12.2 participant metadata); mitigations
779are Track-2 research (§15). Deployments for coercion-sensitive elections should weigh it.
780
781### 12.4 Proof-system notes
782The ballot STARK profile targets ~102-bit *conjectured* FRI soundness (ethSTARK heuristic
783[ETHS]) — an explicit engineering dial (queries × log-blowup + grinding), to be raised for
784high-stakes deployments, and **not** claimed as 128-bit PQ security. The v2-era prototype's
785three known defects (weight-bound bypass at `maxValueSum=0`; wraparound-prone comparators;
786weak hiding-PCS blinding RNG with a constant fallback seed) are normatively fixed in v3
787(§6.1; 256-bit CSPRNG blinding seed, fail-closed).
788
789### 12.5 Out of scope / inherited
790EIP-4844 KZG commitments (Ethereum's own PQ roadmap), organizer/sequencer Ethereum accounts,
791hybrid-mode ECDSA (by construction), and the BN254 PlonK wrapper around ZisK proofs —
792integrity-only, replaceable by direct on-chain STARK verification (indicative public data
793point: ~5–6 MGas for a WHIR/FRI verifier on the EVM [WHIR]; not a measured cost for ZisK
794proofs) — tracked as the final migration phase.
795
796---
797
798## 13. Cost summary
799
800| Metric | v2 | v3-PQ (estimates unless marked measured) |
801|---|---|---|
802| Browser proving | seconds (Groth16, 35.5 MiB key download) | ~10–20 s desktop (STARK; no key download; prototype measured 3.2 s native on a larger trace) |
803| Ballot upload to sequencer | ~2 KB | ~20 KB package + ~400 KB proof (proof not stored on-chain) |
804| DA per ballot | ~2 KB | 1.7–20.5 KB depending on ν and KEM (§8.6 table) |
805| DA per refresh | ~1–2 KB | 40 B (framed) |
806| Batch proving | 2.3–4.0×10^8 steps | + ~1M steps × votes for STARK verification (7,515 Poseidon2 permutations/proof **measured**) |
807| Tally | θ partial decryptions of one accumulator + BSGS | archive-linear warden jobs (§10.1) + one ceremony + on-chain Lagrange |
808| Registry tally cap | 10^12 | 2^61 |
809
810---
811
812## 14. Errors and edge cases (normative)
813
814- **voteID collision** (admission finds the leaf occupied): resample `k` (recovery mode:
815  bump the counter) and re-cast — as v2. Skipped counters are harmless (§5.2 recovery scan).
816- **Unsettled predecessor**: a revote consuming a predecessor not yet settled under the
817  batch's starting root is rejected at admission and retried by the sequencer in a later
818  batch automatically; clients should submit revotes to the sequencer that holds their
819  pending vote, as in v2.
820- **Duplicate revocation race** (two sequencers hold revotes of the same package): the first
821  settles; the loser's re-validation drops the vote at admission (nullifier present) and
822  notifies the voter — the v2 "voteID already in state" pattern.
823- **Live package excluded** ($P_t \in X$): the client detects it (public $X$) and informs
824  the voter they are not counted; no recovery within the election (casting is closed when
825  complaints run).
826- **Warden key unavailable at cast time**: the client refuses to cast (it cannot build a
827  complete package); election creation already requires all ν keys registered (§4).
828- **Ceremony dealer failure**: dealer excluded, session restarted with fresh masks (§10.3);
829  if the roster drops below θ, the tally is lost — counted under liveness (§9.3).
830
831---
832
833## 15. Tracked upgrades
834
8351. **STARK-friendly verifiable encryption** (RLWE-LPR with a Poseidon2-based FO transform) to
836   prove warden transport at admission — removes the complaint window entirely. Requires its
837   own security review before adoption.
8382. **PQ re-randomizable package representation** — would restore v2-grade resistance to
839   revocation-token coercion (§12.3). Open research.
8403. **Locked mode** as a separately specified and reviewed extension (§4).
8414. Direct on-chain STARK verification (drop the PlonK wrapper) once rollup gas permits.
8425. Classic McEliece transport profile for large committees [MCE].
843
844---
845
846## 16. References
847
848- [DAV2] Vocdoni, *DAVINCI protocol specification v2*. https://spec.davinci.vote
849- [FIPS 203] NIST, *Module-Lattice-Based Key-Encapsulation Mechanism Standard (ML-KEM)*, 2024. https://doi.org/10.6028/NIST.FIPS.203
850- [FIPS 205] NIST, *Stateless Hash-Based Digital Signature Standard (SLH-DSA)*, 2024. https://doi.org/10.6028/NIST.FIPS.205
851- [Sha79] A. Shamir, *How to Share a Secret*, CACM 22(11), 1979.
852- [DST] Vocdoni, *davinci-stark: Plonky3 ballot proof prototype*. https://github.com/vocdoni/davinci-stark
853- [P3] Polygon Zero, *Plonky3*. https://github.com/Plonky3/Plonky3
854- [ZISK] Polygon, *ZisK zkVM*. https://github.com/0xPolygonHermez/zisk
855- [POS2] L. Grassi et al., *Poseidon2: A Faster Version of the Poseidon Hash Function*, ePrint 2023/323.
856- [ETHS] StarkWare, *ethSTARK Documentation*, ePrint 2021/582.
857- [EIP4844] V. Buterin et al., *EIP-4844: Shard Blob Transactions*, 2022.
858- [IR89] R. Impagliazzo, S. Rudich, *Limits on the Provable Consequences of One-Way Permutations*, STOC 1989.
859- [NOAH] M. Dahl et al., *Noah's Ark: Efficient Threshold-FHE Using Noise Flooding*, WAHC/CCS 2023.
860- [TEV] J. Alizadeh, *Threshold Post-Quantum E-Voting from Lattice Commitments*, ePrint 2026/2500.
861- [PQK] N. Huber et al., *PQKryvos: Post-Quantum Secure E-Voting With Flexible Ballot Formats and Public Tally-Hiding*, PoPETs 2026.
862- [MCE] D. J. Bernstein et al., *Classic McEliece*. https://classic.mceliece.org
863- [KEMB] *ML-KEM WebAssembly implementations and benchmarks*. https://github.com/dchest/mlkem-wasm
864- [WHIR] *EVM Verification of WHIR over a 31-bit Field*, ethresear.ch, 2025.