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 zero-knowledge 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
14\paragraph{Voter.} Voters are the participants that belong the census that cast their votes in the election.
15
16\subsection{Merkle trees}
17\label{sec:vocdoni-protocol:merkle-trees}
18
19Merkle trees are used to create a cryptographic representation of both the voter registry (census) and the voting process state.
20
21%\begin{itemize}
22% \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.
23% \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.
24%\end{itemize}}
25
26\subsubsection{Census Merkle tree}
27
28The census represents the list of eligible voters and their associated voting weights. It is implemented as a binary Merkle tree using an iden3 Sparse Merkle Tree (SMT) structure with a zkSNARK-friendly hashing function to ensure compatibility with zero-knowledge circuits. Each leaf in the tree corresponds to a unique voter address (e.g., Ethereum address), and stores the associated voting weight. This construction enables efficient Merkle proofs that allow voters to prove their eligibility and weight without revealing the full census dataset.
29
30The organizer is responsible for generating the census and computing its Merkle root, which is then committed on-chain. To minimize on-chain storage, the full census is distributed off-chain—e.g., via IPFS or a trusted HTTPS endpoint—allowing verifiers and sequencers to independently access the dataset and reconstruct Merkle proofs as needed.
31
32The protocol does not prescribe a specific method for constructing the census, but supports multiple approaches to accommodate various use cases:
33
34Private datasets. Organizations with internal lists of eligible voters (e.g., membership databases or CSV files) can directly convert them into the Merkle format. This allows voter registries to remain confidential, with only the root hash made public.
35
36Self-Sovereign Identity (SSI). Voter eligibility can also be derived from SSI systems, where users control their identities. The organizer collects and aggregates this data into the census tree, enabling participation without centralized identity management.
37
38Ethereum-based tokens. Token holdings—such as ERC-20 or NFT balances—can define voter eligibility using either of two approaches:
39
40Optimistic: A snapshot of token holders at a specific Ethereum block is used to build the census off-chain. The root is submitted to the smart contract, and a dispute period allows for fraud proofs (e.g., using Ethereum storage proofs) to challenge incorrect entries.
41
42Zero-knowledge: A zkSNARK circuit verifies that the census has been constructed correctly with respect to the on-chain token balances at a given block. The proof ensures balance correctness and total supply consistency.
43
44This flexible design allows the system to support a wide range of identity and eligibility models while maintaining transparency, verifiability, and scalability.
45
46
47\martai{There is a whole section about the Census Merkle tree in the whitepaper -- CHECK!!}
48
49\martai{It could actually be another type of data structure. We only need to be able to get a commitment and a membership proof that can be proven in-circuit. Mention it in some way.}
50
51\martai{One way to think about it: (weight, pk).}
52
53\subsubsection{State Merkle tree} Explain what it is and the structure. Below, the original text:\\
54
55\martai{Essentially, the first "addresses" or "leaves" are reserved to those items (like processId, censusRoot, etc.), and then the voters' addresses and nullifiers are used as paths to the leave where the encrypted ballot/commitment is stored.}
56
57The State tree contains some special addresses (indices) for storing some required data regarding the voting process:
58
59\begin{itemize}
60 \item Address \texttt{0x0}: it stores \processid, a unique identifier for the voting process.
61 \item Address \texttt{0x1}: it stores \censusroot and \type, which contains the necessary information to validate vote proofs.
62 \martai{they type was a field in case the organization was using a different structure for the census than a MT.}
63 \item Address \texttt{0x2}: it stores \ballotmode, which encodes rules for validating votes, such as the maximum number of selectable options.
64 \item Address \texttt{0x3}: it stores the \epk, which is the public key used to encrypt the votes.
65 \martai{Ideally, EPK is computed before the organization sets the tree, but I am not sure how practical this is.}
66 \item Address \texttt{0x4}: it stores the \addaccumulator. That is, the aggregated encrypted voting results that need to be added.
67 \item Address \texttt{0x5}: it stores the \substractaccumulator. That is, it stores the aggregated encrypted voting results that need to be subtracted.
68 \item Any address: vote \addresses: are stored within the State tree pointing to a voter's identity commitment. Each commitment is a 32-byte hash derived from the voter's unique information and a secret.
69 \martai{(address, commitment).}
70 \item Any address: vote \nullifiers: are stored within the State tree to prevent double voting and to allow vote overwrite. Each nullifier is a 32-byte hash derived from the voter's commitment and a secret.
71 \martai{Nullifiers and addresses are used as indexes (i.e. path to the leaf that stores encrypted ballots/commitments).}
72\end{itemize}
73
74\martai{Maybe the voteID will be included in the tree at some point.}
75
76\begin{figure}[h]
77 \centerline{\includegraphics[width=400pt,draft=false]{\figs/mt-state-mermaid}}
78 \caption{Structure of the state Merkle tree (FIGURE SHOULD BE POLISHED).}
79 \label{fig:mt-state}
80\end{figure}
81
82\textbf{The Initial State}: The voting process begins with an initial state where the Merkle Tree Root is established and published on the Process Management smart contract. Predefined parameters are included, but the results are initialized to zero, and no nullifiers are present. The Process Organizer transaction, contains the initial root and the necessary Merkle proofs. These proofs verify that the initial parameters are correct according to the voting process information and that no additional information is stored. Since the `ProcessId` of the initial state is a unique identifier, there won't be duplicate roots for different processes.
83
84
85\subsection{Smart contracts}
86\label{sec:vocdoni-protocol:smart-contracts}
87
88Old text:
89 \begin{enumerate}
90 \item \textbf{Ethereum}. An Ethereum compatible network is used as the source of truth for the voting system. By leveraging an EVM blockchain, the process management ensures that all transitions are immutable and verifiable by all participants. To this end, we implement several smart contracts.
91 \begin{itemize}
92 \item \textbf{Process management}: Responsible for the lifecycle management of voting processes. It includes the initiation, monitoring, execution, and closure of voting events.
93 \item \textbf{Results verification}: For each voting process, this smart contract maintains the integrity of the cast votes and process lifecycle. It verifies that each state transition committed by a ZK sequencer adheres to the predefined rules.
94 \item \textbf{Sequencer registry}: This smart contract keeps track of the existing available sequencers, stores the collateral to ensure good behavior, and it's used to coordinate the distributed key generation when a new Process is created.
95 \end{itemize}
96 \item \textbf{Sequencer}. 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.
97 \item \textbf{Frontend user interface}. The user interface serves as the primary interaction layer for voters and organizers. It provides tools and functionalities needed by organizers to set up, manage, and oversee elections. This interface simplifies the complexities involved in managing a decentralized vote.
98 \item \textbf{Data availability}. For each voting process, the system needs to keep track of the current State Merkle Tree, which contains all information of such processes. A public data availability layer, ensures that all state transitions are available and verifiable and allows the participation of multiple sequencers within the same voting process.
99 \end{enumerate}
100
101\paragraph{Process management.} This smart contract is responsible for the life-cycle management of voting processes. It includes the initiation, monitoring, execution, and closure of voting events.
102
103\paragraph{Sequencer registry.} 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.
104
105\paragraph{Results verification.} This smart contract 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.\\
106
107\martai{This is wrong. Explanation of SR and RV smart contracts are mixed, I don't know what I was thinking when I wrote it. We should also include a sentence about the management of sequencers.}
108
109
110\begin{figure}[h]
111 \centerline{\includegraphics[width=400pt,draft=false]{\figs/circuit-inputs}}
112 \caption{Caption.}
113 \label{fig:circuit-inputs}
114\end{figure}
115
116
117\subsubsection{Votes [I don't think this is the right place]}
118
119In the \davinci system, a vote comprises several components that work together to ensure secure, private, and verifiable voting. These components are:
120\begin{align*}
121 \vote = [ \processid, \voteid, \encryptedballot, \censuspf, \zkproof, \signature ].
122\end{align*}
123\martai{In the code, the struct is just: address, commitment, nullifier and ballot. Check!}
124
125\martai{Actually, the address could be recomputed by the sequencer (add it as a footnote).}
126
127\martai{In the code, they call it vote, verifierVote. Alternative: envelope.}
128
129Below, we detail each component and its role in the voting process:
130\begin{itemize}
131 \item \processid: the process identifier is a unique 32-byte number 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.
132 \martai{the identifier is computed from the organization address, the Eth nonce, chain ID (e.g. mainnet), formatejat in a certain way.}
133 %
134 \item \encryptedballot: it contains the voter's selections encoded according to the ballot protocol rules. To ensure privacy, the ballot is encrypted using an homomorphic encryption scheme, which allows homomorphic combination of encrypted votes. More specifically, given the voter's choice $m$ and a random element $k$, the vote is encoded as follows:
135 \[ \encryptedballot = \hlget{\Enc}(m; k). \]
136 %
137 \item \voteid: vote identifier, tied to balbla, computed this way.
138 \[ \voteid = .\]
139 %
140 \item \censuspf: the census proof serves as the voter's identity verification mechanism, ensuring that only eligible voters can participate. Depending on the process configuration, the voter provides either a Merkle tree-based proof showing inclusion in the census true, or a credential issued by a trusted third party (e.g. from a credential service provider).
141 %
142 \item \zkproof: the voter generates a ZK proof to prove the correctness of the ballot and encryption process:
143 \[ \zkproof = \text{Prove(), Circuit()}. \]
144 This proof proves the correct computation of the vote encryption, the nullifier, the commitment, and the compliance with the ballot protocol rules.
145 %
146 \item \signature: the signature authenticates the vote and ensure that was cast by a legitimate voter. The voter signs necessary components using their private key, depending on the census configuration (e.g., ECDSA, EdDSA, RSA).
147 \[ \signature = \text{Sign(xxx)}. \]
148\end{itemize}
149
150\subsection{Circuits}
151\label{sec:vocdoni-protocol:circuits}
152
153\martai{The idea of this section is to describe the circuits. Then, in Section~\ref{sec:analysis:implementation} we give the details such as of the number of constants, framework used, etc. I haven't done this split yet.}
154
155\martai{\textbf{About the circuits: in practice (and for optimization), all public inputs $PI$ are private, and we produce a single public input $h = Hash(PI)$. Then, the verifier checks that $Hash(PI) = h$ and verifies the proof only against $h$.} For this, we use the MiMC-7 hash function. Since this is an implementation detail, I propose to write this as a footnote or as an introduction to this section.}
156
157\textit{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.}
158
159\martai{I don't follow the above paragraph.}
160
161\martai{It is called Ballot Mode because we define some modes (like quadratic, etc.) that can be chosen by the organizer. Essentially, each of this modes has a special configuration, but in order to make it easier, the organizer only needs to choose which of the modes (configs) to apply.}
162
163\martai{It's convenient to name the proof associated to each circuit: a proof for this circuit is called [...].\\
164Answer: 1. ballotProof, 2. voteVerifier, 3. aggregator, 4. stateTransition.}
165
166\begin{figure}[h]
167 \centerline{\includegraphics[width=350pt,draft=false]{\figs/circuits-flow}}
168 \caption{Circuits flow.}
169 \label{fig:circuits-flow}
170\end{figure}
171
172\pagebreak
173
174\subsubsection{Voter circuit}
175
176Figure~\ref{fig:circuit-voter} -- BN254.\\
177
178\noi Generated by the user when casting a vote, this circuit proves that the encrypted ballot is valid (i.e. follows the protocol rules) and that the vote identifier is correctly computed.
179
180\begin{spacing}{1.25}
181 \vspace{0.3cm}
182 \noi \textbf{Public inputs}
183 \begin{itemize}
184 \item $\public$ $\processid$: voting process identifier.
185 \item $\public$ $\ballotmode$: ballot protocol configuration.S
186 \item $\public$ $\epk$ ($EPK$): encryption public key.
187 \item $\public$ $\address$: voter's address.
188 \item $\public$ $\weight$: voter's weight.
189 \item $\public$ $(C_1, C_2)$: encrypted ballot.
190 \item $\public$ $\voteid$: vote's unique identifier.
191 \end{itemize}
192 \textbf{Private inputs}
193 \begin{itemize}
194 \item \private $\ballot$: plaintext voter's voting choice.
195 \item \private $k$: random scalar.
196 \end{itemize}
197 \textbf{Constraints}
198 \begin{itemize}
199 \item \emph{Vote encryption}. Correct encryption of the ballot: $(C_1, C_2) = \hlget{\Enc}_{\epk}(\ballot; k).$
200 \item \emph{Protocol rules compliance}. The ballot meets the protocol rules (number of valid choices, etc.): $... + \weight$.
201 \item \emph{Vote identifier}. The vote's identifier is correctly computed: $\voteid = \text{Hash} (\address \conc \processid \conc k)$.
202 \end{itemize}
203 \vspace{-0.3cm}
204\end{spacing}
205
206\begin{figure}[H]
207 \centerline{\includegraphics[width=450pt,draft=false]{\figs/circuit-voter}}
208 \caption{Voter circuit. All public values are framed in green.}
209 \label{fig:circuit-voter}
210\end{figure}
211
212\newpage
213\subsubsection{Authentication circuit}
214\label{sec:vocdoni-protocol:circuits:authentication}
215
216Figure~\ref{fig:circuit-authentication} -- BLS12-377.\\
217
218\noi Generated by the sequencer, this circuit transforms the vote proof to the BLS12-377 curve for native recursion and validates the user's eligibility in the census, as well as their signature.
219
220\begin{spacing}{1.25}
221 \vspace{0.3cm}
222 \noi \textbf{Public inputs}
223 \begin{itemize}
224 \item \public $\processid$: process identifier.
225 \item \public $\ballotmode$: ballot protocol configuration.
226 \item \public $\epk$ ($EPK$): encryption public key.
227 \item \public $(C_1, C_2)$: encrypted ballot.
228 \item \public $\voteid$: voter's identifier.
229 \item \public $\censusroot$: census Merkle tree root.
230 \item \public $\pk$: voter's public key.
231 \end{itemize}
232 \textbf{Private inputs}
233 \begin{itemize}
234 \item \private $\voteproof$: voter's proof.
235 \item \private $\weight$: voter's weight.
236 \item \private $\censuspf$: census membership proof.
237 \item \private $\signature$: voter's signature.
238 \end{itemize}
239 \textbf{Constraints}
240 \begin{itemize}
241 \item \emph{Voter's proof verification.} The vote zkProof is valid for the inputs provided: $P.Verify().$
242 \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.
243 \item \emph{Authentication + non-malleability.} The signature of the vote's identifier is valid for the given public key.
244 \end{itemize}
245 \vspace{-0.3cm}
246\end{spacing}
247
248\begin{figure}[H]
249 \centerline{\includegraphics[width=450pt,draft=false]{\figs/circuit-authentication}}
250 \caption{Authentication circuit. All public values are framed in green.}
251 \label{fig:circuit-authentication}
252\end{figure}
253
254\newpage
255\subsubsection{Aggregation circuit}
256
257Figure~\ref{fig:circuit-aggregate} -- BW6-761.\\
258
259\noi This circuit accumulates multiple authenticated votes into a single proof. It also verifies that all accumulated votes belong to the same voting process.
260
261\martai{Actually, the circuit only takes voteProof and the hash(PI). Circuit 4 is the one that verifies shared PI.}
262
263\martai{The batch, number of verification proofs, is a fixed parameter (currently set to 60). If it includes less proofs than the max size of the batch, the sequencer adds dummy proofs to the circuit.}
264
265\begin{spacing}{1.25}
266 \vspace{0.3cm}
267 \noi \textbf{Public inputs}
268 \begin{itemize}
269 \item \public $(C_1, C_2)_i$: list of voters' encrypted ballots.
270 \item \public $\voteid_i$: set of vote's identifiers.
271 \item \public $\pk_i$: list of voters' public keys.
272 \item \public $\processid$: process identifier.
273 \item \public $\ballotmode$: ballot protocol configuration.
274 \item \public $EPK$: encryption public key.
275 \item \public $\censusroot$: census Merkle tree root.
276 \end{itemize}
277 \textbf{Private inputs}
278 \begin{itemize}
279 \item \private $\authenticationproof_i$: set of authentication proofs.
280 \end{itemize}
281 \textbf{Constraints} \\ \vspace{-0.4cm}
282 \begin{itemize}
283 \item \emph{Votes aggregation.} The accumulated authentication zkProofs are valid (for the given inputs).
284 \item \emph{Shared public inputs.} The public inputs \processid, \ballotmode, \epk, and \censusroot are the same for all proofs.
285 \end{itemize}
286 \vspace{-0.3cm}
287\end{spacing}
288
289\begin{figure}[h]
290 \centerline{\includegraphics[width=450pt,draft=false]{\figs/circuit-aggregate}}
291 \caption{Aggregation circuit. All public values are framed in green.}
292 \label{fig:circuit-aggregate}
293\end{figure}
294
295\newpage
296\subsubsection{State transition circuit} -- BN254. \\
297
298\noi Given the aggregated votes proof, this circuit verifies the correct inclusion of all new votes into the process's state Merkle tree. It generates the final state transition proof that will be validated by the Ethereum smart contract. // This circuit verifies that a batch of votes correctly updates the global Merkle state root, including ballots, commitments, and results. It also verifies that the state transition corresponds to a valid proof aggregation and that overwritten votes are properly accounted for.
299
300\paragraph{Assertions.}
301
302\begin{itemize}
303 \item \emph{Aggregation verification}: The agreggated zkProof is valid.
304 \item \emph{Transition verification}: The MerkleTree transition witness proves every change between Root1 and Root2.
305 \item \emph{Public inputs integrity}: ProcessID, BallotMode, CensusRoot, EncryptionKey remain unchanged.
306 \item \emph{Votes counting}: Ballots are correctly counted as new or overwrites, and added to results accumulators.
307\end{itemize}
308
309When 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.
310
311For 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.
312
313This 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.
314
315\paragraph{Maintaining the Chain.}
316
317The 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.
318
319\begin{itemize}
320 \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.
321 \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.
322 \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.
323 \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.
324\end{itemize}
325
326\paragraph{State Transition}
327
328To 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.
329
330\begin{figure}[H]
331 \centering
332 \fbox{
333 \includegraphics[scale = 0.12, draft = false]{\figs/state-transition.png}}
334\end{figure}
335
336\begin{figure}[H]
337 \centering
338 \fbox{
339 \includegraphics[scale = 0.3, draft = false]{\figs/circuit-inputs.png}}
340\end{figure}
341
342\begin{figure}[H]
343 \centerline{\includegraphics[width=400pt,draft=false]{\figs/circuit-state-transition}}
344 \caption{State transition circuit. All public values are framed in green.}
345 \label{fig:circuit-state-transition}
346\end{figure}
347
348\begin{mdframed}
349 \begin{minipage}[H]{1\textwidth}
350 \begin{spacing}{1.25}
351 \vspace{0.3cm}
352 \begin{center}{STATE TRANSITION CIRCUIT}\end{center}
353 \textbf{Public inputs}
354 \begin{itemize}
355 \item \public $root_{old}$: Merkle tree root before the state transition.
356 \item \public $root_{new}$: Meklre tree root after the state transition.
357 \item \public $blobCommitment$: the commitment to the data blob containing the new votes.
358 \end{itemize}
359 \item \textbf{Private inputs}
360 \begin{itemize}
361 \item \private Votes: The list of new votes being processed, including census proofs and authentication data.
362 \item \private Merkle Proofs of nullifier inclusion: Proofs that each voter nullifier is included in the census.
363 \item \private Merkle Proofs of results update: Proofs that the process results have been correctly updated.
364 \item \private Merkle Tree Update Witnesses: Necessary data (e.g., Merkle paths) to update the Merkle tree from Root1 to Root2.
365 \item \private Process Parameters: Retrieved from Root1 within the circuit.
366 \end{itemize}
367 \textbf{Constraints} \\ \vspace{-0.4cm}
368 \begin{itemize}
369 \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.
370 \item \textbf{Vote validity}: Validate that each vote proof is correct.
371 \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`.
372 \item \textbf{Nullifier non-existence}: Ensure that the nullifier for each vote does not exist in the current state (`Root1`), preventing double voting.
373 \item \textbf{Nullifier addition}: Correctly add each new nullifier to the state, resulting in `Root2`, updating the Merkle tree accordingly.
374 \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`.
375 \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.
376 \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.
377 \end{itemize}
378 \vspace{-0.3cm}
379 \end{spacing}
380 \end{minipage}
381\end{mdframed}
382
383\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).}
384
385\begin{figure}[H]
386 \centerline{\includegraphics[width=600pt,draft=false]{\figs/circuit-state-transition-v2}}
387 \caption{State transition circuit. All public values are framed in green.}
388 \label{fig:circuit-state-transition-v2}
389\end{figure}
390
391\subsection{Protocol flow}
392\label{sec:vocdoni-protocol:flow}
393
394In Figure~\ref{fig:protocol-flow} we describe the protocol flow.
395
396\martai{About the figure: layout should be fixed. In addition, the icons for the different parties are missing.}
397
398\begin{figure}[H]
399 \centerline{\includegraphics[width=400pt,draft=false]{\figs/protocol-flow}}
400 \caption{Vocdoni voting process overview.}
401 \label{fig:protocol-flow}
402\end{figure}
403
404\subsubsection{Prior to voting (only once)}
405\label{sec:vocdoni-protocol:prior-steps}
406
407\martai{Remove the first step, we assume contracts are already deployed or at least, the logic is available.}
408
409This is done only once. Then every voting will start its process from step in Section~\ref{sec:vocdoni-protocol:start}.
410
411Vocdoni:
412\begin{enumerate}
413 \item Deployment of the 3 smart contracts.
414 \item Sequencers registry starts (it doesn't end).
415\end{enumerate}
416
417Sequencers (nodes validadors) -- this process is always open:
418\begin{enumerate}
419 \item Register this and that way.
420 \item Public keys?
421 \martai{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.}
422 \item PROVIDE COLLATERAL.
423 \martai{What happens to the collateral? If done only once, then you lose it? Do you need to send a new tx with more collateral?}
424 \item Send transaction to Sequencer registry smart contract (pay for tx fee).
425\end{enumerate}
426
427\subsubsection{Start of the voting process}
428\label{sec:vocdoni-protocol:start}
429
430The organizer:
431\begin{enumerate}
432 \item Prepares the census data \texttt{census\_data}.
433 \item Generates the census commitment \texttt{MT\_census.root = Com(census\_data)}.
434 \martai{In general, make use (link) to the functions defined in Section~\ref{sec:cryptographic-primitives}. For example, here the \texttt{MT.root()}.}
435 \martai{Additionally, after this step, the organizer should make a Merkle proof available to all eligible voters.}
436 \item Set voting details: duration, options, type, etc. + CENSUS MT ROOT.
437 \item Also a timeout for the DKG ceremony + minimum number of sequencers.
438 \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.
439\end{enumerate}
440
441\subsubsection{Encryption key generation process} %Voting key generation
442\label{sec:vocdoni-protocol:dkg}
443
444The sequencer:
445\begin{enumerate}
446 \item Download all required data from the PM smart contract which includes the census MT root to handle the new vote.
447 \item Make contributions to DKG ceremony.
448\end{enumerate}
449
450After XXX time (set by the organizer in the PM contract?): all contributions to DKG are done.
451
452\martai{The organizer decides a minimum number of sequencers (security factor).}
453
454\begin{itemize}
455 \item EPK ``becomes available".
456 \martai{I understand EPK becomes available in the SR smart contract, and that key is sent to the PM contract?}
457 \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.}
458\end{itemize}
459
460\subsubsection{Voting process}
461\label{sec:vocdoni-protocol:voting}
462
463Voter:
464
465\begin{itemize}
466 \item Choose any of the available sequencers (from?? -- from the SR SC).
467 \item Fetch their census \textbf{Merkle proof} to prove eligibility (from the census registry).
468 \item Collect the process data $\epk$, $\ballotmode$, $\processid$ from the process management smart contract.
469 \item Sample a fresh random $k\in\F$ and use the $\epk$ to encrypt the voting choice:
470 \begin{equation}
471 \label{eq-ciphertext}
472 (C_1, C_2) = \hlget{\Enc}_{\epk}(\ballot; k).
473 \end{equation}
474 \martai{Actually, I would not write $(C_1, C_2)$ but rather \texttt{ciphertext}.}
475 \item Use the user's own Ethereum address $\address$ and the previous $k$ to compute the $\voteid$:
476 \begin{equation}
477 \label{eq-voteid}
478 \voteid = Hash(\address \conc \processid \conc k).
479 \end{equation}
480 \martai{Is this the right order?}
481 \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$. We call this proof \textbf{vote proof}.
482 \item Sign $\voteid$ using the user's secret key $\sk$:
483 \[ \signature = \hlget{\SSign}_{\sk}(\voteid).\]
484 \item Send the encrypted vote, Merkle proof, validity proof, and identity proof to the sequencer.
485 \martai{I understand Validity proof refers to ``voter circuit"? Merkle proof is for inclusion, right? And identity proof is for example a signature??}
486\end{itemize}
487
488Sequencer:
489
490\begin{itemize}
491 \item Fetch current state: retrieve the current valid process state root from the Etherem smart contract and the associated data from Ethereum blobs.
492 \martai{specify which SC.}
493 \item Generate a SK-SNARK proof of state transition proving:
494 \begin{itemize}
495 \item the validity of the ZK-SNARK proof provided by the voter,
496 \item the correct accumulation of votes from users, adding them to the process state,
497 \item the correct sum of the new encrypted votes using the homomorphic properties of ElGamal,
498 \item the new votes are from eligible users by checking the census Merkle proofs,
499 \item the new voters have not already voted by checking their nullifiers, or it is a correct vote overwrite,
500 \item the data blob hash matches the data used to verify the transition.
501 \end{itemize}
502 \item Submit updated state: send the new state root to the smart contract and store the updated data in Ethereum blobs.
503\end{itemize}
504
505Sequencers keep accumulating votes and create state transition until the finalization of the process.
506
507\martai{I understand this finalization is a deadline set by the organizer.}
508
509SC:
510
511\begin{itemize}
512 \item Upon receiving a sequencer's transaction, the SC verifies the zk-SNARK proof provided byt he sequencer.
513 \item Ensure the origin root corresponds to the current stored state root.
514 \item Confirm that the blob hash matches the one stored in Ethereum.
515\end{itemize}
516
517\subsubsection{Results validation}
518\label{sec:vocdoni-protocol:validation}
519
520Once the voting is completed (I understand the timeout set by the organizer expires), the following things happen.
521
522Sequencer:
523
524\begin{itemize}
525 \item $t$ out of $n$ sequencers publish their shares corresponding to the EPK to the Ethereum smart contract.
526 \martai{specify which SC.}
527 \item When the threshold of shares is reached, the results can be decrypted by anyone.
528 \martai{mention that the SC computes the corresponding ESK, or that can be computed by anyone off-chain, since all info is public.}
529 \item Sequencers receive reward for their correct participants depending on the number of sequenced votes.
530 \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?}
531\end{itemize}
532
533This way:
534
535\begin{itemize}
536 \item After the voting period ends and the results are decrypted, anyone can verify the correctness of the final result.
537 \martai{explain how.}
538 \item Use the zkSNARK state proof and publicly available data on-chain to ensure the integrity and correctness of the entire voting process.
539 \martai{elaborate on this.}
540\end{itemize}
541
542\subsubsection{Finalization of the voting process}
543\label{sec:vocdoni-protocol:finalization}