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 Fig.~\ref{fig:protocol-flow}.
4
5\subsubsection{Election setup}
6\label{sec:election-setup}
7
8%Before any election can begin, sequencers must register in the \hlget{\electionregistry} smart contract. This registration is a one-time
9%operation per sequencer and is independent of any particular election.
10%; only registered
11%sequencers are eligible to participate in the processing of votes.
12%
13For each new election, the organizer performs the following steps:
14
15\begin{enumerate}
16
17 \item Prepare the census data \censusdata\ and build the incremental Merkle tree
18 $\censusTree$ from it. Publish the full tree to IPFS, and record the resulting URI as $\censusuri$.
19
20 \item Compute the census commitment $\censusroot = \censusTree.\hlget{\MTRoot}()$.
21
22 \item Define the election details: the start time (\starttime), the duration of the voting period (\duration), the census model $\censusorigin$
23 (see Section~\ref{sec:vocdoni-protocol:census}), and the ballot rules $\ballotmode$
24 (see Section~\ref{sec:ballot-protocol}).
25
26 \item Upload the election metadata (questions, options, description, etc.)\ to IPFS and
27 record the resulting URI as $\electionmetadata$.
28
29 \item Determine the process identifier $\processid$, a 32-byte value derived
30 deterministically from the organizer's Ethereum address, the account nonce, and a prefix
31 encoding the chain identifier and the \hlget{\electionregistry} smart contract. Being deterministic, it can be
32 computed in advance by the organizer, although it is ultimately recomputed and assigned by
33 the contract upon registration.
34
35 \item Obtain the encryption public key $\epk$ for this process. The key is produced by the
36 key wardens through the \ac{DKG} protocol
37 run for the identifier $\processid$, so that no single party knows the corresponding secret key.
38
39 \item Register the process on-chain by submitting a transaction to the
40 \hlget{\electionregistry} smart contract with the election parameters:
41 \begin{align*}
42 \mathsf{tx} = \big(
43 &\censusorigin,\ \censusroot,\ \censusuri,\ \electionmetadata, \\
44 &\ballotmode,\ \epk,\ \starttime,\ \duration\big).
45 \end{align*}
46 Upon accepting this transaction, the \hlget{\electionregistry} contract initializes the reserved configuration leaves
47 of the state tree $\stateTree$ as %
48 $\processid$ at $\mathtt{0x0}$, $\ballotmode$ at $\mathtt{0x2}$, $\epk$ at $\mathtt{0x3}$,
49 $\censusorigin$ at $\mathtt{0x6}$, and the results accumulator $\encresults$ at
50 $\mathtt{0x4}$ initialized to the encryption of zero (see Section~\ref{sec:vocdoni-protocol:state-tree}) and computes the initial state root
51 \[
52 \stateroot = \stateTree.\hlget{\MTRoot}().
53 \]
54\end{enumerate}
55%
56Once this transaction is accepted, the election is publicly registered on-chain and, at its
57scheduled start time, the voting period can begin.
58%
59%Before any election can begin, key wardens must register in the \hlget{\dkgmanagement} smart contract. This registration
60%is a one-time operation per key warden and is independent of any particular election; only
61%registered parties are eligible to participate in the \ac{DKG} phase.
62%%
63%For each new election, the organizer performs the following steps:
64%
65%\begin{enumerate}
66%
67% \item Prepare the census data \censusdata\ and build the \ac{IMT}
68% $\censusTree$ from it. Publish the full tree to IPFS, and record the resulting URI as $\censusuri$.
69%
70% \item Compute the census commitment $\censusroot = \censusTree.\hlget{\MTRoot}()$.
71%
72% \item Define the election details, including duration, the census model $\censusorigin$
73% (see Section~\ref{sec:vocdoni-protocol:census}), and the ballot rules $\ballotmode$
74% (see Section~\ref{sec:ballot-protocol}).
75%
76% \item Upload the election metadata (questions, options, description, etc.)\ to IPFS to obtain {\color{blue}electionMetadata}.
77%
78% \item Compute a unique process identifier $\processid$, which is a 32-byte number derived
79% from the organizer's Ethereum address, nonce, and the chain ID.
80%
81% \item Initialize the state Merkle tree $\stateTree$ by inserting the election configuration
82% parameters into the reserved configuration namespace (see Section~\ref{sec:vocdoni-protocol:state-tree}):
83% $\processid$ at leaf $\mathtt{0x0}$, $\ballotmode$ at leaf $\mathtt{0x2}$,
84% $\censusorigin$ at leaf $\mathtt{0x6}$, and zero-valued accumulators $\addaccumulator$ and
85% $\substractaccumulator$ at leaves $\mathtt{0x4}$ and $\mathtt{0x5}$, respectively. {\color{blue}Compute the
86% initial state root -- is this done by the SC?}
87% \[
88% \stateroot = \stateTree.\hlget{\MTRoot}().
89% \]
90%
91% \item Set security parameters for the \ac{DKG} ceremony (e.g.\ timeout, minimum number
92% of sequencers) {\color{blue}DKG}.
93%
94% \item Submit all this information in a transaction to the \hlget{\electionregistry} smart
95% contract:
96% \begin{align*}
97% tx_{\mathit{org}} = \big(
98% &\processid,\ \censusroot,\ \censusorigin,\ \censusuri, \\
99% &\ballotmode,\ {\color{blue}electionMetadata},\ \stateroot,\ {\color{blue}dkgParameters}
100% \big).
101% \end{align*}
102%
103%\end{enumerate}
104%%
105%Once this transaction is accepted, the election is publicly registered on-chain and the
106%\ac{DKG} phase can begin.
107
108\subsubsection{Encryption key generation}
109\label{sec:vocdoni-protocol:keygen}
110
111In this phase, the \keywardens\ collectively generate the public encryption key ($\epk$) that voters will use to encrypt their ballots. Since the process identifier $\processid$ is derived deterministically (see Section~\ref{sec:election-setup}), it is known in advance, so the \ac{DKG} ceremony for the election can be carried out before the process is registered on-chain.
112
113Each \keywarden\ contributes to the ceremony and publishes a proof that its contribution is well-formed. The \hlget{\dkgmanagement} smart contract verifies these proofs, so that correct participation can be checked without revealing any secret. Once a threshold of valid contributions is collected, the joint public key $\epk$ is derived, while the corresponding secret key remains secret-shared among the wardens. In this way, no single party can decrypt on its own, and later tally decryption requires the collaboration of a threshold of wardens (see Section~\ref{sec:vocdoni-protocol:tally}). The resulting $\epk$ is the key that the organizer includes when registering the election (see Section~\ref{sec:election-setup}). The concrete \ac{DKG} construction is given in Appendix~\ref{sec:cryptographic-primitives:dkg}.
114
115\subsubsection{Voting period}
116\label{sec:vocdoni-protocol:votes}
117
118In this phase, voters cast their ballots and send them to the sequencers, who collect and process them. \\
119
120\noi \textbf{(a) Vote casting.} Each voter holds an Ethereum key pair $(\sk, \pk)$ with
121associated address $\address$ (see Appendix~\ref{sec:cryptographic-primitives:signatures}).
122To cast a ballot, a voter does the following:
123
124\begin{enumerate}
125 \item Retrieve the census membership proof $\censusproof$ to prove eligibility.
126 \item Fetch the parameters $\epk$, $\ballotmode$, and $\processid$ from the
127 \hlget{\electionregistry} contract.
128 \item Select their ballot choice $\ballot$ following the rules of $\ballotmode$.
129 \item Sample fresh randomness $k \in \F$ and encrypt the ballot using $\epk$:
130 \begin{equation}\label{eq-ciphertext}
131 \encryptedballot = \hlget{\Enc}_{\epk}(\ballot; k).
132 \end{equation}
133 \item Use their address $\address$ and the randomness $k$ to compute a unique vote
134 identifier, mapped into the reserved vote-identifier namespace
135 (see Section~\ref{sec:vocdoni-protocol:state-tree}):
136 \begin{equation}\label{eq-voteid}
137 \voteid = N + \bigl(\hlget{\Poseidon}(\processid, \address, k) \bmod N\bigr).
138 \end{equation}
139 \item Use the \ballotcircuit from Section~\ref{sec:vocdoni-protocol:circuits:ballot} to
140 generate a \ac{ZK-SNARK} proof that Eqs.~\labelcref{eq-ciphertext,eq-voteid} are correctly
141 computed and that $\ballot$ satisfies the ballot rules of $\ballotmode$:
142 \begin{align*}
143 \ballotproof = {} & \hlget{\PProve}(\hlget{\ballotcircuit}, \witness = (\ballot, k), \\
144 & \publicinputs = (\processid, \ballotmode, \epk, \address, \weight,
145 \encryptedballot, \voteid)).
146 \end{align*}
147 \item Sign the vote identifier with their Ethereum secret key $\sk$ to authenticate the vote:
148 \[ \signature = \hlget{\SSign}_{\sk}(\voteid). \]
149 \item Select a sequencer and submit the package
150 \[ \vote = [\processid, \voteid, \encryptedballot, \censusproof, \ballotproof, \signature] \]
151 to the chosen sequencer.
152\end{enumerate}
153
154\noi \textbf{(b) Vote batching.} Upon receiving votes, a sequencer does the following:
155
156\begin{enumerate}
157 \item Retrieve the election identifier $\processid$, the current state root $\stateroot$, and
158 the census root $\censusroot$ from the \hlget{\electionregistry} smart contract, together with
159 the associated data from the Ethereum data blobs.
160 \item Upon receiving a vote
161 \[ \vote_i = [\processid, \voteid_i, \encryptedballot_i, \censusproof_i, \ballotproof_i, \signature_i], \]
162 recover the voter's public key $\pk_i = \hlget{\SPubKey}(\signature_i)$.
163 \item For each $\vote_i$, use the \verifiercircuit from
164 Section~\ref{sec:vocdoni-protocol:circuits:verifier} to generate a proof
165 \begin{align*}
166 \authenticationproof_i = {} & \hlget{\PProve}(\hlget{\verifiercircuit},
167 \witness = (\pk_i, \signature_i, \ballotproof_i), \\
168 & \publicinputs = (\processid, \ballotmode, \epk, \encryptedballot_i, \voteid_i,\\
169 &\address_i, \weight_i)).
170 \end{align*}
171 This proof ensures that $\ballotproof_i$ and $\signature_i$ are valid and that $\address_i$
172 is correctly derived from $\pk_i$. The census membership proof $\censusproof_i$ is not
173 used here; it is retained for the state transition circuit
174 (Section~\ref{sec:vocdoni-protocol:circuits:state-transition}), where eligibility is enforced.
175 \item Batch a set of $n$ authentication proofs $\{\authenticationproof_i\}_{i=1}^{n}$ and verify
176 them together using the \aggregationcircuit from
177 Section~\ref{sec:vocdoni-protocol:circuits:aggregation}:
178 \begin{align*}
179 \aggregationproof = {} & \hlget{\PProve}(\hlget{\aggregationcircuit},
180 \witness = (\{\authenticationproof_i\}_{i=1}^{n}), \\
181 & \publicinputs = (\{\encryptedballot_i\}_{i=1}^{n}, \{\voteid_i\}_{i=1}^{n},
182 \{\address_i\}_{i=1}^{n}, \processid, \\
183 &\ballotmode, \epk)).
184 \end{align*}
185 This proof ensures that all $\authenticationproof_i$ are valid and share the same global
186 parameters $\processid$, $\ballotmode$, and $\epk$.
187 \item Prepare the state transition data to be published in an Ethereum blob: pack the votes and
188 results into a 4096-cell blob $\blobdata$ and
189 \begin{itemize}
190 \item compute the data commitment $\blobcom = \hlget{\CCommit}(\blobdata)$,
191 \item derive the evaluation point $\evalpoint = \hlget{\Poseidon}(\processid, \stateroot^{\old}, \blobcom)$,
192 \item build the polynomial $P$ from $\blobdata$ and evaluate $y = P(\evalpoint)$,
193 \item produce the opening proof $\openproof$ for the evaluation $(\evalpoint, y)$.
194 \end{itemize}
195 The consistency $y = P(\evalpoint)$ between the blob and the on-chain state is proven inside
196 the state transition circuit.
197 \item Generate the state transition proof with the \statetransitioncircuit from
198 Section~\ref{sec:vocdoni-protocol:circuits:state-transition}:
199 \begin{align*}
200 \stateproof = {} & \hlget{\PProve}(\hlget{\statetransitioncircuit},
201 \witness = (\aggregationproof, \{\censusproof_i\}_{i=1}^{n},\\
202 &\{\encryptedballot_i\}_{i=1}^{n}, k, \openproof, \dots), \\
203 & \publicinputs = (\censusroot, \stateroot^{\old}, \stateroot^{\new}, \blobcom, \dots)).
204 \end{align*}
205 The complete input list is given in
206 Section~\ref{sec:vocdoni-protocol:circuits:state-transition}. This proof attests that the
207 encrypted votes are correctly accumulated via ElGamal's homomorphic properties, that every
208 processed vote corresponds to an eligible voter (via the census membership proofs), that vote
209 overwrites are handled consistently, and the blob data matches the committed on-chain state.
210 \item Submit the state transition proof $\stateproof$ and the new state root $\stateroot^{\new}$
211 to the \hlget{\electionregistry} smart contract, while the full data is published in the
212 Ethereum blobs.
213\end{enumerate}
214
215\noi Upon receiving the transaction, the smart contract checks that the submitted previous root
216matches the current on-chain state root and that $\stateproof$ is valid before updating the state
217root to $\stateroot^{\new}$. If the on-chain state root changed while the sequencer was preparing
218the batch (because another sequencer committed first), only the state transition proof must be
219regenerated, as noted in Section~\ref{sec:vocdoni-protocol:circuits:state-transition}. Sequencers
220repeat this process until the voting deadline set by the organizer.
221
222\subsubsection{Tally decryption}
223\label{sec:vocdoni-protocol:tally}
224
225After the voting period expires, the \hlget{\electionregistry} smart contract stops accepting new state updates, fixing the final state root and thus the aggregated encrypted results. A threshold of $t$ out of $n$ \keywardens\ then cooperate to decrypt this aggregate: rather than reconstructing the election secret key, each participating warden publishes a partial decryption of the encrypted results together with a proof that its contribution is correct with respect to its key share. Once $t$ valid partial decryptions are available, they are combined to recover the plaintext tally. 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.
226%
227The resulting tally, together with a proof of correct decryption, is published on-chain during the finalization phase (see Section~\ref{sec:vocdoni-protocol:finalization}), where it is checked by the \resultscircuit\ and the \hlget{\resultsverifier} contract. %\Keywardens\ that fail to provide a valid partial decryption may be penalized; the incentive and slashing mechanisms are described in Section~\ref{sec:token}.
228
229
230\subsubsection{Election finalization}
231\label{sec:vocdoni-protocol:finalization}
232
233In this final phase, the organizer (or a sequencer) publishes the election results, together with
234a proof of their correct computation, on-chain.
235
236\begin{enumerate}
237 \item Obtain the plaintext results $\{\text{results}_j\}_{j=1}^{n_f}$ and the corresponding
238 decryption proofs $\{\pi^{\mathrm{dec}}_j\}_{j=1}^{n_f}$ from the tally decryption phase
239 (Section~\ref{sec:vocdoni-protocol:tally}), i.e.\ the combination of the \keywardens'
240 partial decryptions of the aggregated encrypted results.
241 \item Retrieve the encrypted results accumulator $\encresults$ and the encryption key $\epk$
242 from the final state, together with their Merkle inclusion proofs against the final state
243 root $\stateroot$.
244 \item Use the \resultscircuit from Section~\ref{sec:vocdoni-protocol:circuits:results} to
245 generate the results proof:
246 \begin{align*}
247 \resultsproof = {} & \hlget{\PProve}(\hlget{\resultscircuit},
248 \witness = (\encresults, \epk,\\ &\merkleInclusionPf^{\encresults},
249 \merkleInclusionPf^{\epk}, \{\pi^{\mathrm{dec}}_j\}_{j=1}^{n_f}), \\
250 & \publicinputs = (\stateroot, \{\text{results}_j\}_{j=1}^{n_f})).
251 \end{align*}
252 \item Submit the results and $\resultsproof$ to the \hlget{\electionregistry} smart contract.
253 The contract verifies the proof with the \hlget{\resultsverifier}, checks that the state root
254 committed in the proof matches the current on-chain state root, and records the results,
255 marking the process as finalized.
256\end{enumerate}
257
258\noi The election is considered finalized once the decrypted results are available on-chain. At
259this stage, both the results and the complete integrity of the process are permanently recorded
260and publicly auditable: anyone can recompute the on-chain commitments and check the \ac{ZK-SNARK}
261proofs. In particular, the combination of the final state root, the verified decryption of the
262aggregated results, and the publicly verifiable \ac{ZK-SNARK} state and results proofs guarantees
263the integrity of the entire election.
264
265%\begin{figure}%[H]
266% \centerline{\includegraphics[width=370pt,draft=false]{\figs/protocol-flow.pdf}}
267% \caption{Vocdoni voting process overview. {\color{blue}Figure is OUTDATED.}}
268% \label{fig:protocol-flow}
269%\end{figure}