Diogenes is an ambitious project to design and run a “ceremony” to generate an RSA modulus. The Ceremony is a multiparty computation (MPC) protocol of an unprecedented scale. Once completed, the generated modulus will be incorporated into a VDF protocol, which will be used as part of an unbiased random beacon in the Eth2.0 blockchain.

The Ligero Inc team leads the project with LigeroRSA, the code repository implementing Diogenes. It’s 21k C++ lines of code, not including external libraries.

Upon request of the VDF Alliance and the Ethereum Foundation, Zengo is reviewing Diogenes as a real-world cryptographic system. We’ve teamed up with Prof. Claudio Orlandi and Prof. Peter Scholl for the project.

In our first blog post, Diogenes Octopus, we described a potential attack vector that could have gained backdoor access to Ethereum 2.0 VDF. The attack required the central coordinator to collude with one of the participants.

In this post, we present a new attack named* DogByte*. This attack allows any passive observer to covertly learn the secrets** p,q**, completely breaking the security of the protocol.

## The Diogenes protocol in a nutshell

The goal of the Diogenes protocol is to generate a bi-prime ** N=pq** where

**are 1024-bit primes, unknown to any parties. To this end, the parties run the following protocol:**

*p, q*- Each party samples random local secret shares
.*p ᵢ, q ᵢ* - The parties compute a joint public key.
- The parties encrypt their secret shares with the joint public key.
- A designated party, named the coordinator, combines all the ciphertexts and computes homomorphically an encryption of
and*p = (p ₁ + p₂ + .. + p_n), q = (q ₁ + q₂ +…+ q_n)*.*N = p***q* - The parties jointly decrypt to get a candidate
.*N* - The parties run tests to check that
and*p*are two primes (remember that no single party knows*q*, so all tests are run in a distributed fashion)*p,q*

It’s possible that the protocol set out above might fail to produce a bi-prime ** N**. Therefore, the steps are repeated many times in parallel to guarantee that at least one candidate will be valid (pass all tests). The protocol will naturally generate many “bad” candidates. This point should be kept in mind because it will be crucial to the attack.

## Adding zero-knowledge to handle malicious behavior

The protocol above is correct, but it’s not yet secure. Nothing keeps a participant from cheating. For example, what happens if one party in the protocol runs the distributed primality tests on their secret input (step 6) but reports false results? Candidate ** N** might be chosen while not an actual bi-prime.

Letting a malicious party participate in a protocol that assumes honest computation can be devastating: the malicious party can cause a DoS attack, learn secret inputs, or introduce bias.

The solution is conceptually simple.

Each step executed by each party must be accompanied by a proof for the correctness of the computation. Continuing our example, reporting a false result by a malicious party will get caught immediately because the proof for the correctness of the computation will fail. The protocol uses zero-knowledge (ZK) proofs to prevent exposure of secret inputs during each computation.

## The protocol must run in under 20 minutes

The protocol designers faced another issue. Repeating the protocol and adding a ZK proof to each step is expensive and time-consuming. The spec required the protocol to run in under 20 minutes, so the following optimizations were suggested as a remedy:

- Delay all ZK proofs until the last step of the protocol.
- Produce a ZK proof only for the bi-prime candidates that survived all the tests.
- For the rest of the candidates: each party will simply reveal all the secret randomness used to derive the “bad” candidate. The check for correctness of computation will be carried out over the revealed values.

Since the parties’ inputs are independent and random, there is no risk in revealing “bad” candidates as the revealed values cannot leak anything about the random secrets used for the “good” candidates. On the other hand, the ZK proofs will guarantee that “good” candidates were computed correctly, without leaking any bits of its primes p,q.

## Packing encryptions

There is a second important optimization used in the protocol. To understand it, we first need to explain the homomorphic encryption scheme.

The encryption scheme used is *Ring-LWE (RLWE)*: the public key is a pair ** (a,b)**, and the private key is a secret s such that:

**where**

*b = a·s + e***is a small noise term (and “**

*e***” represents inner product). In the case of RLWE, we work with polynomials: in fact:**

*·***are all polynomials of some degree (**

*a, s, b, e***). When we say that**

*d***are small, we mean that all the**

*s, e***coefficients are small and bounded in the same way.**

*d+1*To encrypt a message ** m**:

- Encode it as one coefficient of a polynomial
- Sample small noise polynomials
*x, y, z* - Compute
*c₁ = a·x+y* - Compute
*c₂ = b·x+z+m*

** C = (c₁,c₂)** is the ciphertext. The computation is done over coefficients of the polynomials. But this encrypted scheme is very wasteful, using all those degree (

**) polynomials for a single message. Moreover, the message is encoded as a**

*d**single*coefficient, which leaves all other coefficients to be

**in the message polynomial.**

*0*Indeed, for encrypting multiple messages, there is an obvious optimization here, which is to “**pack**” the different messages into different slots (encode them to different coefficients). This optimization is used in Diogenes protocol: Each participant encrypts its private input, and *all* encryptions are packed to a single ciphertext.

## When the two optimizations collide

Separately, the two optimizations provide considerable improvement to the efficiency of the protocol. However, as we will illustrate, having them together creates an unwanted side-effect: a complete leakage of the secret ** p,q**!

If we assume the attacker gains access to the transcript of the protocol (which is public). By looking at the transcript, the attacker will be able to see the ciphertext, which is a packed encryption of all the parties’ contributions. Now, recall that since ZK proofs are expensive, any unnecessary proof is replaced by revealing the value in the clear. Concretely:

- The
coefficients vector (*m*) of size*c₂*will be revealed except for*d*slots belonging to “good” candidates*k* - The
coefficients vector (*y*) of size*c₁*will be revealed except for*d*slots belonging to “good” candidates*k* - The
coefficients vector (*z*) of size*c₂*will be revealed except for*d*slots belonging to “good” candidates*k*

The ** x** coefficients vector (

**) is kept completely hidden. All of it is used as a witness in the ZK proofs.**

*c₂*The attacker’s target is to learn the ** k** hidden message coefficients. The first thing to do is to recover the

**vector. Now since:**

*x*- The locations of the known coefficients are public.
- Writing
,*c₁*using linear algebra, each one produces*c₂*equations,*d*of them are error-free equations. In total, combining*d-k*,*c₁*, we have*c₂*error-free equations (equations without unknown*2(d-k)*elements).*y, z, m* - Each of the equations is a linear combination of the secret vector
.*x* (size of vector*2(d-k) > d*) in our protocol.*x*

We can recover *x**in full* using Gaussian elimination on ** d** out of the

**equations. Once we learned the**

*2(d-k)***vector, we compute the**

*x***slots directly in the message vector that were kept hidden in the**

*k***equations from**

*k***. And just like that — we learn all the secrets in the protocol.**

*c₂*(In fact, the unknown message slots are masked with small noise elements from ** w** vector. So, there is an additional rounding operation to remove the noise and get the clean message from each equation).

# A toy example

To explain how the attack works more clearly, here is a short toy example with 3 parties. The ciphertext is two public vectors:

*c₁ = [2.2, 2.1, 2.3]*

*c₂ = [4, 4.7, 5.8]*

The public key, also known to all, is the two vectors:

*a = [2, 4, 6]*

*b = [3, 5, 7]*

The message vector is ** [m₁,m₂,m₃]**. Let’s assume only

**represents a “good” candidate (information known to all). Therefore the parties reveal**

*m₃***. The unknown secrets are: the**

*y₁=0.2, y₂ = 0.1 z₁ = 0.4, z₂ = 0.1, m₁ = 1 , m₂ = 2***vector [**

*x***and**

*x₁,x₂,x₃], y₃, z₃***.**

*m₃*Here are all the equations:

*c₁₁ = 2.2 = 2×1 + 4×2 + 6x₃ + 0.2*

*c₁₂ = 2.1 = 2×1 + 4×2 + 6x₃ + 0.1*

*c₁₃ = 2.3 = 2×1 + 4×2 + 6x₃ + y₃*

*c₂₁ = 4 = 3×1 + 5x₂ + 7x₃ + 0.4 + 1*

*c₂₂ = 4.7 = 3×1 + 5x₂ + 7x₃ + 0.1 + 2*

*c₂₃ = 5.8 = 3×1 + 5x₂ + 7x₃ + z₃ + m₃*

We first use the equation for ** c₁₁, c₁₂, c₂₁** to learn

*[x₁,x₂,x₃]***. This is done using Gaussian elimination. Note that the**

*= [0.3, 0,2, 0.1]***equation could have been used as well.**

*c₂₂*We then plug ** x₁,x₂,x₃** into equation

**to get**

*c₂₃*

*z₃ + m₃ = 3.1*Rounding to the closest integer, we get ** m₃ = 3**, and we are done.

## The aftermath, fix, and lessons learned

We responsibly disclosed the attack, and the authors of the paper are working on a fix. The fix will most likely be to not reveal any of the ** y, z, m** slots for the “bad” candidates and use ZK for all. This will probably slow down the protocol by a few minutes.

While the paper does provide a security proof, all optimizations, including those discussed above, are not included in the paper’s security analysis.

Because the DogByte attack’s root cause is the unsafe usage of optimizations, the authors are now writing a full proof for the protocol that includes the optimizations.

As a quick side note, our attack considered the April 20th version of the Diogenes paper. Section 6.3 describes the optimization of revealing all the parties’ secret randomness used in the “bad” candidates computation.

## Acknowledgements

We would like to thank the Ethereum Foundation, VDF Alliance, the Ligero team, Dmitry Khovratovich, Bernardo David, Riad Wahby, Mary Maller, Claudio Orlandi, Peter Scholl, and Ariel Nof for their work and continued dedication.

Stay tuned for part 3 🙂