arnaucube
arnaucube/davinci-paperPublic Self-hosted repository
davinci-paper/v2/sections/protocol-flow.tex
v2/sections/protocol-flow.texRaw
  1% !TeX root = ../build/main.tex
  2
  3In 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}.
  4
  5\begin{figure}[p]
  6	\centerline{\includegraphics[width=\textwidth,draft=false]{\figs/protocol-flow.pdf}}
  7	\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. Fig.~\ref{fig:protocol-flow-results} continues the flow after the end of the voting period.}
  8	\label{fig:protocol-flow}
  9\end{figure}
 10
 11\subsubsection{Election setup}
 12\label{sec:vocdoni-protocol:flow:setup}
 13
 14For each new election, the organizer performs the following steps:
 15
 16\begin{enumerate}
 17
 18	\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$.
 19
 20	\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.
 21
 22	\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$
 23	(see Section~\ref{sec:ballot-protocol}).
 24
 25	\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}.
 26
 27	\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.
 28
 29	\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.
 30
 31	\item Register the process on-chain by submitting a transaction to the
 32	\hlget{\processregistry} smart contract with the election parameters:
 33	\begin{align*}
 34		\mathsf{tx} = \big(
 35		&\texttt{status},\ \starttime,\ \duration,\ \maxvoters,\ \ballotmode,\\
 36		&(\censusorigin,\ \censusroot,\ \censusuri,\ \texttt{contractAddress}),\ \metadatauri,\ \texttt{metadataHash},\\
 37		&\epk,\ (\keymode,\ \texttt{dkgParams})\big),
 38	\end{align*}
 39	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.
 40	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}$:
 41	\[
 42	\stateroot = \stateTree.\hlget{\MTRoot}().
 43	\]
 44\end{enumerate}
 45%
 46Once 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.
 47
 48\subsubsection{Encryption key generation}
 49\label{sec:vocdoni-protocol:keygen}
 50\label{sec:vocdoni-protocol:flow:keys}
 51
 52In 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, it is committed in the genesis state, and the batch and results proofs are the same; the modes differ in who can decrypt and, consequently, in who publishes the results.
 53
 54\begin{figure}[h]
 55	\centerline{\includegraphics[width=\textwidth,draft=false]{\figs/key-modes.pdf}}
 56	\setlength{\abovecaptionskip}{5pt}
 57	\caption{Key modes. The organizer always interacts with the process registry only; the key-management contracts sit behind it. The modes differ in who can decrypt the tally and how the results are published.}
 58	\label{fig:key-modes}
 59\end{figure}
 60
 61\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$.
 62
 63\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.
 64
 65\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.
 66
 67\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 master secret,
 68\[ \sk = \mathsf{HMAC}\text{-}\Sha\bigl(\mathsf{master},\ \texttt{"davinci-election-key-v1"} \conc \texttt{chainID} \conc \texttt{registry} \conc \processid\bigr), \]
 69reduced into $[1, t)$, 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.
 70
 71\subsubsection{Voting period}
 72\label{sec:vocdoni-protocol:votes}
 73
 74In this phase, voters cast their ballots and send them to the sequencers, who collect and process them. \\
 75
 76\noi \textbf{(a) Vote casting.} Each voter holds an Ethereum key pair $(\sk, \pk)$ with
 77associated address $\address$ (see Appendix~\ref{sec:cryptographic-primitives:signatures}).
 78To cast a ballot, a voter does the following:
 79
 80\begin{enumerate}
 81	\item Fetch the parameters $\epk$, $\ballotmode$, $\processid$, and the census configuration from the
 82	\hlget{\processregistry} contract, and the metadata from $\metadatauri$, checking its digest.
 83	\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.
 84	\item Select their ballot choice $\ballot$ following the rules of $\ballotmode$.
 85	\item Sample fresh randomness $k \in \F_s$ and encrypt the ballot using $\epk$, field by field, as specified by the ballot circuit:
 86	\begin{equation}\label{eq-ciphertext}
 87		\encryptedballot = \hlget{\Enc}_{\epk}(\ballot; k).
 88	\end{equation}
 89	\item Use their address $\address$ and the randomness $k$ to compute a unique vote
 90	identifier, mapped into the reserved vote-identifier namespace
 91	(see Section~\ref{sec:vocdoni-protocol:state-tree}):
 92	\begin{equation}\label{eq-voteid}
 93		\voteid = N + \bigl(\hlget{\Poseidon}(\processid, \address, k) \bmod N\bigr).
 94	\end{equation}
 95	\item Use the \ballotcircuit from Section~\ref{sec:vocdoni-protocol:circuits:ballot} to
 96	generate a \ac{ZK-SNARK} proof that Eqs.~\labelcref{eq-ciphertext,eq-voteid} are correctly
 97	computed and that $\ballot$ satisfies the ballot rules of $\ballotmode$:
 98	\begin{align*}
 99		\ballotproof = {} & \hlget{\PProve}\bigl(\hlget{\ballotcircuit},\\
100		& \witness = (\ballot, k, \processid, \ballotmode, \epk,\\ & \phantom{\witness = (}\weight, \encryptedballot), \\
101		& \publicinputs = (\address, \voteid, \ballotinputshash)\bigr).
102	\end{align*}
103	\item Sign the vote identifier with their Ethereum secret key $\sk$ to authenticate the vote:
104	\[ \signature = \hlget{\SSign}_{\sk}(\voteid). \]
105	\item Select a sequencer and submit the package
106	\begin{align*} \vote = [&\processid, \address, \voteid, \encryptedballot, \ballotproof,\\ &\ballotinputshash, \signature, \weight, \censusproof] \end{align*}
107	to the chosen sequencer, where \censusproof is only present for a \ac{CSP} census.
108	\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.
109\end{enumerate}
110A 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. All ballots of one voter should be sent to the same sequencer, which settles them in the order they were cast; across sequencers, the ballot settled last prevails.\\
111
112\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:
113\begin{enumerate}
114	\item Check the ballot proof against the pinned ballot verification key:
115	\[\hlget{\PVerify}\bigl(\ballotproof_i, (\address_i, \voteid_i, \ballotinputshash_i)\bigr) = \true.\]
116	\item Recover the signer, $\pk_i = \hlget{\SPubKey}(\voteid_i, \signature_i)$, and check that its address is $\address_i$.
117	\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.
118	\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$.
119	\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.
120\end{enumerate}
121Accepted 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}.\\
122
123\begin{figure}[h]
124	\centerline{\includegraphics[width=\textwidth,draft=false]{\figs/vote-lifecycle.pdf}}
125	\setlength{\abovecaptionskip}{5pt}
126	\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.}
127	\label{fig:vote-lifecycle}
128\end{figure}
129
130\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:
131\begin{enumerate}
132	\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.
133	\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}).
134	\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.
135	\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}).
136	\item Computes the public values it expects the batch program to output.
137\end{enumerate}
138A 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.\\
139
140\noi \textbf{(d) Proving and settlement.}
141\label{sec:vocdoni-protocol:flow:settlement}
142The sequencer sends the private inputs of the batch to its prover and obtains the batch proof,
143\begin{align*}
144	(\publicvalues, \batchproof) = {} & \hlget{\VMProve}\bigl(\hlget{\batchprogram},\\ & \witness = (\text{ballot proofs, state transition, eligibility, re-encryption, blobs})\bigr).
145\end{align*}
146Before 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.
147
148\begin{itemize}
149	\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
150	\begin{align*} \fn{submitStateTransition}\bigl(&\processid, \publicvalues, \batchproof,\\ &\{\blobcom_b\}, \{y_b\}, \{\openproof_b\}\bigr), \end{align*}
151	where $\openproof_b$ is the \ac{KZG} opening proof of blob $b$ at $z_b$.
152	The registry reads the versioned hashes of the blobs of its own transaction.
153	\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. If the origin moves past the anchor before the settlement lands, the sequencer can call \fn{record} on the \lblobverifier to keep that block usable as an anchor. It then calls
154	\begin{align*} \fn{submitStateTransitionL1}\bigl(&\processid, \publicvalues, \batchproof,\\ &\{\blobcom_b\}, \{y_b\}, \{\openproof_b\}, \Pi^{\mathsf{L1}}\bigr), \end{align*}
155	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.
156\end{itemize}
157Settlement 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:
158\begin{enumerate}
159	\item The entry point matches the registry's data availability mode.
160	\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}).
161	\item The public values are 512 bytes long and report $\okflag = 1$ and $\failmask = 0$.
162	\item $\stateroot^\old$ equals the latest state root of the process.
163	\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.
164	\item \occupiedbefore equals the process's \voterscount, the number of distinct slots written so far.
165	\item The batch adds at least one vote, and $\voterscount + (\numvotes - \numoverwrites) \le \maxvoters$.
166	\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.
167	\item The digest of the $(\blobcom_b, y_b)$ pairs equals \blobsdigest.
168	\item The ZisK verifier accepts the proof:
169	\[\hlget{\ziskverifier}.\fn{verifySnarkProof}(\texttt{batchProgramVK}, \rootc, \publicvalues, \batchproof).\]
170	\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.
171\end{enumerate}
172If 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.
173
174\begin{figure}[h]
175	\centerline{\includegraphics[width=\textwidth,draft=false]{\figs/l1-settlement.pdf}}
176	\setlength{\abovecaptionskip}{5pt}
177	\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.}
178	\label{fig:l1-settlement}
179\end{figure}
180
181\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.
182
183\subsubsection{End of the voting period}
184\label{sec:vocdoni-protocol:flow:grace}
185
186The 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
187\begin{equation}
188	\graceend = \min\bigl(\mathsf{end} + \texttt{graceMaxTotal},\ \max(\mathsf{end}, \lastvoteat) + \grace\bigr),
189	\label{eq:grace-end}
190\end{equation}
191where $\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, and may shorten the voting period, but only to an end time at least \texttt{noticeMin} away, so that every sequencer learns the new end before it applies. 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.
192
193\begin{figure}[h]
194	\centerline{\includegraphics[width=\textwidth,draft=false]{\figs/grace-window.pdf}}
195	\setlength{\abovecaptionskip}{5pt}
196	\caption{The grace window. Admission closes at the end time; transitions keep settling until \graceend, which every settlement pushes forward by \grace, up to \texttt{graceMaxTotal} after the end. Results can only be published after \graceend.}
197	\label{fig:grace-window}
198\end{figure}
199
200\begin{figure}[h]
201	\centerline{\includegraphics[width=\textwidth,draft=false]{\figs/process-status.pdf}}
202	\setlength{\abovecaptionskip}{5pt}
203	\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.}
204	\label{fig:process-status}
205\end{figure}
206
207The 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; sequencers refuse them, and the exposure is bounded by the window and visible, since every transition in the window is recorded on-chain with its time.
208
209\subsubsection{Tally decryption}
210\label{sec:vocdoni-protocol:tally}
211
212After 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.
213
214\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.
215
216\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}} M_j$ (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.
217
218\subsubsection{Election finalization}
219\label{sec:vocdoni-protocol:finalization}
220\label{sec:vocdoni-protocol:flow:results}
221
222In 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.
223
224\begin{figure}[h]
225	\centerline{\includegraphics[width=0.85\textwidth,draft=false]{\figs/protocol-flow-results.pdf}}
226	\setlength{\abovecaptionskip}{5pt}
227	\caption{Message flow of an election: decryption and finalization. The path depends on who holds the election key.}
228	\label{fig:protocol-flow-results}
229\end{figure}
230
231\paragraph{Sequencer mode.} The key holder proceeds as follows:
232\begin{enumerate}
233	\item Retrieve the encrypted results accumulator $\encresults$ and the encryption key $\epk$
234	from the final state, together with their Merkle inclusion proofs against the final state
235	root $\stateroot$.
236	\item Use the \resultsprogram from Section~\ref{sec:vocdoni-protocol:circuits:results} to
237	generate the results proof:
238	\begin{align*}
239		&(\publicvalues, \resultsproof) = \hlget{\VMProve}(\hlget{\resultsprogram}, \witness), \quad \text{with}\\
240		&\witness = \bigl(\encresults, \epk,\\
241		&\qquad \merkleInclusionPf^{\encresults}, \merkleInclusionPf^{\epk}, \{\text{results}_j, \pi^{\mathrm{dec}}_j\}_{j=1}^{16}\bigr),
242	\end{align*}
243	whose public values contain $\stateroot$ and the results.
244	\item Submit the public values and the proof to the \hlget{\processregistry} smart contract with \fn{setProcessResults}.
245	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}.
246\end{enumerate}
247
248\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.
249
250\noi The election is considered finalized once the decrypted results are available on-chain. At
251this stage, both the results and the complete integrity of the process are permanently recorded
252and 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
253aggregated results, and the publicly verifiable proofs of every state transition and of the results guarantees
254the integrity of the entire election.