arnaucube
arnaucube/davinci-paperPublic Self-hosted repository
davinci-paper/v2/sections/vocdoni-protocol.tex
v2/sections/vocdoni-protocol.texRaw
  1% !TeX root = ../build/main.tex
  2
  3\martai{Is the process called voting? Election, poll?}
  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{Components}
 17\label{sec:vocdoni-protocol:components}
 18
 19\subsubsection{Merkle trees} 
 20
 21\textit{Old text: Merkle trees are employed to create a cryptographic representation of both the voter registry (census) and the voting process state:
 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\paragraph{Census Merkle tree.} Explain what it is. \\
 28
 29\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.}
 30
 31\martai{One way to think about it: (weight, pk).}
 32
 33\paragraph{State Merkle tree.} Explain what it is and the structure. Below, the original text:\\
 34
 35\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.}
 36
 37The State tree contains some special addresses (indices) for storing some required data regarding the voting process:
 38
 39\begin{itemize}
 40	\item Address \texttt{0x0}: it stores \processid, a unique identifier for the voting process.
 41	\item Address \texttt{0x1}: it stores \censusroot and \type, which contains the necessary information to validate vote proofs.
 42	\martai{they type was a field in case the organization was using a different structure for the census than a MT.}
 43	\item Address \texttt{0x2}: it stores \ballotmode, which encodes rules for validating votes, such as the maximum number of selectable options.
 44	\item Address \texttt{0x3}: it stores the \epk, which is the public key used to encrypt the votes.
 45	\martai{Ideally, EPK is computed before the organization sets the tree, but I am not sure how practical this is.}
 46	\item Address \texttt{0x4}: it stores the \addaccumulator. That is, the aggregated encrypted voting results that need to be added.
 47	\item Address \texttt{0x5}: it stores the \substractaccumulator. That is, it stores the aggregated encrypted voting results that need to be subtracted.
 48	\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.
 49	\martai{(address, commitment).}
 50	\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.
 51	\martai{Nullifiers and addresses are used as indexes (i.e. path to the leaf that stores encrypted ballots/commitments).}
 52\end{itemize}
 53
 54\martai{Maybe the voteID will be included in the tree at some point.}
 55
 56\begin{figure}[h]
 57sd	\centerline{\includegraphics[width=400pt,draft=false]{\figs/mt-state}}
 58	\caption{Structure of the state Merkle tree (FIGURE SHOULD BE POLISHED).}
 59	\label{fig:mt-state}
 60\end{figure}
 61
 62\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.
 63
 64
 65\subsubsection{Smart contracts}
 66
 67\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.
 68
 69\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.
 70
 71\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.\\
 72
 73\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.}
 74
 75
 76\begin{figure}[h]
 77	\centerline{\includegraphics[width=400pt,draft=false]{\figs/circuit-inputs}}
 78	\caption{Caption.}
 79	\label{fig:circuit-inputs}
 80\end{figure}
 81
 82
 83\subsubsection{Votes [I don't think this is the right place]}
 84
 85In the \davinci system, a vote comprises several components that work together to ensure secure, private, and verifiable voting. These components are:
 86\begin{align*}
 87		\vote = [	\processid, \censuspf, \commitment, \nullifier,	
 88				 	\encryptedballot, \zkproof, \signature ].
 89\end{align*}
 90\martai{In the code, the struct is just: address, commitment, nullifier and ballot. Check!}
 91
 92\martai{Actually, the address could be recomputed by the sequencer (add it as a footnote).}
 93
 94\martai{In the code, they call it vote, verifierVote. Alternative: envelope.}
 95
 96Below, we detail each component and its role in the voting process:
 97\begin{itemize}
 98	\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.
 99	\martai{the identifier is computed from the organization address, the Eth nonce, chain ID (e.g. mainnet), formatejat in a certain way.}
100	%
101	\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).
102	%
103	\item \commitment: the identity commitment is used to prevent a voter from registering multiple nullifiers and avoid collisions if different voters choose the same secret. The commitment is computed the following way:
104	\[ \commitment = \hlget{\Hash}(\address \conc \processid \conc s)\]
105	\martai{Link Hash function to function in Section\ref{sec:cryptographic-primitives}.}
106	{\it Old text:
107	\begin{itemize}
108		\item Stored in state Merkle tree (SMT): indexed by the voter's address.
109		\item Prevents multiple registrations: each address can have only one commitment, ensuring a voter cannot register multiple secrets.
110		\item Collision resistance: including the address in $\commitment$ ensures that commitments are unique even if voters choose the same secret $s$.
111	\end{itemize}
112	
113	The secret $s$ can be implemented from different ways or a combination of them, such as:
114	
115	\begin{itemize}
116		\item A secure enough password introduced by the user.
117		\item A signature of a specific text.
118		\item A random input that the user must store to allow potential vote overwrite.\\
119	\end{itemize}}
120	%
121	\item \nullifier: the nullifier is a 32-byte hash used to prevent double voting. It is computed the following way:
122	\[\nullifier = \hlget{\Hash}(\commitment || s) \]
123	\martai{Link Hash function to function in Section\ref{sec:cryptographic-primitives}.}
124	That is, it ensures that each voter can either cast only one vote or overwrite their previous vote. By means of nullifiers, voters can submit a new vote with the same nullifier to replace their previous vote. Moreover, nullifiers provide users' anonymity, since nullifiers cannot be linked back to the voter's identity without knowledge of the secret $s$.
125	%
126	\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$, the vote is encoded as follows:
127	\[ \encryptedballot = \hlget{\Enc}(m). \]
128	%
129	\item \zkproof: the voter generates a ZK proof to prove the correctness of the ballot and encryption process:
130	\[ \zkproof = \text{Prove(), Circuit()}. \]
131	This proof proves the correct computation of the vote encryption, the nullifier, the commitment, and the compliance with the ballot protocol rules.
132	%
133	\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).	
134	\[ \signature = \text{Sign(xxx)}. \]
135\end{itemize}
136
137\subsection{Circuits}
138\label{sec:vocdoni-protocol:circuits}
139
140\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.}
141
142\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.\\ \vspace{0.2cm}
143	
144In the case of the voter circuit (circuit~1), the hash $h$ is called the \texttt{voteID}, and it allows to voter to trace their vote (it's propagated through the circuits from the sequencer). Since this is an implementation detail but it is used for traceability, I propose to write this as a footnote or as an introduction to this section.}
145
146\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.}
147
148\martai{I don't follow the above paragraph.}
149
150\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.}
151
152\martai{It's convenient to name the proof associated to each circuit: a proof for this circuit is called [...].\\
153Answer: 1. ballotProof, 2. voteVerifier, 3. aggregator, 4. stateTransition.}
154
155\subsubsection{Voter circuit} 
156
157Figure~\ref{fig:circuit-voter} -- BN254.\\
158
159\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 nullifier and commitment are correctly generated.
160
161\begin{figure}[H]
162	\centerline{\includegraphics[width=450pt,draft=false]{\figs/circuit-voter}}
163	\caption{Voter circuit. All public values are framed in green.}
164	\label{fig:circuit-voter}
165\end{figure}
166
167\begin{mdframed}
168	\begin{minipage}[H]{1\textwidth}
169		\begin{spacing}{1.25}
170			\vspace{0.3cm}
171			\begin{center}{VOTER CIRCUIT}\end{center}
172			\textbf{Public inputs}
173				\begin{itemize}
174					\item $\public$ $\processid$: voting process identifier. 
175					\item $\public$ $\ballotmode$: ballot protocol configuration.
176					\item $\public$ $\epk$ ($EPK$): encryption public key.
177					\item $\public$ $\weight$: voter's weight.
178					\item $\public$ $C$: commitment.
179					\item $\public$ $N$: nullifier.
180					\item $\public$ $(C_1, C_2)$: encrypted ballot. 
181				\end{itemize}
182			\textbf{Private inputs}
183				\begin{itemize}								
184					\item \private $\address$: voter's address.
185					\item \private $\ballot$: plaintext voter's voting choice.
186					\item \private $s$: blinder factor (secret).
187					\item \private $k$: random scalar.
188				\end{itemize}
189			\textbf{Constraints} \\ \vspace{-0.4cm}		
190				
191				\emph{Vote encryption}. 
192				\begin{itemize}								
193					\item Correct encryption of the ballot: $(C_1, C_2) = \hlget{\Enc}_{\epk}(\ballot, k).$
194				\end{itemize}
195				\emph{Rules compliance}. 
196				\begin{itemize}								
197					\item The ballot meets the protocol rules (number of valid choices, etc.): $... + \weight$.
198				\end{itemize}
199				\emph{Vote commitment + nullification}. 
200				\begin{itemize}								
201					\item The commitment is correctly computed: $C = \text{Hash} (\address \conc \processid \conc s)$.
202					\item The nullifier is correctly computed: $N = \text{Hash}(C \conc s)$.
203					\item The secret $s$ links the commitment and the nullifier and the voter has knowledge of such $s$.
204				\end{itemize}
205				\vspace{-0.3cm}
206		\end{spacing}
207	\end{minipage}
208\end{mdframed}
209
210\newpage
211\subsubsection{Authentication circuit}
212
213Figure~\ref{fig:circuit-authentication} -- BLS12-377.\\
214
215\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.
216
217\martai{Hash of public inputs is in the wrong place. Well, in practice, it will be placed before the verification of the proof, but if we keep the hash of the PI as an implementation details, then it is in the right place. (I propose to keep it like this and in the footnote, mention the changes in each of the circuits).}
218
219\begin{figure}[H]
220	\centerline{\includegraphics[width=450pt,draft=false]{\figs/circuit-authentication}}
221	\caption{Authentication circuit. All public values are framed in green.}
222	\label{fig:circuit-authentication}
223\end{figure}
224
225\begin{mdframed}
226	\begin{minipage}[H]{1\textwidth}
227		\begin{spacing}{1.25}
228			\vspace{0.3cm}
229			\begin{center}{AUTHENTICATION CIRCUIT}\end{center}
230			\textbf{Public inputs}
231			\begin{itemize}
232				\item \public $\voteproof$: voter's proof.
233				\item \public $\processid$: process identifier.
234				\item \public $\ballotmode$: ballot protocol configuration.
235				\item \public $\epk$ ($EPK$): encryption public key.
236				\item \public $(C_1, C_2)$: encrypted ballot.
237				\item \public $C$: commitment.
238				\item \public $N$: nullifier.		
239				\item \public $\weight$: voter's weight.
240				\item \public $\censuspf$: census membership proof.
241				\item \public $\censusroot$: census Merkle tree root.
242				\item \public $pk$: voter's address.
243				\item \public $\signature$: voter's signature.
244			\end{itemize}
245				\textbf{Constraints} \\ \vspace{-0.4cm}		
246			
247			\emph{Voter's proof verification.} 
248			\begin{itemize}
249				\item The vote zkProof is valid for the inputs provided: $P.Verify().$
250			\end{itemize}
251			\emph{Authentication + non-malleability.}
252			\begin{itemize}
253				\item The signature of the inputs provided is valid for the public key of the voter.
254			\end{itemize} 
255			\emph{Census membership.}
256			\begin{itemize}								
257				\item The address derived from the user public key is part of the census, and verifies the census proof with the user weight provided.
258			\end{itemize}
259			\vspace{-0.3cm}
260		\end{spacing}
261	\end{minipage}
262\end{mdframed}
263
264\newpage
265\subsubsection{Aggregation circuit}
266
267Figure~\ref{fig:circuit-aggregate} -- BW6-761.\\
268
269\noi This circuit accumulates multiple authenticated votes into a single proof. It also verifies that all accumulated votes belong to the same voting process.
270
271\martai{This circuit has changed. Now, the aggregation circuit only include the authentication proof and the \texttt{voteI}D, and then circuit~4 does the "shared public inputs" check and the fact that voteID = Hash(...).}
272
273\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.}
274
275\begin{figure}[h]
276	\centerline{\includegraphics[width=450pt,draft=false]{\figs/circuit-aggregate}}
277	\caption{Aggregation circuit. All public values are framed in green.}
278	\label{fig:circuit-aggregate}
279\end{figure}
280
281\begin{mdframed}
282	\begin{minipage}[H]{1\textwidth}
283		\begin{spacing}{1.25}
284			\vspace{0.3cm}
285			\begin{center}{AGGREGATION CIRCUIT}\end{center}
286			\textbf{Public inputs}
287			\begin{itemize}
288				\item \public $\text{authenticationProof}$: set of authentication proofs.
289				\item \public $C_i$: set of commitments.
290				\item \public $N_i$: set of nullifiers.		
291				\item \public $\address_i$: list of voters' addresses.
292				\item \public $(C_1, C_2)$: list of voters' encrypted ballots.
293				\item \public $\weight_i$: Voters' weights.
294				\item \public $\processid$: process identifier.
295				\item \public $EPK$: encryption public key.
296				\item \public $\ballotmode$: ballot protocol configuration.
297				\item \public $\text{censusRoot}$: census Merkle tree root.
298			\end{itemize}
299			\textbf{Constraints} \\ \vspace{-0.4cm}		
300			
301			\emph{Votes aggregation.} 
302			\begin{itemize}
303				\item The accumulated zkProofs are valid.
304			\end{itemize}
305			\emph{Shared public inputs.}
306			\begin{itemize}
307				\item The ProcessId, CensusRoot, BallotMode and EPK is the same for all of them.
308			\end{itemize}
309			\vspace{-0.3cm}
310		\end{spacing}
311	\end{minipage}
312\end{mdframed}
313
314\newpage
315\subsubsection{State transition circuit} -- BN254. \\
316
317\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.
318
319\paragraph{Assertions.}
320
321\begin{itemize}
322	\item \emph{Aggregation verification}: The agreggated zkProof is valid.
323	\item \emph{Transition verification}: The MerkleTree transition witness proves every change between Root1 and Root2.
324	\item \emph{Public inputs integrity}: ProcessID, BallotMode, CensusRoot, EncryptionKey remain unchanged.
325	\item \emph{Votes counting}: Ballots are correctly counted as new or overwrites, and added to results accumulators.
326\end{itemize}
327
328\martai{The corresponding circuit figure is not done yet.}
329
330\noi \textit{Old original text, I think it will help here:}
331
332When 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.
333
334For 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.
335
336This 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.
337
338\paragraph{Maintaining the Chain.}
339
340The 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.
341
342\begin{itemize}
343	\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.
344	\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.
345	\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.
346	\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.
347\end{itemize}
348
349\paragraph{State Transition}
350
351To 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.
352
353\begin{figure}[H]
354	\centering
355	\fbox{
356		\includegraphics[scale = 0.12, draft = false]{\figs/state-transition.png}}
357\end{figure}
358
359\begin{figure}[H]
360	\centering
361	\fbox{
362		\includegraphics[scale = 0.3, draft = false]{\figs/circuit-inputs.png}}
363\end{figure}
364
365\begin{figure}[H]
366	\centerline{\includegraphics[width=400pt,draft=false]{\figs/circuit-state-transition}}
367	\caption{State transition circuit. All public values are framed in green.}
368	\label{fig:circuit-state-transition}
369\end{figure}
370
371\begin{mdframed}
372	\begin{minipage}[H]{1\textwidth}
373		\begin{spacing}{1.25}
374			\vspace{0.3cm}
375			\begin{center}{STATE TRANSITION CIRCUIT}\end{center}
376			\textbf{Public inputs}
377			\begin{itemize}
378				\item \public $root_{old}$: Merkle tree root before the state transition.
379				\item \public $root_{new}$: Meklre tree root after the state transition.
380				\item \public $blobCommitment$: the commitment to the data blob containing the new votes.
381				\end{itemize}
382				\item \textbf{Private inputs}
383				\begin{itemize}
384				\item \private Votes: The list of new votes being processed, including census proofs and authentication data.
385				\item \private Merkle Proofs of nullifier inclusion: Proofs that each voter nullifier is included in the census.
386				\item \private Merkle Proofs of results update: Proofs that the process results have been correctly updated.
387				\item \private Merkle Tree Update Witnesses: Necessary data (e.g., Merkle paths) to update the Merkle tree from Root1 to Root2.
388				\item \private Process Parameters: Retrieved from Root1 within the circuit.
389			\end{itemize}
390			\textbf{Constraints} \\ \vspace{-0.4cm}		
391			\begin{itemize}
392				\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.
393				\item \textbf{Vote validity}: Validate that each vote proof is correct.
394				\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`.
395				\item \textbf{Nullifier non-existence}: Ensure that the nullifier for each vote does not exist in the current state (`Root1`), preventing double voting.
396				\item \textbf{Nullifier addition}: Correctly add each new nullifier to the state, resulting in `Root2`, updating the Merkle tree accordingly.
397				\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`.
398				\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.
399				\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.
400			\end{itemize}
401			\vspace{-0.3cm}
402		\end{spacing}
403	\end{minipage}
404\end{mdframed}
405
406\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).}
407
408\subsection{Protocol flow}
409\label{sec:vocdoni-protocol:flow}
410
411In Figure~\ref{fig:protocol-flow} we describe the protocol flow.
412
413\martai{About the figure: layout should be fixed. In addition, the icons for the different parties are missing.}
414
415\begin{figure}[H]
416	\centerline{\includegraphics[width=400pt,draft=false]{\figs/protocol-flow}}
417	\caption{Vocdoni voting process overview.}
418	\label{fig:protocol-flow}
419\end{figure}
420
421\subsubsection{Prior to voting (only once)}
422\label{sec:vocdoni-protocol:prior-steps}
423
424\martai{Remove the first step, we assume contracts are already deployed or at least, the logic is available.}
425
426This is done only once. Then every voting will start its process from step in Section~\ref{sec:vocdoni-protocol:start}.
427
428Vocdoni:
429\begin{enumerate}
430	\item Deployment of the 3 smart contracts.
431	\item Sequencers registry starts (it doesn't end).
432\end{enumerate}
433
434Sequencers (nodes validadors) -- this process is always open:
435\begin{enumerate}
436	\item Register this and that way.
437	\item Public keys?
438	\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.}
439	\item PROVIDE COLLATERAL.
440	\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?}
441	\item Send transaction to Sequencer registry smart contract (pay for tx fee).
442\end{enumerate}
443
444\subsubsection{Start of the voting process}
445\label{sec:vocdoni-protocol:start}
446
447The organizer:
448\begin{enumerate}
449	\item Prepares the census data \texttt{census\_data}.
450	\item Generates the census commitment \texttt{MT\_census.root = Com(census\_data)}.
451	\martai{In general, make use (link) to the functions defined in Section~\ref{sec:cryptographic-primitives}. For example, here the \texttt{MT.root()}.}
452	\martai{Additionally, after this step, the organizer should make a Merkle proof available to all eligible voters.}
453	\item Set voting details: duration, options, type, etc. + CENSUS MT ROOT.
454	\item Also a timeout for the DKG ceremony + minimum number of sequencers.
455	\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.
456\end{enumerate}
457
458\subsubsection{Key generation process} %Voting key generation
459\label{sec:vocdoni-protocol:dkg}
460
461The sequencer:
462\begin{enumerate}
463	\item Download all required data from the PM smart contract which includes the census MT root to handle the new vote.
464	\item Make contributions to DKG ceremony.
465\end{enumerate}
466
467After XXX time (set by the organizer in the PM contract?): all contributions to DKG are done.
468
469\martai{The organizer decides a minimum number of sequencers (security factor).}
470	
471\begin{itemize}
472	\item EPK ``becomes available".
473	\martai{I understand EPK becomes available in the SR smart contract, and that key is sent to the PM contract?}
474	\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.}
475\end{itemize}
476
477\subsubsection{Voting process}
478\label{sec:vocdoni-protocol:voting}
479
480Voter:
481
482\begin{itemize}
483	\item Choose any of the available sequencers (from?? -- from the SR SC).
484	\item Fetch their census \textbf{Merkle proof} to prove eligibility (from the census registry).
485	\item Use the EPK to encrypt the voting choice.
486	\item Generate ZK-SNARK of satisfiability of circuit from Fig.~\ref{fig:circuit-voter} with protocol from Section~\ref{sec:cryptographic-primitives:zkp} to prove the validity of the encrypted vote and adherence to ballot protocol rules. We call this proof \textbf{vote proof}.
487	\item Send the encrypted vote, Merkle proof, validity proof, and identity proof to the sequencer.
488	\martai{I understand Validity proof refers to ``voter circuit"? Merkle proof is for inclusion, right? And identity proof is for example a signature??}
489\end{itemize}
490
491Sequencer:
492
493\begin{itemize}
494	\item Fetch current state: retrieve the current valid process state root from the Etherem smart contract and the associated data from Ethereum blobs.
495	\martai{specify which SC.}
496	\item Generate a SK-SNARK proof of state transition proving:
497		\begin{itemize}
498			\item the validity of the ZK-SNARK proof provided by the voter,
499			\item the correct accumulation of votes from users, adding them to the process state,
500			\item the correct sum of the new encrypted votes using the homomorphic properties of ElGamal,
501			\item the new votes are from eligible users by checking the census Merkle proofs,
502			\item the new voters have not already voted by checking their nullifiers, or it is a correct vote overwrite,
503			\item the data blob hash matches the data used to verify the transition.
504		\end{itemize}
505	\item Submit updated state: send the new state root to the smart contract and store the updated data in Ethereum blobs.
506\end{itemize}
507
508Sequencers keep accumulating votes and create state transition until the finalization of the process.
509
510\martai{I understand this finalization is a deadline set by the organizer.}
511
512SC:
513
514\begin{itemize}
515	\item Upon receiving a sequencer's transaction, the SC verifies the zk-SNARK proof provided byt he sequencer.
516	\item Ensure the origin root corresponds to the current stored state root.
517	\item Confirm that the blob hash matches the one stored in Ethereum.
518\end{itemize}
519
520\subsubsection{Results validation}
521\label{sec:vocdoni-protocol:validation}
522
523Once the voting is completed (I understand the timeout set by the organizer expires), the following things happen.
524
525Sequencer:
526
527\begin{itemize}
528	\item $t$ out of $n$ sequencers publish their shares corresponding to the EPK to the Ethereum smart contract.
529	\martai{specify which SC.}
530	\item When the threshold of shares is reached, the results can be decrypted by anyone.
531	\martai{mention that the SC computes the corresponding ESK, or that can be computed by anyone off-chain, since all info is public.}
532	\item Sequencers receive reward for their correct participants depending on the number of sequenced votes.
533	\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?}
534\end{itemize}
535
536This way:
537
538\begin{itemize}
539	\item After the voting period ends and the results are decrypted, anyone can verify the correctness of the final result.
540	\martai{explain how.}
541	\item Use the zkSNARK state proof and publicly available data on-chain to ensure the integrity and correctness of the entire voting process.
542	\martai{elaborate on this.}
543\end{itemize}
544
545\subsubsection{Finalization of the voting process}
546\label{sec:vocdoni-protocol:finalization}