% !TeX root = ../build/main.tex The ballot protocol provides a unified and parametric way to represent a wide range of voting systems within \davinci. Instead of designing a separate circuit for each voting rule, the protocol defines ballots as fixed-length arrays of integers, subject to a small set of configurable parameters. These parameters constrain the values that can appear in each field of the ballot and the aggregate properties of the ballot as a whole. By adjusting these parameters, the same circuit can implement approval voting, ranking, quadratic voting, multiple choice, and many other schemes. In the protocol we refer to the different configurations as the \emph{ballot mode} ($\ballotmode$). This abstraction has two key advantages. First, it allows a broad variety of voting systems to be supported with a minimal circuit design, avoiding conditional logic that would otherwise increase constraint counts. Second, it provides a common interface for tallying, since all ballots are aggregated into a single results array regardless of the voting mode. \paragraph{Definition of parameters.} Each ballot is defined as an array of integer values subject to a set of configurable parameters, illustrated in Fig.~\ref{fig:ballot-variables}. These parameters are defined as follows: \begin{itemize} \item \numfields: the number of fields (i.e., options) in the ballot, between $1$ and $16$. The ballot circuit and the batch program always handle $16$ fields; the fields beyond \numfields are inactive. \item \groupsize: the size of the groups into which an application may split the fields to present several questions in one ballot. It must not exceed \numfields, and it does not change the constraints below. \item \minvalue: the minimum value that each field in the ballot can take. \item \maxvalue: the maximum value that each field in the ballot can take. \item \uniquevalues: a Boolean flag indicating whether all field values must be different (as in ranking systems). \item \costexponent: the exponent applied when computing the cost of casting votes in a field. This parameter enables quadratic or higher-order voting rules. \item \minvaluesum: the minimum allowed total sum of a ballot, computed as $\sum_{i=1}^{\numfields} v_i^{\costexponent}$, where $v_i$ are the field values. \item \maxvaluesum: the maximum allowed total sum of a ballot, computed as $\sum_{i=1}^{\numfields} v_i^{\costexponent}$, where $v_i$ are the field values (e.g., to enforce a budget of credits). The value zero means that the bound is the voter's weight. \end{itemize} \vspace{-0.5cm} \begin{figure}[H] \centering \includegraphics[scale = 0.8, draft = false]{\figs/ballot-variables.pdf} \caption{Schematic representation of the parameters that define a ballot in \davinci.} \label{fig:ballot-variables} \end{figure} \vspace{-0.6cm} \noi The ballot mode is stored in the state tree, and given to the ballot circuit, packed into a single integer below $2^{247}$, as shown in Fig.~\ref{fig:ballot-mode-packing}. The packing fixes the range of every parameter: \maxvalue and \minvalue are below $2^{48}$, \minvaluesum and \maxvaluesum below $2^{63}$, and \costexponent, \numfields, and \groupsize below $2^{8}$. When a process is created, the registry rejects a ballot mode that does not fit this packing or that violates $1 \le \numfields \le 16$, $\groupsize \le \numfields$, $\minvalue \le \maxvalue$, or $\minvaluesum \le \maxvaluesum$, and it rejects a process whose worst-case tally could not be decrypted, i.e., one with $\maxvalue \cdot \maxvoters > 10^{12}$. \begin{figure}[h] \centerline{\includegraphics[width=0.85\textwidth,draft=false]{\figs/ballot-mode-packing.pdf}} \setlength{\abovecaptionskip}{5pt} \caption{Packing of the ballot mode into one integer. Numbers below the fields are the position of their least significant bit.} \label{fig:ballot-mode-packing} \end{figure} \paragraph{Definition of constraints.} Given a ballot with $n_f = \numfields$ active fields, each filled with a value $v_i$ for $i = 1, \dots, n_f$, and cast by a voter with weight $\weight$, we enforce the following constraints (captured in Fig.~\ref{fig:ballot-variables}): \begin{itemize} \item $\groupsize \le \numfields = n_f$, \item If $\uniquevalues = \true$, then $v_i \neq v_j$ for all $i\neq j$. \item $\minvalue \leq v_i \leq \maxvalue$ for all $i\in\{1, \dots, n_f\}$. \item $\minvaluesum \leq \sum_{i=1}^{n_f} v_i^{\costexponent} \leq \mathsf{max}$, where $\mathsf{max} = \maxvaluesum$ if $\maxvaluesum > 0$, and $\mathsf{max} = \weight$ otherwise. \end{itemize} The inactive fields $n_f < i \le 16$ are not constrained by the ballot circuit, but the batch program requires their ciphertexts to be the identity, so they always contribute zero to the tally. \paragraph{General mechanism.} A ballot is valid if and only if all the above constraints are satisfied. Invalid ballots are rejected at the circuit level and do not contribute to the tally. Valid ballots are aggregated into a results array, where each entry is the sum of all votes cast for the corresponding field across all voters. Voter weights, defined in the census (see Section~\ref{sec:vocdoni-protocol:census}), enter the ballot rules as a budget: when \maxvaluesum is zero, a voter may distribute at most their weight across the fields, so the weight bounds each voter's contribution to the tally. By default, all voters have the same weight. The ballot circuit enforces the bound with the weight committed in \ballotinputshash, and the batch program checks that this weight is the one certified by the census (see Sections~\ref{sec:vocdoni-protocol:circuits:ballot} and~\ref{sec:vocdoni-protocol:circuits:batch} for further details). \paragraph{Ballot modes.} Ballot modes correspond to different voting systems, each adjusted with the variables above ballot configurations. For usability, the organizer does not need to set every parameter manually: instead, they simply select one of the predefined ballot modes (e.g., quadratic voting, ranking, approval), each corresponding to a fixed parameter configuration. Some representative modes are shown in Table~\ref{tab:ballot-modes}, which illustrates the expressiveness of the ballot protocol. For example, in \emph{approval voting}, each field is binary and voters can approve or reject multiple options simultaneously. In \emph{ranking}, fields must form a permutation of the integers from $1$ to \numfields, enforcing uniqueness of values. In \emph{quadratic voting}, voters allocate credits across options, and the cost is quadratic in the number of credits used, captured by setting \costexponent$=2$. Other systems such as single-choice or multiple-choice elections are special cases of the same framework. Table~\ref{tab:ballot-examples} illustrates examples of voters' ballots, with the last column indicating whether each ballot is valid or invalid under the rules of the selected mode, and the tally of the valid ones. \begin{table}[h] \centering \caption{Voting systems expressed as ballot modes. Each row is a fixed configuration of the ballot parameters; \groupsize is zero in all of them.} \label{tab:ballot-modes} \scriptsize \begin{tabular}{p{0.11\textwidth} p{0.19\textwidth} p{0.2\textwidth} c c c c c c c} \toprule \textbf{Mode} & \textbf{Description} & \textbf{Example} & \rotatebox{90}{\numfields} & \rotatebox{90}{\minvalue} & \rotatebox{90}{\maxvalue} & \rotatebox{90}{\uniquevalues} & \rotatebox{90}{\costexponent} & \rotatebox{90}{\minvaluesum} & \rotatebox{90}{\maxvaluesum} \\ \midrule Approval & Several fields, each 0 or 1 & A referendum with 5 yes/no questions & 5 & 0 & 1 & \texttt{false} & 1 & 0 & 5 \\ Rating & Each field rated independently & Rate 5 items from 0 to 10 stars & 5 & 0 & 10 & \texttt{false} & 1 & 0 & 50 \\ Ranking & Number the options from 1 to $n_f$, each number once & Rank 5 destinations for a school trip & 5 & 1 & 5 & \texttt{true} & 1 & 6 & 15 \\ Quadratic & Distribute credits among the options, at quadratic cost & Distribute 12 credits among 5 options & 5 & 0 & 12 & \texttt{false} & 2 & 0 & 12 \\ Single choice & Select one option & Select one winner among 5 candidates & 5 & 0 & 1 & \texttt{false} & 1 & 1 & 1 \\ Multiple choice & Select up to a given number of options & Select up to 3 finalists among 5 candidates & 5 & 0 & 1 & \texttt{false} & 1 & 0 & 3 \\ \bottomrule \end{tabular} \end{table} \begin{table}[h] \centering \caption{Example ballots for the modes of Table~\ref{tab:ballot-modes}. For each ballot, the cost sum $\sum_i v_i^{\costexponent}$ and whether it is valid (1) or invalid (0) under the mode; the last row of each mode is the tally of its valid ballots.} \label{tab:ballot-examples} \footnotesize \begin{tabular}{l l ccccc c c} \toprule \textbf{Mode} & & $v_1$ & $v_2$ & $v_3$ & $v_4$ & $v_5$ & \textbf{Cost sum} & \textbf{Valid} \\ \midrule \multirow{4}{*}{Approval} & ballot 1 & 0 & 1 & 0 & 1 & 1 & 3 & 1 \\ & ballot 2 & 1 & 1 & 1 & 1 & 1 & 5 & 1 \\ & ballot 3 & 0 & 1 & 0 & 0 & 0 & 1 & 1 \\ & \textbf{tally} & \textbf{1} & \textbf{3} & \textbf{1} & \textbf{2} & \textbf{2} & & \textbf{3} \\ \midrule \multirow{4}{*}{Rating} & ballot 1 & 8 & 6 & 4 & 7 & 10 & 35 & 1 \\ & ballot 2 & \textcolor{red}{5} & \textcolor{red}{4} & \textcolor{red}{6} & \textcolor{red}{12} & \textcolor{red}{4} & \textcolor{red}{31} & 0 \\ & ballot 3 & 0 & 1 & 3 & 5 & 2 & 11 & 1 \\ & \textbf{tally} & \textbf{8} & \textbf{7} & \textbf{7} & \textbf{12} & \textbf{12} & & \textbf{2} \\ \midrule \multirow{4}{*}{Ranking} & ballot 1 & 1 & 3 & 2 & 4 & 5 & 15 & 1 \\ & ballot 2 & \textcolor{red}{1} & \textcolor{red}{5} & \textcolor{red}{3} & \textcolor{red}{4} & \textcolor{red}{5} & \textcolor{red}{18} & 0 \\ & ballot 3 & \textcolor{red}{0} & \textcolor{red}{1} & \textcolor{red}{3} & \textcolor{red}{5} & \textcolor{red}{2} & \textcolor{red}{11} & 0 \\ & \textbf{tally} & \textbf{1} & \textbf{3} & \textbf{2} & \textbf{4} & \textbf{5} & & \textbf{1} \\ \midrule \multirow{4}{*}{Quadratic} & ballot 1 & 1 & 1 & 2 & 0 & 0 & 6 & 1 \\ & ballot 2 & \textcolor{red}{3} & \textcolor{red}{0} & \textcolor{red}{0} & \textcolor{red}{0} & \textcolor{red}{2} & \textcolor{red}{13} & 0 \\ & ballot 3 & 3 & 1 & 0 & 1 & 0 & 11 & 1 \\ & \textbf{tally} & \textbf{4} & \textbf{2} & \textbf{2} & \textbf{1} & \textbf{0} & & \textbf{2} \\ \midrule \multirow{4}{*}{Single choice} & ballot 1 & 1 & 0 & 0 & 0 & 0 & 1 & 1 \\ & ballot 2 & 0 & 1 & 0 & 0 & 0 & 1 & 1 \\ & ballot 3 & \textcolor{red}{0} & \textcolor{red}{1} & \textcolor{red}{1} & \textcolor{red}{0} & \textcolor{red}{0} & \textcolor{red}{2} & 0 \\ & \textbf{tally} & \textbf{1} & \textbf{1} & \textbf{0} & \textbf{0} & \textbf{0} & & \textbf{2} \\ \midrule \multirow{4}{*}{Multiple choice} & ballot 1 & 1 & 0 & 1 & 1 & 0 & 3 & 1 \\ & ballot 2 & 0 & 1 & 1 & 0 & 1 & 3 & 1 \\ & ballot 3 & \textcolor{red}{1} & \textcolor{red}{2} & \textcolor{red}{3} & \textcolor{red}{0} & \textcolor{red}{0} & \textcolor{red}{6} & 0 \\ & \textbf{tally} & \textbf{1} & \textbf{1} & \textbf{2} & \textbf{1} & \textbf{1} & & \textbf{2} \\ \bottomrule \end{tabular} \end{table}