% !TeX root = ../build/main.tex In this section we describe the overall flow of the \davinci voting protocol. An election is structured into five main phases: election setup, encryption key generation, voting period, tally decryption, and election finalization. Each phase specifies the interactions between the organizer, \keywardens, voters, sequencers, and the smart contracts that coordinate the election. An overview of the complete process is shown in Figs.~\ref{fig:protocol-flow} and~\ref{fig:protocol-flow-results}. \begin{figure}[p] \centerline{\includegraphics[width=0.94\textwidth,draft=false]{\figs/protocol-flow.pdf}} \caption{Message flow of an election: setup and voting. The voting loop runs for every batch; settlement is shown in L1-blob mode, in which the blobs are posted to Ethereum while the batch is proven. Solid arrows are calls and dashed arrows replies or events; the \textsf{opt} fragments apply only in the given key mode. Fig.~\ref{fig:protocol-flow-results} continues the flow after the end of the voting period.} \label{fig:protocol-flow} \end{figure} \subsubsection{Election setup} \label{sec:vocdoni-protocol:flow:setup} For each new election, the organizer performs the following steps: \begin{enumerate} \item Prepare the census data \censusdata\ according to the chosen census model $\censusorigin$ (see Section~\ref{sec:vocdoni-protocol:census}). For an off-chain census, build the lean \ac{IMT} $\censusTree$ from it, publish the list of members, and record its location as $\censusuri$; for an on-chain census, deploy or reuse a census contract; for a \ac{CSP} census, record the endpoint of the \ac{CSP} as $\censusuri$. \item Compute the census commitment: $\censusroot = \censusTree.\hlget{\MTRoot}()$ for an off-chain census, or the address of the \ac{CSP}'s signing key for a \ac{CSP} census. \item Define the election details: the start time (\starttime), the duration of the voting period (\duration), the maximum number of voters (\maxvoters), and the ballot rules $\ballotmode$ (see Section~\ref{sec:ballot-protocol}). \item Publish the election metadata (questions, options, description, etc.)\ and record its location as $\metadatauri$ and the SHA-256 digest of its exact bytes as \texttt{metadataHash}. \item Determine the process identifier $\processid$, which the \hlget{\processregistry} derives from the organizer's address, a prefix that encodes the chain and the registry, and the organizer's process nonce (see Section~\ref{sec:vocdoni-protocol:smart-contracts}). Being deterministic, it can be read in advance from the registry, although it is ultimately recomputed and assigned by the contract upon registration. \item Choose the key mode \keymode and obtain what it requires (see Section~\ref{sec:vocdoni-protocol:flow:keys}): the encryption public key $\epk$ for $\processid$ from a sequencer, in the sequencer mode; nothing, in the automatic \ac{DKG} mode; an organizer key pair and a proof of possession of its secret, in the locked \ac{DKG} mode; or the identifier of a council ceremony, in the council mode. \item Register the process on-chain by submitting a transaction to the \hlget{\processregistry} smart contract with the election parameters: \begin{align*} \mathsf{tx} = \big( &\texttt{status},\ \starttime,\ \duration,\ \maxvoters,\ \ballotmode,\\ &(\censusorigin,\ \censusroot,\ \censusuri,\ \texttt{contractAddress}),\ \metadatauri,\ \texttt{metadataHash},\\ &\epk,\ (\keymode,\ \texttt{dkgParams})\big), \end{align*} where \texttt{status} is \texttt{READY} or \texttt{PAUSED} and $\epk$ is left empty in the \ac{DKG} and council modes. The registry validates the parameters: the ballot mode must satisfy the bounds of Section~\ref{sec:ballot-protocol}; the worst-case tally must be decryptable, $\maxvalue \cdot \maxvoters \le 10^{12}$; the census must be consistent with its origin; the voting period must not start in the past and must end in the future; and the metadata must be non-empty. In the \ac{DKG} and council modes, the registry obtains $\epk$ from the corresponding key-management contract (see Section~\ref{sec:vocdoni-protocol:flow:keys}). In every mode, $\epk$ must be a canonical BabyJubjub point other than the identity. Upon accepting this transaction, the \hlget{\processregistry} contract computes the genesis state root, whose tree contains only the configuration leaves (see Section~\ref{sec:vocdoni-protocol:state-tree}): $\processid$ at $\mathtt{0x0}$, $\ballotmode$ at $\mathtt{0x2}$, $\epk$ at $\mathtt{0x3}$, the results accumulator $\encresults$ at $\mathtt{0x4}$ initialized to the encryption of zero, $\censusorigin$ at $\mathtt{0x6}$, and the pinned $\ballotvkhash$ at $\mathtt{0x7}$: \[ \stateroot = \stateTree.\hlget{\MTRoot}(). \] \end{enumerate} % Once this transaction is accepted, the election is publicly registered on-chain, the registry emits a \fn{ProcessCreated} event, and, at its scheduled start time, the voting period can begin. Sequencers learn of the new process from the event: each sequencer that wishes to serve it validates the configuration, downloads or indexes the census, rebuilds the census tree and checks its root, and creates the genesis state tree locally, checking that its root equals the one computed by the registry. \subsubsection{Encryption key generation} \label{sec:vocdoni-protocol:keygen} \label{sec:vocdoni-protocol:flow:keys} In this phase, the public encryption key ($\epk$) that voters will use to encrypt their ballots is established. \Davinci supports four key modes, chosen by the organizer at creation and summarized in Fig.~\ref{fig:key-modes}. In all of them, the key is fixed when the process is created and committed in the genesis state, and the batch proof is the same; the modes differ in who can decrypt and, consequently, in how the results are published: the sequencer mode uses the results program, while the \ac{DKG} and council modes rely on the verified partial decryptions of their committees. \begin{figure}[h] \centerline{\includegraphics[width=\textwidth,draft=false]{\figs/key-modes.pdf}} \setlength{\abovecaptionskip}{5pt} \caption{Key modes. Elections are created through the process registry, which calls the key-management contracts; council ceremonies are set up on the council manager beforehand. The modes differ in who can decrypt the tally and how the results are published.} \label{fig:key-modes} \end{figure} \paragraph{\ac{DKG} automatic mode.} The \keywardens are the operators of a permissionless \ac{DKG} network~\cite{davinci-dkg}, which runs the non-interactive \ac{DKG} protocol of Appendix~\ref{sec:cryptographic-primitives:dkg} in \emph{epochs}. At the start of each epoch, a committee of $\nu$ operators is drawn by a public lottery among the registered operators, and each committee member submits one contribution that deals, with Feldman verifiable secret sharing~\cite{feldman1987practical}, shares of sixteen independent pool keys at once, together with a Groth16 proof that the contribution is well-formed and that every share is encrypted to its recipient. The \dkgmanager verifies these proofs, so that correct participation can be checked without revealing any secret. Once enough valid contributions are collected, a single proof computes the sixteen pool keys $P_0, \dots, P_{15}$ and a commitment to every member's share of each, and the epoch becomes live. Any $\theta$ of the $\nu$ committee members, where $\theta$ is the threshold of the epoch, can then decrypt under any pool key, while no smaller coalition learns anything about the secrets. When a process is created in this mode, the \dkgadapter registers it as an application of the newest live epoch, under an application identifier that embeds the adapter's address and a salt derived from the chain, the registry, and \processid, so that no other party can claim it. The application is assigned a free pool key $P_j$, which becomes the election key, $\epk = P_j$. \paragraph{\ac{DKG} locked mode.} The organizer generates a key pair $(\sk_{\mathsf{org}}, \pk_{\mathsf{org}})$ and provides $\pk_{\mathsf{org}}$, together with a Schnorr proof of possession of $\sk_{\mathsf{org}}$, at creation. The election key is $\epk = P_j + \pk_{\mathsf{org}}$, and the \ac{DKG} contracts refuse every decryption of the application until the organizer reveals $\sk_{\mathsf{org}}$ on-chain, which they check against $\pk_{\mathsf{org}}$. The organizer thus decides when the tally can be opened, but not what it contains, and not even $\theta$ colluding committee members can open it alone. Losing $\sk_{\mathsf{org}}$ makes the tally permanently undecryptable. \paragraph{Council mode.} The \keywardens are the members of a council: up to sixteen participants invited by an organizer, who run a dedicated key ceremony on the \councilmanager~\cite{davinci-council}. Each member deals a Feldman sharing of a random secret with a Groth16 proof of correct dealing, the election key is the sum of the dealers' public constants, and any $\theta$ of its $\nu$ members can decrypt, for a threshold $\theta$ fixed when the ceremony is created. A council ceremony also fixes when decryption may start, either on a scheduled date or when the organizer of the ceremony opens it, optionally with a fallback date. Several processes may be bound to the same ceremony, provided that the ceremony organizer has allowed the registry's \counciladapter and has authorized the account creating each process; all of them share the ceremony's key. \paragraph{Sequencer mode.} When the organizer accepts a weaker trust model, a single sequencer acts as the only \keywarden. Before creating the process, the organizer requests from a sequencer the key for the (predictable) identifier \processid. The sequencer derives the secret key from a 32-byte master secret: with $X = \texttt{"davinci-election-key-v1"} \conc \texttt{chainID}_{\text{BE8}} \conc \texttt{registry}_{20} \conc \processid_{31}$, \[ h_i = \mathsf{HMAC}\text{-}\Sha(\mathsf{master},\ X \conc i_{\text{8 bits}}), \quad i \in \{0, 1\}, \qquad \sk = 1 + \bigl(\mathsf{BE}(h_0 \conc h_1) \bmod (t - 1)\bigr), \] so that $\sk \in [1, t)$ with negligible bias, and returns $\epk = \sk \cdot \BJ{G}$. Since the key is derived, the sequencer stores nothing per request, and a key handed out for one process is useless under any other. That sequencer can decrypt every ballot published in the blobs, and it is the only party able to publish the results. This mode suits testing and elections in which the organizer trusts the operator of the sequencer. \subsubsection{Voting period} \label{sec:vocdoni-protocol:votes} In this phase, voters cast their ballots and send them to the sequencers, who collect and process them. \\ \noi \textbf{(a) Vote casting.} Each voter holds an Ethereum key pair $(\sk, \pk)$ with associated address $\address$ (see Appendix~\ref{sec:cryptographic-primitives:signatures}). To cast a ballot, a voter does the following: \begin{enumerate} \item Fetch the parameters $\epk$, $\ballotmode$, $\processid$, and the census configuration from the \hlget{\processregistry} contract, and the metadata from $\metadatauri$, checking its digest. \item Retrieve the weight $\weight$ and, for a \ac{CSP} census, the credential $\censusproof = (\signature^{\mathsf{CSP}}, \idx)$. For a Merkle census, the weight and the membership proof can be obtained from any sequencer serving the election, and checked against $\censusroot$; the sequencer does not need the proof from the voter, since it derives it from its own copy of the census. \item Select their ballot choice $\ballot$ following the rules of $\ballotmode$. \item Sample fresh randomness $k \in \F_s$ and encrypt the ballot using $\epk$, field by field, as specified by the ballot circuit: \begin{equation}\label{eq-ciphertext} \encryptedballot = \hlget{\Enc}_{\epk}(\ballot; k). \end{equation} \item Use their address $\address$ and the randomness $k$ to compute a unique vote identifier, mapped into the reserved vote-identifier namespace (see Section~\ref{sec:vocdoni-protocol:state-tree}): \begin{equation}\label{eq-voteid} \voteid = N + \bigl(\hlget{\Poseidon}(\processid, \address, k) \bmod N\bigr). \end{equation} \item Use the \ballotcircuit from Section~\ref{sec:vocdoni-protocol:circuits:ballot} to generate a \ac{ZK-SNARK} proof that Eqs.~\labelcref{eq-ciphertext,eq-voteid} are correctly computed and that $\ballot$ satisfies the ballot rules of $\ballotmode$: \begin{align*} \ballotproof = {} & \hlget{\PProve}\bigl(\hlget{\ballotcircuit},\\ & \witness = (\ballot, k, \processid, \ballotmode, \epk,\\ & \phantom{\witness = (}\weight, \encryptedballot), \\ & \publicinputs = (\address, \voteid, \ballotinputshash)\bigr). \end{align*} \item Sign the vote identifier with their Ethereum secret key $\sk$ to authenticate the vote: \[ \signature = \hlget{\SSign}_{\sk}(\voteid). \] \item Select a sequencer and submit the package \begin{align*} \vote = [&\processid, \address, \voteid, \encryptedballot, \ballotproof,\\ &\ballotinputshash, \signature, \weight, \censusproof] \end{align*} to the chosen sequencer, where \censusproof is only present for a \ac{CSP} census. \item Follow the status of the vote through its identifier. Once the vote is settled, obtain from any sequencer an inclusion proof of the leaf \voteid under the state root, and check it against the root recorded in the \processregistry. \end{enumerate} A voter may repeat these steps any number of times while the voting period is open; each new ballot, once settled, replaces the previous one in the voter's slot. The protocol enforces that the ballot settled last prevails. An honest sequencer settles the ballots of a slot in the order in which it received them, which is not necessarily the order in which the voter created them, and ballots sent to different sequencers have no common order; voters should therefore send their ballots to one sequencer, one after another.\\ \noi \textbf{(b) Vote admission.} Upon receiving a vote $\vote_i$, a sequencer runs every per-vote check of the batch program before accepting it, so that a single invalid vote cannot invalidate a batch: \begin{enumerate} \item Check the ballot proof against the pinned ballot verification key: \[\hlget{\PVerify}\bigl(\ballotproof_i, (\address_i, \voteid_i, \ballotinputshash_i)\bigr) = \true.\] \item Recover the signer, $\pk_i = \hlget{\SPubKey}(\voteid_i, \signature_i)$, and check that its address is $\address_i$. \item Recompute $\ballotinputshash_i$ from the process configuration and the submitted values, and check that the ciphertexts are canonical points with the identity in every inactive field. \item Check eligibility: for a Merkle census, that $\address_i$ is a member with weight $\weight_i$ in the sequencer's copy of the census; for a \ac{CSP} census, that the credential recovers the \ac{CSP} address $\censusroot$. \item Check the state: the vote identifier is neither in the state tree nor in the queue, the election is accepting votes (it is ready or paused, and its voting period is open), and the vote would not make the number of distinct voters exceed \maxvoters. \end{enumerate} Accepted votes are queued, one queue per slot, and their status becomes \emph{pending}; a vote then moves through the states of Fig.~\ref{fig:vote-lifecycle}.\\ \begin{figure}[h] \centerline{\includegraphics[width=\textwidth,draft=false]{\figs/vote-lifecycle.pdf}} \setlength{\abovecaptionskip}{5pt} \caption{Lifecycle of a vote in a sequencer. A batch that loses a settlement race, or that the registry refuses while the election is paused, returns its votes to the queue; votes still queued when the grace window closes, or that the program rejects, end in error.} \label{fig:vote-lifecycle} \end{figure} \noi \textbf{(c) Vote batching.} A sequencer seals a batch from the queue when it holds enough votes, when its oldest vote has waited long enough, or when the end of the voting period approaches. Waiting for several distinct slots before sealing mixes the votes of different voters in one transition; each wait carries a random jitter, so the settlement time of a batch reveals little about when its votes were cast. The batch takes the oldest vote of each slot, in arrival order, and is sized so that its proof and settlement fit before the deadline of the election, that it respects \maxvoters, and that its blobs fit the limit of the settlement mode. To build the batch, the sequencer: \begin{enumerate} \item Draws a fresh secret $\seed$ and a uniformly random refresh set $\mathcal{R}$ of occupied slots not written by the batch, of the size required by the batch program, from the operating system's random number generator. Both exist only in memory, for this batch, and are never logged or stored. \item Re-encrypts every ballot along the scalar chain of the seed and the refreshed ballots after them (see Section~\ref{sec:vocdoni-protocol:circuits:batch}). \item Applies the batch to a copy of its state tree, producing the chains of tree transitions, the new results accumulator, and the new root. \item Lays out the blob cells, computes the \ac{KZG} commitment $\blobcom_b$ of each blob, the evaluation point $z_b$, the value $y_b = p_b(z_b)$, and the opening proof $\openproof_b$ (see Section~\ref{sec:vocdoni-protocol:circuits:blobs}). \item Computes the public values it expects the batch program to output. \end{enumerate} A batch may reach the chain even if its sequencer later drops it, for instance after losing a race or when its blobs were posted but its settlement failed. If one of its votes is later sealed again in a different batch, with a different refresh draw, an observer comparing the two transitions could single out the slots written in both. To prevent this, every sequencer keeps a persistent coverage history of the batches that carried each vote, its own and those of other sequencers that it fetched, and a batch that carries such a vote again also refreshes every slot of those earlier batches that it does not write. The history contains only slot keys and vote identifiers that the blobs already publish, so keeping it reveals nothing new.\\ \noi \textbf{(d) Proving and settlement.} \label{sec:vocdoni-protocol:flow:settlement} The sequencer sends the private inputs of the batch to its prover and obtains the batch proof, \begin{align*} (\publicvalues, \batchproof) = {} & \hlget{\VMProve}\bigl(\hlget{\batchprogram},\\ & \witness = (\text{ballot proofs, state transition, eligibility, re-encryption, blobs})\bigr). \end{align*} Before using it, the sequencer checks that the proof is valid under the pinned program key and setup, that $\okflag = 1$, and that every public value equals the value it computed itself. It then settles the batch in one of the two data availability modes of the registry. \begin{itemize} \item \emph{Blob mode} (registry on a chain with native blob transactions, such as Ethereum). The sequencer sends a single blob-carrying transaction that carries the $\nblobs \le 6$ blobs of the batch and calls \begin{align*} \fn{submitStateTransition}\bigl(&\processid, \publicvalues, \batchproof,\\ &\{\blobcom_b\}, \{y_b\}, \{\openproof_b\}\bigr), \end{align*} where $\openproof_b$ is the \ac{KZG} opening proof of blob $b$ at $z_b$. The registry reads the versioned hashes of the blobs of its own transaction. \item \emph{L1-blob mode} (registry on an OP Stack rollup). The sequencer posts the blobs to Ethereum while the batch is being proven, in blob-carrying transactions of at most six blobs each, sent one after another. Once the proof is ready, every blob transaction is included, and the L1 origin of the rollup has reached the newest of them, the sequencer builds an L1 proof $\Pi^{\mathsf{L1}}$: the Ethereum headers from the anchor down to the oldest blob transaction, and a \ac{MPT} inclusion proof of each blob transaction in its block. Since the L1 origin advances every few seconds, a sequencer may preserve a usable anchor by calling \fn{record} on the \lblobverifier while that block is the current origin; if the origin advances past an unrecorded anchor before the settlement lands, the proof is rebuilt against the new origin or another recorded block. It then calls \begin{align*} \fn{submitStateTransitionL1}\bigl(&\processid, \publicvalues, \batchproof,\\ &\{\blobcom_b\}, \{y_b\}, \{\openproof_b\}, \Pi^{\mathsf{L1}}\bigr), \end{align*} and the registry obtains the versioned hashes, in order, from $\lblobverifier.\fn{verify}(\Pi^{\mathsf{L1}})$. Fig.~\ref{fig:l1-settlement} shows the timeline of this mode. \end{itemize} Settlement is permissionless: the proof, the blob openings, and the continuity of state roots authenticate the transition, whoever sends it. Upon receiving the transaction, the registry performs the following checks, and reverts if any fails: \begin{enumerate} \item The entry point matches the registry's data availability mode. \item The process is ready or ended, or paused past its end time, and the current time is between \starttime and the end of the grace window (Section~\ref{sec:vocdoni-protocol:flow:grace}). \item The public values are 512 bytes long and report $\okflag = 1$ and $\failmask = 0$. \item $\stateroot^\old$ equals the latest state root of the process. \item \censusroot is accepted for the census origin of the process (Table~\ref{tab:census-models}); for an on-chain census, the registry asks the census contract for the last block at which the root was current, and requires it to be between the creation block of the process and the current block. \item \occupiedbefore equals the process's \voterscount, the number of distinct slots written so far. \item The batch adds at least one vote, and $\voterscount + (\numvotes - \numoverwrites) \le \maxvoters$. \item There are exactly \nblobs commitments, evaluations, and opening proofs, $\nblobs \ge 1$, each commitment and opening proof is 48 bytes long, and there are as many non-zero versioned hashes: in blob mode, the transaction carries no blob beyond the first \nblobs; in L1-blob mode, the L1 proof yields exactly \nblobs versioned hashes. \item The digest of the $(\blobcom_b, y_b)$ pairs equals \blobsdigest. \item The ZisK verifier accepts the proof: \[\hlget{\ziskverifier}.\fn{verifySnarkProof}(\texttt{batchProgramVK}, \rootc, \publicvalues, \batchproof).\] \item For every blob $b$, the point-evaluation precompile accepts the opening of $\blobcom_b$ at $z_b = \Sha(\processid \conc \stateroot^\old \conc \blobcom_b) \bmod q_{\mathsf{BLS}}$ with value $y_b$, against the $b$-th versioned hash. \end{enumerate} If all checks pass, the registry sets the latest state root to $\stateroot^\new$, increases \voterscount by $\numvotes - \numoverwrites$ and \overwrittencount by \numoverwrites, increments \texttt{batchNumber}, records the current time as \lastvoteat, and emits \fn{ProcessStateTransitioned}; in L1-blob mode, it also emits \fn{ProcessStateTransitionedL1} with the Ethereum block and the versioned hash of every blob, so that anyone can locate the data on Ethereum. \begin{figure}[p] \centerline{\includegraphics[width=0.85\textwidth,draft=false]{\figs/l1-settlement.pdf}} \setlength{\abovecaptionskip}{5pt} \caption{Settlement in L1-blob mode. The blob transactions are posted to Ethereum while the batch is proven; the settlement on the rollup proves, from a chain of Ethereum headers anchored at the rollup's L1 origin, that they are part of the Ethereum chain. Here the blobs of the batch travel in two transactions, mined in blocks $B_1$ and $B_2$.} \label{fig:l1-settlement} \end{figure} \medskip \noi \textbf{(e) Concurrent sequencers and synchronization.} Several sequencers may serve the same election, and each builds its batches on the latest state root it knows. When two of them prepare a transition from the same root, the first one to land advances the election, and the settlement of the other reverts because its $\stateroot^\old$ is no longer the latest root. The losing sequencer returns its votes to the queue, synchronizes, and builds its next batch on the new root; a lost race costs only the gas of the reverted transaction and, in L1-blob mode, the posted blobs. To synchronize, a sequencer fetches the blobs of every transition settled by others, checks them against the versioned hashes recorded by the settlement, decodes the vote identifiers and the updated slots with their ballots, recomputes the results accumulator from the ballots it already holds, applies the updates to its tree, and requires the resulting root to equal the one recorded on-chain. Queued votes whose identifier appears in the tree are thereby settled. An observer runs the same procedure for every transition, which checks the election, and its encrypted tally, independently of the sequencers. Sequencers apply transitions only once they are buried under a configurable number of blocks, and they detect deeper reorganizations of the settlement chain, in which case they roll back the affected transitions and replay the chain from the published blobs. \subsubsection{End of the voting period} \label{sec:vocdoni-protocol:flow:grace} The voting period ends at $\starttime + \duration$, or earlier if the organizer ends or cancels the process. From that moment, sequencers refuse new votes. Votes received before the end may still be queued or being proven, so the registry keeps accepting state transitions during a \emph{grace window} that closes at \begin{equation} \graceend = \min\bigl(\mathsf{end} + \texttt{graceMaxTotal},\ \max(\mathsf{end}, \lastvoteat) + \grace\bigr), \label{eq:grace-end} \end{equation} where $\mathsf{end}$ is the end time and \lastvoteat the time of the latest settled transition. Every transition that lands during the window extends it, so a backlog drains batch by batch, while \texttt{graceMaxTotal} bounds the total extension. The organizer may set \grace before the end within the bounds \texttt{graceFloor} and \texttt{graceCeil} of the registry. The organizer may also shorten the voting period with \fn{setProcessDuration}, which only accepts a new end at least \texttt{noticeMin} away, so that sequencers that follow the chain learn the new end before it applies; ending the process explicitly with \fn{setProcessStatus} closes it at once, without notice. From shortly before the end, sequencers stop waiting to fill batches and seal everything pending as soon as the proving budget allows. Fig.~\ref{fig:grace-window} illustrates the window, and Fig.~\ref{fig:process-status} the statuses a process goes through. \begin{figure}[h] \centerline{\includegraphics[width=\textwidth,draft=false]{\figs/grace-window.pdf}} \setlength{\abovecaptionskip}{5pt} \caption{The grace window. Honest sequencers stop admitting votes at the end time; transitions keep settling until \graceend, which every settlement resets to its own time plus \grace, up to \texttt{graceMaxTotal} after the end (Eq.~\eqref{eq:grace-end}). Results can only be published after \graceend. Sequencers flush their queues from shortly before the end. On OP Mainnet, \grace is 300\,s by default (the organizer may choose 240 to 600\,s), \texttt{graceMaxTotal} is 1800\,s, and \texttt{noticeMin} is 60\,s.} \label{fig:grace-window} \end{figure} \begin{figure}[h] \centerline{\includegraphics[width=\textwidth,draft=false]{\figs/process-status.pdf}} \setlength{\abovecaptionskip}{5pt} \caption{Statuses of a process in the registry. Solid transitions are made by the organizer; dashed transitions are made by the registry when results are requested or published. Transitions from the voting states apply to \texttt{READY} and \texttt{PAUSED} alike; a process can be paused only before its end, and the registry leaves a voting state only after the end time and the grace window.} \label{fig:process-status} \end{figure} The grace window lets a sequencer include votes cast before the end but settled after it. The registry cannot tell a vote cast after the end from a delayed one, so a dishonest sequencer could include late votes during the window; honest sequencers refuse them. The opportunity is bounded by the window, and the transitions settled in it are public, but the contract cannot distinguish delayed submissions from submissions received after the end. \subsubsection{Tally decryption} \label{sec:vocdoni-protocol:tally} After the grace window closes, the \hlget{\processregistry} smart contract stops accepting new state updates, fixing the final state root and thus the aggregated encrypted results $\encresults$. Every sequencer that follows the election holds $\encresults$ in its own state tree, and the results can only be requested or published from this point on, which guarantees that the decrypted tally is that of the final state. How the tally is decrypted depends on the key mode. \paragraph{Threshold decryption (\ac{DKG} and council modes).} Any sequencer with a signing key submits the final accumulator $\encresults$, together with its inclusion proof $\merkleInclusionPf^{\encresults}$ under the latest state root, by calling \fn{requestResultsDecryption}. The registry checks that every coordinate of $\encresults$ is canonical, that $\Sha(\encresults)$ is the value of leaf \texttt{0x4} under the latest state root, moves the process to the ended status, and submits the ciphertext of every active field to the key-management contract through its adapter. Fields whose ciphertext is the identity decrypt to zero under any key and are recorded as zero without being submitted. A threshold of $\theta$ out of $\nu$ \keywardens\ then cooperate to decrypt each submitted ciphertext $(C_1, C_2)$: rather than reconstructing the election secret key, each participating warden $i$ publishes a partial decryption $D_i = \mathsf{sh}_i \cdot C_1$, where $\mathsf{sh}_i$ is its key share, together with a Groth16 proof that $D_i$ is consistent with its committed share. Once $\theta$ valid partial decryptions are available, anyone combines them by Lagrange interpolation, $M = C_2 - \sum_i \lambda_i D_i$, recovers the plaintext $m$ with $M = m \cdot \BJ{G}$ by a bounded discrete-logarithm search, and submits it; the key-management contract checks that $m$ is the correct combination (with a \ac{ZK} proof in the \ac{DKG} network, and by direct computation in the council) before storing it. In the locked mode, partial decryptions are only accepted after the organizer reveals $\sk_{\mathsf{org}}$, and the combination also removes its contribution. In the council mode, they are only accepted once the ceremony's decryption gate has opened. Because only the aggregated results are decrypted and never the individual ballots, voter privacy is preserved throughout the election, and the secret key is never reconstructed by any single party. Moving the process to the ended status when the decryption is requested matters: the plaintexts become public on the key-management contract before the registry records them, and an organizer that could still cancel the process could otherwise veto a tally after reading it. \paragraph{Sequencer decryption (sequencer mode).} The sequencer that holds $\sk$ decrypts each field $j$ of $\encresults$ as $M_j = C_{2,j} - \sk \cdot C_{1,j}$, recovers $\text{results}_j$ with $M_j = \text{results}_j \cdot \BJ{G}$ by a baby-step giant-step search bounded by $\maxvoters \cdot \maxvalue$, and produces a Chaum--Pedersen proof $\pi^{\mathrm{dec}}_j$ that $\log_{\BJ{G}} \epk = \log_{C_{1,j}} D_j$, where $D_j = C_{2,j} - \text{results}_j \cdot \BJ{G}$ (see Appendix~\ref{sec:cryptographic-primitives:encryption}). It can do so during the grace window, once nothing is pending, and submit the result as soon as the window closes, provided that the root has not changed. \subsubsection{Election finalization} \label{sec:vocdoni-protocol:finalization} \label{sec:vocdoni-protocol:flow:results} In this final phase, the election results are published on-chain, together with the evidence of their correct computation. Fig.~\ref{fig:protocol-flow-results} shows the messages of both finalization paths. \begin{figure}[p] \centerline{\includegraphics[width=0.85\textwidth,draft=false]{\figs/protocol-flow-results.pdf}} \setlength{\abovecaptionskip}{5pt} \caption{Message flow of an election: decryption and finalization. The path depends on who holds the election key; in the threshold path, partial decryptions also wait for the organizer's reveal (locked mode) or for the council's decryption gate.} \label{fig:protocol-flow-results} \end{figure} \paragraph{Sequencer mode.} The key holder proceeds as follows: \begin{enumerate} \item Retrieve the encrypted results accumulator $\encresults$ and the encryption key $\epk$ from the final state, together with their Merkle inclusion proofs against the final state root $\stateroot$. \item Use the \resultsprogram from Section~\ref{sec:vocdoni-protocol:circuits:results} to generate the results proof: \begin{align*} &(\publicvalues, \resultsproof) = \hlget{\VMProve}(\hlget{\resultsprogram}, \witness), \quad \text{with}\\ &\witness = \bigl(\encresults, \epk,\\ &\qquad \merkleInclusionPf^{\encresults}, \merkleInclusionPf^{\epk}, \{\text{results}_j, \pi^{\mathrm{dec}}_j\}_{j=1}^{16}\bigr), \end{align*} whose public values contain $\stateroot$ and the results. \item Submit the public values and the proof to the \hlget{\processregistry} smart contract with \fn{setProcessResults}. The contract checks that the process is in the sequencer mode, that it has neither been canceled nor finalized, that it has ended and its grace window has closed, that $\okflag = 1$ and $\failmask = 0$, and that the state root in the public values is the latest root of the process. It then verifies the proof with the \hlget{\ziskverifier} under the pinned results program key, records the first \numfields results, sets the status to \texttt{RESULTS}, and emits \fn{ProcessResultsSet}. \end{enumerate} \paragraph{\ac{DKG} and council modes.} Once every submitted ciphertext has been decrypted, any sequencer calls \fn{finalizeResultsFromDKG} for the process. The registry reads the stored plaintexts through the adapter, requires all of them to be available and, for a council process, the decryption gate to be open, fills in the zero-valued fields, records the results, sets the status to \texttt{RESULTS}, and emits \fn{ProcessResultsSet}. Both this call and the request are permissionless, and every signing sequencer is ready to make them; to avoid duplicate transactions, each sequencer waits a random delay and sends a call only if it is still missing. \medskip \noi The election is considered finalized once the decrypted results are available on-chain. At this stage, both the results and the complete integrity of the process are permanently recorded and publicly auditable: anyone can recompute the on-chain commitments and check the proofs. In particular, the combination of the final state root, the verified decryption of the aggregated results, and the publicly verifiable proofs of every state transition and of the results guarantees the integrity of the entire election.