davinci-paper/v2/sections/vocdoni-protocol.tex
v2/sections/vocdoni-protocol.texRaw
1% !TeX root = ../build/main.tex
2
3This section outlines the \davinci voting protocol. We introduce the parties involved in the process in Section~\ref{sec:vocdoni-protocol:parties}. In Section~\ref{sec:vocdoni-protocol:merkle-trees}, we describe the census and state Merkle trees, and in Section~\ref{sec:vocdoni-protocol:smart-contracts} the Ethereum smart contracts. In Section~\ref{sec:vocdoni-protocol:circuits}, we present the ZK circuits used to enforce vote validity, authentication, aggregation, and state transitions. Finally, in Section~\ref{sec:vocdoni-protocol:flow}, we detail the full protocol flow step by step, from the voting setup to the results validation and process finalization.
4
5\subsection{Parties involved}
6\label{sec:vocdoni-protocol:parties}
7
8A voting process involves three types of participants: the organizer, the sequencer, and the voters.
9
10\paragraph{Organizer.} The organizer is the entity responsible for defining and setting up the voting process. Its key responsibilities include defining the voting parameters and gathering the census data. The organizer ensures that the election is structured correctly but does not participate in vote collection or tallying.
11
12\paragraph{Sequencer.} Sequencers are a set of decentralized parties that facilitate the voting process. On the one hand, they collaboratively generate a public encryption key that voters use to encrypt their votes. Then, during the voting phase, they receive and verify encrypted votes from voters and reencrypt votes to prevent coercion.
13%Old text: the Sequencer is a specialized component designed to handle the voting process using zero-knowledge proof mechanisms. It ensures that all transactions related to this process are validated and sequenced. The Sequencers periodically commit the state of the voting process to Ethereum.
14
15\paragraph{Voter.} Voters are the participants that belong the census that cast their votes in the election.
16
17\subsection{Merkle trees}
18\label{sec:vocdoni-protocol:merkle-trees}
19
20Merkle trees are used to create a cryptographic representation of both the voter census registry and the voting process state.
21
22%\begin{itemize}
23% \item \textbf{Census}: Each voter is assigned a Merkle proof, which they use to prove their eligibility to vote. This mechanism ensures efficient and secure verification of voter eligibility.
24% \item \textbf{State}: The voting process state is represented as a Merkle tree, with new votes being added to the tree. The root of this Merkle tree is stored on Ethereum, allowing multiple sequencers to participate in the voting phase and ensuring consistency.
25%\end{itemize}}
26
27\subsubsection{Census tree}
28
29The census Merkle tree, denoted by $\hlget{\censusTree}$ encodes the list of eligible voters and their associated voting weights. Formally, it is implemented as a sparse Merkle tree (SMT) of fixed depth\footnote{In the present work, all circuits are instantiated using sparse Merkle trees as described above. However, the protocol does not strictly depend on this structure: any authenticated data structure that supports efficient commitments and membership proofs verifiable inside zero-knowledge circuits could be employed. Adapting the protocol to such alternatives would only require modifying the corresponding circuits, while the overall flow of the voting process would remain unchanged.}, as described in Section~\ref{sec:cryptographic-primitives:merkle-trees}. Each voter is mapped to a unique path in the tree, typically derived from their Ethereum address or another unique identifier, and the corresponding leaf stores the voting weight of that address. While the default weight is usually one, the system also supports weighted voting, where different participants may have different levels of influence.
30
31To construct the census, the organizer collects the dataset of eligible voters and their weights, computes the corresponding tree, and publishes its root (\censusroot) on-chain. The full dataset does not need to be stored on-chain; instead, it is distributed off-chain (e.g., via IPFS or another content-addressed storage system), enabling verifiers and sequencers to independently reconstruct the tree and produce membership proofs when needed. This design ensures transparency and verifiability while minimizing on-chain storage requirements.
32
33The census tree plays a central role during the voting phase. Voters must provide a Merkle proof showing that their address and weight are included in the tree committed by the organizer. These proofs are then verified within ZK circuits, which guarantees that only eligible participants can cast ballots without requiring the disclosure of the entire census. In this way, the census Merkle tree provides a compact, cryptographically verifiable commitment to voter eligibility that supports both privacy and scalability.
34
35Although the protocol does not mandate a specific method for constructing the census tree, different instantiations are possible depending on the application context:
36%
37\begin{itemize}
38 \item \emph{Private datasets}. Organizations maintaining internal voter registries (e.g., membership databases or CSV files) can directly convert them into the Merkle format. This approach keeps the registry confidential, with only the root hash made public.
39 \item \emph{Self-sovereign identity (SSI)}. If voters manage identities through SSI systems, the organizer can aggregate these identities and build
40 the tree accordingly. This enables participation without requiring centralized identity management.
41 \item \textit{Ethereum-based tokens}. Token balances (e.g., ERC-20 or NFTs) may also define eligibility. In this setting, the census can either be created via the optimistic approach, taking a snapshot of token balances and allowing a dispute period for fraud proofs, or through a ZK-SNARK that proves correctness directly from Ethereum storage proofs and ensures that both individual balances and the token’s total supply are consistent.
42\end{itemize}
43%
44This flexibility allows the protocol to accommodate a wide range of use cases, from private associations to decentralized communities, while maintaining the same security and verifiability guarantees.
45
46\subsubsection{State tree}
47
48The state Merkle tree, denoted by $\hlget{\stateTree}$, represents the evolving state of the voting process. Like the census tree, it is implemented as a SMT of fixed depth, as described in Section~\ref{sec:cryptographic-primitives:merkle-trees}. In contrast to the census tree, which remains static once the election begins, the state tree is dynamic: it is updated throughout the process as new votes are cast, validated, and incorporated by the sequencers.
49
50The leaves of the state tree store the global process parameters, the encrypted ballots, and the set of vote identifiers, as illustrated in Figure~\ref{fig:mt-state}. More specifically:
51
52\paragraph{Reserved addresses for metadata.} The first six addresses are reserved for the process parameters as follows:
53
54\begin{itemize}
55 \item \texttt{0x0}: it stores a unique identifier for the voting process (\processid).
56 \item \texttt{0x1}: it stores the committed census root (\censusroot). %and \type, a field in case the organization was using a different structure for the census than a MT.
57 \item \texttt{0x2}: it stores the ballot mode configuration, which is the set of rules for validating votes (\ballotmode).
58 \item \texttt{0x3}: it stores the encryption public key used to encrypt the votes (\epk).
59 \item \texttt{0x4}: it stores an accumulator of the encrypted votes that need to be added to the tally (\addaccumulator).
60 \item \texttt{0x5}: it stores an accumulator of the encrypted votes that need to be substracted from the tally because they have been overwritten (\substractaccumulator).
61\end{itemize}
62
63\paragraph{Encrypted ballots.} Each voter’s encrypted ballot is stored in the state tree at a leaf whose path corresponds to their Ethereum address (or another unique identifier). The leaf value is the ciphertext corresponding to the ballot generated under the election’s public encryption key. If the voter later overwrites their ballot, the same path is updated with the new ciphertext.
64
65\paragraph{Vote identifiers.} In addition to storing ballots, the state tree also tracks the set of vote identifiers. Each vote identifier \voteid, which is derived from the \processid, the voter’s address, and fresh randomness, determines the path to a dedicated leaf. Initially empty, these leaves are filled when the corresponding \voteid is used, thereby recording that it has been consumed. This enables efficient non-membership proofs: before accepting a new ballot, the sequencer checks that the corresponding \voteid path is still empty, and upon inclusion, the leaf is marked as used to prevent reuse. \\
66
67%Figure~\ref{fig:mt-state} illustrates the structure of the state tree, showing the reserved slots for process parameters as well as the leaves used for ballots and vote identifiers.
68
69\begin{figure}[h]
70 \centerline{\includegraphics[width=400pt,draft=false]{\figs/mt-state-mermaid}}
71 \caption{Structure of the state Merkle tree. The first leaves are reserved for global process parameters while subsequent leaves store encrypted ballots indexed by voter addresses and vote identifiers.}
72 \label{fig:mt-state}
73\end{figure}
74
75At the beginning of the election, the state tree is initialized with the process parameters and empty accumulators, and its root ($\stateroot$) is published on-chain. As the voting progresses, sequencers update the tree whenever new votes are received, producing a new root for each transition. To guarantee correctness, each update is accompanied by a ZK-SNARK proof attesting that the transition from the previous root to the new root respects all protocol constraints: ballots are well-formed and comply with the voting rules, voters are eligible according to the census, the \voteid non-membership condition prevents double voting (or overwrites are handled correctly), and encrypted results are aggregated consistently. In addition, sequencers reencrypt stored ciphertexts, including both newly submitted and already included ballots. This mechanism refreshes the randomness of the encrypted votes without altering their underlying content, ensuring receipt-freeness and concealing whether a particular ballot has been overwritten or simply re-randomized.
76
77In this way, the state tree provides a compact and tamper-proof commitment to the current status of the election. At the end of the process, the final state root together with the on-chain verification of all transitions serves as a complete cryptographic record of the election, encapsulating both the tally and the integrity of the entire voting procedure.
78
79\subsection{Smart contracts}
80\label{sec:vocdoni-protocol:smart-contracts}
81
82An Ethereum compatible network is used as the source of truth for the voting system. By leveraging an Ethereum virutal machine (EVM) blockchain, the voting process management ensures that all transitions are immutable and verifiable by all participants. To this end, we implement the following three smart contracts.
83
84\paragraph{Process management smart contract.} It is responsible for the life-cycle management of voting processes. It includes the initiation, monitoring, execution, and closure of voting events.
85
86\paragraph{Sequencer registry smart contract.} It keeps track of the existing available sequencers, stores the collateral of the sequencers to ensure (that incentivizes) good behaviour, and is used to coordinate the distributed key generation when a new voting process is created.
87
88\paragraph{Results verification smart contract.} For each voting process, this smart contract maintains the integrity of the cast votes and process life cycle. It verifies that each state transition committed by a sequencer adheres to the predefined rules.\\
89
90\subsection{Circuits}
91\label{sec:vocdoni-protocol:circuits}
92
93At the core of \davinci lie a set of arithmetic circuits that enforce the correctness of every step of the voting process. Each circuit 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}) ensures that encrypted votes are valid and well-formed, the \emph{verifier circuit} (Section~\ref{sec:vocdoni-protocol:circuits:verifier}) verifies voter eligibility and census membership; the \emph{aggregation circuit} (Section~\ref{sec:vocdoni-protocol:circuits:aggregation}) combines multiple authenticated votes into a single proof; and the \emph{state transition circuit} (Section~\ref{sec:vocdoni-protocol:circuits:state-transition}) updates the global state root and produces the ZK-SNARK proof that is verified on-chain. The flow of these circuits and their interactions is shown in Figure~\ref{fig:circuits-flow}.
94
95\begin{figure}[h]
96 \centerline{\includegraphics[width=\linewidth,draft=false]{\figs/circuits-flow-v2}}
97 \caption{
98 Overview of the circuit flow in \davinci.}
99 \label{fig:circuits-flow}
100\end{figure}
101
102For clarity, the circuits are described in this section with their full set of public inputs explicitly listed. In the actual implementation, however, we apply an optimization: rather than exposing all public inputs individually, we compute a single commitment $h = Hash(PI)$ and use $h$ as the only public input. The proof verifier then checks that $Hash(PI) = h$, ensuring that the original public inputs are consistent while reducing both proof size and verification cost. In \davinci, this commitment is computed using the MiMC-7 hash function {\color{blue}(use hlget to point "Hash" to MiMC-7)}. Note that this optimization does not alter the semantics of the circuits but significantly reduces verifier complexity and on-chain verification costs. Other implementation aspects such as the exact number of constraints and the proving frameworks used are deferred to Section~\ref{sec:analysis:implementation}.
103
104% Old text: By structuring the process this way, we ensure that voting can be performed from any device-including smartphones and web browsers-while keeping the sequencer's computational requirements within the capabilities of accessible, CPU-based machines with 64 GiB of memory.
105
106\subsubsection{Ballot circuit}
107\label{sec:vocdoni-protocol:circuits:ballot}
108
109The ballot circuit, illustrated in Figure~\ref{fig:circuit-ballot}, is generated 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 ZK proof generated using the ZK-SNARK protocol described in Section~\ref{sec:cryptographic-primitives:zkp}, instantiated over the BN254 curve. We call the resulting proof \textit{ballot proof} and denote it as $\hlset{\ballotproof}$. We detail below the inputs and constraints of the ballot circuit.
110
111\begin{spacing}{1.25}
112 \vspace{0.3cm}
113 \noi \textbf{Public inputs}
114 \begin{itemize}
115 \item $\public$ $\processid$: voting process identifier.
116 \item $\public$ $\ballotmode$: ballot protocol configuration.S
117 \item $\public$ $\epk$ ($EPK$): encryption public key.
118 \item $\public$ $\address$: voter's address.
119 \item $\public$ $\weight$: voter's weight.
120 \item $\public$ $(C_1, C_2)$: encrypted ballot.
121 \item $\public$ $\voteid$: vote's unique identifier.
122 \end{itemize}
123 \textbf{Private inputs}
124 \begin{itemize}
125 \item \private $\ballot$: plaintext voter's voting choice.
126 \item \private $k$: random scalar.
127 \end{itemize}
128 \textbf{Constraints}
129 \begin{itemize}
130 \item \emph{Vote encryption}. Correct encryption of the ballot: $(C_1, C_2) = \hlget{\Enc}_{\epk}(\ballot; k).$
131 \item \emph{Protocol rules compliance}. The ballot meets the protocol rules (number of valid choices, etc.): $... + \weight$.
132 \item \emph{Vote identifier}. The vote's identifier is correctly computed: $\voteid = \text{Hash} (\processid \conc \address \conc k).$
133 \end{itemize}
134 \vspace{-0.3cm}
135\end{spacing}
136
137\begin{figure}[H]
138 \centerline{\includegraphics[width=420pt,draft=false]{\figs/circuit-voter}}
139 \caption{Ballot circuit. All public values are framed in green.}
140 \label{fig:circuit-ballot}
141\end{figure}
142
143\subsubsection{Verifier circuit}
144\label{sec:vocdoni-protocol:circuits:verifier}
145
146The verifier circuit, illustrated in Figure~\ref{fig:circuit-verifier}, is generated by the sequencer when processing a vote. This circuit verifies the ballot's proof generated by the voter and it also validates the voter’s eligibility in the census and the correctness of their digital signature. The correctness of this circuit is attested by a ZK proof generated using the ZK-SNARK protocol described in Section~\ref{sec:cryptographic-primitives:zkp}, instantiated over the BLS12-377 curve. We call the resulting proof the \textit{authentication proof} and denote it as $\hlset{\authenticationproof}$. We detail below the inputs and constraints of this circuit. {\color{blue}-- Authentication of verification proof?}
147
148\begin{spacing}{1.25}
149 \vspace{0.3cm}
150 \noi \textbf{Public inputs}
151 \begin{itemize}
152 \item \public $\processid$: process identifier.
153 \item \public $\ballotmode$: ballot protocol configuration.
154 \item \public $\epk$ ($EPK$): encryption public key.
155 \item \public $(C_1, C_2)$: encrypted ballot.
156 \item \public $\voteid$: voter's identifier.
157 \item \public $\censusroot$: census Merkle tree root.
158 \item \public $\pk$: voter's public key.
159 \end{itemize}
160 \textbf{Private inputs}
161 \begin{itemize}
162 \item \private $\ballotproof$: voter's ballot proof.
163 \item \private $\weight$: voter's weight.
164 \item \private $\censuspf$: census membership proof.
165 \item \private $\signature$: voter's signature.
166 \end{itemize}
167 \textbf{Constraints}
168 \begin{itemize}
169 \item \emph{Voter's proof verification.} The vote zkProof is valid for the inputs provided:
170 $$\hlget{\PVerify}\left(\ballotproof, PI = (\processid, \ballotmode, \epk, (C_1, C_2), \voteid, \weight)\right).$$
171 \item \emph{Census membership.} The address derived from the user's public key is part of the census, and verifies the census proof with the user's weight provided:
172 $$ \hlget{\censusTree}.\hlget{\MTMembershipProof}(\weight, \address = \hlget{\Keccak}(\pk), \censuspf, \censusroot). $$
173 \item \emph{Authentication + non-malleability.} The signature of the vote's identifier is valid for the given public key:
174 $$ \hlget{\SVer}_{\pk}(\voteid, \signature). $$
175 \end{itemize}
176 \vspace{-0.3cm}
177\end{spacing}
178
179\begin{figure}[H]
180 \centerline{\includegraphics[width=450pt,draft=false]{\figs/circuit-authentication}}
181 \caption{Authentication circuit. All public values are framed in green.}
182 \label{fig:circuit-verifier}
183\end{figure}
184
185\subsubsection{Aggregation circuit}
186\label{sec:vocdoni-protocol:circuits:aggregation}
187
188The aggregation circuit, illustrated in Figure~\ref{fig:circuit-aggregate}, is generated by the sequencer to combine multiple authenticated votes into a single proof. Its purpose is to reduce verification overhead by recursively aggregating individual authentication proofs, while ensuring that all aggregated votes belong to the same voting process. The batch size, i.e., the maximum number of proofs aggregated in a single execution, is a fixed parameter (currently set to 60). If fewer proofs are available, the sequencer pads the batch with dummy proofs so that the circuit always operates on a fixed-size input. The correctness of this circuit is attested by a ZK proof generated using the ZK-SNARK protocol described in Section~\ref{sec:cryptographic-primitives:zkp}, instantiated over the BW6-761 curve. We call the resulting proof the \textit{aggregation proof} and denote it as $\hlset{\aggregationproof}$. We detail below the inputs and constraints of the aggregation circuit.
189
190\begin{spacing}{1.25}
191 \vspace{0.3cm}
192 \noi \textbf{Public inputs}
193 \begin{itemize}
194 \item \public $(C_1, C_2)_i$: list of voters' encrypted ballots.
195 \item \public $\voteid_i$: set of vote's identifiers.
196 \item \public $\pk_i$: list of voters' public keys.
197 \item \public $\processid$: process identifier.
198 \item \public $\ballotmode$: ballot protocol configuration.
199 \item \public $EPK$: encryption public key.
200 \item \public $\censusroot$: census Merkle tree root.
201 \end{itemize}
202 \textbf{Private inputs}
203 \begin{itemize}
204 \item \private $\authenticationproof_i$: set of authentication proofs.
205 \end{itemize}
206 \textbf{Constraints} \\ \vspace{-0.4cm}
207 \begin{itemize}
208 \item \emph{Votes aggregation.} The accumulated authentication proofs are valid (for the given inputs). For every $i$:
209 $$\hlget{\PVerify}(\authenticationproof, PI = ((C_1, C_2)_i, \voteid_i, \pk_i, \processid, \ballotmode, EPK, \censusroot)).$$
210 \item \emph{Shared public inputs.} The public inputs \processid, \ballotmode, \epk, and \censusroot are the same for all proofs.
211 \end{itemize}
212 \vspace{-0.3cm}
213\end{spacing}
214
215\begin{figure}[h]
216 \centerline{\includegraphics[width=450pt,draft=false]{\figs/circuit-aggregate}}
217 \caption{Aggregation circuit. All public values are framed in green.}
218 \label{fig:circuit-aggregate}
219\end{figure}
220
221\subsubsection{State transition circuit}
222\label{sec:vocdoni-protocol:circuits:state-transition}
223
224The state transition circuit, illustrated in Figure~\ref{fig:circuit-state-transition-v2}, is generated by the sequencer to update the global state of the voting process. Its purpose is to verify that a batch of aggregated votes has been correctly incorporated into the state Merkle tree, that overwrites and vote identifiers are handled consistently, and that the accumulators of encrypted results are updated accordingly. The correctness of this circuit is attested by a ZK proof generated using the ZK-SNARK protocol described in Section~\ref{sec:cryptographic-primitives:zkp}, instantiated over the BN254 curve, which is supported by Ethereum’s native precompiles for proof verification. We call the resulting proof the \textit{state proof} and denote it as $\hlset{\stateproof}$. This proof is submitted on-chain and verified by the process management smart contract, ensuring that every accepted state transition complies with the protocol rules.
225
226\pagebreak
227
228\paragraph{Assertions.}
229
230\begin{itemize}
231 \item \emph{Aggregation verification}: The agreggated zkProof is valid.
232 \item \emph{Transition verification}: The MerkleTree transition witness proves every change between Root1 and Root2.
233 \item \emph{Public inputs integrity}: ProcessID, BallotMode, CensusRoot, EncryptionKey remain unchanged.
234 \item \emph{Votes counting}: Ballots are correctly counted as new or overwrites, and added to results accumulators.
235\end{itemize}
236
237When a new voting process begins, the Sequencer initializes a new State, represented by the root hash of a Merkle tree. This tree encapsulates all essential information about the voting process, including process parameters, voter registry (census), ballot configurations, and initial results.
238
239For each new batch of votes, the Sequencer updates the state by generating a zkSNARK proof that \textbf{validates the state transition from the current Root to a new Root}. This proof is submitted on-chain for settlement. By doing so, we maintain an immutable and verifiable record of the voting process on the blockchain.
240
241This approach allows anyone to access the latest verified state of the voting process from the Results Verification smart contract, along with the necessary data to process subsequent state updates. The system's design enables multiple Sequencers to participate in tallying votes. They can take the current State Root and its associated data to construct the next state, incorporating new votes into the tally. This decentralization of Sequencers helps prevent potential censorship and reinforces the robustness of the voting process.
242
243\paragraph{Maintaining the Chain.}
244
245The chain of integrity is maintained through a combination of smart contract enforcement and strict zkSNARK circuit constraints. This ensures that each state transition is valid and builds upon the last accepted state without requiring additional mechanisms.
246
247\begin{itemize}
248 \item \textbf{Sequential state roots}: Each state transition updates the Merkle tree from a previous root (`Root1`) to a new root (`Root2`) after processing a batch of votes.
249 \item \textbf{Smart contract enforcement}: The smart contract verifies that the `Root1` provided in the zkSNARK proof matches the last committed state root stored on-chain. This guarantees that all transitions are sequential and based on the latest accepted state.
250 \item \textbf{Proof validation}: The smart contract uses the zkSNARK verification key to validate the submitted proof. A valid proof confirms that the transition from `Root1` to `Root2` adheres to all protocol rules enforced by the circuit.
251 \item \textbf{State update}: Upon successful verification, the smart contract updates the stored state root hash to`Root2`, ensuring an immutable and continuous chain of states.
252\end{itemize}
253
254\paragraph{State Transition}
255
256To validate and process state transitions, \textbf{we employ a zkSNARK circuit that enforces all protocol constraints}. This circuit proves that the transition from the previous state Root to the new state Root is valid based on the newly processed votes.
257
258\begin{figure}[H]
259 \centering
260 \fbox{
261 \includegraphics[scale = 0.12, draft = false]{\figs/state-transition.png}}
262\end{figure}
263
264%\begin{figure}[H]
265% \centering
266% \fbox{
267% \includegraphics[scale = 0.3, draft = false]{\figs/circuit-inputs.png}}
268%\end{figure}
269%
270%\begin{figure}[H]
271% \centerline{\includegraphics[width=400pt,draft=false]{\figs/circuit-state-transition}}
272% \caption{State transition circuit. All public values are framed in green.}
273% \label{fig:circuit-state-transition}
274%\end{figure}
275
276\begin{mdframed}
277 \begin{minipage}[H]{1\textwidth}
278 \begin{spacing}{1.25}
279 \vspace{0.3cm}
280 \begin{center}{STATE TRANSITION CIRCUIT}\end{center}
281 \textbf{Public inputs}
282 \begin{itemize}
283 \item \public $root_{old}$: Merkle tree root before the state transition.
284 \item \public $root_{new}$: Meklre tree root after the state transition.
285 \item \public $blobCommitment$: the commitment to the data blob containing the new votes.
286 \end{itemize}
287 \item \textbf{Private inputs}
288 \begin{itemize}
289 \item \private Votes: The list of new votes being processed, including census proofs and authentication data.
290 \item \private Merkle Proofs of nullifier inclusion: Proofs that each voter nullifier is included in the census.
291 \item \private Merkle Proofs of results update: Proofs that the process results have been correctly updated.
292 \item \private Merkle Tree Update Witnesses: Necessary data (e.g., Merkle paths) to update the Merkle tree from Root1 to Root2.
293 \item \private Process Parameters: Retrieved from Root1 within the circuit.
294 \end{itemize}
295 \textbf{Constraints} \\ \vspace{-0.4cm}
296 \begin{itemize}
297 \item \textbf{Immutable process parameters}: Ensure that critical process parameters (such as `censusRoot` or `processId`) retrieved from `Root1` remain consistent and are not altered in the transition.
298 \item \textbf{Vote validity}: Validate that each vote proof is correct.
299 \item \textbf{Voter eligibility}: Confirm that each voter is included in the census by verifying Merkle proofs of inclusion against the `censusRoot` retrieved from `Root1`.
300 \item \textbf{Nullifier non-existence}: Ensure that the nullifier for each vote does not exist in the current state (`Root1`), preventing double voting.
301 \item \textbf{Nullifier addition}: Correctly add each new nullifier to the state, resulting in `Root2`, updating the Merkle tree accordingly.
302 \item \textbf{Results update}: Ensure that the voting results are accurately updated by adding the new votes to the previous results retrieved from `Root1`, so that `results2 = results1 + votes`.
303 \item \textbf{Blob data integrity}: Confirm that the data used in the circuit (votes, nullifiers) corresponds to the `blobCommitment` provided as a public input, ensuring that the votes processed are exactly those published in the data blob.
304 \item \textbf{State transition validity}: Ensure that the new state root (`Root2`) is correctly computed from `Root1` by applying the validated votes and updates to the Merkle tree.
305 \end{itemize}
306 \vspace{-0.3cm}
307 \end{spacing}
308 \end{minipage}
309\end{mdframed}
310
311\martai{STATE TRANSITION CIRCUIT: a potential problem is that a sequencer may know if one of their votes has been overwritten, for this reason, sequencers reencrypt a certain amount of ballots every time (already existing ballots I mean). So, the circuit should include the reencryptions: both for existing ballots and also for the new votes, which should be reencrypted (for receipt-freeness).}
312
313\begin{landscape}
314%\thispagestyle{empty} % removes the page number
315\begin{figure}[H]
316 \centerline{\includegraphics[width=560pt,draft=false]{\figs/circuit-state-transition-v2}}
317 \caption{State transition circuit. All public values are framed in green.}
318 \label{fig:circuit-state-transition-v2}
319\end{figure}
320\end{landscape}
321
322\subsubsection{Results circuit}
323\label{sec:vocdoni-protocol:circuits:results}
324
325TBA.
326
327\subsection{Protocol flow}
328\label{sec:vocdoni-protocol:flow}
329
330\martai{Rename steps: 1. voting setup, 2. encryption key generation, 3. votes collection, 4. results validation.}
331
332In Figure~\ref{fig:protocol-flow} we describe the protocol flow.
333
334\begin{figure}%[H]
335 \centerline{\includegraphics[width=370pt,draft=false]{\figs/protocol-flow}}
336 \caption{Vocdoni voting process overview.}
337 \label{fig:protocol-flow}
338\end{figure}
339
340\subsubsection{Prior to voting (only once)}
341\label{sec:vocdoni-protocol:prior-steps}
342
343%\martai{Remove the first step, we assume contracts are already deployed or at least, the logic is available.}
344%
345%This is done only once. Then every voting will start its process from step in Section~\ref{sec:vocdoni-protocol:start}.
346%
347%Vocdoni:
348%\begin{enumerate}
349% \item Deployment of the 3 smart contracts.
350% \item Sequencers registry starts (it doesn't end).
351%\end{enumerate}
352
353\sequencers -- this process is always open:
354\begin{enumerate}
355 \item Register this and that way.
356 \item Public keys? Sequencers must also publish how they can be reached (either when they register or when they contribute to the DKG). They can use a URI: Uniform Resource Identifier.
357 \item PROVIDE COLLATERAL. What happens to the collateral? If done only once, then you lose it? Do you need to send a new tx with more collateral?
358 \item Send transaction to Sequencer registry smart contract (pay for tx fee).
359\end{enumerate}
360
361\subsubsection{Start of the voting process}
362\label{sec:vocdoni-protocol:start}
363
364\organizer
365\begin{enumerate}
366 \item Prepares the census data \censusdata and generates census Merkle tree $\hlget{\censusTree}$.
367 \item Generates the census commitment: $\censusroot = \hlget{\censusTree}.\hlget{\MTRoot}()$.
368 \martai{Additionally, after this step, the organizer should make a Merkle proof available to all eligible voters.}
369 \item Set voting details: {\color{blue}duration, options, type, etc. + CENSUS MT ROOT.}
370 \item Compute the process identifier \processid, which is a unique 32-byte number derived from the organizer's Ethereum address and nonce, and the chain ID.
371 %that uniquely identifies a specific voting process. This variable encapsulates essential information about the voting, such as the rules and constraints for ballots and the unique identifier of the \davinci blockchain instance.
372 \item Set security factors for DKG: a timeout for the DKG ceremony + minimum number of sequencers.
373 \item Send transaction to the Ethereum process management smart contract with all data. Note this transaction has a cost (Eth tx fees) that needs to be covered by the organizer. The transaction includes the fields:
374 \[\processid, etc.\]
375\end{enumerate}
376
377\subsubsection{Encryption key generation process} %Voting key generation
378\label{sec:vocdoni-protocol:dkg}
379
380\sequencers
381\begin{enumerate}
382 \item Fetch the \processid, \ballotmode, and \censusroot from the process management smart contract.
383 \item Make contributions to DKG ceremony before the timeout set by the organizer.
384\end{enumerate}
385
386\noi After the timeout, all contributions to DKG are done. The smart contract checks if minimum number of sequencers is reached. If so, the \epk ``becomes available".
387
388\martai{The idea here is that some sequencer makes EPK available (a.k.a. sends a transaction). Alternatively, generate a SNARK proving the EPK has been generated correctly and the SC verifies it. It is not clear to me if it is sent to SR or PM. }
389
390\subsubsection{Voting process}
391\label{sec:vocdoni-protocol:voting}
392\voter
393
394\begin{itemize}
395 \item Choose any of the available sequencers from the sequencer registry smart contract.
396 \item Fetch from the census registry their membership proof $\censusproof$ to prove eligibility.
397 \item Collect %the process data
398 the $\epk$, $\ballotmode$, $\processid$ from the process management smart contract.
399 \item Select their voting choice $\ballot$ according to the election rules specified by the $\ballotmode$ parameter. \item Sample a fresh random $k \in \F$ and encrypt the selected choice using the public key $\epk$:
400 \begin{equation}
401 \label{eq-ciphertext}
402 (C_1, C_2) = \hlget{\Enc}_{\epk}(\ballot; k).
403 \end{equation}
404 \item Use the user's own Ethereum address $\address$ and the previous $k$ to compute the $\voteid$:
405 \begin{equation}
406 \label{eq-voteid}
407 \voteid = \hlget{\Multimimc}(\processid \conc \address \conc k).
408 \end{equation}
409 \item Generate ZK-SNARK of satisfiability of circuit from Fig.~\ref{fig:circuit-voter} with the proof system from Section~\ref{sec:cryptographic-primitives:zkp} to prove that Eqs.~\labelcref{eq-ciphertext,eq-voteid} are correctly computed, and that $\ballot$ satisfies ballot protocol rules according to $\ballotmode$.
410 \[ \voteproof = \text{Prove(), Circuit(), PublicInputs}.\]
411 \item Sign $\voteid$ using the user's secret key $\sk$ to authenticates the vote and ensure that was cast by a legitimate voter:
412 \[ \signature = \hlget{\SSign}_{\sk}(\voteid).\]
413 \item Send the following data, which includes the encrypted vote, census membership proof, signature\footnote{Note that the address is not send because it can be recomputed from the signature.} and vote proof, to the selected sequencer:
414 \[ \vote = [ \processid, \voteid, \encryptedballot, \censuspf, \voteproof, \signature ]. \]
415\end{itemize}
416
417\noi \sequencers
418
419\begin{itemize}
420 \item Fetch current state: retrieve the current valid process state root from the process management smart contract and the associated data from Ethereum blobs.
421 \item $\censusroot = \hlget{\censusTree}.\hlget{\MTRoot}()$.
422 \item $\stateroot = \hlget{\stateTree}.\hlget{\MTRoot}()$.
423 \item Generate a SK-SNARK proof of state transition proving:
424 \begin{itemize}
425 \item the validity of the ZK-SNARK proof provided by the voter,
426 \item the correct accumulation of votes from users, adding them to the process state,
427 \item the correct sum of the new encrypted votes using the homomorphic properties of ElGamal,
428 \item the new votes are from eligible users by checking the census Merkle proofs,
429 \item the new voters have not already voted by checking their nullifiers, or it is a correct vote overwrite,
430 \item the data blob hash matches the data used to verify the transition.
431 \end{itemize}
432 \item Submit updated state: send the new state root to the smart contract and store the updated data in Ethereum blobs.
433\end{itemize}
434
435Sequencers keep accumulating votes and create state transition until the finalization of the process.
436
437\martai{I understand this finalization is a deadline set by the organizer.}
438
439SC:
440
441\begin{itemize}
442 \item Upon receiving a sequencer's transaction, the SC verifies the zk-SNARK proof provided byt he sequencer.
443 \item Ensure the origin root corresponds to the current stored state root.
444 \item Confirm that the blob hash matches the one stored in Ethereum.
445\end{itemize}
446
447\subsubsection{Results validation}
448\label{sec:vocdoni-protocol:validation}
449
450Once the voting is completed (I understand the timeout set by the organizer expires), the following things happen.
451
452\noi \sequencers
453
454\begin{itemize}
455 \item $t$ out of $n$ sequencers publish their shares corresponding to the EPK to the Ethereum smart contract.
456 \martai{specify which SC.}
457 \item When the threshold of shares is reached, the results can be decrypted by anyone.
458 \martai{mention that the SC computes the corresponding ESK, or that can be computed by anyone off-chain, since all info is public.}
459 \item Sequencers receive reward for their correct participants depending on the number of sequenced votes.
460 \martai{slash if they don't provide the right share? reward only dependent of sequenced votes? any relation to their participation in the computation of either EPK or ESK?}
461\end{itemize}
462
463This way:
464
465\begin{itemize}
466 \item After the voting period ends and the results are decrypted, anyone can verify the correctness of the final result.
467 \martai{explain how.}
468 \item Use the zkSNARK state proof and publicly available data on-chain to ensure the integrity and correctness of the entire voting process.
469 \martai{elaborate on this.}
470\end{itemize}
471
472\subsubsection{Finalization of the voting process}
473\label{sec:vocdoni-protocol:finalization}