% !TeX root = ../build/main.tex At the core of \davinci lie three proof statements that enforce the correctness of every step of the election. Each statement corresponds to a distinct task and, taken together, they guarantee that all protocol rules are satisfied without revealing any private information. Specifically, the \emph{ballot circuit} (Section~\ref{sec:vocdoni-protocol:circuits:ballot}), proven by the voter, ensures that an encrypted vote is valid and well-formed; the \emph{batch program} (Section~\ref{sec:vocdoni-protocol:circuits:batch}), proven by a sequencer in a \ac{zkVM}, verifies a batch of votes, applies it to the state tree, and lays out the published data, producing the single proof that is verified on-chain for each state transition; and the \emph{results program} (Section~\ref{sec:vocdoni-protocol:circuits:results}) proves that the election results were correctly decrypted from the final state. The ballot circuit is an arithmetic circuit proven with Groth16, small enough to be proven on a voter's device. The two programs are Rust programs compiled to RISC-V and proven with the ZisK \ac{zkVM}, whose proofs are verified on-chain by the \hlget{\ziskverifier} contract (see Section~\ref{sec:background:zkp}). The flow of these proofs and their interactions is shown in Fig.~\ref{fig:circuits-flow}. \begin{figure}[h] \centerline{\includegraphics[width=\linewidth,draft=false]{\figs/circuits-flow.pdf}} \caption{Flow of the voter's circuit and the sequencer's \ac{zkVM} programs.} \label{fig:circuits-flow} \end{figure} The batch program replaces the pipeline of a verifier circuit, an aggregation circuit, and a state transition circuit used by an earlier design of \davinci. The statement is the same in spirit, but writing it as one program removes the need for recursion over several curves and makes it possible to prove properties that are impractical in circuits, such as the reconstruction of the published blob data from the verified state. A \ac{zkVM} program differs from a circuit in one respect that the protocol must account for: the program always runs to completion and commits its public values, including a flag that reports whether every check passed. A proof of the batch program is therefore only meaningful together with the flag, and the registry rejects any proof whose flag is not set (see Section~\ref{sec:vocdoni-protocol:circuits:batch}). \begin{remark} For clarity, the statements are described in this section with their full set of inputs and outputs explicitly listed. In the actual implementation, the ballot circuit applies an optimization: rather than exposing all of its public inputs $\publicinputs$ individually, it exposes the voter's address, the vote identifier, and a single commitment $\ballotinputshash = \hlget{\Poseidon}(\publicinputs)$ to all the inputs that the batch program must bind (see the multi-input Poseidon construction in Appendix~\ref{sec:cryptographic-primitives:hash}). The batch program recomputes the commitment from the values it uses and checks that it matches the one proven by the voter. This optimization does not alter the semantics of the circuit but significantly reduces the cost of verifying ballot proofs. Similarly, the public values of the \ac{zkVM} programs reach the ZisK verifier as a single SHA-256 digest. Other implementation aspects such as the exact number of constraints and the proving frameworks used are deferred to Section~\ref{sec:analysis:implementation}. \end{remark} \subsubsection{Ballot circuit} \label{sec:vocdoni-protocol:circuits:ballot} The ballot circuit (\hlset{\ballotcircuit}), illustrated in Fig.~\ref{fig:circuit-ballot}, is proven locally by the voter at the time of casting a ballot. Its purpose is twofold: first, to prove that the encrypted ballot is valid and complies with the protocol rules defined by the organizer; and second, to prove that the vote identifier (\voteid) has been correctly derived. The correctness of this circuit is attested by a \ac{ZK} proof generated using the Groth16 protocol described in Appendix~\ref{sec:cryptographic-primitives:zkp}, instantiated over the BN254 curve. We call the resulting proof \textit{ballot proof} and denote it as $\hlset{\ballotproof}$. The circuit is compiled for the maximum number of ballot fields, $16$; ballots with fewer fields leave the remaining ones unconstrained here, and the batch program requires their ciphertexts to be the identity. We detail below the inputs and constraints of the ballot circuit. \vspace{0.3cm} \noi \textbf{Public inputs} \begin{itemize} \item $\public$ $\address$: voter's address. \item $\public$ $\voteid$: vote's unique identifier. \item $\public$ $\ballotinputshash$: commitment to the inputs that the batch program binds, namely $\processid$, $\ballotmode$, $\epk$, $\address$, $\voteid$, $\encryptedballot$, and $\weight$. \end{itemize} \textbf{Private inputs} \begin{itemize} \item \private $\processid$: election identifier. \item \private $\ballotmode$: ballot protocol configuration, packed as in the state tree. \item \private $\epk$: encryption public key. \item \private $\weight$: voter's weight. \item \private $\encryptedballot$: encrypted ballot, i.e., one ElGamal ciphertext per ballot field. \item \private $\ballot$: voter's voting choice, i.e., one value per ballot field. \item \private $k$: random scalar. \end{itemize} \textbf{Constraints} \begin{itemize} \item \emph{Inputs commitment}. The commitment is computed over the inputs in a fixed order: \begin{align*}\ballotinputshash = \hlget{\Poseidon}(&\processid, \ballotmode, \epk, \address,\\ &\voteid, \encryptedballot, \weight).\end{align*} \item \emph{Vote encryption}. Correct encryption of the ballot. Every field $j \in \{1,\dots,\numfields\}$ is encrypted with its own randomness, derived from $k$ by iterated hashing: \[k_0 = k, \qquad k_j = \hlget{\Poseidon}(k_{j-1}), \qquad \encryptedballot_j = \hlget{\Enc}_{\epk}(\ballot_j; k_j).\] \item \emph{Encryption key}. The key $\epk$ lies in the prime-order subgroup of BabyJubjub and is not the identity. \item \emph{Protocol rules compliance}. The voter's ballot meets the protocol rules (see Section~\ref{sec:ballot-protocol}): \[\text{protocolRulesCompliance}(\ballotmode, \weight, \ballot) = \true.\] \item \emph{Vote identifier}. The vote's identifier is correctly computed ($N = 2^{63}$, see Section~\ref{sec:vocdoni-protocol:state-tree}): \[\voteid = N + \bigl(\hlget{\Poseidon}(\processid,\address,k) \bmod N\bigr).\] \end{itemize} \vspace{-0.3cm} \begin{figure}[H] \centerline{\includegraphics[width=\linewidth,draft=false]{\figs/circuit1.pdf}} \caption{Ballot circuit. Public values are framed in green, secret private values in red, and private values bound by \ballotinputshash in orange.} \label{fig:circuit-ballot} \end{figure} \noi The ballot proof does not authenticate the voter: anyone who knows a voter's address could prove a ballot for it. Authentication is provided by a separate signature over the vote identifier, $\signature = \hlget{\SSign}_{\sk}(\voteid)$, produced with the voter's SECP256K1 key and verified by the batch program. Because the vote identifier is bound to the encrypted ballot through $k$ and through \ballotinputshash, the signature authorizes exactly one encrypted ballot. \subsubsection{Batch program} \label{sec:vocdoni-protocol:circuits:batch} The batch program (\hlset{\batchprogram}), illustrated in Fig.~\ref{fig:batch-program}, is executed by the sequencer to update the global state of the election with a batch of votes. Its purpose is to verify that every vote in the batch is valid, authenticated, and cast by an eligible voter; that the batch has been correctly incorporated into the state Merkle tree, with overwrites and vote identifiers handled consistently; that every stored ballot is a correct re-encryption of the ballot the voter proved; that a sample of other stored ballots has been silently re-encrypted; that the encrypted results accumulator is updated accordingly; and that the data published in Ethereum blobs is exactly the data needed to rebuild the new state. The correctness of an execution is attested by a ZisK proof wrapped in PlonK over BN254, which we call the \textit{batch proof} and denote as $\hlset{\batchproof}$. It is submitted on-chain and verified by the \hlget{\processregistry} smart contract, ensuring that every accepted state transition complies with the protocol rules. To formalize the setting, let the sequencer collect a batch of $n$ votes, $1 \le n \le 1024$, of which $w$ overwrite a ballot already stored in the state and $n - w$ are the first ballot of their voter. In addition, the sequencer selects a set $\mathcal{R}$ of $|\mathcal{R}| \le 2048$ occupied slots, not written by the batch, whose ballots it re-encrypts. Each ballot consists of $16$ ElGamal ciphertexts over BabyJubjub, of which the first $n_f = \numfields$ are active and the rest are the identity. We write $B_i$ for the encrypted ballot proven by voter $i$, $B'_i$ for its re-encryption, and $B^\old_i$ for the stored ballot that it overwrites, if any; $R_j$ and $R'_j$ for the stored ballot of the $j$-th refreshed slot and its re-encryption; and $A$ for the results accumulator \encresults. A ballot is a vector of 16 ciphertexts, and $B_{i,f}$ denotes its $f$-th ciphertext. In the following, we describe the public outputs, the private inputs, and the constraints of the batch program. The private inputs are organized as the program reads them, in five blocks: ballot proofs, state transition, eligibility, re-encryption, and blobs. \vspace{0.3cm} \noi \textbf{Public outputs} \begin{itemize} \item \public $\okflag$, $\failmask$: whether every constraint below holds, and a bit mask of the groups of constraints that failed. \item \public $\stateroot^\old$: current Merkle root of the state tree. \item \public $\stateroot^\new$: new tree root after all state transitions are applied. \item \public $\numvotes$: number of votes in the batch, $n$. \item \public $\numoverwrites$: number of votes in the batch that overwrite a stored ballot, $w$. \item \public $\censusroot$: root of the census tree used by the membership proofs or, for a \ac{CSP} census, the address of the \ac{CSP}. \item \public $\occupiedbefore$: number of occupied ballot slots before the batch. \item \public $\blobsdigest$, $\nblobs$: digest of the blob commitments and evaluations, and number of blobs. \end{itemize} \textbf{Private inputs} \begin{itemize} \item \private $\mathsf{vk}$: verification key of the ballot circuit. \item \private $\{\ballotproof_i, \address_i, \voteid_i, \ballotinputshash_i, \signature_i\}_{i=1}^{n}$: ballot proofs with their public inputs, and the voters' signatures.\\ % \item \private $\processid$: election identifier. \item \private $\{\merkleInclusionPf^{\kappa}\}_{\kappa \in \{\texttt{0x0}, \texttt{0x2}, \texttt{0x3}, \texttt{0x6}, \texttt{0x7}\}}$: inclusion proofs of the configuration leaves \processid, \ballotmode, \epk, \censusorigin, and \ballotvkhash under $\stateroot^\old$. \item \private $\{\tau^{\voteid}_i\}_{i=1}^{n}$, $\{\tau^{\encryptedballot}_i\}_{i=1}^{n}$, $\{\tau^{\mathcal{R}}_j\}_{j=1}^{|\mathcal{R}|}$, $\tau^{\encresults}$: chains of tree transitions that insert the vote identifiers, write the ballots, refresh the sample, and update the results accumulator (see below). \item \private $\{\reencryptedballot_i\}_{i=1}^{n}$: the re-encrypted ballots written to the voters' slots. \item \private $\{\encryptedballot_i^\old\}$: the $w$ stored ballots that the batch overwrites. \item \private $\{\encryptedballot^{\mathcal{R}}_j\}_{j=1}^{|\mathcal{R}|}$: the stored ballots of the refreshed slots. \item \private $\encresults^\old$: current accumulator of votes. \\ % \item \private $\{\censuspf_i\}_{i=1}^{n}$: census membership proofs (Merkle paths, or \ac{CSP} signatures with their indexes and weights).\\ % \item \private $\epk$: encryption public key. \item \private $\seed$: secret seed of the batch, from which all re-encryption randomness is derived. \item \private $\{\encryptedballot_i\}_{i=1}^{n}$: the voters' encrypted ballots, as proven.\\ % \item \private $\{\blobcom_b\}_{b=1}^{\nblobs}$: \ac{KZG} commitments to the blobs. \end{itemize} \textbf{Constraints} \\ \vspace{-0.4cm} \begin{itemize} \item \emph{Ballot proof verification.} Every ballot proof is valid under the ballot verification key of the election. The program first checks that the key is the one committed in the state, $\Sha(\mathsf{vk}) = \ballotvkhash$, where the key is serialized as its points $\alpha, \beta, \gamma, \delta$, the number of coefficients of $L$ as a 64-bit little-endian word, and the coefficients of $L$, each coordinate as four 64-bit little-endian limbs, and the digest is read as a big-endian integer. It also checks that all proof points are on their curves and not the identity, and that the $\BN{\G}_2$ points of the key are in the prime-order subgroup. It then verifies the $n$ proofs at once with a randomized batch check~\cite{bellare1998batch}: it derives coefficients $\rho_1 = 1$ and $\rho_i = \mathsf{lo}_{128}\bigl(\Sha(\Sha(T) \conc \mathsf{LE64}(i-1))\bigr)$ for $i \ge 2$ from the transcript $T = \texttt{"groth16-batch-v2"} \conc A_1 \conc B_1 \conc C_1 \conc x_1 \conc \cdots \conc A_n \conc B_n \conc C_n \conc x_n$ of all proofs $(A_i, B_i, C_i)$ and public inputs $x_i$, encoded as raw limbs (a zero coefficient is replaced by $1$), and checks the single pairing equation obtained as the $\rho$-weighted product of the $n$ Groth16 verification equations, computing every scalar multiplication itself. A batch containing an invalid proof passes this check with probability at most $2^{-128}$. For every $i \in \{1,\dots,n\}$, this establishes $$\hlget{\PVerify}\bigl(\ballotproof_i, (\address_i, \voteid_i, \ballotinputshash_i)\bigr) = \true.$$ % \item \emph{Authentication.} Every ballot is signed by the owner of its address. For every $i$, the vote identifier is a 64-bit integer, a public key is recovered from the signature over the 32-byte message $\texttt{0x00}^{24} \conc \voteid_{i,\text{BE8}}$ in the Ethereum personal-message format, and its address is the voter's: $$\pk_i = \hlget{\SPubKey}(\voteid_i, \signature_i), \qquad \address_i = \mathsf{low\text{-}20}\bigl(\hlget{\Keccak}(\pk_i)\bigr).$$ % \item \emph{Census membership.} Each processed vote must correspond to an eligible voter, according to the census configuration specified by the parameter \censusorigin. \begin{itemize} \item If the census is a Merkle tree ($\censusorigin \in \{1,2,3\}$), then for every $i$ the program verifies a Merkle membership proof of the leaf $\address_i \cdot 2^{88} + \weight_i$ (Eq.~\eqref{eq:census-leaf}), \[ \hlget{\censusTree}.\hlget{\MTVerify}\big(\address_i \cdot 2^{88} + \weight_i, \idx_i, \censuspf_i, \censusroot\big) = \true, \] where $\idx_i$ is the position carried by the proof; all proofs share the same root, which is published as \censusroot, no leaf appears twice, and every path has a canonical shape (at most 61 siblings, and no index bit beyond the path length). \item If $\censusorigin = 4$ (\ac{CSP}), then for every $i$ the program recovers a public key from the credential over the message of Eq.~\eqref{eq:csp-message} and requires all credentials of the batch to recover the same key, whose address is published as \censusroot: \begin{gather*} \pk^{\mathsf{CSP}} = \hlget{\SPubKey}\big((\processid, \address_i, \weight_i, \idx_i), \censuspf_i\big),\\ \censusroot = \mathsf{low\text{-}20}\bigl(\hlget{\Keccak}(\pk^{\mathsf{CSP}})\bigr). \end{gather*} Addresses must be canonical 160-bit integers, and no address and no index may appear twice in the batch. \end{itemize} \item \emph{Binding.} The values used by the different checks are the same. For every $i$, the address of the census leaf (or credential) equals $\address_i$; the commitment recomputed from the values used below equals the one proven by the voter, \[\ballotinputshash_i = \hlget{\Poseidon}(\processid, \ballotmode, \epk, \address_i, \voteid_i, B_i, \weight_i);\] and the ballot written to the voter's slot is the re-encryption computed below. The election key is the one committed in the state: $\Sha(\epk_{x,\text{BE32}} \conc \epk_{y,\text{BE32}})$ equals the value of leaf \texttt{0x3}. Finally, the blob block refers to the same \processid and $\stateroot^\old$ as the state block. % \item \emph{Configuration.} The configuration of the election is read from the current state. The program verifies the inclusion proofs of the five configuration leaves under $\stateroot^\old$, in the order \texttt{0x0}, \texttt{0x2}, \texttt{0x3}, \texttt{0x6}, \texttt{0x7}, and requires the value of leaf \texttt{0x0} to be the \processid of the state block: \[\hlget{\stateTree}.\hlget{\MTVerify}(v_\kappa, \kappa, \merkleInclusionPf^{\kappa}, \stateroot^\old) = \true, \qquad \kappa \in \{\texttt{0x0}, \texttt{0x2}, \texttt{0x3}, \texttt{0x6}, \texttt{0x7}\}.\] The number of active fields $n_f$ is read from the packed \ballotmode and must lie in $[1, 16]$. % \item \emph{Key namespaces.} Every vote identifier lies in the vote identifier namespace, $N \le \voteid_i < 2^{64}$, and every ballot is written to its voter's slot, which lies in the ballot namespace: $\slot_i = \slot(\address_i)$ (Eq.~\eqref{eq:slot}) for a Merkle census, or $\slot_i = 16 + \idx_i$ for a \ac{CSP} census. The slots of a batch are pairwise distinct. % \item \emph{Transition verification.} The state evolves from $\stateroot^\old$ to $\stateroot^\new$ through a contiguous chain of tree transitions, in this order (see Fig.~\ref{fig:smt-chain}), where each transition is a valid insertion or update proven against the root left by the previous one, and the last one ends at $\stateroot^\new$: \begin{enumerate} \item For every vote $i = 1,\dots,n$, insert the vote identifier with value zero: $\hlget{\stateTree}.\hlget{\MTInsert}(\voteid_i, 0)$. An insertion of a key already present fails, so a vote identifier can never be reused. \item For every vote $i = 1,\dots,n$, write the ballot digest to the voter's slot, with an insertion if the slot is empty and an update if it is occupied: \[\hlget{\stateTree}.\hlget{\MTInsert}\bigl(\slot_i, \Sha(B'_i)\bigr) \quad \text{or} \quad \hlget{\stateTree}.\hlget{\MTUpdate}\bigl(\slot_i, \Sha(B'_i)\bigr).\] The number of updates is exactly $w$, and the value replaced by each update is $\Sha(B^\old_i)$. \item For every refreshed slot $j = 1,\dots,|\mathcal{R}|$, in strictly increasing order of slots, \[\hlget{\stateTree}.\hlget{\MTUpdate}\bigl(\slot^{\mathcal{R}}_j, \Sha(R'_j)\bigr),\] where the replaced value is $\Sha(R_j)$. The refreshed slots are occupied, distinct, and disjoint from the slots written in step 2. \item Update the accumulator: $\hlget{\stateTree}.\hlget{\MTUpdate}(\texttt{0x4}, \Sha(A^\new))$, where the replaced value is $\Sha(A^\old)$. This update is present if and only if the batch writes or refreshes at least one ballot. \end{enumerate} % \item \emph{Re-encryption.} Every ballot written to the tree is a re-encryption of its source, with randomness derived from the secret seed. The program derives a chain of scalars from the seed and the current root, \[ \eta_0 = \Sha(\texttt{"davinci-reenc-v1"} \conc \seed \conc \stateroot^\old) \bmod s, \qquad \eta_{c+1} = \Sha(\eta_c) \bmod s, \] where $s$ is the order of the BN254 scalar field (the base field of BabyJubjub), and consumes one scalar per active ciphertext, first through the $n$ voters' ballots and then through the $|\mathcal{R}|$ refreshed ballots, field by field (see Fig.~\ref{fig:re-encryption}); the seed, the root, and every $\eta_c$ enter the hash as 32-byte big-endian integers. A ciphertext $(C_1, C_2)$ that consumes $\eta_c$ becomes $(C_1 + \eta_c \cdot \BJ{G},\ C_2 + \eta_c \cdot \epk)$, that is, \[B'_{i,f} = \hlget{\ReEnc}_{\epk}(B_{i,f}; \eta_c), \qquad R'_{j,f} = \hlget{\ReEnc}_{\epk}(R_{j,f}; \eta_{c'}),\] for the scalars $\eta_c$ and $\eta_{c'}$ that these ciphertexts consume. Inactive fields must be the identity, before and after, in every ballot. The key $\epk$ must be on the curve, not the identity, and in the prime-order subgroup. % \item \emph{Results accumulation.} The new accumulator adds the new ballots, subtracts the overwritten ones, and adds the difference introduced by each refresh, which is an encryption of zero: \[A^\new = A^\old + \sum_{i=1}^{n} B'_i - \sum_{\text{overwrites}} B^\old_i + \sum_{j=1}^{|\mathcal{R}|} \bigl(R'_j - R_j\bigr),\] where sums of ballots are field-wise homomorphic additions of ciphertexts (\hlget{\EncAdd}) and subtraction adds the inverse point. % \item \emph{Silent refresh.} The number of refreshed slots is large enough to hide the overwrites: with $o = \occupiedbefore$, it must hold that $o \ge w$ and \[ |\mathcal{R}| \ \ge\ \min\bigl(\mathsf{target}(n, w),\ o - w\bigr), \qquad \mathsf{target}(n, w) = \min\bigl(2048,\ \max(16,\ 2w,\ n)\bigr).\] % \item \emph{Data blob}. The blob contents are rebuilt from the verified data and bound to the commitments. \begin{itemize} \item From the vote identifiers and from every slot written or refreshed by the batch, with its new ballot, construct the blob cells as described in Section~\ref{sec:vocdoni-protocol:circuits:blobs}, and split them into $\nblobs = \lceil T / 4096 \rceil$ blobs, where $T$ is the number of cells. The number of commitments must be $\nblobs$, with $1 \le \nblobs \le 32$. \item For every blob $b$, derive the polynomial $p_b(x)$ whose evaluations over the blob domain are the cells of the blob. \item Compute the evaluation point from the commitment and the election context, \[ z_b = \Sha\bigl(\processid_{\text{BE32}} \conc \stateroot^\old_{\text{BE32}} \conc \blobcom_b\bigr) \bmod q_{\mathsf{BLS}}, \] where $q_{\mathsf{BLS}}$ is the order of the BLS12-381 scalar field. \item Compute the evaluation \(y_b = p_b(z_b)\). \item Output \( \blobsdigest = \Sha(\blobcom_1 \conc y_1 \conc \cdots \conc \blobcom_{\nblobs} \conc y_{\nblobs}) \). \end{itemize} The program does not verify the \ac{KZG} openings, which would require pairings over BLS12-381; the registry verifies them with the point-evaluation precompile, against the versioned hashes of the blobs actually published. \end{itemize} \vspace{-0.3cm} \begin{figure}[p] \centering \includegraphics[angle=90,height=0.85\textheight,draft=false]{\figs/batch-program.pdf} \caption{Batch program. The private input blocks (left) feed the groups of constraints (center), which produce the public outputs (right). Private values are framed in red, public values in green.} \label{fig:batch-program} \end{figure} \begin{figure}[h] \centerline{\includegraphics[width=0.9\linewidth,draft=false]{\figs/smt-chain.pdf}} \caption{Chain of state tree transitions proven by the batch program. Configuration leaves are read under the old root; then vote identifiers, ballots, refreshes, and the results accumulator are written in a fixed order, each transition starting from the root left by the previous one.} \label{fig:smt-chain} \end{figure} \begin{figure}[h] \centerline{\includegraphics[width=\linewidth,draft=false]{\figs/re-encryption.pdf}} \caption{Re-encryption in the batch program. A single secret seed and the old state root start a chain of scalars, each consumed by exactly one active ciphertext, first of the voters' ballots and then of the refreshed ballots. The accumulator absorbs the new ballots, the inverse of the overwritten ones, and the encryptions of zero introduced by the refreshes.} \label{fig:re-encryption} \end{figure} \paragraph{Verdict and public values.} Each group of constraints sets a bit of \failmask when it fails, and all groups are evaluated even after a failure, so the mask helps diagnose a rejected batch. The program sets $\okflag = 1$ if and only if every constraint holds. The public values form 46 32-bit words, laid out as in Table~\ref{tab:batch-outputs}; a ZisK proof carries 64 such words, of which words 46 to 63 are zero, and on-chain the public values encode each word as 8 little-endian bytes, 512 bytes in total. The proof of an execution with $\okflag = 0$ is a valid proof of a rejected batch, so every consumer of a batch proof must check, besides the proof itself, that $\okflag = 1$ and $\failmask = 0$. \begin{table}[h] \centering \caption{Public values of the batch program, as 32-bit words. Roots and digests take eight words, in little-endian order; the registry reads \censusroot as the big-endian integer obtained by reversing these bytes.} \label{tab:batch-outputs} \small \begin{tabular}{p{0.14\textwidth} p{0.27\textwidth} p{0.49\textwidth}} \toprule \textbf{Words} & \textbf{Name} & \textbf{Content} \\ \midrule 0, 1 & \okflag, \failmask & Verdict and failed groups of constraints. \\ 2--9, 10--17 & $\stateroot^\old$, $\stateroot^\new$ & State roots before and after the batch. \\ 18, 19 & \numvotes, \numoverwrites & Votes and overwrites in the batch. \\ 20--27 & \censusroot & Census root, or \ac{CSP} address. \\ 28--35, 36 & \blobsdigest, \nblobs & Digest of the $(\blobcom_b, y_b)$ pairs, and blob count. \\ 42 & \occupiedbefore & Occupied ballot slots before the batch. \\ 37--41, 43--45 & & Reserved (zero) and diagnostic values. \\ \bottomrule \end{tabular} \end{table} \paragraph{Checks left to the verifier.} The batch program proves a transition from whatever root and census it is given. The binding of the proof to the right election, to the current state, and to the published data is performed by the registry when the proof is submitted (see Section~\ref{sec:vocdoni-protocol:flow:settlement}), which checks that: the proof is valid under the pinned program key and setup; $\okflag = 1$ and $\failmask = 0$; $\stateroot^\old$ is the latest root of the process; \censusroot is a root the election accepts (Table~\ref{tab:census-models}); \occupiedbefore equals the number of distinct slots written so far; the batch carries at least one vote; and every $(\blobcom_b, y_b)$ pair opens correctly against the versioned hash of the corresponding blob. \paragraph{Blob layout.} \label{sec:vocdoni-protocol:circuits:blobs} The blobs of a state transition carry exactly the data an observer needs to rebuild the new state from the old one, and nothing else. Every cell is a 32-byte big-endian element of the BLS12-381 scalar field. The program lays out the cells as follows (see Fig.~\ref{fig:blob-layout}): \begin{enumerate} \item A header cell, $n_{\mathsf{up}} + 2^{64} \cdot n_{\mathsf{id}}$, where $n_{\mathsf{id}} = n$ is the number of vote identifiers and $n_{\mathsf{up}} = n + |\mathcal{R}|$ the number of updated slots. \item The list of the $n_{\mathsf{id}}$ vote identifiers, in increasing order and without their most significant bit, followed by the list of the $n_{\mathsf{up}}$ updated slots, in increasing order, packed four 63-bit integers per cell: $\mathsf{pack4}(a,b,c,d) = a \cdot 2^{189} + b \cdot 2^{126} + c \cdot 2^{63} + d$. \item For each updated slot, in the same order, the $2 n_f$ points of its new ballot, one cell per point: a point $(x,y)$ is encoded as $y + 2^{254} \cdot (x \bmod 2)$, which identifies the point given the curve equation. \item Zero cells up to the end of the last blob. \end{enumerate} The updated slots include the new votes, the overwrites, and the refreshes, merged into one sorted list. An observer therefore cannot tell an overwrite from a refresh, which is the purpose of silent revoting; only the first write of a slot is distinguishable, as discussed in Section~\ref{sec:vocdoni-protocol:state-tree}. The results accumulator is not published: an observer that holds the previous state recomputes it as $\encresults^\old + \sum_{u} (B^\new_u - B^\old_u)$ over the updated slots, where $B^\old_u$ is the identity for a previously empty slot, which equals the accumulator of the constraint above. The total number of cells is \[ T = 1 + \bigl\lceil (n_{\mathsf{id}} + n_{\mathsf{up}})/4 \bigr\rceil + 2\, n_f\, n_{\mathsf{up}}, \] so, for instance, a batch of 512 new votes with 512 refreshes at $n_f = 16$ needs $1 + 384 + 32768 = 33153$ cells, that is, 9 blobs, and a batch of 512 overwrites, which requires 1024 refreshes, needs 13 blobs. \begin{figure}[h] \centerline{\includegraphics[width=\linewidth,draft=false]{\figs/blob-layout.pdf}} \caption{Layout of the cells of the blobs of a state transition.} \label{fig:blob-layout} \end{figure} \subsubsection{Results program} \label{sec:vocdoni-protocol:circuits:results} The results program (\hlset{\resultsprogram}), illustrated in Fig.~\ref{fig:results-program}, is executed at the end of the election by the holder of the election key, when the key is held by a single sequencer, to prove that the published tally was correctly obtained from the encrypted results committed in the final state. Crucially, the program does not take the decryption key as input, nor does it decrypt inside the proof: instead, for each ballot field it verifies a proof of correct decryption against the encryption public key that is committed in the state tree. The correctness of an execution is attested by a ZisK proof wrapped in PlonK over BN254, verified on-chain by the \hlget{\processregistry} through the \hlget{\ziskverifier} contract. We call the resulting proof the \textit{results proof} and denote it as $\hlset{\resultsproof}$. Elections whose key is held by \keywardens do not use this program: the registry binds the accumulator to the final state root itself, and the \keywardens' contracts verify a proof of every partial decryption (see Section~\ref{sec:vocdoni-protocol:flow:results}). We detail below the inputs and constraints of the results program. \vspace{0.3cm} \noi \textbf{Public outputs} \begin{itemize} \item \public $\okflag$, $\failmask$: whether every constraint below holds, and the groups that failed. \item \public $\stateroot$: final root of the state tree. \item \public $\{\text{results}_j\}_{j=1}^{16}$: decrypted tally, one 64-bit entry per ballot field. \end{itemize} \noi The public values are 43 32-bit words: \okflag and \failmask in words 0 and 1, \stateroot in words 2 to 9, the low and high halves of $\text{results}_j$ in words $10 + 2(j-1)$ and $11 + 2(j-1)$, and, in word 42, the index of the first decryption proof that failed. The registry reads the first \numfields results. \noi \textbf{Private inputs} \begin{itemize} \item \private $\encresults$: encrypted results accumulator stored in the state ($16$ ElGamal ciphertexts). \item \private $\epk$: encryption public key. \item \private $\merkleInclusionPf^{\encresults}$: proof that $\encresults$ is stored in leaf $\texttt{0x4}$ of the state tree. \item \private $\merkleInclusionPf^{\epk}$: proof that $\epk$ is stored in leaf $\texttt{0x3}$ of the state tree. \item \private $\{\pi^{\mathrm{dec}}_j\}_{j=1}^{16}$: per-field Chaum--Pedersen proofs of correct decryption. \end{itemize} \textbf{Constraints} \begin{itemize} \item \emph{Canonical encodings}. Every coordinate is below the field order and every proof scalar below the subgroup order, so that each point and scalar has a single encoding. \item \emph{Encryption key}. The key $\epk$ is on the curve, not the identity, and in the prime-order subgroup. \item \emph{State commitment}. The encrypted results and the encryption public key match the values committed in the final state: \[\stateTree.\hlget{\MTVerify}(\Sha(\encresults), \texttt{0x4}, \merkleInclusionPf^{\encresults}, \stateroot),\] \[\stateTree.\hlget{\MTVerify}(\Sha(\epk), \texttt{0x3}, \merkleInclusionPf^{\epk}, \stateroot).\] \item \emph{Correct decryption}. For every ballot field $j \in \{1, \dots, 16\}$, the public result $\text{results}_j$ is the decryption of the encrypted accumulator $\encresults_j$ under $\epk$, as attested by $\pi^{\mathrm{dec}}_j$ (see Appendix~\ref{sec:cryptographic-primitives:encryption}): \[\hlget{\CPVerify}_{\epk}\bigl(\encresults_j,\ \text{results}_j,\ \pi^{\mathrm{dec}}_j\bigr) = \true.\] \item \emph{Results range}. Each result is a 64-bit integer, $0 \le \text{results}_j < 2^{64}$, which is below the order $t$ of the BabyJubjub prime-order subgroup, so the plaintext of each ciphertext is unique. \end{itemize} % \noi The per-field decryption proofs $\pi^{\mathrm{dec}}_j$ are produced by the key holder, who decrypts the aggregated results, recovers each value by a bounded discrete-logarithm search, and attests, through a discrete-log-equality proof, that the decryption was performed correctly under the election key. By checking these proofs against the public key committed at leaf $\texttt{0x3}$, the program guarantees that the released tally corresponds exactly to the encrypted results accumulated in the final state, without ever exposing the decryption key inside the proof. Inactive fields hold the identity ciphertext, for which only the value zero can be proven. If any constraint fails, the program outputs zero in place of the root and the results, so a consumer that omitted the check of $\okflag$ still could not match a root or read a tally. \begin{figure}[h] \centerline{\includegraphics[width=\linewidth,draft=false]{\figs/results-program.pdf}} \caption{Results program. Public values are framed in green and private values in red.} \label{fig:results-program} \end{figure} \begin{remark} The batch proofs are verified on-chain one by one, which publishes the data of every batch as it is settled and lets several sequencers compete for each transition. The \ac{zkVM} also supports a \emph{chained} mode, in which batch proofs are produced as \acp{STARK} without the PlonK wrapper and an aggregator program (\aggregatorprogram) verifies them recursively, enforces the continuity of state roots across batches, and folds a whole election into a single proof that is verified on-chain once, together with the results. Chained mode trades the per-batch settlement and data publication for a lower on-chain cost; it is not used by the deployment described in this paper, and the sequencer does not support it for dynamic censuses or threshold-held keys. \end{remark}