arnaucube
arnaucube/davinci-paperPublic Self-hosted repository
davinci-paper/v2/sections/protocol-flow.tex
v2/sections/protocol-flow.texRaw
  1% !TeX root = ../build/main.tex
  2
  3In this section we describe the overall flow of the \davinci voting protocol. An election is structured into five main phases: election setup, encryption key generation, voting period, tally decryption, and election finalization. Each phase specifies the interactions between the organizer, \keywardens, voters, sequencers, and the smart contracts that coordinate the election. An overview of the complete process is shown in Fig.~\ref{fig:protocol-flow}.
  4
  5\subsubsection{Election setup}
  6\label{sec:election-setup}
  7
  8Before any election can begin, sequencers must register by staking \token tokens in the
  9{\color{blue}sequencer-registry} smart contract (see Section~\ref{sec:token}). This registration
 10is a one-time operation per sequencer and is independent of any particular election; only
 11registered sequencers are eligible to participate in the \ac{DKG} phase and to process votes.
 12%
 13For each new election, the organizer performs the following steps:
 14
 15\begin{enumerate}
 16	
 17	\item Prepare the census data \censusdata\ and build the incremental Merkle tree
 18	$\censusTree$ from it. Publish the full tree to IPFS, and record the resulting URI as $\censusuri$.
 19	
 20	\item Compute the census commitment $\censusroot = \censusTree.\hlget{\MTRoot}()$.
 21	
 22	\item Define the election details, including duration, the census model $\censusorigin$
 23	(see Section~\ref{sec:vocdoni-protocol:census}), and the ballot rules $\ballotmode$
 24	(see Section~\ref{sec:ballot-protocol}). 
 25	
 26	\item Upload the election metadata (questions, options, description, etc.)\ to IPFS to obtain {\color{blue}electionMetadata}.
 27	
 28	\item Compute a unique process identifier $\processid$, which is a 32-byte number derived
 29	from the organizer's Ethereum address, nonce, and the chain ID.
 30	
 31	\item Initialize the state Merkle tree $\stateTree$ by inserting the election configuration
 32	parameters into the reserved configuration namespace (see Section~\ref{sec:vocdoni-protocol:state-tree}):
 33	$\processid$ at leaf $\mathtt{0x0}$, $\ballotmode$ at leaf $\mathtt{0x2}$,
 34	$\censusorigin$ at leaf $\mathtt{0x6}$, and zero-valued accumulators $\addaccumulator$ and
 35	$\substractaccumulator$ at leaves $\mathtt{0x4}$ and $\mathtt{0x5}$, respectively. {\color{blue}Compute the
 36	initial state root -- is this done by the SC?}
 37	\[
 38	\stateroot = \stateTree.\hlget{\MTRoot}().
 39	\]
 40	
 41	\item Set security parameters for the \ac{DKG} ceremony (e.g.\ timeout, minimum number
 42	of sequencers) {\color{blue}DKG}.
 43	
 44	\item Submit all this information in a transaction to the \hlget{\electionregistry} smart
 45	contract:
 46	\begin{align*}
 47		tx_{\mathit{org}} = \big(
 48		&\processid,\ \censusroot,\ \censusorigin,\ \censusuri, \\
 49		&\ballotmode,\ {\color{blue}electionMetadata},\ \stateroot,\ {\color{blue}dkgParameters}
 50		\big).
 51	\end{align*}
 52	
 53\end{enumerate}
 54%
 55Once this transaction is accepted, the election is publicly registered on-chain and the
 56\ac{DKG} phase can begin.
 57
 58\subsubsection{Encryption key generation}
 59\label{sec:vocdoni-protocol:keygen}
 60
 61In this phase, \keywardens collectively generate the public encryption key.\\
 62
 63\noi \Keywardens fetch the process parameters ($\processid$, $\ballotmode$, $\censusroot$) from the \hlget{\electionregistry} smart contract and participate in a \ac{DKG} protocol before the timeout set by the organizer expires. If the minimum number of contributions is reached, the public encryption key $\epk$ is derived and made available on-chain. This ensures that no single party controls the secret key, and that decryption later requires threshold participation {\color{blue}(give more details)}.\\
 64
 65\noi {\color{blue} Alternatively, generate a SNARK proving the EPK has been generated correctly and the contract verifies it.}
 66
 67\subsubsection{Voting period}
 68\label{sec:vocdoni-protocol:votes}
 69
 70In this phase, voters cast their ballots and send them to the sequencers, who collect and process them. \\
 71
 72\noi \textbf{(a) Vote casting.} To cast a ballot, a voter does the following:
 73
 74\begin{enumerate}
 75	\item Select a sequencer.  
 76	\item Retrieve their census membership proof $\censusproof$ to prove eligibility.  
 77	\item Fetch parameters $\epk$, $\ballotmode$, and $\processid$ from the \hlget{\electionregistry} smart contract.  
 78	\item Select their ballot choice $\ballot$ according to the rules of $\ballotmode$.  
 79	\item Sample fresh randomness $k \in \F$ and encrypt the ballot using $\epk$:  
 80		  \begin{equation}
 81		  \label{eq-ciphertext}
 82		  	\encryptedballot ={ }\hlget{\Enc}_{\epk}(\ballot; k).
 83		  \end{equation}
 84	\item Use their Ethereum address $\address$ and the previous $k$ to compute a unique vote identifier:
 85		\begin{equation}
 86			\label{eq-voteid}
 87			\voteid ={ }\hlget{\Poseidon}(\processid \conc \address \conc k).
 88		\end{equation}
 89	\item Use the \ballotcircuit from Section~\ref{sec:vocdoni-protocol:circuits:ballot} to generate a ZK-SNARK proof to prove that Eqs.~\labelcref{eq-ciphertext,eq-voteid} are correctly computed and that $\ballot$ satisfies the ballot protocol rules according to $\ballotmode$:
 90		\begin{align*}
 91		\voteproof ={ } & \hlget{\PProve}(
 92			\hlget{\ballotcircuit},
 93			\witness = (\ballot, k), 
 94			\publicinputs = (\processid, \ballotmode,\\
 95			&\epk, \address, \weight, \encryptedballot, \voteid)).
 96		\end{align*}	
 97	\item Sign the vote identifier with their Ethereum secret key $\sk$ to authenticate the vote and ensure that was cast by a legitimate voter:  
 98		\[ \signature = \hlget{\SSign}_{\sk}(\voteid).\]
 99	\item Submit the package  
100	\[\vote = [\processid, \voteid, \encryptedballot, \censusproof, \voteproof, \signature]\]  
101	to the chosen sequencer.  
102\end{enumerate}
103
104%\item Sign $\voteid$ using the user's secret key $\sk$ to authenticates the vote and ensure that was cast by a legitimate voter:
105%\[ \signature = \hlget{\SSign}_{\sk}(\voteid).\]
106%\item Send the following data, which includes the encrypted vote, census membership proof, signature\footnote{Note that the address is not send because it can be recomputed from the signature.} and vote proof, to the selected sequencer:
107%\[ \vote = [ \processid, \voteid, \encryptedballot, \censuspf, \voteproof, \signature ]. \]
108
109\noi \textbf{(b) Vote batching.} Upon receiving votes, a sequencer does the following:
110
111\begin{enumerate}
112	\item Retrieve election identifier $\processid$, current state root $\stateroot$, and census root $\censusroot$ from the \hlget{\electionregistry} smart contract and the associated data from the Ethereum data blobs.  
113	\item Upon receiving a vote
114	\[\vote_i = [\processid, \voteid, \encryptedballot, \censusproof, \voteproof, \signature],\]
115	extract the voter's public key $\pk_i = \hlget{\SPubKey}(\signature)$.
116	\item For each $\vote_i$ received, use \verifiercircuit from Section~\ref{sec:vocdoni-protocol:circuits:verifier} to generate a proof 
117	\begin{align*}
118		\authenticationproof_i ={ } & \hlget{\PProve}(\hlget{\verifiercircuit}, 
119		\witness = (\ballotproof, \weight, \censusproof, \signature),\\
120		& \publicinputs = (\processid, \ballotmode, \epk, \encryptedballot, \voteid, \\
121		& \censusroot, \pk)).
122	\end{align*}
123	This proof ensures that the voter’s \voteproof, the \signature, and the \censusproof are all valid.
124	\item Batch a set of $n$ proofs $\{\authenticationproof_i\}_{i = 1}^n$ and batch verify them together using \aggregationcircuit from Section~\ref{sec:vocdoni-protocol:circuits:aggregation}:
125	\begin{align*}
126		\aggregationproof = { } &\hlget{\PProve}(\hlget{\aggregationcircuit}, 
127						\witness = (\{\authenticationproof_i\}_{i = 1}^n),\\
128						&\publicinputs = (\encryptedballot, \{\voteid_i\}_{i = 1}^n),
129						\{\pk_i\}_{i = 1}^n,
130						\processid,
131						\ballotmode,\\
132						&
133						\epk,
134						\censusroot
135						).
136	\end{align*}
137	This proof ensures that the public inputs corresponding to the global process parameters ($\processid$, $\ballotmode$, $\epk$, $\censusroot$) are correct and that all $\authenticationproof_i$ are valid.
138	
139	\item Prepare the state transition data that will be stored in an Ethereum blob: pack votes/results into a 4096-cell blob \blobdata. 
140		\begin{itemize}
141			\item Compute data commitment $\blobcom = \hlget{\CCommit}(\blobdata)$. 
142			\item Derive evaluation point $\evalpoint = \hlget{\Poseidon}(\processid, oldRoot, \blobcom).$
143			\item Prepare polynomial $P$ from $\blobdata$.
144			\item Evaluate $y = P(\evalpoint)$.
145			\item Generate opening proof $\openproof$ from $...$.
146			\item The following step (circuit) will prove that $y = P(\evalpoint)$.
147		\end{itemize}
148		
149	\item {\color{blue}Before doing state transitions, we need to prepare the data that will be stored on chain as a blob. Hence, collect xxxx, create commitment. In circuit (next step), we will prove that... .}
150	
151	\item Finally, prove that all transitions are correct .... with circuit from Section~\ref{sec:vocdoni-protocol:circuits:state-transition}.
152	consistency between data blobs and the on-chain state:
153	
154	\begin{align*}
155		\stateproof ={ } \hlget{\PProve}(\hlget{\statetransitioncircuit}, 
156		\witness = (), \publicinputs = ()).	
157	\end{align*}
158	
159	\item Verify each $\vote$ submission received by generating a state transition proof (see Section~\ref{sec:vocdoni-protocol:circuits:state-transition}), ensuring:
160		\begin{itemize}
161			\item correct accumulation of encrypted votes via ElGamal’s homomorphic properties,  
162			\item eligibility of voters (via census Merkle proofs),  
163			\item absence of double voting (or correct handling of overwrites via nullifiers),  
164		\end{itemize}
165	\item Submit the updated state root to the smart contract, while the full data are stored in Ethereum blobs.  
166	\martai{If \stateroot changed, repeat last circuit.}
167\end{enumerate}
168
169Sequencers repeat this process until the voting deadline set by the organizer.
170
171Upon receiving a valid transaction, the \electionregistry smart contract does the following checks:
172
173\subsubsection{Tally decryption}
174\label{sec:vocdoni-protocol:deckey-gen}
175
176{\color{blue} After the voting period expires, $t$ out of $n$ sequencers publish their decryption shares of the election private key. Once the threshold is reached, the election secret key can be reconstructed (on-chain or off-chain), enabling the decryption of the aggregated tally.  
177	
178Rewards and penalties for sequencers are managed according to their correct participation: sequencers are rewarded proportionally to the number of votes sequenced, and may be slashed for failing to provide a valid decryption share (see Seciton~\ref{sec:token} for details on incentivation mechanisms.)}
179	
180
181\subsubsection{Election finalization}
182\label{sec:vocdoni-protocol:results}
183
184In this final phase, the organizer/a sequencer computes the tally and publishes the result, together with a proof of its correct computation, on-chain.
185
186\begin{enumerate}
187	\item Retrieve $\decryptionkey$ from \dots.
188	\item ...
189	\item Use \resultscircuit from Section~\ref{sec:vocdoni-protocol:circuits:results} to generate a proof 
190	\begin{align*}
191		\resultsproof = { } \hlget{\PProve}(\hlget{\resultscircuit}, 
192		\witness = (...), 
193		\publicinputs = (...)).
194	\end{align*}
195\end{enumerate}
196
197The election is considered finalized once the decrypted tally is available on-chain. At this stage, both the election results and the complete integrity of the process are permanently recorded and publicly auditable.
198
199{\color{blue} Note that, anyone can verify the correctness of the final results by checking the \ac{ZK-SNARK} state proofs and on-chain commitments. Moreover, the combination of the final state root, the decryption of the accumulators, and the publicly verifiable \ac{ZK-SNARK} proofs guarantees the integrity of the entire election.}
200
201\begin{figure}%[H]
202	\centerline{\includegraphics[width=370pt,draft=false]{\figs/protocol-flow.pdf}}
203	\caption{Vocdoni voting process overview. {\color{blue}Figure is OUTDATED.}}
204	\label{fig:protocol-flow}
205\end{figure}