% !TeX root = ../build/main.tex At the core of \davinci lie a set of arithmetic circuits that enforce the correctness of every step of the voting process. Each circuit corresponds to a distinct task and, taken together, they guarantee that all protocol rules are satisfied without revealing any private information. Specifically, the \emph{ballot circuit} (Section~\ref{sec:vocdoni-protocol:circuits:ballot}) ensures that encrypted votes are valid and well-formed, the \emph{verifier circuit} (Section~\ref{sec:vocdoni-protocol:circuits:verifier}) verifies voter eligibility and census membership; the \emph{aggregation circuit} (Section~\ref{sec:vocdoni-protocol:circuits:aggregation}) combines multiple authenticated votes into a single proof; and the \emph{state transition circuit} (Section~\ref{sec:vocdoni-protocol:circuits:state-transition}) updates the global state root and produces the ZK-SNARK proof that is verified on-chain. The flow of these circuits and their interactions is shown in Figure~\ref{fig:circuits-flow}. \begin{figure}[h] \centerline{\includegraphics[width=\linewidth,draft=false]{\figs/circuits-flow-v2}} \caption{ Overview of the circuit flow in \davinci.} \label{fig:circuits-flow} \end{figure} For clarity, the circuits are described in this section with their full set of public inputs explicitly listed. In the actual implementation, however, we apply an optimization: rather than exposing all public inputs individually, we compute a single commitment $h = Hash(PI)$ and use $h$ as the only public input. The proof verifier then checks that $Hash(PI) = h$, ensuring that the original public inputs are consistent while reducing both proof size and verification cost. In \davinci, this commitment is computed using the MiMC-7 hash function {\color{blue}(use hlget to point "Hash" to MiMC-7)}. Note that this optimization does not alter the semantics of the circuits but significantly reduces verifier complexity and on-chain verification costs. Other implementation aspects such as the exact number of constraints and the proving frameworks used are deferred to Section~\ref{sec:analysis:implementation}. % 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. \subsubsection{Ballot circuit} \label{sec:vocdoni-protocol:circuits:ballot} The ballot circuit, illustrated in Figure~\ref{fig:circuit-ballot}, is generated locally by the voter at the time of casting a ballot. Its purpose is twofold: first, to prove that the encrypted ballot is valid and complies with the protocol rules defined by the organizer; and second, to prove that the vote identifier (\voteid) has been correctly derived. The correctness of this circuit is attested by a ZK proof generated using the ZK-SNARK protocol described in Section~\ref{sec:cryptographic-primitives:zkp}, instantiated over the BN254 curve. We call the resulting proof \textit{ballot proof} and denote it as $\hlset{\ballotproof}$. We detail below the inputs and constraints of the ballot circuit. \begin{spacing}{1.25} \vspace{0.3cm} \noi \textbf{Public inputs} \begin{itemize} \item $\public$ $\processid$: voting process identifier. \item $\public$ $\ballotmode$: ballot protocol configuration.S \item $\public$ $\epk$ ($EPK$): encryption public key. \item $\public$ $\address$: voter's address. \item $\public$ $\weight$: voter's weight. \item $\public$ $(C_1, C_2)$: encrypted ballot. \item $\public$ $\voteid$: vote's unique identifier. \end{itemize} \textbf{Private inputs} \begin{itemize} \item \private $\ballot$: plaintext voter's voting choice. \item \private $k$: random scalar. \end{itemize} \textbf{Constraints} \begin{itemize} \item \emph{Vote encryption}. Correct encryption of the ballot: $(C_1, C_2) = \hlget{\Enc}_{\epk}(\ballot; k).$ \item \emph{Protocol rules compliance}. The ballot meets the protocol rules (number of valid choices, etc.): $... + \weight$. \item \emph{Vote identifier}. The vote's identifier is correctly computed: $\voteid = \text{Hash} (\processid \conc \address \conc k).$ \end{itemize} \vspace{-0.3cm} \end{spacing} \begin{figure}[H] \centerline{\includegraphics[width=420pt,draft=false]{\figs/circuit-voter}} \caption{Ballot circuit. All public values are framed in green.} \label{fig:circuit-ballot} \end{figure} \subsubsection{Verifier circuit} \label{sec:vocdoni-protocol:circuits:verifier} The verifier circuit, illustrated in Figure~\ref{fig:circuit-verifier}, is generated by the sequencer when processing a vote. This circuit verifies the ballot's proof generated by the voter and it also validates the voter’s eligibility in the census and the correctness of their digital signature. The correctness of this circuit is attested by a ZK proof generated using the ZK-SNARK protocol described in Section~\ref{sec:cryptographic-primitives:zkp}, instantiated over the BLS12-377 curve. We call the resulting proof the \textit{authentication proof} and denote it as $\hlset{\authenticationproof}$. We detail below the inputs and constraints of this circuit. {\color{blue}-- Authentication of verification proof?} \begin{spacing}{1.25} \vspace{0.3cm} \noi \textbf{Public inputs} \begin{itemize} \item \public $\processid$: process identifier. \item \public $\ballotmode$: ballot protocol configuration. \item \public $\epk$ ($EPK$): encryption public key. \item \public $(C_1, C_2)$: encrypted ballot. \item \public $\voteid$: voter's identifier. \item \public $\censusroot$: census Merkle tree root. \item \public $\pk$: voter's public key. \end{itemize} \textbf{Private inputs} \begin{itemize} \item \private $\ballotproof$: voter's ballot proof. \item \private $\weight$: voter's weight. \item \private $\censuspf$: census membership proof. \item \private $\signature$: voter's signature. \end{itemize} \textbf{Constraints} \begin{itemize} \item \emph{Voter's proof verification.} The vote zkProof is valid for the inputs provided: $$\hlget{\PVerify}\left(\ballotproof, PI = (\processid, \ballotmode, \epk, (C_1, C_2), \voteid, \weight)\right).$$ \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: $$ \hlget{\censusTree}.\hlget{\MTMembershipProof}(\weight, \address = \hlget{\Keccak}(\pk), \censuspf, \censusroot). $$ \item \emph{Authentication + non-malleability.} The signature of the vote's identifier is valid for the given public key: $$ \hlget{\SVer}_{\pk}(\voteid, \signature). $$ \end{itemize} \vspace{-0.3cm} \end{spacing} \begin{figure}[H] \centerline{\includegraphics[width=450pt,draft=false]{\figs/circuit-authentication}} \caption{Authentication circuit. All public values are framed in green.} \label{fig:circuit-verifier} \end{figure} \subsubsection{Aggregation circuit} \label{sec:vocdoni-protocol:circuits:aggregation} The aggregation circuit, illustrated in Figure~\ref{fig:circuit-aggregate}, is generated by the sequencer to combine multiple authenticated votes into a single proof. Its purpose is to reduce verification overhead by recursively aggregating individual authentication proofs, while ensuring that all aggregated votes belong to the same voting process. The batch size, i.e., the maximum number of proofs aggregated in a single execution, is a fixed parameter (currently set to 60). If fewer proofs are available, the sequencer pads the batch with dummy proofs so that the circuit always operates on a fixed-size input. The correctness of this circuit is attested by a ZK proof generated using the ZK-SNARK protocol described in Section~\ref{sec:cryptographic-primitives:zkp}, instantiated over the BW6-761 curve. We call the resulting proof the \textit{aggregation proof} and denote it as $\hlset{\aggregationproof}$. We detail below the inputs and constraints of the aggregation circuit. \begin{spacing}{1.25} \vspace{0.3cm} \noi \textbf{Public inputs} \begin{itemize} \item \public $(C_1, C_2)_i$: list of voters' encrypted ballots. \item \public $\voteid_i$: set of vote's identifiers. \item \public $\pk_i$: list of voters' public keys. \item \public $\processid$: process identifier. \item \public $\ballotmode$: ballot protocol configuration. \item \public $EPK$: encryption public key. \item \public $\censusroot$: census Merkle tree root. \end{itemize} \textbf{Private inputs} \begin{itemize} \item \private $\authenticationproof_i$: set of authentication proofs. \end{itemize} \textbf{Constraints} \\ \vspace{-0.4cm} \begin{itemize} \item \emph{Votes aggregation.} The accumulated authentication proofs are valid (for the given inputs). For every $i$: $$\hlget{\PVerify}(\authenticationproof, PI = ((C_1, C_2)_i, \voteid_i, \pk_i, \processid, \ballotmode, EPK, \censusroot)).$$ \item \emph{Shared public inputs.} The public inputs \processid, \ballotmode, \epk, and \censusroot are the same for all proofs. \end{itemize} \vspace{-0.3cm} \end{spacing} \begin{figure}[h] \centerline{\includegraphics[width=450pt,draft=false]{\figs/circuit-aggregate}} \caption{Aggregation circuit. All public values are framed in green.} \label{fig:circuit-aggregate} \end{figure} \subsubsection{State transition circuit} \label{sec:vocdoni-protocol:circuits:state-transition} The state transition circuit, illustrated in Figure~\ref{fig:circuit-state-transition-v2}, is generated by the sequencer to update the global state of the voting process. Its purpose is to verify that a batch of aggregated votes has been correctly incorporated into the state Merkle tree, that overwrites and vote identifiers are handled consistently, and that the accumulators of encrypted results are updated accordingly. The correctness of this circuit is attested by a ZK proof generated using the ZK-SNARK protocol described in Section~\ref{sec:cryptographic-primitives:zkp}, instantiated over the BN254 curve, which is supported by Ethereum’s native precompiles for proof verification. We call the resulting proof the \textit{state proof} and denote it as $\hlset{\stateproof}$. This proof is submitted on-chain and verified by the process management smart contract, ensuring that every accepted state transition complies with the protocol rules. \begin{spacing}{1.25} \vspace{0.3cm} \noi \textbf{Public inputs} \begin{itemize} \item \public $\stateroot^{old}$: most recent state tree root. \item \public $\stateroot^{new}$: most recent state tree root. \item \public $numOverwrites^{old}$: \item \public $numOverwrites^{new}$: \item \public $numVotes^{old}$: \item \public $numVotes^{new}$: \end{itemize} \textbf{Private inputs} \begin{itemize} \item \private $\{\aggregationproof_i\}$: set of aggregation proofs. \item \private $\censusroot$: census Merkle tree root. \item \private $\ballotmode$: ballot protocol configuration. \item \private $EPK$: encryption public key. \item \private $\processid$: process identifier. \item \private $\{\voteid_i\}$: set of vote's identifiers. \item \private $\{(C_1, C_2)_i\}$: set of vote's identifiers. \item \private $\{\pk_i\}$: list of voters' public keys. \item \private $\{MerkleProofs_i\}$: list of voters' public keys. \item \private $\{resultsAdd^{old}\}$: list of voters' public keys. \item \private $\{resultsSub^{old}\}$: list of voters' public keys. \item \private $k$: random scalar. \end{itemize} \textbf{Constraints} \\ \vspace{-0.4cm} \begin{itemize} \item \emph{Aggregation verification.} The accumulated authentication proofs are valid (for the given inputs). For every $i$: $$\hlget{\PVerify}(\authenticationproof, PI = ((C_1, C_2)_i, \voteid_i, \pk_i, \processid, \ballotmode, EPK, \censusroot)).$$ \item \emph{Transition verification.} The public inputs \processid, \ballotmode, \epk, and \censusroot are the same for all proofs. \end{itemize} \vspace{-0.3cm} \end{spacing} -------------------------------------------------------- \newpage \paragraph{Assertions.} \begin{itemize} \item \emph{Aggregation verification}: The agreggated zkProof is valid. \item \emph{Transition verification}: The MerkleTree transition witness proves every change between Root1 and Root2. \item \emph{Public inputs integrity}: ProcessID, BallotMode, CensusRoot, EncryptionKey remain unchanged. \item \emph{Votes counting}: Ballots are correctly counted as new or overwrites, and added to results accumulators. \end{itemize} When 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. For 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. This 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. \paragraph{Maintaining the Chain.} The 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. \begin{itemize} \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. \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. \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. \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. \end{itemize} \paragraph{State Transition} To 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. \begin{figure}[H] \centering \fbox{ \includegraphics[scale = 0.12, draft = false]{\figs/state-transition.png}} \end{figure} %\begin{figure}[H] % \centering % \fbox{ % \includegraphics[scale = 0.3, draft = false]{\figs/circuit-inputs.png}} %\end{figure} % %\begin{figure}[H] % \centerline{\includegraphics[width=400pt,draft=false]{\figs/circuit-state-transition}} % \caption{State transition circuit. All public values are framed in green.} % \label{fig:circuit-state-transition} %\end{figure} \begin{mdframed} \begin{minipage}[H]{1\textwidth} \begin{spacing}{1.25} \vspace{0.3cm} \begin{center}{STATE TRANSITION CIRCUIT}\end{center} \textbf{Public inputs} \begin{itemize} \item \public $root_{old}$: Merkle tree root before the state transition. \item \public $root_{new}$: Meklre tree root after the state transition. \item \public $blobCommitment$: the commitment to the data blob containing the new votes. \end{itemize} \item \textbf{Private inputs} \begin{itemize} \item \private Votes: The list of new votes being processed, including census proofs and authentication data. \item \private Merkle Proofs of nullifier inclusion: Proofs that each voter nullifier is included in the census. \item \private Merkle Proofs of results update: Proofs that the process results have been correctly updated. \item \private Merkle Tree Update Witnesses: Necessary data (e.g., Merkle paths) to update the Merkle tree from Root1 to Root2. \item \private Process Parameters: Retrieved from Root1 within the circuit. \end{itemize} \textbf{Constraints} \\ \vspace{-0.4cm} \begin{itemize} \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. \item \textbf{Vote validity}: Validate that each vote proof is correct. \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`. \item \textbf{Nullifier non-existence}: Ensure that the nullifier for each vote does not exist in the current state (`Root1`), preventing double voting. \item \textbf{Nullifier addition}: Correctly add each new nullifier to the state, resulting in `Root2`, updating the Merkle tree accordingly. \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`. \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. \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. \end{itemize} \vspace{-0.3cm} \end{spacing} \end{minipage} \end{mdframed} \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).} \begin{landscape} %\thispagestyle{empty} % removes the page number \begin{figure}[H] \centerline{\includegraphics[width=560pt,draft=false]{\figs/circuit-state-transition-v2}} \caption{State transition circuit. All public values are framed in green.} \label{fig:circuit-state-transition-v2} \end{figure} \end{landscape} \subsubsection{Results circuit} \label{sec:vocdoni-protocol:circuits:results} {\color{blue}{It needs to be done.}}