davinci-paper/v1/sections/sequencer-state-transition.tex
v1/sections/sequencer-state-transition.texRaw
1% !TeX root = ../build/main.tex
2
3When 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.
4
5For 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.
6
7This 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.
8
9\subsection{Maintaining the Chain}
10
11The 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.
12
13\begin{itemize}
14 \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.
15 \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.
16 \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.
17 \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.
18\end{itemize}
19
20\subsection{State Merkle Tree Structure}
21
22The State tree contains some special addresses (indices) for storing some required data regarding the voting process:
23
24\begin{itemize}
25 \item Address `0x0`: \textbf{Process Identifier}: stores a unique identifier for the voting process.
26 \item Address `0x1`: \textbf{Census Root and Type}: contains the information necessary to validate vote proofs.
27 \item Address `0x2`: \textbf{Ballot Mode}: encodes rules for validating votes, such as the maximum number of selectable options.
28 \item Address `0x3`: \textbf{Threshold Encryption key}: the public key used to encrypt the votes.
29 \item Address `0x4`: \textbf{Added Results Accumulator}: stores the aggregated encrypted voting results that need to be added.
30 \item Address `0x5`: \textbf{Subtract Results Accumulator}: stores the aggregated encrypted voting results that need to be subtracted.
31 \item Any Address: \textbf{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.
32 \item Any Address: \textbf{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.
33\end{itemize}
34
35\begin{figure}[H]
36 \centering
37 \fbox{
38 \includegraphics[scale = 0.3, draft = false]{\figs/merkle-tree-state.png}}
39\end{figure}
40
41\subsection{The Initial State}
42
43The 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.
44
45The 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.
46
47\subsection{State Transition}
48
49To 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.
50
51\begin{figure}[H]
52 \centering
53 \fbox{
54 \includegraphics[scale = 0.12, draft = false]{\figs/state-transition.png}}
55\end{figure}
56
57The circuit have the following inputs (the public ones are required to verify the proof).
58
59\begin{itemize}
60 \item \textbf{Public Inputs:}
61 \begin{itemize}
62 \item Previous State Root (Root1): The Merkle tree root before the state transition.
63 \item New State Root (Root2): The Merkle tree root after the state transition.
64 \item Blob Data Commitment (blobCommitment): The commitment to the data blob containing the new votes.
65 \end{itemize}
66 \item \textbf{Private Inputs:}
67 \begin{itemize}
68 \item Votes: The list of new votes being processed, including census proofs and authentication data.
69 \item Merkle Proofs of nullifier inclusion: Proofs that each voter nullifier is included in the census.
70 \item Merkle Proofs of results update: Proofs that the process results have been correctly updated.
71 \item Merkle Tree Update Witnesses: Necessary data (e.g., Merkle paths) to update the Merkle tree from Root1 to Root2.
72 \item Process Parameters: Retrieved from Root1 within the circuit.
73 \end{itemize}
74\end{itemize}
75
76\begin{figure}[H]
77 \centering
78 \fbox{
79 \includegraphics[scale = 0.3, draft = false]{\figs/circuit-inputs.png}}
80\end{figure}
81
82The following constraints must be enforced by the circuit.
83
84\begin{itemize}
85 \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.
86 \item \textbf{Vote Validity}: Validate that each vote proof is correct.
87 \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`.
88 \item \textbf{Nullifier Non-Existence}: Ensure that the nullifier for each vote does not exist in the current state (`Root1`), preventing double voting.
89 \item \textbf{Nullifier Addition}: Correctly add each new nullifier to the state, resulting in `Root2`, updating the Merkle tree accordingly.
90 \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`.
91 \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.
92 \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.
93\end{itemize}
94
95\subsection{Finalization of the Voting Process}
96
97At the conclusion of the voting period, the smart contract ceases to accept new state updates, effectively finalizing the process. The final State is then available on-chain for verification, providing an immutable record of the voting outcome.