arnaucube
arnaucube/davinci-paperPublic Self-hosted repository
davinci-paper/v2/sections/cryptographic-primitives.tex
v2/sections/cryptographic-primitives.texRaw
  1% !TeX root = ../build/main.tex
  2
  3%hash-based commitments: trees
  4%authentication: signatures
  5%confidentiality: encryption
  6%decentralized trust: DKG
  7%verifiability: ZKPs
  8
  9In this section, we present the cryptographic primitives used in the protocol described in Section~\ref{sec:vocdoni-protocol}. We first introduce elliptic curves as the underlying algebraic setting, and then describe the following building blocks, each tied to a specific role in the system: hash functions and Merkle trees for commitments to structured data; digital signatures for voter authentication; encryption schemes for ballot confidentiality; \ac{DKG} for decentralizing trust in the election keys; and zero-knowledge proofs (\acp{ZK-SNARK}) for verifiability of computations. For each primitive, we also specify the concrete choice of parameters used.
 10
 11%\paragraph{Notation.} Throughout the document, we use the following conventions. Given a set $S$, we denote sampling an element $x$ uniformly at random from $S$ by $x \sample S$. We denote all bitstrings of arbitrary length by $\{0,1\}^*$. 
 12%Any group $\G$ used is of a large prime order, and we assume that the discrete logarithm problem is hard in $\G$. If two elements are denoted by the same letter in upper and lower case, e.g. $a, A$, this often means that $A$ is a public key corresponding to the secret key $a$. 
 13%$\F_p$ denotes de finite field of order $p$, and $\F_p^* = \F_p/\{0\}$.
 14
 15\subsection{Elliptic curves}
 16\label{sec:cryptographic-primitives:elliptic-curves}
 17
 18\Davinci relies on multiple elliptic curves to ensure interoperability with Ethereum, compatibility with available cryptographic primitives, and efficient in-circuit operations. On the one hand, SECP256K1~\cite{brown2010sec} is used because Ethereum public keys are elements of this curve. As \Davinci assumes each voter holds a standard Ethereum address, cryptographic operations such as digital signatures and identity verification rely on SECP256K1 to match the Ethereum ecosystem. On the other hand, BN254~\cite{wood2014ethereum} is chosen because it is the curve supported by Ethereum's precompiled contracts for ZK proof verification, which makes it the optimal choice for verifying SNARK proofs on-chain with minimal gas cost. Then, BabyJubjub~\cite{belles2021twisted} is used as an inner curve for elliptic curve operations within arithmetic circuits. Finally, BLS12-377~\cite{bowe2020zexe} and BW6-761~\cite{elhousni2020optimized} are used to enable recursive proof composition. More specifically, BLS12-377 acts as the inner curve for constructing proofs, while BW6-761 serves as the outer curve that verifies those proofs within larger ZK-SNARK circuits. This pairing enables succinct verification and composability of ZK-SNARKs within other ZK-SNARKs, which we use for \davinci’s aggregation and state transition logic. Below, we give the details of these curves.
 19
 20\paragraph{Parameters.}
 21
 22\begin{itemize}
 23	%
 24	\item[$\bullet$] $p = \tt{\hspace{0.04cm}0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f}$ (256-bit prime).
 25	\item[$\bullet$] $q = \tt{\hspace{0.01cm}0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141}$ (256-bit prime).	
 26	%
 27	\item[$\bullet$] $r = \tt{0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47}$ (254-bit prime).
 28	\item[$\bullet$] $s = \tt{\hspace{0.03cm}0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001}$ (254-bit prime).
 29	\item[$\bullet$] $t = \tt{\hspace{0.07cm}0x60c89ce5c263405370a08b6d0302b0bab3eedb83920ee0a677297dc392126f1}$ (251-bit prime).
 30	%
 31	\item[$\bullet$] $u = \tt{0x122e824fb83ce0ad187c94004faff3eb926186a81d14688528275ef8087be41707ba638e584e9190}$
 32	\item[] \hspace{0.53cm} $\tt{3cebaff25b423048689c8ed12f9fd9071dcd3dc73ebff2e98a116c25667a8f8160cf8aeeaf0a437e69}$
 33	\item[] \hspace{0.53cm} $\tt{13e6870000082f49d00000000008b}$ (761-bit prime).
 34	\item[$\bullet$] $v = \tt{0x01ae3a4617c510eac63b05c06ca1493b1a22d9f300f5138f1ef3622fba094800170b5d4430000000}$
 35	\item[] \hspace{0.52cm} $\tt{8508c00000000001}$ (377-bit prime).
 36	\item[$\bullet$] $w = \tt{0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a11800000000001}$ (253-bit prime).
 37	%
 38\end{itemize}
 39
 40\paragraph{Elliptic curve groups.}
 41\begin{itemize}
 42	%
 43	\item SECP256K1 curve: $\SEC{E}/\F_p$ defined by equation $\SEC{E}: y^2 = x^3 + 7$, with group $\SEC{\G}$ of prime order $q$. 
 44	%
 45	\item BN254 curve: $\BN{E}/\F_r$ defined by equation \( \BN{E}: y^2 = x^3 + 3\), with subgroups $\BN{\G}_1, \BN{\G}_2$ of prime order $s$, and an efficiently computable pairing \(e:\BN{\G}_1\times\BN{\G}_2 \rightarrow \BN{\G}_T,\) where $\BN{\G}_T \subset \F_{s^{12}}$ and has order $s$. 
 46	\item BabyJubjub curve: $\BJ{E}/\F_s$ defined by equation $\BJ{E}: 168700 x^2 + y^2 = 1 + 168696 x^2y^2$, with subgroup $\BJ{\G}$ of prime order $t$. 
 47	%
 48	\item BW6-761 curve: $\BW{E}/\F_u$ defined by equation $\BW{E}: y^2 = x^3 - 1$, with subgroups $\BW{\G}_1, \BW{\G}_2$ of prime order $v$, and an efficiently computable pairing \({e}:\BW{\G}_1\times\BW{\G}_2 \rightarrow \BW{\G}_T,\) where $\BW{\G}_T \subset \F_{v^{6}}$ and has order $v$ as well. 
 49	\item BLS12-377 curve: $\BLS{E}/\F_v$ defined by equation \(\BLS{E}: y^2 = x^3 + 1,\) with subgroups $\BLS{\G}_1, \BLS{\G}_2$ of prime order $w$, and an efficiently computable pairing \({e}:\BLS{\G}_1\times\BLS{\G}_2 \rightarrow \BLS{\G}_T,\) where $\BLS{\G}_T \subset \F_{w^{12}}$ and has order~$w$. 
 50	%
 51\end{itemize}
 52
 53\paragraph{Finite fields.}
 54\begin{itemize}
 55	%
 56	\item $\F_p$: base field of the SECP256K1 curve.
 57	\item $\F_q$: scalar field of $\SEC{\G}$.
 58	%
 59	\item $\F_r$: base field of the BN254 curve.	
 60	\item $\F_s$: scalar field of $\BN{\G}_1, \BN{\G}_2, \BN{\G}_T$ and base field of the BabyJubjub curve.
 61	\item $\F_t$: scalar field of $\BJ{\G}$.
 62	%
 63	\item $\F_u$: base field of the BW6-761 curve.
 64	\item $\F_v$: scalar field of $\BW{\G}_1, \BW{\G}_2, \BW{\G}_T$ and base field of the BLS12-377 curve.
 65	\item $\F_w$: scalar field of $\BLS{\G}_1, \BLS{\G}_2, \BLS{\G}_T$.
 66	%
 67\end{itemize}
 68
 69\paragraph{Generators.}\mbox{}\\
 70
 71\noi We denote by $\hlget{\SEC{G}}$ the generator of $\SEC{\G}$ as defined in~\cite{brown2010sec}, $\hlget{\BN{G}}$ the generator of $\BN{\G}_1$ as defined in~\cite{wood2014ethereum}, $\hlget{\BJ{G}}$ the generator of $\BJ{\G}$ as defined in~\cite{erc2494}, $\hlget{\BW{G}}$ the generator of $\BW{\G}_1$ as defined in~\cite{eip3026}, and $\hlget{\BLS{G}}$ the generator of $\BLS{\G}_1$ as defined in~\cite{eip2539}.
 72
 73\begin{itemize}
 74	\item
 75		$
 76		\hlset{\SEC{G}} = 
 77		(\tt{0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,0x483ada7726} \allowbreak
 78		\rule{1.37cm}{0pt}
 79		\tt{a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8}).
 80		$
 81	\item 
 82		$
 83		\hlset{\BN{G}}\hspace{0.14cm} = \: (\tt{0x01}, \tt{0x02}).
 84		$
 85
 86	\item
 87		$
 88		\hlset{\BJ{G}}\hspace{0.18cm} = 
 89		\hspace{0.09cm} (\tt{0x0b9feffffffffaaabfffffffffffffffeffffffffffffffffffffffffffffff}, 
 90		\tt{0x17fffffffff} \\
 91		\rule{1.37cm}{0pt}
 92		\tt{ffffffffffffffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141}).				
 93		$
 94	\item 
 95		$
 96		\hlset{\BW{G}}\hspace{0.085cm} = 
 97		\hspace{0.09cm} (\tt{0x1075b020ea190c8b277ce98a477beaee6a0cfb7551b27f0ee05c54b85f56fc779017ffac15520}\\
 98		\rule{1.37cm}{0pt}
 99		\tt{ac11dbfcd294c2e746a17a54ce47729b905bd71fa0c9ea097103758f9a280ca27f6750dd0356133}\\
100		\rule{1.37cm}{0pt}		
101		\tt{e82055928aca6af603f4088f3af66e5b43d, 0x58b84e0a6fc574e6fd637b45cc2a420f952589884} \\
102		\rule{1.37cm}{0pt}
103		\tt{c9ec61a7348d2a2e573a3265909f1af7e0dbac5b8fa1771b5b806cc685d31717a4c55be3fb90b6f} \\
104		\rule{1.37cm}{0pt}
105		\tt{c2cdd49f9df141b3053253b2b08119cad0fb93ad1cb2be0b20d2a1bafc8f2db4e95363)}.
106		$
107	\item 
108		$
109		\hlset{\BLS{G}}\hspace{0.07cm} = 
110		\hspace{0.06cm}(\tt{0x008848defe740a67c8fc6225bf87ff5485951e2caa9d41bb188282c8bd37cb5cd5481512ffcd3} \\
111		\rule{1.37cm}{0pt}
112		\tt{94eeab9b16eb21be9ef,0x01914a69c5102eff1f674f5d30afeec4bd7fb348ca3e52d96d182ad44} \\
113		\rule{1.37cm}{0pt}
114		\tt{fb82305c2fe3d3634a9591afd82de55559c8ea6}).
115		$
116\end{itemize}
117
118%\begin{itemize}
119%	\item Generator of $\SEC{\G}$ as defined in~\cite{}: 
120%	\begin{align*}
121%		\hlset{\SEC{G}} = 
122%		(&\tt{0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798},\\
123%		&\tt{0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8}).
124%	\end{align*}
125%	%
126%	\item Generator of $\BN{\G}_1$ as defined in~\cite{}:
127%	%https://ethereum.github.io/yellowpaper/paper.pdf
128%	\begin{align*}
129%		\hlset{\BN{G}} = 
130%		(\tt{0x01}, \tt{0x02}).
131%	\end{align*}
132%	% (-1, 1) o bé (1, 2)?
133%	%
134%	\item Generator of $\BJ{\G}$ as defined in~\cite{}:
135%	%https://eips.ethereum.org/EIPS/eip-2494
136%	\begin{align*}
137%		\hlset{\BJ{G}} = 
138%		(&\tt{0x0b9feffffffffaaabfffffffffffffffeffffffffffffffffffffffffffffff},\\
139%		&\tt{0x17fffffffffffffffffffffffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141}).
140%	\end{align*}
141%	%
142%	\item Generator of $\BW{\G}_1$ as defined in~\cite{}:
143%	%https://eips.ethereum.org/EIPS/eip-3026
144%	\begin{align*}
145%		\hlset{\BW{G}} = 
146%		(&\tt{0x1075b020ea190c8b277ce98a477beaee6a0cfb7551b27f0ee05c54b85f56fc779017ffac15520ac11dbfcd294c2e746a17a54ce47729b905bd71fa0c9ea097103758f9a280ca27f6750dd0356133e82055928aca6af603f4088f3af66e5b43d},\\
147%		&\tt{0x58b84e0a6fc574e6fd637b45cc2a420f952589884c9ec61a7348d2a2e573a3265909f1af7e0dbac5b8fa1771b5b806cc685d31717a4c55be3fb90b6fc2cdd49f9df141b3053253b2b08119cad0fb93ad1cb2be0b20d2a1bafc8f2db4e95363}).
148%	\end{align*}
149%	%
150%	\item Generator of $\BLS{\G}_1$ as defined in~\cite{}:
151%	%https://eips.ethereum.org/EIPS/eip-2539
152%	\begin{align*}
153%		\hlset{\BLS{G}} = 
154%		(&\tt{0x008848defe740a67c8fc6225bf87ff5485951e2caa9d41bb188282c8bd37cb5cd5481512ffcd394eeab9b16eb21be9ef},\\
155%		&\tt{0x01914a69c5102eff1f674f5d30afeec4bd7fb348ca3e52d96d182ad44fb82305c2fe3d3634a9591afd82de55559c8ea6}).
156%	\end{align*}
157%	%
158%\end{itemize}
159
160\subsection{Hash functions}
161\label{sec:cryptographic-primitives:hash}
162
163\Davinci uses different hash functions. On the one side, we use Keccak256~\cite{bertoni2011keccak} for Ethereum address derivation, and Poseidon~\cite{grassi2021poseidon}, MiMC and MiMC-7~\cite{albrecht2016mimc} for arithmetic circuits within zero-knowledge proofs.
164
165\paragraph{Keccak256.} Keccak256 is the standard hash function used by Ethereum and is employed in \davinci to compress messages for signing and deriving Ethereum addresses from public keys over $\SEC{\G}$. Keccak256 takes arbitrary-length bitstrings and outputs 256-bit digests: $\hlset{\Keccak} : \{0,1\}^* \rightarrow \{0,1\}^{256}$. This function is not SNARK-friendly and it is used exclusively in the authentication circuit, where the verification of Ethereum-compatible signatures requires reproducing the original message hash computed by Ethereum clients (see Section~\ref{sec:vocdoni-protocol:circuits:verifier}).
166
167\paragraph{Poseidon.} Poseidon is a SNARK-optimized hash function designed for efficient implementation inside arithmetic circuits. It is used in \davinci for computing commitments, nullifiers, and the state Merkle tree roots. Poseidon is used as $\hlset{\Poseidon} : \mathfrak{F}_s \rightarrow \F_s$, where $\mathfrak{F}_s$ is the set of tuples of $\F_s$-elements of any length, and $\F_s$ is the field described in Section~\ref{sec:cryptographic-primitives:elliptic-curves}.
168
169{\color{blue} \paragraph{MiMC-7.} Finally, we use  functions from the MiMC family. On the one side, MiMC-7 hash function $\hlset{\Mimc} : \F_p \rightarrow \F_p$, where $\F_p$ is the set of tuples of $\F_p$-elements of any length, and $\F_p$ is the field described in Section~\ref{sec:cryptographic-primitives:elliptic-curves}. This hash is used to hash the public inputs of the different circuits and verify the associated proofs more efficiently (see Section~\ref{sec:vocdoni-protocol:circuits} for further details). On the other side, $\hlset{\Multimimc}$. Different curves.}
170
171%MiMC-7~\cite{mimc} is another hash function optimized for zero-knowledge circuits, with extremely low multiplicative complexity. It is used in \davinci for hashing public inputs inside zkSNARKs, especially when generating a unique identifier for a vote (see Section~\ref{sec:vocdoni-protocol:circuits}).
172%We use the cubic S-box S(x)=x7S(x)=x7, and instantiate MiMC-7 over the same field FpFp​ as the SNARK circuit:
173%MiMC7:Fpt→Fp
174%MiMC7:Fpt​→Fp​
175%This function is denoted Hash3Hash3 in our implementation.
176
177{\color{blue} For the sake of clarity, in our notation we admit anything as an input of the above hash functions, although it might not be parsed as a sequence of field elements. Any bitstring can be converted to a tuple of field elements, so this does not change the actual working of the hash computation. In this document, it is implied that the proper conversion happens before feeding the input into the actual hash function.}
178
179%\subsection{Commitment schemes}
180%\label{sec:cryptographic-primitives:commitments}
181
182%Pedersen commitment scheme~\cite{pedersen1991non}. 
183
184\subsection{Merkle trees}
185\label{sec:cryptographic-primitives:merkle-trees}
186
187{\color{blue}\textbf{TODO}: Add description of Incremental Merkle trees.}\\
188
189The \davinci protocol uses sparse Merkle Trees (SMTs) as its primary data structure for maintaining off-chain state. Following the construction in~\cite{baylina2019sparse}, these are full binary trees of fixed depth in which each leaf encodes a key-value pair and empty leaves are explicitly represented, allowing for both inclusion and non-inclusion proofs. A key property of SMTs is that the hash of each key determines a unique traversal path from the root to the leaf, regardless of insertion order. When inserting a new key, the tree descends until it encounters either an empty node or a leaf. In case of a path collision, the algorithm splits at the first differing bit, creating intermediate nodes accordingly. 
190%SMTs support efficient membership and non‑membership proofs, enabling a party to prove that a given key-value is (or is not) present in the tree without revealing the content. 
191
192In \davinci, SMTs are used to represent two core data structures: the census tree, which encodes the list of eligible voters along with their respective voting weights, and the state tree, which encodes the current status of submitted votes. Both trees have fixed depth 64. The census tree is instantiated with the MiMC hash function over the BLS12-377 scalar field, while the state tree uses Poseidon over the BN254 scalar field. Only the root hash of each tree is published on-chain, ensuring verifiability with minimal on-chain storage. 
193%
194To support state transitions and circuit verification, each tree $\tree{}$ has the following functions associated:
195
196\begin{itemize}
197	\item $\tree.\hlset{\MTRoot}()$: it returns the current Merkle root of the tree.
198	\item $\tree.\hlset{\MTInsert}(path, \leaf)$: it inserts a new leaf $\leaf$ at the position defined by the given path.
199	\item $\tree.\hlset{\MTUpdate}(\leaf_{old}, \leaf)$: it updates an existing leaf in the tree.
200	\item $\tree.\hlset{\MTMembershipProof}(\leaf)$: it returns a Merkle proof of inclusion for the given leaf.
201	\item $\tree.\hlset{\MTNonMembershipProof}(\leaf)$: it returns a proof that the given leaf is not included in the tree.
202	\item $\tree.\hlset{\MTVerify}(\leaf, \MTProof, \root{})$: it verifies that the given proof corresponds to the claimed root and leaf.
203\end{itemize}
204
205These functions are used by sequencers to construct proofs that certify the validity of state transitions. In particular, they allow for off-chain state evolution that is independently verifiable on-chain and within ZK circuits. Additional details on the structure of the census and state trees, as well as the encoding of their leaves, are provided in Sections~\ref{sec:vocdoni-protocol:census} and~\ref{sec:vocdoni-protocol:state-tree}.
206
207\subsection{Commitment schemes}
208\label{sec:cryptographic-primitives:commitments}
209
210{\color{blue} Description of KZG~\cite{kate2010constant} with SRS \textbf{[add link to Ethereum's BLS12-381 SRS]}, $\hlset{\CCommit}()$, and $\hlset{\CVerify}()$.}\\
211Original methods: \hlset{\CSetup}, \hlset{\COpen}, \hlset{\CVerifyPoly}, \hlset{\CCreateWitness}, \hlset{\CVerifyEval}, \hlset{\CProve}, \hlset{\CVerify}.
212
213\subsection{Digital signature schemes}
214\label{sec:cryptographic-primitives:signatures}
215
216{\color{blue}{\textbf{TODO}: add \hlset{\SPubKey} that extracts $\pk$ from $\signature$ (in Ethereum it's called \texttt{ECRecover}).}}\\
217
218\noi \Davinci uses the {elliptic curve digital signature algorithm} (ECDSA)~\cite{johnson2001ecdsa} over the SECP256K1 curve to ensure compatibility with standard Ethereum wallets. %, such as MetaMask~\ref{} or Ledger~\ref{}, 
219%
220%\Davinci uses the elliptic curve digital signature algorithm (ECDSA)~\cite{johnson01ecdsa} over the SECP256K1 curve for user authentication and vote authorization. This decision is taken to ensure that \davinci is compatible with standard Ethereum wallets, such as MetaMask~\ref{} or Ledger~\ref{}, without requiring users to generate or manage additional cryptographic keys. 
221%
222Verification of ECDSA signatures is performed inside zero-knowledge proofs using a specialized circuit that emulates SECP256K1 arithmetic. This approach is necessary because SECP256K1 is defined over a 256-bit prime field that differs from the native field used in the ZK-SNARK circuit (see Section\ref{sec:vocdoni-protocol:circuits} for more details). Below, we describe the algorithms, which follow the standard ECDSA protocol.
223%
224{\color{blue} (The output of the hash does not match -- check where variables live.)}
225
226\begin{mdframed}
227	\begin{minipage}[t]{0.46\textwidth}
228		\begin{itemize}
229			\item[$\bullet$] $\hlset{\SSign}_{\sk}(\msg \in \{0,1\}^\star)$:  \vspace{0.1cm}
230			\begin{enumerate}
231				\item Compute $h = \hlget{\Keccak}(\msg) \bmod q$.
232				\item\label{item:ssign-step} Select a random scalar $k \sample \Z_q^{*}$.
233				\item Compute $R = k \cdot \hlget{\SEC{G}} = (x_R, y_R) \in \SEC{\G}$.
234				\item Set $r = x_R \bmod q$. 
235				\begin{itemize}
236					\item If $r = 0$, go back to step~\ref{item:ssign-step}. 
237					\item Else, continue.
238				\end{itemize}
239				\item Compute $s = k^{-1} \cdot (h + r \cdot \sk) \bmod q.$ 
240				\begin{itemize}
241					\item If $s = 0$, go back to step~\ref{item:ssign-step}. 
242					\item Else, continue.
243				\end{itemize}
244				\item Output $\sigma = (r, s)$.
245			\end{enumerate}
246		\end{itemize}
247	\end{minipage}
248	\begin{minipage}[t]{0.54\textwidth}
249		\begin{itemize}
250			\item[$\bullet$] $\hlset{\SVer}_{\pk}(\msg \in \{0,1\}^\star, \sigma = (r, s)\in(\Z_q^*)^2)$: %\vspace{0.1cm}
251			\begin{enumerate}
252				\item Check that $\pk \in \SEC{\G}$.
253				\item Compute $h = \hlget{\Keccak}(\msg) \bmod q$.
254				\item Compute $w = s^{-1} \bmod q$.
255				\item Compute $u_1 = h \cdot w \bmod q$.
256				\item Compute $u_2 = r \cdot w \bmod q$.
257				\item Compute $$X = u_1 \cdot \hlget{\SEC{G}} + u_2 \cdot \pk = (x_X, y_X) \in \SEC{\G}.$$
258				\item Accept if $r = x_X \bmod q$; otherwise, reject.
259			\end{enumerate}
260		\end{itemize}
261	\end{minipage}
262\end{mdframed}
263
264\subsection{Encryption schemes}
265\label{sec:cryptographic-primitives:encryption}
266
267To preserve ballot secrecy while enabling tallying, \davinci employs a threshold variant of the ElGamal cryptosystem instantiated over the BabyJubjub curve~\cite{sutikno1998implementation}. This scheme offers two properties crucial for the protocol: \emph{additive homomorphism}, which allows the aggregation of encrypted votes without decryption, and \emph{re-encryption}, which enables ciphertext randomization without altering the underlying plaintext. Together, these properties allow sequencers to tally votes while preventing voters from producing receipts that could be used for coercion or vote selling. The corresponding public key is generated collectively by the sequencers via the distributed key generation protocol described in Section~\ref{sec:cryptographic-primitives:dkg}, ensuring that no single entity can decrypt ballots unilaterally.
268
269\paragraph{Encryption and decryption.}
270Given a message $m$, the ElGamal encryption algorithm maps it into a group element $M$ of $\BJ{\G}$ and outputs a ciphertext as follows:
271%
272\begin{mdframed}
273	\begin{minipage}[t]{0.54\textwidth}
274		\begin{itemize}
275			\item[$\bullet$] $\hlset{\Enc}_{\pk}(m; k \in \F_t)$:
276			\begin{enumerate}
277				\item Map $m$ to $\BJ{\G}$ via $M = m \cdot \hlget{\BJ{G}}$.
278				\item Compute $C_1 = k \cdot \hlget{\BJ{G}} \in \BJ{\G}$.
279				\item Compute $C_2 = k \cdot \pk + M \in \BJ{\G}$.
280				\item Output $\enc = (C_1, C_2) \in {(\BJ{\G})}^2$.
281			\end{enumerate}
282		\end{itemize}
283	\end{minipage}
284	\begin{minipage}[t]{0.44\textwidth}
285		\begin{itemize}
286			\item[$\bullet$] $\hlset{\Dec}_{\sk}(\enc)$:
287			\begin{enumerate}
288				\item Parse $\enc = (C_1, C_2)$.
289				\item Compute $K = \sk \cdot C_1 \in \BJ{\G}$.
290				\item Output $M = C_2 - K$.
291			\end{enumerate}
292		\end{itemize}
293	\end{minipage}
294\end{mdframed}
295
296Since the plaintext message space is typically small, recovering $m$ from $M$ is efficient: although the mapping $m \mapsto M$ is not generally invertible, it can be reversed by brute-force search or optimized techniques such as baby-step giant-step~\cite{blake1995elliptic}.%Blake: section V.4. 
297
298\paragraph{Homomorphic addition and reencryption.} ElGamal encryption is additively homomorphic. Given two ciphertexts $(C_1, C_2)$ and $(C_1', C_2')$, their component-wise addition yields another valid ciphertext $(C_1 + C_1',\, C_2 + C_2')$. The resulting ciphertext decrypts to the sum of the two underlying messages. This property allows sequencers to aggregate encrypted ballots directly. Moreover, to prevent linkability and ensure receipt-freeness, sequencers also re-randomize ciphertexts. Re-encryption exploits this property by adding to a ciphertext an encryption of zero. This operation yields a fresh ciphertext of the same message under new randomness, making it computationally infeasible to link the re-encrypted ballot with the original submission.
299
300\begin{mdframed}
301	\begin{minipage}[t]{0.53\textwidth}
302		\begin{itemize}
303			\item[$\bullet$] $\hlset{\EncAdd}_{\pk}(\enc \in {(\BJ{\G})}^2, \enc' \in {(\BJ{\G})}^2)$:
304			\begin{enumerate}
305				\item Parse $\enc = (C_1, C_2) \in {(\BJ{\G})}^2$.
306				\item Parse $\enc' = (C_1', C_2') \in {(\BJ{\G})}^2$.
307				\item Output $(C_1 + C_1', C_2 + C_2') \in {(\BJ{\G})}^2$.
308			\end{enumerate}
309		\end{itemize}
310	\end{minipage}
311	\begin{minipage}[t]{0.45\textwidth}
312		\begin{itemize}
313			\item[$\bullet$] $\hlset{\ReEnc}_{\pk}(\enc \in {(\BJ{\G})}^2; k\in\F_t)$: \vspace{0.1cm}
314			\begin{enumerate}
315				\item Parse $\enc = (C_1, C_2) \in {(\BJ{\G})}^2$.
316				\item Compute $\enc' = \hlget{\Enc}_{\pk}(0; k)$.
317				\item Output $\hlget{\EncAdd}_{\pk}(\enc, \enc')$.
318%				\item Compute $C_1' = k \cdot G + C_1 \in \J$.
319%				\item Compute $C_2' = k \cdot \pk + C_2 \in \J$. 
320%				\item Output $\enc' = (C_1', C_2') \in \J^2$.				
321			\end{enumerate}
322		\end{itemize}
323	\end{minipage}
324\end{mdframed}
325
326In the protocol, re-encryption is applied not only to newly submitted ballots but also to ballots already stored in the state tree. By refreshing the randomness of both new and existing ciphertexts, sequencers ensure that it is indistinguishable whether a ballot has been overwritten or merely re-randomized. This mechanism is essential for guaranteeing receipt-freeness: voters cannot produce a verifiable receipt of their choice, and adversaries cannot detect or prove whether a particular vote has been replaced (see Section~\ref{sec:analysis}).
327
328\subsection{Key generation schemes}
329\label{sec:cryptographic-primitives:dkg}
330
331To ensure that no single entity controls the decryption key, DAVINCI employs a \ac{DKG} protocol to jointly derive the ElGamal encryption key pair used for ballots encryption~\cite{todocitation}. Participants who contribute to the \ac{DKG} ceremony are called \emph{\keywardens}, and they are each identified by a unique index~$i$. The outcome is a collective public key (\epk) that is published on-chain and used by voters to encrypt their ballots, while the corresponding private key is secret-shared among the \keywardens. Only a threshold number $t$ out of $n$ \keywardens can later collaborate to decrypt the tally. Unlike classical \ac{DKG} protocols where shares are exchanged in the clear, our construction uses encrypted shares and \ac{ZK-SNARK} proofs of correctness. This allows the Ethereum smart contract to verify compliance without learning any of the underlying secrets, ensuring both security and verifiability in a fully decentralized setting. 
332
333{\color{blue} Let $t$ be the threshold parameter and $n$ the number of \keywardens, with $t\leq n$. Let $G$ be a generator of the elliptic curve group of order $q$. Each participant $P_i$ runs the following procedure.
334
335\begin{mdframed}
336		\begin{itemize}
337			{\color{blue} 
338			\item[$\bullet$] $\hlset{\GenerateEncryptedShares}(i)$: 
339			\begin{enumerate}
340				\item Select random scalars $a_{i,0},\dots,a_{i,t-1} \sample \Z_q$.
341				\item Define the polynomial $f_i(x) = \sum_{j=0}^{t-1} a_{i,j} x^j$.
342				\item For each $j \in \{0,\dots,t-1\}$, compute public commitments $C_{i,j} = a_{i,j}\cdot G$.
343				\item For each participant $P_\ell$ with index
344				$\ell \in \{1,\dots,n\}$, compute the secret share $s_{i,\ell} = f_i(\ell)$.
345				\item Encrypt each $s_{i,\ell}$ under $P_\ell$'s public key using a simplified version of the EC integrated encryption scheme (ECIES), obtaining $EncECIES(s_{i,\ell})$.
346				\item Output $\{C_{i,j}\}_{j=0}^{t-1}$ and $\{EncECIES(s_{i,\ell})\}_{\ell=1}^n$, together with a ZK-SNARK proof attesting that the encrypted values are consistent with the commitments.
347			\end{enumerate}
348			}
349		\end{itemize}
350\end{mdframed}
351
352The smart contract verifies the encrypted shares.
353
354\begin{mdframed}
355		\begin{itemize}
356			{\color{blue} 
357			\item[$\bullet$] $\hlset{\VerifyEncryptedShare}(i, \ell, EncECIES(s_{i,\ell}), \{C_{i,j}\})$: 
358			\begin{enumerate}
359				\item Verify that the ZK-SNARK proof attached to $EncECIES(s_{i,\ell})$ is correct.
360				\item If the proof is valid, the share is accepted; otherwise, the participant $P_i$ may be slashed.
361			\end{enumerate}
362		}
363		\end{itemize}
364\end{mdframed}
365
366After collecting valid encrypted shares, each participant $P_j$ can recover their secret share $s_j$ by decrypting all contributions addressed to them:}
367
368\begin{mdframed}
369	\begin{itemize}
370	{\color{blue} 
371		\item[$\bullet$] $\hlset{\DeriveSecretShare}(j)$:
372		\begin{enumerate}
373			\item Decrypt all $EncECIES(s_{i,j})$ values received from other participants.
374			\item Compute $s_j = \sum_{i=1}^n s_{i,j} \mod q$.
375			\item Output $s_j$.
376		\end{enumerate}
377	}
378	\end{itemize}
379\end{mdframed}
380
381\begin{mdframed}
382	\begin{itemize}
383		{\color{blue} 
384			\item[$\bullet$] $\hlset{\DerivePublicKey}(\{C_{i,0}\}_{i=1}^n)$:
385			\begin{enumerate}
386				\item Compute $pk = \sum_{i=1}^n C_{i,0}$.
387				\item Output $pk$.
388			\end{enumerate}
389			Note that $C_{i,0} = a_{i,0}\cdot G$, so the collective public key corresponds to $pk = s \cdot G$, where $s = \sum_{i=1}^n a_{i,0} \bmod q$ is the collective private key, unknown to any single participant.
390		}
391	\end{itemize}
392\end{mdframed}
393
394This approach ensures that the encryption public key is securely generated in a decentralized way, that each \keywarden learns only their own secret share, and that the correctness of the entire \ac{DKG} procedure is verifiable on-chain. Misbehavior, such as submitting invalid shares, can be detected and penalized through the slashing mechanism enforced by the smart contract (see Section~\ref{sec:token}).
395
396\subsection{Zero-knowledge proof systems}
397\label{sec:cryptographic-primitives:zkp}
398
399{Zero-knowledge succinct non-interactive arguments of knowledge (ZK-SNARKs)} are a crucial component in ensuring the integrity of the election. Voters generate ZK-SNARK proofs to demonstrate that their encrypted ballots comply with the rules and constraints defined by the election parameters, without revealing any information about their choices. Similarly, sequencers produce proofs to certify the correctness of vote aggregation and state transitions throughout the protocol. {\color{blue}\hlset{\PProve}(), \hlset{\PVerify}(proof, PI) -- pkey, vkey.}
400
401All ZK circuits in \davinci are compiled using the Groth16 proof system~\cite{groth2016size}, a widely adopted ZK-SNARK construction known for its succinctness, efficient verification, and minimal proof size. Although all circuits rely on the same proving system, they are instantiated with different elliptic curves depending on the cryptographic requirements of each phase. Specifically, the vote validity circuit is compiled over the BN254 curve, the census-related circuit uses BLS12-377, and the aggregation circuit is instantiated over BW6-761. Finally, the last circuit used by the sequencer—responsible for generating the final proof of correct tallying and result—is compiled over BN254 as well, since this is the proof that is verified on-chain by the smart contract using Ethereum’s native precompiles. Further details on the circuits are provided in Section~\ref{sec:vocdoni-protocol:circuits} and a summary of the instantiations can be found in Figure~\ref{fig:circuits-flow}.