% !TeX root = ../build/main.tex The state Merkle tree, denoted by $\hlset{\stateTree}$, represents the evolving global state of an election in \davinci. It is implemented as a \ac{SMT} of fixed depth $D = 64$, as described in Appendix~\ref{sec:cryptographic-primitives:merkle-trees}. The state tree acts as a cryptographic accumulator that compactly commits to all relevant election data, including configuration parameters, vote identifiers, encrypted ballots, and the encrypted tally. By organizing the election state in a single \ac{SMT}, \davinci supports efficient membership and update proofs that can be verified inside \ac{ZK} proofs, enabling succinct and verifiable state transitions. Its structure is depicted in Fig.~\ref{fig:state-tree}. The root of the state tree, denoted $\stateroot$, is committed on-chain and serves as the authoritative reference to the current election state. Each state transition performed by a sequencer updates the tree and produces a new root. The correctness of this update, namely, that it follows the protocol rules and correctly incorporates new votes, is attested by a proof of the batch program, which the $\hlget{\processregistry}$ smart contract verifies before the new root is accepted. \begin{figure}[h] \centerline{\includegraphics[width=\textwidth,draft=false]{\figs/state-tree.pdf}} \setlength{\abovecaptionskip}{5pt} \caption{Structure of the state Merkle tree. The 64-bit key space is split into three namespaces: configuration parameters, encrypted ballot slots, and vote identifiers.} \label{fig:state-tree} \end{figure} \paragraph{Hashing and encoding.} The state tree uses the SHA-256 hash function (\hlget{\Sha}, see Appendix~\ref{sec:cryptographic-primitives:hash}), which both the \ac{zkVM} and the \ac{EVM} evaluate efficiently. A leaf with key $\kappa$ and value $v$ is hashed as $\Sha(\kappa_{\text{LE8}} \conc v_{\text{LE32}} \conc \texttt{0x01})$, where the subscripts denote the little-endian encoding of the key in 8 bytes and of the value in 32 bytes, and an internal node with children $L$ and $R$ is hashed as $\Sha(L \conc R)$. The path of a key is given by its bits, least significant first. Values that are themselves digests, such as the hash of an encrypted ballot, are SHA-256 outputs read as big-endian integers. The state root is the raw 32-byte digest of the root node, and it is stored as such in the registry. Following the arbo convention, a digest denotes the integer of which it is the little-endian encoding; when the root is used as an integer, for instance in the evaluation points of the blobs, its value is read in little-endian order. \paragraph{Namespaced key space.} The state tree operates over keys in the range $[0, 2^D-1]$. To prevent collisions between different categories of data stored in the state, the 64-bit key space is partitioned into three disjoint numeric namespaces using a fixed threshold $N$. We define \( N = 2^{D-1}\), which we use to split the key space into a lower region for configuration parameters and encrypted ballot storage, and an upper region strictly reserved for vote identifiers. Within the lower region, the first sixteen keys are reserved for configuration. This strict separation ensures that configuration entries, vote identifiers, and ballots never collide. \paragraph{Configuration namespace.} The lowest indices of the tree are reserved for a small set of process parameters. Most are configuration values fixed at election setup and never modified thereafter (\processid, \ballotmode, \epk, \censusorigin, \ballotvkhash); the remaining entry is a mutable accumulator (\encresults) updated on every state transition. In all cases these keys occupy deterministic, well-known positions and use a negligible portion of the key space. The entries are: \begin{itemize} \item \texttt{0x0}: the election identifier (\processid), read as a 248-bit integer. \footnote{The indices \texttt{0x1} and \texttt{0x5} are currently unused: \texttt{0x1} is reserved for backward compatibility (historically used for alternative census structures), and \texttt{0x5} is reserved for future use (an earlier design stored a separate subtractive results accumulator there; the current design keeps a single net results accumulator at \texttt{0x4}). The indices \texttt{0x8} to \texttt{0xF} are reserved for future parameters.} \item \texttt{0x2}: the ballot mode configuration, which is the set of rules for validating votes (\ballotmode), packed into a single 247-bit integer (see Section~\ref{sec:ballot-protocol}). \item \texttt{0x3}: the encryption public key used to encrypt the ballots (\epk). For a key with twisted Edwards coordinates $(x,y)$, the leaf stores $\Sha(x_{\text{BE32}} \conc y_{\text{BE32}})$. \item \texttt{0x4}: the running encrypted results (\encresults), stored as the SHA-256 digest of the 64 coordinates of its 16 ciphertexts, each encoded in 32 big-endian bytes. \item \texttt{0x6}: the census origin (\censusorigin). \item \texttt{0x7}: the digest of the ballot circuit's verification key (\ballotvkhash), which fixes the only ballot proofs the batch program accepts for this election. \end{itemize} Let $\configmax$ denote the largest index reserved for configuration parameters, $\configmax = 15$. When an election is created, the \processregistry computes the \emph{genesis root}: the root of the tree that contains exactly the six entries above, with \encresults set to the identity accumulator, in which every ciphertext is the pair of identity points $((0,1),(0,1))$ and therefore an encryption of zero. Every subsequent transition must start from the root the registry holds, so the configuration of an election cannot differ from the one recorded on-chain. \paragraph{Encrypted ballot namespace.} The region immediately following the configuration parameters, the interval $[\configmax + 1, N - 1]$, is reserved for storing encrypted ballots. Ballot storage locations, called \emph{slots}, are deterministic and derived from the voter's identity. For a Merkle census, the slot is derived from the voter's address: \begin{equation} \begin{aligned} h &= \Sha(\texttt{"davinci-slot-v1"} \conc \address_{\text{20}}),\\ \slot(\address) &= (\configmax + 1) + \bigl(\mathsf{BE64}(h_{[0..8]}) \bmod (N - \configmax - 1)\bigr), \end{aligned} \label{eq:slot} \end{equation} where the first eight bytes of the digest $h$ are read as a big-endian integer. For a \ac{CSP} census, the slot is $(\configmax + 1) + \idx$, where $\idx$ is the index signed by the \ac{CSP}. In both cases, the result lies in the ballot namespace. The value stored at a slot is the SHA-256 digest of the voter's latest encrypted ballot, after re-encryption by the sequencer; the ciphertexts themselves are published in the data blobs (see Section~\ref{sec:vocdoni-protocol:circuits:batch}). This construction assigns each eligible voter a unique, reserved leaf in the state tree. Because the address is authenticated by the voter's signature and bound to the census proof (or the index is authenticated by the \ac{CSP}'s signature), a voter can only write to their own slot. Deriving the slot from the address rather than from the voter's position in the census also keeps slots stable when the census grows, and avoids relying on the position of a leaf in a lean \ac{IMT}, which a membership proof does not pin (see Section~\ref{sec:background:mt}). This enables efficient \emph{last-vote-wins} semantics: if a voter overwrites their ballot, the new ciphertext replaces the previous one at the same slot, while the tally is updated by subtracting the old contribution and adding the new one. The uniqueness of slots among the members of a census is discussed in Section~\ref{sec:vocdoni-protocol:census}. Besides the slots written by votes, every state transition also rewrites a random sample of already occupied slots with fresh re-encryptions of the ballots they hold (see Section~\ref{sec:vocdoni-protocol:circuits:batch}). As a consequence, a change in the value of a slot does not reveal whether its voter cast a new ballot. Only the first write to a slot, which turns an empty leaf into an occupied one, is distinguishable, and it reveals that the voter participated, not how. \paragraph{Vote identifier namespace.} The upper portion of the tree, $[N, 2^D - 1]$, is reserved for \emph{vote identifiers} (\voteid), which allow voters to verify that their vote has been included in the election state, without revealing or linking to the corresponding encrypted ballot. Vote identifiers are derived by hashing the process identifier, the voter's address, and fresh randomness, and then mapping the result into the allowed range by setting the most significant bit to 1: \begin{equation} \voteid = N + \bigl(\hlget{\Poseidon}(\processid,\address,k) \bmod N\bigr), \label{eq:voteid} \end{equation} where $k$ is the secret randomness of the voter's ballot encryption. The value stored under a vote identifier is zero: the leaf only records that the identifier has been used. The ballot circuit enforces this derivation, and the batch program enforces that $N \le \voteid < 2^D$ and that each vote identifier is inserted into an empty leaf, guaranteeing that vote identifiers cannot overlap with configuration entries or ballot storage and cannot be reused. Unlike classical nullifiers, vote identifiers are not used to prevent duplicate voting directly: duplicate voting is prevented by the slot, which a voter can only overwrite. Instead, a vote identifier is a receipt of inclusion that does not reveal the slot. Since the vote identifier depends on a fresh random value $k$, if a collision occurs (i.e., the computed leaf is already occupied), the sequencer rejects the ballot, and the batch program would reject any transition that inserted it. In that case, the voter must resample $k$, re-encrypt the ballot, and recompute a new vote identifier until an unused leaf is obtained. As a result, collisions do not compromise correctness or liveness, but merely require retrying the identifier derivation. Note that the maximum number of vote identifiers that can be stored is bounded by the size of this namespace ($2^{D-1}$), which upper-bounds the total number of votes and overwrites that can be processed throughout the election. This capacity is orders of magnitude larger than any realistic election workload: historical elections peak at $\approx 10^{9}$ votes~\cite{reuters2024india}, ensuring that identifier exhaustion is practically impossible and that collisions are exceptionally rare \footnote{Based on the birthday paradox, the probability of at least one collision occurring is given by $P=1 - e^{-n^2/2d}$, where $n$ is the number of vote identifiers and $d = 2^{D-1}$. For a large-scale national election of $10^8$ votes emitted, this probability is vanishingly small ($\approx0.054\%$), and for an extreme workload of $10^9$ votes, the probability of a single collision is only $\approx5.3\%$, meaning that the need to resample $k$ remains highly improbable.}. Together, the state tree provides a compact and tamper-proof commitment to the current status of the election. At the end of the election, 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.