% !TeX root = ../build/main.tex In 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}. \subsubsection{Election setup} \label{sec:election-setup} Before any election can begin, sequencers must register by staking \token tokens in the {\color{blue}sequencer-registry} smart contract (see Section~\ref{sec:token}). This registration is a one-time operation per sequencer and is independent of any particular election; only registered sequencers are eligible to participate in the \ac{DKG} phase and to process votes. % For each new election, the organizer performs the following steps: \begin{enumerate} \item Prepare the census data \censusdata\ and build the incremental Merkle tree $\censusTree$ from it. Publish the full tree to IPFS, and record the resulting URI as $\censusuri$. \item Compute the census commitment $\censusroot = \censusTree.\hlget{\MTRoot}()$. \item Define the election details, including duration, the census model $\censusorigin$ (see Section~\ref{sec:vocdoni-protocol:census}), and the ballot rules $\ballotmode$ (see Section~\ref{sec:ballot-protocol}). \item Upload the election metadata (questions, options, description, etc.)\ to IPFS to obtain {\color{blue}electionMetadata}. \item Compute a unique process identifier $\processid$, which is a 32-byte number derived from the organizer's Ethereum address, nonce, and the chain ID. \item Initialize the state Merkle tree $\stateTree$ by inserting the election configuration parameters into the reserved configuration namespace (see Section~\ref{sec:vocdoni-protocol:state-tree}): $\processid$ at leaf $\mathtt{0x0}$, $\ballotmode$ at leaf $\mathtt{0x2}$, $\censusorigin$ at leaf $\mathtt{0x6}$, and zero-valued accumulators $\addaccumulator$ and $\substractaccumulator$ at leaves $\mathtt{0x4}$ and $\mathtt{0x5}$, respectively. {\color{blue}Compute the initial state root -- is this done by the SC?} \[ \stateroot = \stateTree.\hlget{\MTRoot}(). \] \item Set security parameters for the \ac{DKG} ceremony (e.g.\ timeout, minimum number of sequencers) {\color{blue}DKG}. \item Submit all this information in a transaction to the \hlget{\electionregistry} smart contract: \begin{align*} tx_{\mathit{org}} = \big( &\processid,\ \censusroot,\ \censusorigin,\ \censusuri, \\ &\ballotmode,\ {\color{blue}electionMetadata},\ \stateroot,\ {\color{blue}dkgParameters} \big). \end{align*} \end{enumerate} % Once this transaction is accepted, the election is publicly registered on-chain and the \ac{DKG} phase can begin. \subsubsection{Encryption key generation} \label{sec:vocdoni-protocol:keygen} In this phase, \keywardens collectively generate the public encryption key.\\ \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)}.\\ \noi {\color{blue} Alternatively, generate a SNARK proving the EPK has been generated correctly and the contract verifies it.} \subsubsection{Voting period} \label{sec:vocdoni-protocol:votes} In this phase, voters cast their ballots and send them to the sequencers, who collect and process them. \\ \noi \textbf{(a) Vote casting.} To cast a ballot, a voter does the following: \textit{\color{blue}-- mention that the voter has a (sk, pk, address) as described in Section~\ref{}.} \begin{enumerate} \item Select a sequencer. \item Retrieve their census membership proof $\censusproof$ to prove eligibility. \item Fetch parameters $\epk$, $\ballotmode$, and $\processid$ from the \hlget{\electionregistry} smart contract. \item Select their ballot choice $\ballot$ following the rules of $\ballotmode$. \item Sample fresh randomness $k \in \F$ and encrypt the ballot using $\epk$: \begin{equation} \label{eq-ciphertext} \encryptedballot ={ }\hlget{\Enc}_{\epk}(\ballot; k). \end{equation} \item Use their Ethereum address $\address$ and the previous $k$ to compute a unique vote identifier: \begin{equation} \label{eq-voteid} \voteid = N + \bigl(\hlget{\Poseidon}(\processid,\address,k) \bmod N\bigr), \end{equation} where $N$ is defined by the protocol as described in Section~\ref{sec:vocdoni-protocol:circuits:state-transition}. \item Use the \ballotcircuit from Section~\ref{sec:vocdoni-protocol:circuits:ballot} to generate a \ac{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$: \begin{align*} \voteproof ={ } & \hlget{\PProve}( \hlget{\ballotcircuit}, \witness = (\ballot, k), \publicinputs = (\processid, \ballotmode,\\ &\epk, \address, \weight, \encryptedballot, \voteid)). \end{align*} \item Sign the vote identifier with their Ethereum secret key $\sk$ to authenticate the vote and ensure that was cast by a legitimate voter: \[ \signature = \hlget{\SSign}_{\sk}(\voteid).\] \item Submit the package \[\vote = [\processid, \voteid, \encryptedballot, \voteproof, \signature]\] to the chosen sequencer. \end{enumerate} %\item Sign $\voteid$ using the user's secret key $\sk$ to authenticates the vote and ensure that was cast by a legitimate voter: %\[ \signature = \hlget{\SSign}_{\sk}(\voteid).\] %\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: %\[ \vote = [ \processid, \voteid, \encryptedballot, \censuspf, \voteproof, \signature ]. \] \noi \textbf{(b) Vote batching.} Upon receiving votes, a sequencer does the following: \begin{enumerate} \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. \item Upon receiving a vote \[\vote_i = [\processid, \voteid, \encryptedballot, \voteproof, \signature],\] extract the voter's public key $\pk_i = \hlget{\SPubKey}(\signature)$. -- {\color{blue}Add this function to Appendix.} \item For each $\vote_i$ received, use \verifiercircuit from Section~\ref{sec:vocdoni-protocol:circuits:verifier} to generate a proof \begin{align*} \authenticationproof_i ={ } & \hlget{\PProve}(\hlget{\verifiercircuit}, \witness = (\ballotproof, \pk, \signature),\\ & \publicinputs = (\processid, \ballotmode, \epk, \encryptedballot, \voteid, \\ & \address, \weight)). \end{align*} This proof ensures that the voter’s \voteproof and \signature are valid. \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}: \begin{align*} \aggregationproof = { } &\hlget{\PProve}(\hlget{\aggregationcircuit}, \witness = (\{\authenticationproof_i\}_{i = 1}^n),\\ &\publicinputs = (\{\encryptedballot\}_{i = 1}^n, \{\voteid_i\}_{i = 1}^n), \{\address_i\}_{i = 1}^n, \processid,\\ & \ballotmode, \epk ). \end{align*} This proof ensures that public inputs corresponding to the global process parameters ($\processid$, $\ballotmode$, $\epk$) are correct and that all $\authenticationproof_i$ are valid. \item Prepare the state transition data that will be stored in an Ethereum blob: pack votes/results into a 4096-cell blob \blobdata. \begin{itemize} \item Compute data commitment $\blobcom = \hlget{\CCommit}(\blobdata)$. \item Derive evaluation point $\evalpoint = \hlget{\Poseidon}(\processid, \stateroot^\old, \blobcom).$ \item Prepare polynomial $P$ from $\blobdata$. \item Evaluate $y = P(\evalpoint)$. \item Generate opening proof $\openproof$ from $...$. \item The following step (circuit) will prove that $y = P(\evalpoint)$. \end{itemize} \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... .} \item {\color{blue}The sequencer must retrieve the voter's membership proof. Add as a footnote that this can be done by the voter and sent to the sequencer, who verifies it, but we want to minimize the actions of the voter.} \item Finally, prove that all transitions are correct .... with circuit from Section~\ref{sec:vocdoni-protocol:circuits:state-transition}. consistency between data blobs and the on-chain state: \begin{align*} \stateproof ={ } \hlget{\PProve}(\hlget{\statetransitioncircuit}, \witness = (), \publicinputs = ()). \end{align*} \item Verify each $\vote$ submission received by generating a state transition proof (see Section~\ref{sec:vocdoni-protocol:circuits:state-transition}), ensuring: \begin{itemize} \item correct accumulation of encrypted votes via ElGamal’s homomorphic properties, \item eligibility of voters (via census Merkle proofs), \end{itemize} \item Submit the updated state root to the smart contract, while the full data are stored in Ethereum blobs. \martai{If \stateroot changed, repeat last circuit.} \end{enumerate} Sequencers repeat this process until the voting deadline set by the organizer. Upon receiving a valid transaction, the \electionregistry smart contract does the following checks: \subsubsection{Tally decryption} \label{sec:vocdoni-protocol:deckey-gen} {\color{blue} After the voting period expires, $t$ out of $n$ sequencers share their decryption shares of the election private key \textbf{to whom?}. Once the threshold is reached, the election secret key can be reconstructed (on-chain or off-chain), enabling the decryption of the aggregated tally. Rewards 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.)} \subsubsection{Election finalization} \label{sec:vocdoni-protocol:results} In this final phase, the organizer/a sequencer computes the tally and publishes the result, together with a proof of its correct computation, on-chain. \begin{enumerate} \item Retrieve $\decryptionkey$ from \dots. \item ... \item Use \resultscircuit from Section~\ref{sec:vocdoni-protocol:circuits:results} to generate a proof \begin{align*} \resultsproof = { } \hlget{\PProve}(\hlget{\resultscircuit}, \witness = (...), \publicinputs = (...)). \end{align*} \end{enumerate} The 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. {\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.} \begin{figure}%[H] \centerline{\includegraphics[width=370pt,draft=false]{\figs/protocol-flow.pdf}} \caption{Vocdoni voting process overview. {\color{blue}Figure is OUTDATED.}} \label{fig:protocol-flow} \end{figure}