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