davinci-paper/v2/sections/merkle-trees.tex
v2/sections/merkle-trees.texRaw
1% !TeX root = ../build/main.tex
2
3{\color{blue}Consider removing this section and creating new sections \textbf{1. Census} and \textbf{2. State tree}.}\\
4
5\noi Merkle trees are used to create a cryptographic representation of both the voter census registry and the election state.
6
7%\begin{itemize}
8% \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.
9% \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.
10%\end{itemize}}
11
12\subsubsection{Census tree}
13\label{sec:vocdoni-protocol:merkle-trees:census}
14
15The census Merkle tree, denoted by $\hlget{\censusTree}$ encodes the list of eligible voters and their associated voting weights. Formally, it is implemented as a sparse Merkle tree (SMT) of fixed depth\footnote{In the present work, all circuits are instantiated using sparse Merkle trees as described above. However, the protocol does not strictly depend on this structure: any authenticated data structure that supports efficient commitments and membership proofs verifiable inside zero-knowledge circuits could be employed. Adapting the protocol to such alternatives would only require modifying the corresponding circuits, while the overall flow of the voting process would remain unchanged.}, as described in Section~\ref{sec:cryptographic-primitives:merkle-trees}. Each voter is mapped to a unique path in the tree, typically derived from their Ethereum address or another unique identifier, and the corresponding leaf stores the voting weight of that address. While the default weight is usually one, the system also supports weighted voting, where different participants may have different levels of influence.
16
17To construct the census, the organizer collects the dataset of eligible voters and their weights, computes the corresponding tree, and publishes its root (\censusroot) on-chain. The full dataset does not need to be stored on-chain; instead, it is distributed off-chain (e.g., via IPFS or another content-addressed storage system), enabling verifiers and sequencers to independently reconstruct the tree and produce membership proofs when needed. This design ensures transparency and verifiability while minimizing on-chain storage requirements.
18
19The census tree plays a central role during the voting phase. Voters must provide a Merkle proof showing that their address and weight are included in the tree committed by the organizer. These proofs are then verified within ZK circuits, which guarantees that only eligible participants can cast ballots without requiring the disclosure of the entire census. In this way, the census Merkle tree provides a compact, cryptographically verifiable commitment to voter eligibility that supports both privacy and scalability.
20
21Although the protocol does not mandate a specific method for constructing the census tree, different instantiations are possible depending on the application context:
22%
23\begin{itemize}
24 \item \emph{Private datasets}. Organizations maintaining internal voter registries (e.g., membership databases or CSV files) can directly convert them into the Merkle format. This approach keeps the registry confidential, with only the root hash made public.
25 \item \emph{Self-sovereign identity (SSI)}. If voters manage identities through SSI systems, the organizer can aggregate these identities and build
26 the tree accordingly. This enables participation without requiring centralized identity management.
27 \item \textit{Ethereum-based tokens}. Token balances (e.g., ERC-20 or NFTs) may also define eligibility. In this setting, the census can either be created via the optimistic approach, taking a snapshot of token balances and allowing a dispute period for fraud proofs, or through a ZK-SNARK that proves correctness directly from Ethereum storage proofs and ensures that both individual balances and the token’s total supply are consistent.
28\end{itemize}
29%
30This flexibility allows the protocol to accommodate a wide range of use cases, from private associations to decentralized communities, while maintaining the same security and verifiability guarantees.
31
32\subsubsection{State tree}
33\label{sec:vocdoni-protocol:merkle-trees:state}
34
35The state Merkle tree, denoted by $\hlget{\stateTree}$, represents the evolving state of the voting process. Like the census tree, it is implemented as a SMT of fixed depth, as described in Section~\ref{sec:cryptographic-primitives:merkle-trees}. In contrast to the census tree, which remains static once the election begins, the state tree is dynamic: it is updated throughout the process as new votes are cast, validated, and incorporated by the sequencers.
36
37The leaves of the state tree store the global process parameters, the encrypted ballots, and the set of vote identifiers, as illustrated in Figure~\ref{fig:mt-state}. More specifically:
38
39\paragraph{Reserved addresses for metadata.} The first six addresses are reserved for the process parameters as follows:
40
41\begin{itemize}
42 \item \texttt{0x0}: it stores a unique identifier for the election (\processid).
43 \item \texttt{0x1}: it stores the committed census root (\censusroot). %and \type, a field in case the organization was using a different structure for the census than a MT.
44 \item \texttt{0x2}: it stores the ballot mode configuration, which is the set of rules for validating votes (\ballotmode).
45 \item \texttt{0x3}: it stores the encryption public key used to encrypt the votes (\epk).
46 \item \texttt{0x4}: it stores an accumulator of the encrypted votes that need to be added to the tally (\addaccumulator).
47 \item \texttt{0x5}: it stores an accumulator of the encrypted votes that need to be substracted from the tally because they have been overwritten (\substractaccumulator).
48\end{itemize}
49
50\paragraph{Encrypted ballots.} Each voter’s encrypted ballot is stored in the state tree at a leaf whose path corresponds to their Ethereum address (or another unique identifier). The leaf value is the ciphertext corresponding to the ballot encrypted under the election’s encryption public key. If the voter later overwrites their ballot, the same path is updated with the new ciphertext.
51
52\paragraph{Vote identifiers.} In addition to storing ballots, the state tree also tracks the set of vote identifiers. Each vote identifier \voteid, which is derived from the \processid, the voter’s address, and fresh randomness, determines the path to a dedicated leaf. Initially empty, these leaves are filled when the corresponding \voteid is used, thereby recording that it has been consumed. This enables efficient non-membership proofs: before accepting a new ballot, the sequencer checks that the corresponding \voteid path is still empty, and upon inclusion, the leaf is marked as used to prevent reuse. \\
53
54%Figure~\ref{fig:mt-state} illustrates the structure of the state tree, showing the reserved slots for process parameters as well as the leaves used for ballots and vote identifiers.
55
56\begin{figure}[h]
57 \centerline{\includegraphics[width=400pt,draft=false]{\figs/mt-state-mermaid}}
58 \caption{Structure of the state Merkle tree. The first leaves are reserved for global process parameters while subsequent leaves store encrypted ballots indexed by voter addresses and vote identifiers.}
59 \label{fig:mt-state}
60\end{figure}
61
62\paragraph{Initial state.} At the beginning of the election, the state tree is initialized with the process parameters and empty accumulators, and its root ($\stateroot$) is published on-chain.
63
64\paragraph{State transitions.} As the voting progresses, sequencers update the tree whenever new votes are received, producing a new root for each transition. To guarantee correctness, each update is accompanied by a \ac{ZK-SNARK} proof attesting that the transition from the previous root to the new root respects all protocol constraints: ballots are well-formed and comply with the voting rules, voters are eligible according to the census, the \voteid non-membership condition prevents double voting (or overwrites are handled correctly), and encrypted results are aggregated consistently. In addition, sequencers reencrypt stored ciphertexts, including both newly submitted and already included ballots. This mechanism refreshes the randomness of the encrypted votes without altering their underlying content, ensuring receipt-freeness and concealing whether a particular ballot has been overwritten or simply re-randomized.
65
66In this way, the state tree provides a compact and tamper-proof commitment to the current status of the election. At the end of the process, the final state root together with the on-chain verification of all transitions serves as a complete cryptographic record of the election, encapsulating both the tally and the integrity of the entire voting procedure.