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
  3In this section, we detail the cryptographic primitives used in Section~\ref{sec:vocdoni-protocol}. We briefly introduce elliptic curves, hash functions, Merkle trees, encryption schemes, and proof systems used in the protocol. We also specify at each step the concrete parameters with which each of the primitives is instantiated.
  4
  5%\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\}^*$. 
  6%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$. 
  7%$\F_p$ denotes de finite field of order $p$, and $\F_p^* = \F_p/\{0\}$.
  8
  9\subsection{Elliptic curves}
 10\label{sec:cryptographic-primitives:elliptic-curves}
 11
 12\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{brown10sec} 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{jancar20bn256} is chosen because it is the curve supported by Ethereum's precompiled contracts for ZK proof verification, which makes it ideal for verifying SNARK proofs on-chain with minimal gas cost. then, BabyJubjub~\cite{belles21twisted} is used as an inner curve for elliptic curve operations within arithmetic circuits. Finally, BLS12-377~\cite{bowe20zexe} and BW6-761~\cite{elhousni20optimized} 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.
 13
 14\paragraph{Parameters.}
 15
 16\begin{itemize}
 17	%
 18	\item[$\bullet$] $p = \tt{\hspace{0.04cm}0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f}$ (256-bit prime).
 19	\item[$\bullet$] $q = \tt{\hspace{0.01cm}0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141}$ (256-bit prime).	
 20	%
 21	\item[$\bullet$] $r = \tt{0x2523648240000001ba344d80000000086121000000000013a700000000000013}$ (254-bit prime).
 22	\item[$\bullet$] $s = \tt{\hspace{0.04cm}0x2523648240000001ba344d8000000007ff9f800000000010a10000000000000d}$ (254-bit prime).
 23	\item[$\bullet$] $t = \tt{\hspace{0.01cm}0x60c89ce5c263405370a08b6d0302b0bab3eedb83920ee0a677297dc392126f1}$ (251-bit prime).
 24	%
 25	\item[$\bullet$] $u = \tt{0x122e824fb83ce0ad187c94004faff3eb926186a81d14688528275ef8087be41707ba638e584e9190}$
 26	\item[] \hspace{0.53cm} $\tt{3cebaff25b423048689c8ed12f9fd9071dcd3dc73ebff2e98a116c25667a8f8160cf8aeeaf0a437e69}$
 27	\item[] \hspace{0.53cm} $\tt{13e6870000082f49d00000000008b}$ (761-bit prime).
 28	\item[$\bullet$] $v = \tt{0x01ae3a4617c510eac63b05c06ca1493b1a22d9f300f5138f1ef3622fba094800170b5d4430000000}$
 29	\item[] \hspace{0.52cm} $\tt{8508c00000000001}$ (377-bit prime).
 30	\item[$\bullet$] $w = \tt{0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a11800000000001}$ (253-bit prime).
 31	%
 32\end{itemize}
 33
 34\paragraph{Elliptic curve groups.}
 35\begin{itemize}
 36	%
 37	\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$. 
 38	%
 39	\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$. 
 40	\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$. 
 41	%
 42	\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. 
 43	\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$. 
 44	%
 45\end{itemize}
 46
 47\paragraph{Finite fields.}
 48\begin{itemize}
 49	%
 50	\item $\F_p$: base field of the SECP256K1 curve.
 51	\item $\F_q$: scalar field of $\SEC{\G}$.
 52	%
 53	\item $\F_r$: base field of the BN254 curve.	
 54	\item $\F_s$: scalar field of $\BN{\G}_1, \BN{\G}_2, \BN{\G}_T$ and base field of the BabyJubjub curve.
 55	\item $\F_t$: scalar field of $\BJ{\G}$.
 56	%
 57	\item $\F_u$: base field of the BW6-761 curve.
 58	\item $\F_v$: scalar field of $\BW{\G}_1, \BW{\G}_2, \BW{\G}_T$ and base field of the BLS12-377 curve.
 59	\item $\F_w$: scalar field of $\BLS{\G}_1, \BLS{\G}_2, \BLS{\G}_T$.
 60	%
 61\end{itemize}
 62
 63\paragraph{Generators.}\mbox{}\\
 64
 65\noi We denote by $\hlget{\SEC{G}}$ the generator of $\SEC{\G}$ as defined in~\cite{brown10sec}, $\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}.
 66
 67\begin{itemize}
 68	\item
 69		$
 70		\hlset{\SEC{G}} = 
 71		(\tt{0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,0x483ada7726} \allowbreak
 72		\rule{1.37cm}{0pt}
 73		\tt{a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8}).
 74		$
 75	\item 
 76		$
 77		\hlset{\BN{G}}\hspace{0.14cm} = \: (\tt{0x01}, \tt{0x02}).
 78		$
 79
 80	\item
 81		$
 82		\hlset{\BJ{G}}\hspace{0.18cm} = 
 83		\hspace{0.09cm} (\tt{0x0b9feffffffffaaabfffffffffffffffeffffffffffffffffffffffffffffff}, 
 84		\tt{0x17fffffffff} \\
 85		\rule{1.37cm}{0pt}
 86		\tt{ffffffffffffffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141}).				
 87		$
 88	\item 
 89		$
 90		\hlset{\BW{G}}\hspace{0.085cm} = 
 91		\hspace{0.09cm} (\tt{0x1075b020ea190c8b277ce98a477beaee6a0cfb7551b27f0ee05c54b85f56fc779017ffac15520}\\
 92		\rule{1.37cm}{0pt}
 93		\tt{ac11dbfcd294c2e746a17a54ce47729b905bd71fa0c9ea097103758f9a280ca27f6750dd0356133}\\
 94		\rule{1.37cm}{0pt}		
 95		\tt{e82055928aca6af603f4088f3af66e5b43d, 0x58b84e0a6fc574e6fd637b45cc2a420f952589884} \\
 96		\rule{1.37cm}{0pt}
 97		\tt{c9ec61a7348d2a2e573a3265909f1af7e0dbac5b8fa1771b5b806cc685d31717a4c55be3fb90b6f} \\
 98		\rule{1.37cm}{0pt}
 99		\tt{c2cdd49f9df141b3053253b2b08119cad0fb93ad1cb2be0b20d2a1bafc8f2db4e95363)}.
100		$
101	\item 
102		$
103		\hlset{\BLS{G}}\hspace{0.07cm} = 
104		\hspace{0.06cm}(\tt{0x008848defe740a67c8fc6225bf87ff5485951e2caa9d41bb188282c8bd37cb5cd5481512ffcd3} \\
105		\rule{1.37cm}{0pt}
106		\tt{94eeab9b16eb21be9ef,0x01914a69c5102eff1f674f5d30afeec4bd7fb348ca3e52d96d182ad44} \\
107		\rule{1.37cm}{0pt}
108		\tt{fb82305c2fe3d3634a9591afd82de55559c8ea6}).
109		$
110\end{itemize}
111
112%\begin{itemize}
113%	\item Generator of $\SEC{\G}$ as defined in~\cite{}: 
114%	\begin{align*}
115%		\hlset{\SEC{G}} = 
116%		(&\tt{0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798},\\
117%		&\tt{0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8}).
118%	\end{align*}
119%	%
120%	\item Generator of $\BN{\G}_1$ as defined in~\cite{}:
121%	%https://ethereum.github.io/yellowpaper/paper.pdf
122%	\begin{align*}
123%		\hlset{\BN{G}} = 
124%		(\tt{0x01}, \tt{0x02}).
125%	\end{align*}
126%	% (-1, 1) o bé (1, 2)?
127%	%
128%	\item Generator of $\BJ{\G}$ as defined in~\cite{}:
129%	%https://eips.ethereum.org/EIPS/eip-2494
130%	\begin{align*}
131%		\hlset{\BJ{G}} = 
132%		(&\tt{0x0b9feffffffffaaabfffffffffffffffeffffffffffffffffffffffffffffff},\\
133%		&\tt{0x17fffffffffffffffffffffffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141}).
134%	\end{align*}
135%	%
136%	\item Generator of $\BW{\G}_1$ as defined in~\cite{}:
137%	%https://eips.ethereum.org/EIPS/eip-3026
138%	\begin{align*}
139%		\hlset{\BW{G}} = 
140%		(&\tt{0x1075b020ea190c8b277ce98a477beaee6a0cfb7551b27f0ee05c54b85f56fc779017ffac15520ac11dbfcd294c2e746a17a54ce47729b905bd71fa0c9ea097103758f9a280ca27f6750dd0356133e82055928aca6af603f4088f3af66e5b43d},\\
141%		&\tt{0x58b84e0a6fc574e6fd637b45cc2a420f952589884c9ec61a7348d2a2e573a3265909f1af7e0dbac5b8fa1771b5b806cc685d31717a4c55be3fb90b6fc2cdd49f9df141b3053253b2b08119cad0fb93ad1cb2be0b20d2a1bafc8f2db4e95363}).
142%	\end{align*}
143%	%
144%	\item Generator of $\BLS{\G}_1$ as defined in~\cite{}:
145%	%https://eips.ethereum.org/EIPS/eip-2539
146%	\begin{align*}
147%		\hlset{\BLS{G}} = 
148%		(&\tt{0x008848defe740a67c8fc6225bf87ff5485951e2caa9d41bb188282c8bd37cb5cd5481512ffcd394eeab9b16eb21be9ef},\\
149%		&\tt{0x01914a69c5102eff1f674f5d30afeec4bd7fb348ca3e52d96d182ad44fb82305c2fe3d3634a9591afd82de55559c8ea6}).
150%	\end{align*}
151%	%
152%\end{itemize}
153
154\pagebreak
155
156\subsection{Hash functions}
157\label{sec:cryptographic-primitives:hash}
158
159\Davinci uses different hash functions. On the one side, we use Keccak256~\cite{bertoni11keccak} for Ethereum address derivation, and Poseidon~\cite{grassi21poseidon}, MiMC and MiMC-7~\cite{albrecht16mimc} for arithmetic circuits within zero-knowledge proofs.
160
161\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:authentication}).
162
163\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}.
164
165\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). {\color{blue}On the other side, $\hlset{\Multimimc}$.}
166
167\martai{MiMC two instantiations: MiMC and MiMC-7, and also the curves. Check!}
168
169%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}).
170%We use the cubic S-box S(x)=x7S(x)=x7, and instantiate MiMC-7 over the same field FpFp​ as the SNARK circuit:
171%MiMC7:Fpt→Fp
172%MiMC7:Fpt​→Fp​
173%This function is denoted Hash3Hash3 in our implementation.
174
175{\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.}
176
177%\subsection{Commitment schemes}
178%\label{sec:cryptographic-primitives:commitments}
179
180%Pedersen commitment scheme~\cite{pedersen1991non}. 
181
182\subsection{Encryption schemes}
183\label{sec:cryptographic-primitives:encryption}
184
185\textit{Old text: Threshold homomorphic encryption, specifically the ElGamal scheme, is used to allow the summation of encrypted votes without decrypting them. This enables the system to compute the final vote tally while maintaining the privacy of individual votes. By ensuring that no vote is exposed during the aggregation phase, this scheme preserves voter confidentiality and provides anti-coercion protection, as voters cannot prove their choice to a third party once an encrypted vote is added.}\\
186
187ElGamal [CITE].
188
189\medskip
190
191\begin{mdframed}
192	\begin{minipage}[t]{0.54\textwidth}
193		\begin{itemize}
194			\item[$\bullet$] $\hlset{\Enc}_{\pk}(\msg \in \{0,1\}^\star; k\in\F_t)$:  \vspace{0.1cm}
195			\begin{enumerate}
196				\item Map $\msg$ to $\BJ{\G}$ via $M = m \hlget{\BJ{G}}$.
197				\item Compute $C_1 = k \cdot \hlget{\BJ{G}} \in \BJ{\G}$.
198				\item Compute $C_2 = k \cdot \pk + M \in \BJ{\G}$. 
199				\item Output $\enc = (C_1, C_2) \in {(\BJ{\G})}^2$.
200			\end{enumerate}
201		\end{itemize}
202	\end{minipage}
203	\begin{minipage}[t]{0.44\textwidth}
204		\begin{itemize}
205			\item[$\bullet$] $\hlset{\Dec}_{\sk}(\enc \in {(\BJ{\G})}^2)$: \vspace{0.1cm}
206			\begin{enumerate}
207
208				%From a ciphertext (C,D) calculate C′=xC, and retrieve the point Pm with Pm=D−C′=(k(xP)+Pm)−(x(kP)). Then calculate the message m with f−1(Pm).
209				
210				\item Parse $\enc = (C_1, C_2) \in {(\BJ{\G})}^2$.
211				\item Compute $K = \sk \cdot C_1 \in \BJ{\G}$.
212				\item Output $\msg = C_2 - K$. 
213			\end{enumerate}
214		\end{itemize}
215	\end{minipage}
216\end{mdframed}
217
218\martai{It remains to explain how to recover $m$ from $M$. I propose to define a function $P_m$ that maps $m$ to $\J$, and then say that although it is generally not invertible, in this case the message space is small, and therefore, it can be done via brute-force search or using the baby-step giant-step algorithm [CITE].}
219
220Note that this scheme is additively homomorphic. That is, given two ciphertexts $(C_1, C_2)$ and $(C_1', C_2')$, their component-wise addition yields: $(C_1^{sum}, C_2^{sum}) = (C_1 + C_1', C_2 + C_2')$. The aggregated ciphertext decrypts to the sum of the messages $M^{sum} = M_1 + M_2$.
221
222\martai{The $pk$ used to encrypt is generated by multiple parties as defined in Section~\ref{sec:cryptographic-primitives:dkg}.}
223
224\martai{Add reencryption algorithm, which essentially adds $\Enc(0)$: $\Enc(v) = \Enc(v + 0) = \Enc(v) + \Enc(0)$.}
225
226\begin{mdframed}
227	\begin{minipage}[t]{0.53\textwidth}
228		\begin{itemize}
229			\item[$\bullet$] $\hlset{\EncAdd}_{\pk}(\enc \in {(\BJ{\G})}^2, \enc' \in {(\BJ{\G})}^2)$:
230			\begin{enumerate}
231				\item Parse $\enc = (C_1, C_2) \in {(\BJ{\G})}^2$.
232				\item Parse $\enc' = (C_1', C_2') \in {(\BJ{\G})}^2$.
233				\item Output $(C_1 + C_1', C_2 + C_2') \in {(\BJ{\G})}^2$.
234			\end{enumerate}
235		\end{itemize}
236	\end{minipage}
237	\begin{minipage}[t]{0.45\textwidth}
238		\begin{itemize}
239			\item[$\bullet$] $\hlset{\ReEnc}_{\pk}(\enc \in {(\BJ{\G})}^2; k\in\F_t)$: \vspace{0.1cm}
240			\begin{enumerate}
241				\item Parse $\enc = (C_1, C_2) \in {(\BJ{\G})}^2$.
242				\item Compute $\enc' = \hlget{\Enc}_{\pk}(0; k)$.
243				\item Output $\hlget{\EncAdd_{\pk}(\enc, \enc')}$.
244%				\item Compute $C_1' = k \cdot G + C_1 \in \J$.
245%				\item Compute $C_2' = k \cdot \pk + C_2 \in \J$. 
246%				\item Output $\enc' = (C_1', C_2') \in \J^2$.				
247			\end{enumerate}
248		\end{itemize}
249	\end{minipage}
250\end{mdframed}
251
252\subsection{Digital signature schemes}
253\label{sec:cryptographic-primitives:signatures}
254
255\Davinci uses the elliptic curve digital signature algorithm (ECDSA)~\cite{johnson01ecdsa} over the SECP256K1 curve to ensure compatibility with standard Ethereum wallets. %, such as MetaMask~\ref{} or Ledger~\ref{}, 
256%
257%\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. 
258%
259Verification of ECDSA signatures is \textit{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.
260
261\begin{mdframed}
262	\begin{minipage}[t]{0.46\textwidth}
263		\begin{itemize}
264			\item[$\bullet$] $\hlset{\SSign}_{\sk}(\msg \in \{0,1\}^\star)$:  \vspace{0.1cm}
265			\begin{enumerate}
266				\item Compute $h = \hlget{\Keccak}(\msg) \bmod q$.
267				\item\label{item:ssign-step} Select a random scalar $k \sample \Z_q^{*}$.
268				\item Compute $R = k \cdot \hlget{\SEC{G}} = (x_R, y_R) \in \SEC{\G}$.
269				\item Set $r = x_R \bmod q$. If $r = 0$, go back to step~\ref{item:ssign-step}. 
270				\item Compute $s = k^{-1} \cdot (h + r \cdot \sk) \bmod q.$ If $s = 0$, go back to step~\ref{item:ssign-step}. 
271				\item Output $\sigma = (r, s)$.
272			\end{enumerate}
273		\end{itemize}
274	\end{minipage}
275	\begin{minipage}[t]{0.54\textwidth}
276		\begin{itemize}
277			\item[$\bullet$] $\hlset{\SVer}_{\pk}(\msg \in \{0,1\}^\star, \sigma = (r, s)\in(\Z_q^*)^2)$: %\vspace{0.1cm}
278			\begin{enumerate}
279				\item Check that $\pk \in \SEC{\G}$.
280				\item Compute $h = \hlget{\Keccak}(\msg) \bmod q$.
281				\item Compute $w = s^{-1} \bmod q$.
282				\item Compute $u_1 = h \cdot w \bmod q$ and $u_2 = r \cdot w \bmod q$.
283				\item Compute $$X = u_1 \cdot \hlget{\SEC{G}} + u_2 \cdot \pk = (x_X, y_X) \in \SEC{\G}.$$
284				\item Accept if $r = x_X \bmod q$; otherwise, reject.
285			\end{enumerate}
286		\end{itemize}
287	\end{minipage}
288\end{mdframed}
289
290\martai{The output of the hash does not match, CHECK!}
291
292\subsection{Key generation schemes}
293\label{sec:cryptographic-primitives:dkg}
294
295\textit{Old text: The DKG protocol is used to generate the encryption public key (EPK) in a decentralized manner. Sequencers collaboratively participate in the DKG process to create the EPK, ensuring that no single party has full control over the key. This approach guarantees that the encryption key remains secure and that decryption of results is only possible when a threshold number of sequencers publish their shares.}\\
296
297We use the distributed key generation (DKG) protocol that allows a group of participants to jointly generate a pair of public/private keys for the ElGamal cryptosystem [CITE]. Each participant holds a share of the private key, and only a threshold number of participants can collaborate to decrypt messages. 
298
299\martai{We use a variation of DKG because of the encryption of shares. Below I described the original functions but they should be changed!}
300\martai{Mention that in the SC participants are listed, that is, they have an associated number $i$.}
301
302Let $t$ be the threshold parameter (minimum number of participants required to decrypt messages) and $n$ the total number of participants participating in the DKG protocol ($t \leq n$). Let $G$ be generator point of order $q$. (This will already be defined in the EC section).
303
304\begin{mdframed}
305Each participant $P_i$ will use $\hlget{\GenerateShares}$ to generate their share. Then, they will make the set $\{C_i\}_{i=1}^{t-1}$ publicly available and send each $s_j$ privately to each participant $s_j$. Every participant $P_i$ can verify the share $s_{j,i}$ received from $P_j$ (from of the others) using the algorithm $\hlget{\VerifyShare}$.\\
306
307\noindent
308\begin{minipage}[t]{0.5\textwidth}
309	\begin{itemize}
310		\item[$\bullet$] $\hlset{\GenerateShares}(\text{participant $i$})$:  \vspace{0.1cm}
311		\begin{enumerate}
312			\item Select random scalars $a_{i,0} \sample \Z_q$.
313			\item Define the polynomial $f_i(x) = \sum_{j = 0}^{t-1} a_{i,j} x^{j}$.
314			\item For every $j\in\{0,\dots,t-1\}$, compute 
315			$$C_{i, j} = a_{i,j}\cdot G.$$
316			\item For every $j\in\{1,\dots,n\}$, compute shares 
317			$$s_{i, j} = f_i(j).$$
318			\item Output $\{C_{i,j}\}_{i=0}^{t-1}$ and $\{s_{i,j}\}_{j=1}^{n}$.  
319		\end{enumerate}
320	\end{itemize}
321	\martai{This is not true - according to the specs, shares are encrypted using a simplified version of the EC integrated encryption scheme (ECIES). Each participant generates a zkSNARK proof to prove the correctness of the encrypted shares and compliance of the DKG protocol. This allows the Ethereum SC to verify the validity without revealing the secrets.}
322	\martai{Change the name of algorithm to $\texttt{GenerateEncryptedShares}$.}
323\end{minipage}
324\begin{minipage}[t]{0.5\textwidth}
325	\begin{itemize}
326	\item[$\bullet$] $\hlset{\VerifyShare}(i, j, s_{i,j}, C_i)$:  \vspace{0.1cm}
327	\begin{enumerate}
328		\item Compute $V = \sum_{i = 0}^{t-1} C_i$.
329		\item Verify that $V = s_{i,j} \cdot G$.
330		\martai{This is done by the smart contract - the shares are not in the clear but encrypted.}
331	\end{enumerate}
332	\end{itemize}
333	\martai{Describe slashing mechanism in SC section if one of the shares fails the verification?}
334\end{minipage}
335\end{mdframed}
336%%%%
337%
338%%%%
339\begin{mdframed}
340Participant $P_j$ uses the algorithm $\hlget{\DeriveSecretShare}$ to compute their portion of the collective private key. The algorithm $\hlget{\DerivePublicKey}$ generates the public key from the committed data from the participants. \\
341
342\noindent 
343\begin{minipage}[t]{0.5\textwidth}
344	\begin{itemize}
345		\item[$\bullet$] $\hlset{\DeriveSecretShare}(\text{participant $j$})$:  \vspace{0.1cm}
346		\begin{enumerate}
347			\item Compute $s_j = \sum_{i = 1}^{n} s_{i, j} \mod q$.
348			\item Output $s_j$.
349		\end{enumerate}
350	\end{itemize}
351\end{minipage}
352%
353\begin{minipage}[t]{0.5\textwidth}
354	\begin{itemize}
355	\item[$\bullet$] $\hlset{\DerivePublicKey}(\{C_{i,0}\}_{i=1}^n)$:  \vspace{0.1cm}
356	\begin{enumerate}
357		\item Let $pk = \sum_{i=1}^n C_{i,0}$.
358		\item Output $pk$.
359	\end{enumerate}
360	\end{itemize}
361	Note that since $C_{i,0} = a_{i,0} \cdot G$, the public key is effectively $sG$ where $s = \sum_{i = 1}^n a_{i,0} \mod q$ is the collective private key (unknown to any single participant).
362	\martai{As before, this should be changed to the encrypted version. It should be explained how the public key is generated from the encrypted shares.}
363\end{minipage}
364%
365\end{mdframed}
366
367\subsection{Merkle trees}
368\label{sec:cryptographic-primitives:merkle-trees}
369
370The \davinci protocol uses sparse Merkle trees (SMTs) as defined in ~\cite{baylina19sparse}. Essentially, in this kind of trees each leaf corresponds to a key-value pair, with empty leaves explicitly represented to enable both inclusion and non-inclusion proofs. The key feature of these trees is that the hash of each entry defines a unique traversal path in the tree from root to leaf, regardless of insertion order. When inserting, the algorithm descends until it encounters an empty node or a leaf; if there is a hash prefix collision, the tree is split at the first differing bit, creating new intermediate nodes appropriately. 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. 
371
372In \davinci, both the census (voter registry with weights) and the vote state are maintained using SMTs. The root hashes are committed on-chain, while full tree contents remain off-chain. Sequencers generate and submit Merkle proofs to the verification circuits, which reconstruct and validate the root transitions. This design allows compact, verifiable state updates and enables independent verification without relying on trusted data sources.
373
374\noi To each Merkle tree $\tree$, we associate the following functions:
375
376\begin{itemize}
377	\item ${\tree.\hlset{\MTRoot}}()$: it returns the root of the tree.
378	\item ${\tree.\hlset{\MTInsert}}()$: it inserts a new leaf in the tree. The root is updated.
379%	\item ${\tree.\hlset{\MTRemove}}()$: it removes a leaf from the tree. The root is updated.
380	\item ${\tree.\hlset{\MTProof}}()$: it returns the Merkle tree inclusion proof of the given leaf.
381	%	\item ${\MT.\UpdateRoot}_{\pp}({\leaf, \pos, \root})$: it updates the root.
382	\item ${\tree.\hlset{\MTVerify}}
383	()$: it takes a Merkle proof and a root as an input and verifies the proof against the given root. 
384\end{itemize}
385
386\martai{\textbf{(1) State MT:} Poseidon with BN254 scalar field. \textbf{(2) Census MT:} MiMC with BLS12-377 scalar field.}
387
388\martai{Sparse MTs (binary) with depth $64$. Structure of sparse MT from iden3.}
389
390\martai{Add MT.Update, for those ciphertexts that are overwrites.}
391
392\subsection{Zero-knowledge proof systems}
393\label{sec:cryptographic-primitives:zkp}
394
395Groth16~\cite{groth2016size} with different curves. 
396\textit{Zero-knowledge succinct non-interactive arguments of knowledge are a crucial component in ensuring the validity of the voting results. Voters generate zkSNARK proofs to prove that their encrypted votes comply with the rules and requirements of the voting process, without revealing any information about their choices. Sequencers also generate zkSNARK proofs to prove the correct aggregation of votes into the shared state that maintains the status of the voting process.}