Groth-Sahai Proofs Are Not That Scary
Mikhail Volkhov, Dimitris Kolonelos, Dmitry Khovratovich, Mary Maller | June 6, 2022
Groth-Sahai (GS) proofs are a zero-knowledge proving technique which can seem daunting to understand. This is because much of the literature attempts to generalise all possible things you can prove using GS techniques rather than because the proofs are overly complicated. In fact GS proofs are one of the simplest zero-knowledge constructions. For statements about group elements in pairing based groups, they are ideal because there is no heavy reduction to an NP constraint system, and this makes the prover very fast. Security wise they also rely on much more standard assumptions than SNARKs and thus are more likely to be secure.
In this post we will walk through an example Groth-Sahai proof and attempt to make the explanation accessible to a general cryptographic audience. Specifically we discuss how to prove that an ElGamal ciphertext contains or . Our example includes the improvements by Escala and Groth. Prerequisites include knowledge about what a zero-knowledge argument is and what Type-III pairings are (but not how they are constructed).
And for those interested in experimenting with GS proofs in practice we have written a simple implementation in python -- check it out! It includes both the example we will be going through in this paper, and the more general proving framework that you can use to construct proofs for your language.
ElGamal in Pairing Product Equations
In order to prove that an ElGamal ciphertext contains or we must first arithmetise this statement into a form that is compatible with GS proofs. GS proofs take as input pairing-product equations; pairing product equations can be seen as the equivalent of arithmetic circuits in the sense that they arithmetise the relation that we are trying to prove. Thus in this section we show how to represent our statement using pairing product equations. In later sections we will show how to prove that these equations are satisfied under zero-knowledge.
Notation and Pairings
Recall the standard property of pairings: We denote the first source group by and the second source group by . Elements from are denoted with wide hat like . We will write and trying, where it's possible, to use lowercase letters for exponents of the corresponding capital letter element.
Pairings allow us to define quadratic equations in the logarithms of the arguments, e.g.
If you have not worked with pairings with multiple bases, see this explanation:
Collapsible: On Pairings with Multible Bases
As later we will employ multiple bases and not just , pairing equations will also work "in parallel" for all pairs of bases from and . Consider the following example. By bilinearity of the pairing is equivalent to: In such a case we will always have when all and are chosen independently and uniformly at random.
Here is an example of how it works:
ElGamal Verification in Pairing Equations
We first present our solution for arithmetising the statement "This ciphertext contains or " directly and after explain the intuition for how we derived these equations. Let generate , and . Consider a (lifted) ElGamal ciphertext
Then is either or if and only if there exist witnesses such that
Note that the witness components must be kept secret because they reveal information about the message .
Our purpose now is to explain how we arrived at the above set of pairing product equations and along the way to illustrate the design constraints that the GS proving system presents us with. Arithmetising statements is an art that Daira Hopwood is exceptionally skilled at (check out the Zcash spec, Appendix A, for many cool arithemetisation tricks). Alas, we are not Daira so please bear with us even if our solution is not optimal.
One characteristic feature of GS proofs is that all secret witness components must be group elements rather than field elements. So our secret that we want to keep hidden cannot be field elements or or , but must instead be group elements or or . For our ciphertext to encrypt or we thus desire that . Turning to the equation (1) we have that this condition that is equivalent to
where logarithm is taken with base . Denote We wish to check that . Our one and only method of checking constraints is using pairing equations. We cannot pair with itself because we can only pair elements with elements. Thus we choose to "bridge" into by introducing an additional group element such that
where is a logarithm of some element and is a logarithm of some element .
Then (2) is equivalent to
That first condition in (3) that currently does not look very much like a pairing product equation. We cannot use logarithms in PPEs, so we need an alternative method for arithmetising that As are all in , we make another bridge:
In pairing equations this is equivalent to
Combining all our pairing equations together we arrive at our final pairing product equation for arithmetising that encrypts or .
General Proof Structure
In this section we describe the GS setup, prover and the verifier used in representing the statement "This ciphertext encrypts or ".
Transparent Setup
We discuss how to run the GS setup. The setup does not depend on our pairing product equations at all and the same setup is used for proving any statement. It is only the prover and the verifier that depend on the pairing product equation explicitly.
NIZK proofs are constructed with a common reference string (CRS), that is used for both producing and verifying proofs. In GS proofs the CRS is constructed using public randomness and therefore they are said to have a trustless setup (this is a positive thing because we do not have to trust a third party or MPC that replaces it, like with many SNARKs). The GS CRS consists of eight independent elements --- four in each group.
In practice these elements are typically sampled as the output of a hash function, and the seed is published so that anyone can verify the setup procedure. It is permitted and encouraged to have fun (not too much fun) when choosing the seed and we sometimes like to use the opening lines of famous books.
We will reuse the generator for our ElGamal ciphertext which helps us to simplify the structure of prover and verifier.
Commitments to Witnesses
We now describe our GS prover. The prover aims to show the existence of a witness that satisfies the pairing product equations. The witness is secret and cannot be revealed directly. Thus instead the prover commits to the witness, and proves that the committed witness satisfies a related set of pairing product equations. We discuss the form of this commitment before we present the related set of equations.
The prover computes two elements using an algorithm that looks a lot like ElGamal encryption. To commit to it chooses random field elements , sets and returns . We have expressed the commitment with respect to . To commit to elements in we use the same method with respect to the generators instead of .
Typically when we present this commitment scheme to cryptographers their immediate response is "why two generators?" or "why not use Pedersen commitments?". The answer to this question is highly nuanced and answering it here would disrupt the flow of this explanation. Thus we're not going to. But as a teaser, we will say that Groth and Sahai describe this commitment scheme as one that either satisfies hiding or binding depending on how the setup parameters are chosen.
Now, in our particular case of ElGamal encryption, we commit to our witness once for all equations :
The Prover and The Verifier
While the commitments are shared across all pairing product equations, each pairing equation requires a unique set of proof elements and verifier equations, so forms a "sub-proof". Here, mostly to stay concise, we show and later derive the proof system (prover and verifier) only for the second equation . For the full system thus, prover must produce proofs for all four equations, and verifier must verify them all.
Recall that has the form
The honest prover needs to construct the following eight elements, where are sampled randomly:
And the four equations the verifier must check on the commitments and proof elements are as follows:
The reader is encouraged to attempt deriving the same equations for which are both easier than our case (we put our derivation for them at the end of the blog post). A more sadistical writer might also ask the reader to derive equations for as an exercise (possibly hinting that it is a simple), but after having attempted this exercise for ourselves we realised that is more involved due to its quadratic component. Thus at the end of this document we will actively discuss .
The form of proof elements and equations is somewhat homogeneous: we always have 8 proof elements and 4 verification equation per pairing equation, and the LHS of verification equations is always the same. However, the number of pairings in verification equations depends on the particular form of the pairing equation (reflected in the RHS). The commitments, as mentioned before, are generated once for all pairing equations, which amounts to 2 elements per witness element.
The following illustration shows how it works on a large scale:
Deriving Equations for
The intention of this section is to provide an intuitive step-by-step explanation of how the proof elements and verification equations for the pairing product equation are derived. We describe our general strategy, but after that things are going to get more technical. To readers that don't fancy wading through pages of algebra, we recommend you stop reading after the general strategy is explained. To other readers who are more dedicated to understanding the magic behind GS proofs, we recommend you get comfortable with continously switching between additive and multiplicative notation because we do this a lot (we promise not in the same equation).
The General Strategy
We have a pairing product equation that the prover claims to hold for hidden witness variables. The prover cannot give the witness in the clear, this would violate zero-knowledge, but it still must tell the verifier something about its witness. The prover therefore generates a commitment which binds them to their witness without revealing any additional information.
Our general strategy now is to find an alternative set of pairing product equations that hold if and only if the contents of the commitments satisfy the original pairing product equation. Our strategy will proceed in two parts.
- During our first part we search for intemediary proof elements that satisfy an intermediary set of pairing product equations if and only if the contents of the commitment satisfy the original pairing product equation. We treat soundness as if it holds unconditionally i.e. as if the only way for the prover to cancel out the randomness from the CRS is to multiply by zero. In the formal proof, we actually show that soundness does hold unconditionally provided the CRS is chosen carefully.
- During our second part, we show how to randomise the intemediary proofs and pairing product equations in a way that fully hides the witness. This results in our final equations. Here we focus mostly on satisfying zero-knowledge but we must not break soundness in the process. In other words we try to ensure that a malicious verifier learns nothing from an honest prover, beyond the correctness of the ciphertext.
For arguing indistinguishability, one of the key properties we require is that the number of randomisers is equal to the number of proof elements minus the number of verifier equations. That way we can say e.g. that Element 1 is random, Element 2 is random, and Element 3 is the unique value satisfying Equation 1 given Elements 1 and 2. Thus our strategy is to add in additional randomisers to our proof elements and edit our verifier equations such that they still hold for the randomised proofs. To keep things sound we also have to add additional verifier equations to enforce that the prover doesn't abuse their newfound freedom. The other property we require is that there are no linear combinations between our randomisers such that they cancel out in undesirable ways. While deriving our equations for () we are merely going to optimistically hope that this holds, but formally check that it is the case later.
The Intemediary Pairing Product Equations for Commitments
For the first part of our strategy, we must find an intermediary set of pairing product equations demonstrating that the contents of the commitments
satisfy the second equation
For this explanation we find it helpful to work in logarithms, so here is some notation denoting the logarithms of generators in the CRS
Then the logarithms of our commitments are given by
If we now actually look at the logarithmic equation defined by () we get that
where . Notice that are known to the prover while are not. We make no assumptions on whether is known to the prover or not.
Our derivation strategy is, by introducing new variables, to obtain a set of equations equivalent to such that
- The equations do not contain ;
- The equations are bilinear, i.e. each term has at most one variable from each group.
Step 1: We first express and in terms of the commitments and the randomness , . The commitment should use the same randomness , as the commitment . Therefore, we substitute into the equation for and obtain:
Similarly for the second commitment:
Step 2: Substituting into we get
Step 3: The terms are already in the pairing equation form (degree at most two, at most two elements from different groups), so we leave them alone, moving to the RHS, and swapping sides of the equation:
Now, we want the RHS summands to be in the pairing-friendly form too. Currently they are not. For example, we cannot pair with because these are both in the same source group.
Step 4: To get the RHS into a pairing friendly form, we will introduce new elements. For each summand we introduce one proof element. For example, where is multiplied by , we introduce . This suggests creating four additional elements:
The additional proof elements we introduced is somewhat arbitrary --- there are many (closely related if not equivalent) ways to construct GS verification equations. Now our first equation is in the following well-formed pairing-compatible form:
Step 5: Our fifth and final step for determining the intemediary pairing equations is to enforce the previous four equations for . We start by joining the first two (substituting the second into the first) and obtaining: Similarly, by joining the third and the fourth equations, we get:
Resulting Intemediary Pairing Product Equation: Putting all steps together, our intemediary pairing product equation challenges the prover to find
such that they satisfy
(Proof elements in verification equations are without primes since they are considered to be formal variables.) Together these show that the commitments and contain witness elements and such that the second pairing product equation () is satisfied.
We are now going to frustrate the reader by observing that the above process was rather circular. Indeed we cannot reveal in the clear: they reveal too much information about the witness and violate zero-knowledge. For example observe that
for our secret message. The next step, however, will not be circular and we will show how to randomise these proof components in a manner that does not break zero-knowledge. That we have really gained is that depend only on the original pairing product equations and the commitment randomness . In particular they do not depend on the witness , .
A general property that is required (but not sufficient!) for zero knowledge is that number of randomisers number of proof elements number of verification equations. Here we have commitment elements with randomisers and then proof elements with no additional randomisers. Given verifier equations this leaves us randomiser short.
Adding Zero-Knowledge: Getting Sufficient Randomisers
For the second part of our strategy, we must randomise our intermediary proofs and pairing product equations to keep the witness hidden. We do this by adding blinding factors to (order does not matter), and cancelling out the additional noise using other proof elements. Often the only way we can balance the randomised pairing equations is by adding additional proof elements. When we do this, we either add at least one new randomiser to the new proof element, or a new verifier equation which is a quadratic combinations of our other proof elements.
Step 1: We first introduce a randomiser to . We must then edit our intemediary equations to adjust for the extra randomness. We set
By substituting this into the RHS of
we see that an additional term has been acquired. This is unwanted noise that we must cancel out. To cancel the extra terms we edit accordingly
because this term is multiplied by . Now satisfy and do not reveal the witness.
Step 2: We edit so that our randomised proof elements can satisfy it. The RHS of is given by
and this has aquired the additional noise . We cannot hope to cancel this noise out with because of the multiplier. For soundness, we also want to enforce that the noise added in is actually a multiple of and does not interfere with the witness. We thus introduce a new proof element that will be paired with blinded by an additional randomiser
And therefore, becomes
Now does not prevent from being satisfied whenever is satisfied because is an unused basis. To make this equation balance we modify and get
and we see is still satisfied.
Step 3: We look back at with respect to our randomised proof element . By substituting this into the RHS of
we see that an additional term has been acquired. This is unwanted noise that we must cancel out. To cancel the extra terms we edit accordingly
because this term is multiplied by . Now satisfy and do not reveal the witness.
Step 4: We edit so that our randomised proof elements can satisfy it. The RHS of is given by
and this has aquired the additional noise . To cancel out the extra noise we introduce two new proof elements that will be paired with and respectively, and blind them with and
And therefore, becomes
Now does not prevent from being satisfied whenever is satisfied because is an unused basis. To make this equation balance we modify :
and we see is still satisfied.
Step 5: We look back at with respect to our randomised proof element . By substituting this into the RHS of
we see that an additional term has been acquired. This is unwanted noise that we must cancel out. To cancel the extra terms we edit and accordingly
Now satisfy and do not reveal the witness.
Step 6: We edit so that our randomised proof elements can satisfy it. The RHS of is given by and this has aquired the additional noise .
We shall need to add a proof element which is paired with to cancel the noise. We cannot balance any additional randomness that this new element introduces because and already both have components. Thus for our final proof element to not use up a randomiser we instead add a verification equation. See that
We thus introduce a new proof element
and a verification equation
Now becomes
We do not need to edit or because no proof elements have been edited.
Resulting Verifier Equations: Putting everything together, we have the following eight proof elements
and verification equations