# Secure Multiparty Computation (MPC)

Currently, proof generation is supported with two different MPC protocols:

- 3-party replicated secret sharing (based on ABY3
^{1}) with semi-honest security - N-party Shamir secret sharing
^{2}(based on DN07^{3}) with semi-honest security

## Notation

With $[x]$ we denote that $x∈F_{p}$ is additively secret shared amongst $n$ parties, such that $[x]=(x_{1},x_{2},...,x_{n})$ and $x=∑_{i}x_{i}$. With $[x]_{B}$ we denote that $x∈F_{p}$ is binary secret shared amongst $n$ parties, such that $[x]_{B}=(x_{1},x_{2},...,x_{n})$ and $x=x_{1}⊕x_{2}⊕...⊕x_{n}$. With $[x]_{t}$ we denote that $x∈F_{p}$ is Shamir secret shared amongst $n$ parties, such that $[x]=(x_{1},x_{2},...,x_{n})$ and $x_{i}=Q(i)$ such that $Q(X)$ is a polynomial of degree $t$ with $x=Q(0)$. Similar, for a group element $X∈G$ in an additive Group $G$ (e.g., elliptic curve groups) we denote by $[X]$ its additive secret sharing amongst $n$ parties, and by $[X]_{t}$ its Shamir sharing, such that $[X]=(X_{1},X_{2},...,X_{n})$. Furthermore, indices of shares are taken modulo the number of parties.

## 3-Party Replicated Sharing

Replicated secret sharing is based on additive secret sharing, with the twist that each party has multiple additive shares. Thus, in the 3-party case a secret $x∈F_{p}$ is shared the following way. First, the $x$ is split into three random shares $x_{1},x_{2},x_{3}∈F_{p}$ such that $x=x_{1}+x_{2}+x_{3}modp$ and each party gets two shares: $P_{1}:(x_{1},x_{3})P_{2}:(x_{2},x_{1})P_{3}:(x_{3},x_{2})$

### Rng Setup

Random values are required during many parts of MPC executions. For cheaper randomness generation, correlated random number generators are set up before protocol execution.

#### Random Values

In order to create random shares $(r_{i},r_{i−1})$, random additive shares of $0$ (i.e., $r_{i}−r_{i−1}$), or random binary shares of $0$ (i.e., $r_{i}⊕r_{i−1}$) without interaction, Rep3 sets up a correlated random number generator during the setup phase. Each party $P_{i}$ chooses a seed $s_{i}$ and sends it to the next party $P_{i+1}$. Thus, each party has two seeds and can set up an RNG's, where two party are able to create the same random numbers:

$P_{1}:(RNG_{1},RNG_{3})P_{2}:(RNG_{2},RNG_{1})P_{3}:(RNG_{3},RNG_{2})$

#### Binary To Arithmetic Conversion

For the binary to arithmetic conversion, we need correlated randomness as well. The goal is to setup RNG's, such that:

$P_{1}:(RNG1_{1},RNG1_{3}),(RNG2_{1},RNG2_{2},RNG2_{3})P_{1}:(RNG1_{1},RNG1_{2},RNG1_{3}),(RNG2_{2},RNG2_{1})P_{3}:(RNG1_{1},RNG1_{2},RNG1_{3}),(RNG2_{1},RNG2_{2},RNG2_{3})$ In other words, $P_{2}$ and $P_{3}$ can use RNG1 create the same field element, while all parties can sample valid shares for it. Similar, $P_{1}$ and $P_{3}$ can use RNG2 to create the same field element, while all parties can sample valid shares for it. This setup can be achieved by sampling seeds from the already set up RNG for shared random values and resharing the seeds correctly.

### Supported operations

#### Linear Operations

Due to being based on additive secret sharing, linear operations can be performed on shares without party interaction.

- Constant addition: $[x]+y=(x_{1}+y,x_{2},x_{3})$
- Share addition: $[x]+[y]=(x_{1}+y_{1},x_{2}+y_{2},x_{3}+y_{3})$
- Constant Multiplication: $[x]⋅y=(x_{1}⋅y,x_{2}⋅y,x_{3}⋅y)$

Similar, linear operations can be computed locally in the binary domain as well.

- Constant addition: $[x]_{B}⊕y=(x_{1}⊕y,x_{2},x_{3})$
- Share addition: $[x]_{B}⊕[y]_{B}=(x_{1}⊕y_{1},x_{2}⊕y_{2},x_{3}⊕y_{3})$
- Constant Multiplication: $[x]_{B}∧y=(x_{1}∧y,x_{2}∧y,x_{3}∧y)$

#### Multiplications

One main advantage of replicated secret sharing is the presence of a simple multiplication protocol. First, due to having two additive shares, each party can calculate an additive share of the result without interaction. For $[z]=[x]⋅[y]$, $z_{i}=x_{i}⋅y_{i}+x_{i}⋅y_{i−1}+x_{i−1}⋅y_{i}$ is a valid additive share of $z$.

Thus, multiplications involve a local operation followed by a resharing of the result to translate the additive share to a replicated share. Resharing requires to randomize the share to not leak any information to the other party. For that reason, a fresh random share of zero is added, which can be sampled locally without party interaction (see RNG setup).

Thus, party $P_{i}$ calculates: $r_{i}=RNG_{i}−RNG_{i−1}z_{i}=x_{i}⋅y_{i}+x_{i}⋅y_{i−1}+x_{i−1}⋅y_{i}+r_{i}z_{i−1}=SendReceive(z_{i})$

The resharing, thereby, is simply implemented as $P_{i}$ sending $z_{i}$ to $P_{i+1}$.

#### AND

AND gates follow directly from multiplications:

$r_{i}=RNG_{i}⊕RNG_{i−1}z_{i}=(x_{i}∧y_{i})⊕(x_{i}∧y_{i−1})⊕(x_{i−1}∧y_{i})⊕r_{i}z_{i−1}=SendReceive(z_{i})$

#### Arithmetic to Binary Conversion

In replicated sharing over rings $Z_{2_{k}}$ (e.g., ABY3), arithmetic to binary conversion of a share $[x]$ is implemented by first locally splitting the shares to valid binary sharings, i.e., $[x_{1}]_{B}=(x_{1},0,0)$, $[x_{2}]_{B}=(0,x_{2},0)$, and $[x_{3}]_{B}=(0,0,x_{3})$ and combining them in MPC using binary addition circuits. Then $[x]_{B}=BinAdd(BinAdd([x_{1}]_{B},[x_{2}]_{B}),[x_{3}]_{B})$ is a valid binary sharing of $x$. This approach works because binary addition circuits implicitly perform modular reductions mod $2_{k}$.

Thus, in $F_{p}$ we have to include the mod $p$ reductions manually in the circuit. For improved performance, we use the following protocol to translate $[x]$:

- $P_{i}$ samples $r_{i}$ to be a new random binary share of $0$
- Set $[x_{3}]_{B}=(0,0,x_{3})$
- $P_{2}$ calculates $t=(x_{1}+x_{2}modp)⊕r_{2}$
- It follows that $(r_{1},t,r_{3})$ is a valid binary sharing of $(x_{1}+x_{2}modp)$

- $P_{i}$ sends its share of $(r_{1},t,r_{3})$ to $P_{i+1}$
- Each party now has a valid binary replicated sharing $[x_{1,2}]_{B}$ of $(x_{1}+x_{2}modp)$

- The parties compute a binary adder circuit of $k=⌈g_{2}(p)⌉$ bits to sum up $[x_{3}]_{B}$ and $[x_{1,2}]_{B}$ to get $[t_{1}]_{B}$ with $k+1$ bits (including overflow bit).
- The parties compute the subtraction of $[t_{1}]_{B}−p$ inside a binary circuit to get $[t_{2}]_{B}$.
- The $(k+1)$-th bit of $[t_{2}]_{B}$ indicates an overflow of the subtraction. If an overflow occurs, the result should be the first $k$ bits of $[t_{1}]_{B}$, otherwise the first $k$ bits of $[t_{2}]_{B}$. This if statement can be computed with a CMUX gate.

#### Binary to Arithmetic Conversion

For the binary to arithmetic conversion, the general strategy for replicated sharing is the following. We sample random binary shares $[x_{2}]_{B}$ and $[x_{3}]_{B}$ using the special correlated randomness, such that $P_{3}$ gets both values in addition to it's shares, while $P_{1}$ and $P_{2}$ get $x_{3}$ and $x_{2}$ in clear respectively. Then we compute a binary circuit to add $[x_{1}]_{B}=BinAdd(BinAdd([x]_{B},[x_{2}]_{B}),[x_{3}]_{B})$. Finally, we open $[x_{1}]_{B}$ to $P_{1}$ and $P_{2}$. The arithmetic shares then are $[x]=(x_{1},−x_{2},−x_{3})$.

To account for modular reductions in finite fields, we follow a similar strategy as for the arithmetic to binary conversion to translate $[x]_{B}$:

- $P_{i}$ samples $r_{i}$ to be a new random binary share of $0$
- $P_{1}$ samples $x_{3}$ using RNG2 and sets $x_{3}=−x_{3}$;
- $P_{2}$ samples $x_{2}$ using RNG1 and sets $x_{2}=−x_{2}$;
- $P_{3}$ samples $x_{2}$ using RNG1 and $x_{3}$ using RNG2, sets $x_{2}=−x_{2}$, $x_{3}=−x_{3}$, and $t=(x_{2}+x_{3}modp)⊕r_{3}$;
- It follows that $(r_{1},t,r_{3})$ is a valid binary sharing of $(x_{2}+x_{3}modp)$

- $P_{i}$ sends its share of $(r_{1},t,r_{3})$ to $P_{i+1}$
- Each party now has a valid binary replicated sharing $[x_{2,3}]_{B}$ of $(x_{2}+x_{3}modp)$

- The parties compute a binary adder circuit of $k=⌈g_{2}(p)⌉$ bits to sum up $[x]_{B}$ and $[x_{2,3}]_{B}$ to get $[t_{1}]_{B}$ with $k+1$ bits (including overflow bit).
- The parties compute the subtraction of $[t_{1}]_{B}−p$ inside a binary circuit to get $[t_{2}]_{B}$.
- The $(k+1)$-th bit of $[t_{2}]_{B}$ indicates an overflow of the subtraction. If an overflow occurs, $[x_{1}]_{B}$ should be the first $k$ bits of $[t_{1}]_{B}$, otherwise the first $k$ bits of $[t_{2}]_{B}$. This if statement can be computed with a CMUX gate.
- We open $[x_{1}]_{B}$ to $P_{1}$ and $P_{2}$
- The final sharing is $[x]=(x_{1},x_{2},x_{3})$ and each party has (only) access to the shares it requires for the replication.

#### Bit Injection

To translate a single shared bit $[x]_{B}$ to a arithmetic sharing, we perform share splitting and create valid arithmetic shares of the shares: $[x_{1}]=(x_{1},0,0)$, $[x_{2}]=(0,x_{2},0)$, and $[x_{3}]=(0,0,x_{3})$. Then, we combine the shares by calculating arithmetic XORs: $[x]=AXor(AXor([x_{1}],[x_{2}]),[x_{3}])$, where $AXor(a,b)=a+b−2⋅a⋅b$.

#### Binary Addition Circuits

As mentioned in the arithmetic to binary conversions, we need binary addition circuits. Since the bitlength of the used prime fields is large, we use depth-optimized carry-lookahead adders for the conversions. Currently, we implement Kogge-Stone adders, since these can be computed efficiently using shifts and AND/XOR gates without extracting specific bits.

The general structure of a Kogge-Stone adder to add two binary values $x,y$ is to first compute $p[i]=x[i]⊕y[i]$ and $g[i]=x[i]∧y[i]$, where $x[i]$ is the $i$-th bit of $x$. Then, $p$ and $g$ are combined using a circuit with logarithmic depth (in the bitsize). This circuit is implemented in the `kogge_stone_inner`

function.

For binary subtraction circuits, we basically compute an addition circuit with the two's complement of $y$. Thus, we essentially compute $2_{k}+x−y$. If $y$ is public, the $2_{k}−y$ can directly be computed and the result is just fed into the Kogge-Stone adder. If $y$ is shared, we invert all $k$ bits and set the carry-in flag for the Kogge-Stone adder. This simulates two's complement calculation. The set carry-in flag has the following effects: First, $g[0]$ must additionally be XORed by $p[0]$. Finally, the LSB of the result of the Kogge-Stone circuit needs to be flipped.

### Reconstruction

Reconstruction of a value is implemented as $P_{i}$ sending $z_{i−1}$ to $P_{i+1}$. Then each party has all shares.

### Security

Our implementation provides semi-honest security with honest majority, i.e., the scheme is secure if all parties follow the protocol honestly and no servers collude.

## Shamir Secret Sharing

Shamir secret sharing is a different way of instantiating a linear secret sharing scheme which is based on polynomials. To share a value $x∈F_{p}$, one first has to sample a random polynomial of degree $t$, where $x$ is in the constant term. I.e., one samples $a_{1},a_{2},...,a_{t}$ randomly from $F_{p}$ and sets: $Q(X)=x+a_{1}⋅X+a_{2}⋅X_{2}+...+a_{t}⋅X_{t}$. The share of party $i$ then is $Q(i)$. In other words, $[x]_{t}=(x_{1},x_{2},...,x_{n})$, where $x_{i}=Q(i)$.

Reconstruction then works via lagrange interpolation of any $t+1$ shares: $x=∑_{i}λ_{i}x_{i}$, where $λ_{i}$ is the corresponding lagrange coefficient.

### Supported operations

#### Linear Operations

Shamir's secret sharing allows, similar to additive sharing, to compute linear functions locally without party interaction:

- Constant addition: $[x]_{t}+y=(x_{1}+y,x_{2}+y,x_{3}+y)$
- Share addition: $[x]_{t}+[y]_{t}=(x_{1}+y_{1},x_{2}+y_{2},x_{3}+y_{3})$
- Constant Multiplication: $[x]_{t}⋅y=(x_{1}⋅y,x_{2}⋅y,x_{3}⋅y)$

#### Multiplications

Shamir secret sharing comes with a native multiplication protocol: $z_{i}=x_{i}⋅y_{i}$ is a valid share of $[z]_{2t}=[x]_{t}⋅[y]_{t}$. However, $z_{i}$ is a point on a polynomial with degree $2t$. In other words, the degree doubles after a multiplication and twice as many parties ($2t+1$) are required to reconstruct the secret $z$. Thus, one needs to perform a degree reduction step in MPC for further computations. In DN07, this is done by sampling a random value, which is shared as a degree-$t$ ($[r]_{t}$) and degree-$2t$ ($[r]_{2t}$) polynomial. Then, the parties open $[z]_{2t}+[r]_{2t}$ to $P_{1}$, who reconstructs it to $z_{′}=z+r$. Then. $P_{1}$ shares $z_{′}$ as a fresh degree-$t$ share to all parties, who calculate $[z]_{t}=[z_{′}]_{t}−[r]_{t}$.

#### Rng Setup

For the degree reduction step after a multiplication we require degree-$t$ and degree-$2t$ sharings of the same random value $r$. We generate these values following the techniques proposed in DN07, to generate $t$ random pairs at once:

- Each party $P_{i}$ generates a random value $s_{i}$ and shares it as degree-$t$ share $[s_{i}]_{t}$ and degree-$2t$ share $[s_{i}]_{2t}$ to the other parties.
- After receiving the all shares, one sets $[s]_{t}=([s_{1}]_{t},[s_{2}]_{t},...,[s_{n}]_{t})_{T}$ and $[s]_{2t}=([s_{1}]_{2t},[s_{2}]_{2t},...,[s_{n}]_{2t})_{T}$.
- Calculate $([r_{1}]_{t},[r_{2}]_{t},...,[r_{t}]_{t})_{T}=M⋅[s]_{t}$ and $([r_{1}]_{2t},[r_{2}]_{2t},...,[r_{t}]_{2t})_{T}=M⋅[s]_{2t}$, where $M∈F_{p}$ is a Vandermonde matrix.
- The pairs $([r_{i}]_{t},[r_{i}]_{2t})$ for $1≤i≤t$ are then valid random shares which can be used for resharing.

For simplicity we use the following Vandermonde matrix: $M= 111⋮1 122_{2}⋮2_{t} 133_{2}⋮3_{t} .........⋱... 1nn_{2}⋮n_{t} $

### Reconstruction

Reconstruction is currently implemented as $P_{i}$ sending its share $x_{i}$ to the next $t$ parties. Then, each party has $t+1$ shares to reconstruct the secret.

### Security

Our implementation provides semi-honest security with honest majority, i.e., the scheme is secure if all parties follow the protocol honestly and at most $t$ servers collude. $t$ can, thereby, be chosen to be $t≤2n−1 $.

## MPC for group operations

So far, we only discussed MPC for field elements $F_{p}$. However, one can easily extend it to MPC over Group elements $G$. W.l.o.g. we will use the notation for additive groups $G$ (e.g., elliptic curve groups). A secret share $[x]∈F_{p}$ can be translated to a shared group element by $[X]=[x]⋅G$, where $G$ is a generator of $G$. Then, $[X]=(X_{1},X_{2},...,X_{n})$ is a valid share of $X=x⋅G$. Linear operations directly follow from the used linear secret sharing scheme: $[Z]=a⋅[X]+b⋅[Y]+C=(a⋅[x]+b⋅[y]+c)⋅G$. Shared scalar multiplications also follow from the secret sharing scheme: $[Z]=[x]⋅[Y]=[x]⋅[y]⋅G$.

## Shamir vs Rep3

Shamir and Rep3 are both linear secret sharing schemes which provide semi-honest security with honest-majority. However, they have some important differences.

- Shamir can be instantiated with $n≥3$ parties, while Rep3 is limited to $n=3$ parties.
- In Shamir, each share is just one field element $∈F_{p}$, while in Rep3 each share is composed of two field elements.
- In Shamir, the overhead on the CPU is significantly smaller compared to Rep3, where each operation is applied to two shares.
- Rep3 allows efficient arithmetic-to-binary conversions.

## Witness Extension

Due to not having an efficient arithmetic to binary conversion, we do not have a witness extension implementation for Shamir sharing at the moment. However, we provide a bridge implementation, which can translate Rep3 shares to 3-party Shamir shares (with threshold/poly-degree $t=1$).

This bridge works by first letting $P_{i}$ translate its first additive share $x_{i}$ to a Shamir share by dividing by the corresponding lagrange coefficient. This, however, creates a 3-party Shamir sharing with threshold/poly-degree $t=2$. Thus, we perform the same degree-reduction step, which is also required after a Shamir multiplication.

^{1}