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 Merkle trees, the commitment and encryption schemes, proof systems, elliptic curves and hash functions used. We also specify at each step the concrete parameters with which each of the primitives is instantiated.\\
4
5\martai{Maybe it should go under the protocol section?}
6
7\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\}^*$.
8%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$.
9%$\F_p$ denotes de finite field of order $p$, and $\F_p^* = \F_p/\{0\}$.
10
11\subsection{Elliptic curves}
12\label{sec:cryptographic-primitives:elliptic-curves}
13
14\martai{Include the motivation for the use of each of the curves (e.g. native arithmetic, regular Eth addresses...).}
15
16\davinci uses BW6-761~\cite{elhousni20optimized}, BLS12-377~\cite{bowe20zexe}, BN254~\cite{jancar20bn256}, BabyJubjub~\cite{belles21twisted}, and Secp256k1~\cite{brown10sec} elliptic curves. Below, we give the details of these curves.
17
18\paragraph{Parameters.}
19
20\begin{itemize}
21 \item[$\bullet$] $p = \tt{0x122e824fb83ce0ad187c94004faff3eb926186a81d14688528275ef8087be41707ba638e584e9190}$
22 \item[] \hspace{0.53cm} $\tt{3cebaff25b423048689c8ed12f9fd9071dcd3dc73ebff2e98a116c25667a8f8160cf8aeeaf0a437e69}$
23 \item[] \hspace{0.53cm} $\tt{13e6870000082f49d00000000008b}$ (761-bit prime).
24 \item[$\bullet$] $q = \tt{0x01ae3a4617c510eac63b05c06ca1493b1a22d9f300f5138f1ef3622fba094800170b5d4430000000}$
25 \item[] \hspace{0.52cm} $\tt{8508c00000000001}$ (377-bit prime).
26 \item[$\bullet$] $r = \tt{0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a11800000000001}$ (253-bit prime).
27 \item[$\bullet$] $s = \tt{0x2523648240000001ba344d80000000086121000000000013a700000000000013}$ (254-bit prime).
28 \item[$\bullet$] $t = \tt{\hspace{0.04cm}0x2523648240000001ba344d8000000007ff9f800000000010a10000000000000d}$ (254-bit prime).
29 \item[$\bullet$] $u = \tt{\hspace{0.01cm}0x60c89ce5c263405370a08b6d0302b0bab3eedb83920ee0a677297dc392126f1}$ (251-bit prime).
30 \item[$\bullet$] $v = \tt{\hspace{0.04cm}0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f}$ (256-bit prime).
31 \item[$\bullet$] $w = \tt{\hspace{0.01cm}0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141}$ (256-bit prime).
32\end{itemize}
33
34\paragraph{Elliptic curve groups.}
35\begin{itemize}
36 \item BW6-761 curve: $\BW{E}/\F_p$ defined by equation $\BW{E}: y^2 = x^3 - 1$, with subgroups $\BW{\G}_1, \BW{\G}_2$ of prime order $q$, and an efficiently computable pairing \({e}:\BW{\G}_1\times\BW{\G}_2 \rightarrow \BW{\G}_T,\) where $\BW{\G}_T \subset \F_{q^{6}}$ and has order $q$ as well.
37 \item BLS12-377 curve: $\BLS{E}/\F_q$ defined by equation \(\BLS{E}: y^2 = x^3 + 1,\) with subgroups $\BLS{\G}_1, \BLS{\G}_2$ of prime order $r$, and an efficiently computable pairing \({e}:\BLS{\G}_1\times\BLS{\G}_2 \rightarrow \BLS{\G}_T,\) where $\BLS{\G}_T \subset \F_{r^{12}}$ and has order $r$.
38 \item BN254 curve: $\BN{E}/\F_s$ defined by equation \( \BN{E}: y^2 = x^3 + 3\), with subgroups $\BN{\G}_1, \BN{\G}_2$ of prime order $t$, and an efficiently computable pairing \(e:\BN{\G}_1\times\BN{\G}_2 \rightarrow \BN{\G}_T,\) where $\BN{\G}_T \subset \F_{t^{12}}$ and has order $t$.
39 \item BabyJubjub curve: $\BJ{E}/\F_t$ defined by equation $\BJ{E}: 168700 x^2 + y^2 = 1 + 168696 x^2y^2$, with subgroup $\BJ{\G}$ of prime order $u$.
40 \item SECP256K1 curve: $\SEC{E}/\F_v$ defined by equation $\SEC{E}: y^2 = x^3 + 7$, with group $\SEC{\G}$ of prime order $w$.
41\end{itemize}
42
43\paragraph{Finite fields.}
44\begin{itemize}
45 \item $\F_p$: base field of the BW6-761 curve.
46 \item $\F_q$: scalar field of $\BW{\G}_1, \BW{\G}_2, \BW{\G}_T$ and base field of the BLS12-377 curve.
47 \item $\F_r$: scalar field of $\BLS{\G}_1, \BLS{\G}_2, \BLS{\G}_T$.
48 \item $\F_s$: base field of the BN254 curve.
49 \item $\F_t$: scalar field of $\BN{\G}_1, \BN{\G}_2, \BN{\G}_T$ and base field of the BabyJubjub curve.
50 \item $\F_u$: scalar field of $\BJ{\G}$.
51 \item $\F_v$: base field of the SECP256K1 curve.
52 \item $\F_w$: scalar field of $\SEC{\G}$.
53\end{itemize}
54
55\paragraph{Generators.}
56\begin{itemize}
57 \item Generator of $\BW{\G}_1$: XXX.
58 \item Generator of $\BLS{\G}_1$: XXX.
59 \item Generator of $\BN{\G}_1$: XXX.
60 \item Generator of $\BJ{\G}$: XXX.
61 \item Generator of $\SEC{\G}$: XXX.
62\end{itemize}
63
64\subsection{Hash functions}
65\label{sec:cryptographic-primitives:hash}
66
67\martai{Poseidon? Specify parameters? And $p$ may actually not be $p$, and probably it will be instantiated with different curves, depending on the circuit.}
68
69\martai{Yes, Poseidon. But also MiMC-7 for hashing the public inputs and passing them between circuits (for efficiency).}
70
71We use the Poseidon~\cite{grassi21poseidon} hash function $ \hlset{\Hash} : \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}. In particular, we make use of the \textsc{Poseidon-128} permutation \[\pi: \F_p^t\rightarrow \F_p^t,\] where $t=r+c$, with the following parameters:
72\begin{table}[H]
73 \begin{center}
74 \begin{tabular}{| c | c | c | c | c | }
75 \hline
76 Rate & Capacity & Full rounds & Partial rounds & S-box \\
77 \hline
78 $r=4$ & $c=1$ & $R_F=8$ & $R_P=59$ & $S(x)=x^5$ \\
79 \hline
80 \end{tabular}
81 \end{center}
82\end{table}
83
84% \begin{itemize}
85 % \item Rate $r=4$.
86 % \item Capacity $c=1$.
87 % \item Full rounds $R_F = 8$.
88 % \item Partial rounds $R_P = 59$.
89 % \item S-box: $S(x) = x^5$.
90 % \end{itemize}
91
92For the sake of clarity, in our notation we admit anything as an input of $\Hash$, although it might not be parsed as a sequence of $\F_p$-elements. Any bitstring can be converted to a tuple of $\F_p$-elements, so this does not change the actual working of the hash computation. In this document, is implied that the proper conversion happens before feeding the input into the actual hash function.
93
94\subsection{Commitment schemes}
95\label{sec:cryptographic-primitives:commitments}
96
97%Pedersen commitment scheme~\cite{pedersen1991non}.
98
99\subsection{Encryption schemes}
100\label{sec:cryptographic-primitives:encryption}
101
102\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.}\\
103
104ElGamal [CITE].
105
106\medskip
107
108\begin{mdframed}
109 \begin{minipage}[t]{0.54\textwidth}
110 \begin{itemize}
111 \item[$\bullet$] $\hlset{\Enc}_{\pk}(\msg \in \{0,1\}^\star)$: \vspace{0.1cm}
112 \begin{enumerate}
113 \item Map $\msg$ to $\J$ via $M = mG$. (link G).
114 \item Select a random scalar $k \sample $.
115 \item Compute $C_1 = k \cdot G \in \J$.
116 \item Compute $C_2 = k \cdot \pk + M \in \J$.
117 \item Output $\enc = (C_1, C_2) \in \J^2$.
118 \end{enumerate}
119 \end{itemize}
120 \end{minipage}
121 \begin{minipage}[t]{0.44\textwidth}
122 \begin{itemize}
123 \item[$\bullet$] $\hlset{\Dec}_{\sk}(\enc \in \J)$: \vspace{0.1cm}
124 \begin{enumerate}
125
126 %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).
127
128 \item Parse $\enc = (C_1, C_2) \in \J^2$.
129 \item Compute $K = \sk \cdot C_1 \in \J$.
130 \item Output $\msg = C_2 - K$.
131 \end{enumerate}
132 \end{itemize}
133 \end{minipage}
134\end{mdframed}
135
136\martai{The group $\J$ is not the right group. This should be changed after writing the elliptic curves section. Actually, I am unsure we should specify where do all elements live.}
137
138\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].}
139
140Note 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$.
141
142\martai{The $pk$ used to encrypt is generated by multiple parties as defined in Section~\ref{sec:cryptographic-primitives:dkg}.}
143
144\martai{Add reencryption algorithm, which essentially adds $\Enc(0)$: $\Enc(v) = \Enc(v + 0) = \Enc(v) + \Enc(0)$.}
145
146\subsection{Digital signature schemes}
147\label{sec:cryptographic-primitives:signatures}
148
149ECDSA.
150
151\subsection{Key generation schemes}
152\label{sec:cryptographic-primitives:dkg}
153
154\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.}\\
155
156We 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.
157
158\martai{We use a variation of DKG because of the encryption of shares. Below I described the original functions but they should be changed!}
159\martai{Mention that in the SC participants are listed, that is, they have an associated number $i$.}
160
161Let $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).
162
163\begin{mdframed}
164Each 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}$.\\
165
166\noindent
167\begin{minipage}[t]{0.5\textwidth}
168 \begin{itemize}
169 \item[$\bullet$] $\hlset{\GenerateShares}(\text{participant $i$})$: \vspace{0.1cm}
170 \begin{enumerate}
171 \item Select random scalars $a_{i,0} \sample \Z_q$.
172 \item Define the polynomial $f_i(x) = \sum_{j = 0}^{t-1} a_{i,j} x^{j}$.
173 \item For every $j\in\{0,\dots,t-1\}$, compute
174 $$C_{i, j} = a_{i,j}\cdot G.$$
175 \item For every $j\in\{1,\dots,n\}$, compute shares
176 $$s_{i, j} = f_i(j).$$
177 \item Output $\{C_{i,j}\}_{i=0}^{t-1}$ and $\{s_{i,j}\}_{j=1}^{n}$.
178 \end{enumerate}
179 \end{itemize}
180 \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.}
181 \martai{Change the name of algorithm to $\texttt{GenerateEncryptedShares}$.}
182\end{minipage}
183\begin{minipage}[t]{0.5\textwidth}
184 \begin{itemize}
185 \item[$\bullet$] $\hlset{\VerifyShare}(i, j, s_{i,j}, C_i)$: \vspace{0.1cm}
186 \begin{enumerate}
187 \item Compute $V = \sum_{i = 0}^{t-1} C_i$.
188 \item Verify that $V = s_{i,j} \cdot G$.
189 \martai{This is done by the smart contract - the shares are not in the clear but encrypted.}
190 \end{enumerate}
191 \end{itemize}
192 \martai{Describe slashing mechanism in SC section if one of the shares fails the verification?}
193\end{minipage}
194\end{mdframed}
195%%%%
196%
197%%%%
198\begin{mdframed}
199Participant $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. \\
200
201\noindent
202\begin{minipage}[t]{0.5\textwidth}
203 \begin{itemize}
204 \item[$\bullet$] $\hlset{\DeriveSecretShare}(\text{participant $j$})$: \vspace{0.1cm}
205 \begin{enumerate}
206 \item Compute $s_j = \sum_{i = 1}^{n} s_{i, j} \mod q$.
207 \item Output $s_j$.
208 \end{enumerate}
209 \end{itemize}
210\end{minipage}
211%
212\begin{minipage}[t]{0.5\textwidth}
213 \begin{itemize}
214 \item[$\bullet$] $\hlset{\DerivePublicKey}(\{C_{i,0}\}_{i=1}^n)$: \vspace{0.1cm}
215 \begin{enumerate}
216 \item Let $pk = \sum_{i=1}^n C_{i,0}$.
217 \item Output $pk$.
218 \end{enumerate}
219 \end{itemize}
220 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).
221 \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.}
222\end{minipage}
223%
224\end{mdframed}
225
226\subsection{Merkle trees}
227\label{sec:cryptographic-primitives:merkle-trees}
228
229\martai{I am not sure a Merkle trees section is needed, but I thought we could use it to specify the hash function used in the trees, the depth, and the -arity. We could also include some functions like \texttt{MT.Root()}, etc.}
230\martai{Sparse MTs (binary) with depth $64$. Instantiated with Poseidon hash function.}
231\martai{Structure of spare Merkle trees from iden3.}
232
233\subsection{Zero-knowledge proof systems}
234\label{sec:cryptographic-primitives:zkp}
235
236\textit{Old text: 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.}