% !TeX root = ../build/main.tex In 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.\\ \martai{Maybe it should go under the protocol section?} \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\}^*$. %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$. %$\F_p$ denotes de finite field of order $p$, and $\F_p^* = \F_p/\{0\}$. \subsection{Elliptic curves} \label{sec:cryptographic-primitives:elliptic-curves} \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. \paragraph{Parameters.} \begin{itemize} \item[$\bullet$] $p = \tt{0x122e824fb83ce0ad187c94004faff3eb926186a81d14688528275ef8087be41707ba638e584e9190}$ \item[] \hspace{0.53cm} $\tt{3cebaff25b423048689c8ed12f9fd9071dcd3dc73ebff2e98a116c25667a8f8160cf8aeeaf0a437e69}$ \item[] \hspace{0.53cm} $\tt{13e6870000082f49d00000000008b}$ (761-bit prime). \item[$\bullet$] $q = \tt{0x01ae3a4617c510eac63b05c06ca1493b1a22d9f300f5138f1ef3622fba094800170b5d4430000000}$ \item[] \hspace{0.52cm} $\tt{8508c00000000001}$ (377-bit prime). \item[$\bullet$] $r = \tt{0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a11800000000001}$ (253-bit prime). \item[$\bullet$] $s = \tt{0x2523648240000001ba344d80000000086121000000000013a700000000000013}$ (254-bit prime). \item[$\bullet$] $t = \tt{\hspace{0.04cm}0x2523648240000001ba344d8000000007ff9f800000000010a10000000000000d}$ (254-bit prime). \item[$\bullet$] $u = \tt{\hspace{0.01cm}0x60c89ce5c263405370a08b6d0302b0bab3eedb83920ee0a677297dc392126f1}$ (251-bit prime). \item[$\bullet$] $v = \tt{\hspace{0.04cm}0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f}$ (256-bit prime). \item[$\bullet$] $w = \tt{\hspace{0.01cm}0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141}$ (256-bit prime). \end{itemize} \paragraph{Elliptic curve groups.} \begin{itemize} \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. \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$. \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$. \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$. \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$. \end{itemize} \paragraph{Finite fields.} \begin{itemize} \item $\F_p$: base field of the BW6-761 curve. \item $\F_q$: scalar field of $\BW{\G}_1, \BW{\G}_2, \BW{\G}_T$ and base field of the BLS12-377 curve. \item $\F_r$: scalar field of $\BLS{\G}_1, \BLS{\G}_2, \BLS{\G}_T$. \item $\F_s$: base field of the BN254 curve. \item $\F_t$: scalar field of $\BN{\G}_1, \BN{\G}_2, \BN{\G}_T$ and base field of the BabyJubjub curve. \item $\F_u$: scalar field of $\BJ{\G}$. \item $\F_v$: base field of the SECP256K1 curve. \item $\F_w$: scalar field of $\SEC{\G}$. \end{itemize} \paragraph{Generators.} \begin{itemize} \item Generator of $\BW{\G}_1$: XXX. \item Generator of $\BLS{\G}_1$: XXX. \item Generator of $\BN{\G}_1$: XXX. \item Generator of $\BJ{\G}$: XXX. \item Generator of $\SEC{\G}$: XXX. \end{itemize} \subsection{Hash functions} \label{sec:cryptographic-primitives:hash} \martai{Poseidon? Specify parameters? And $p$ may actually not be $p$, and probably it will be instantiated with different curves, depending on the circuit.} \martai{Yes, Poseidon. But also MiMC-7 for hashing the public inputs and passing them between circuits (for efficiency).} We 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: \begin{table}[H] \begin{center} \begin{tabular}{| c | c | c | c | c | } \hline Rate & Capacity & Full rounds & Partial rounds & S-box \\ \hline $r=4$ & $c=1$ & $R_F=8$ & $R_P=59$ & $S(x)=x^5$ \\ \hline \end{tabular} \end{center} \end{table} % \begin{itemize} % \item Rate $r=4$. % \item Capacity $c=1$. % \item Full rounds $R_F = 8$. % \item Partial rounds $R_P = 59$. % \item S-box: $S(x) = x^5$. % \end{itemize} For 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. \subsection{Commitment schemes} \label{sec:cryptographic-primitives:commitments} %Pedersen commitment scheme~\cite{pedersen1991non}. \subsection{Encryption schemes} \label{sec:cryptographic-primitives:encryption} \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.}\\ ElGamal [CITE]. \medskip \begin{mdframed} \begin{minipage}[t]{0.54\textwidth} \begin{itemize} \item[$\bullet$] $\hlset{\Enc}_{\pk}(\msg \in \{0,1\}^\star)$: \vspace{0.1cm} \begin{enumerate} \item Map $\msg$ to $\J$ via $M = mG$. (link G). \item Select a random scalar $k \sample $. \item Compute $C_1 = k \cdot G \in \J$. \item Compute $C_2 = k \cdot \pk + M \in \J$. \item Output $\enc = (C_1, C_2) \in \J^2$. \end{enumerate} \end{itemize} \end{minipage} \begin{minipage}[t]{0.44\textwidth} \begin{itemize} \item[$\bullet$] $\hlset{\Dec}_{\sk}(\enc \in \J)$: \vspace{0.1cm} \begin{enumerate} %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). \item Parse $\enc = (C_1, C_2) \in \J^2$. \item Compute $K = \sk \cdot C_1 \in \J$. \item Output $\msg = C_2 - K$. \end{enumerate} \end{itemize} \end{minipage} \end{mdframed} \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.} \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].} Note 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$. \martai{The $pk$ used to encrypt is generated by multiple parties as defined in Section~\ref{sec:cryptographic-primitives:dkg}.} \subsection{Digital signature schemes} \label{sec:cryptographic-primitives:signatures} ECDSA. \subsection{Key generation schemes} \label{sec:cryptographic-primitives:dkg} \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.}\\ We 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. \martai{We use a variation of DKG because of the encryption of shares. Below I described the original functions but they should be changed!} \martai{Mention that in the SC participants are listed, that is, they have an associated number $i$.} Let $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). \begin{mdframed} Each 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}$.\\ \noindent \begin{minipage}[t]{0.5\textwidth} \begin{itemize} \item[$\bullet$] $\hlset{\GenerateShares}(\text{participant $i$})$: \vspace{0.1cm} \begin{enumerate} \item Select random scalars $a_{i,0} \sample \Z_q$. \item Define the polynomial $f_i(x) = \sum_{j = 0}^{t-1} a_{i,j} x^{j}$. \item For every $j\in\{0,\dots,t-1\}$, compute $$C_{i, j} = a_{i,j}\cdot G.$$ \item For every $j\in\{1,\dots,n\}$, compute shares $$s_{i, j} = f_i(j).$$ \item Output $\{C_{i,j}\}_{i=0}^{t-1}$ and $\{s_{i,j}\}_{j=1}^{n}$. \end{enumerate} \end{itemize} \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.} \martai{Change the name of algorithm to $\texttt{GenerateEncryptedShares}$.} \end{minipage} \begin{minipage}[t]{0.5\textwidth} \begin{itemize} \item[$\bullet$] $\hlset{\VerifyShare}(i, j, s_{i,j}, C_i)$: \vspace{0.1cm} \begin{enumerate} \item Compute $V = \sum_{i = 0}^{t-1} C_i$. \item Verify that $V = s_{i,j} \cdot G$. \martai{This is done by the smart contract - the shares are not in the clear but encrypted.} \end{enumerate} \end{itemize} \martai{Describe slashing mechanism in SC section if one of the shares fails the verification?} \end{minipage} \end{mdframed} %%%% % %%%% \begin{mdframed} Participant $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. \\ \noindent \begin{minipage}[t]{0.5\textwidth} \begin{itemize} \item[$\bullet$] $\hlset{\DeriveSecretShare}(\text{participant $j$})$: \vspace{0.1cm} \begin{enumerate} \item Compute $s_j = \sum_{i = 1}^{n} s_{i, j} \mod q$. \item Output $s_j$. \end{enumerate} \end{itemize} \end{minipage} % \begin{minipage}[t]{0.5\textwidth} \begin{itemize} \item[$\bullet$] $\hlset{\DerivePublicKey}(\{C_{i,0}\}_{i=1}^n)$: \vspace{0.1cm} \begin{enumerate} \item Let $pk = \sum_{i=1}^n C_{i,0}$. \item Output $pk$. \end{enumerate} \end{itemize} 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). \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.} \end{minipage} % \end{mdframed} \subsection{Merkle trees} \label{sec:cryptographic-primitives:merkle-trees} \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.} \martai{Sparse MTs (binary) with depth $64$. Instantiated with Poseidon hash function.} \subsection{Zero-knowledge proof systems} \label{sec:cryptographic-primitives:zkp} \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.}