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