Skip to main content
Try out the RareSkills ZK AI Tutor!
The RareSkills Book of Zero Knowledge

Reducing the number of equality checks (constraints) through random linear combinations

Last updated on Nov 13, 2024

Random linear combinations are a common trick in zero knowledge proof algorithms to enable m equality checks to be probabilistically checked with a single equality check. Suppose we have m inner products we are trying to prove. Instead of creating m proofs, we create a random linear combination of the equalities and prove that.

Equality of Pedersen Commitments

First, let’s consider how we might prove the equality of multiple Pedersen commitments.

If we have elliptic curve points G and B with unknown discrete logs, and blinding terms α and β we can construct Pedersen committments L and R where

L=aG+αB
R=bG+βB

The verifier can check if a=b if the prover provides the difference in the blinding terms. The verifier cannot simply check L=R because the blinding terms will generally not be equal to each other, i.e. α≠β.

If the prover wishes to convince the verifier that a and b are committed to L and R respectively, but without revealing a and b, the prover can compute

π=α−β

And give π to the verifier. The verifier computes

L=?R+πB

Under the hood, this expands to

(aG+αB)=(bG+βB)+(α−β)B

All the blinding terms will cancel out leaving aG=?bG.

But suppose the prover wishes to establish equality for several commitments, i.e. L1=L2,L2=R2,...,Lm=Rm. The naïve solution is to send m blinding terms π1,...,πm and the verifier will run m equality checks. This will require sending m field elements (π1,...,πm) and the verifier’s algorithm will run in 𝒪(m) time.

Why the prover cannot simply add up all the commitments

Suppose we have l1,l2,r1,r2 with commitments L1,L2,R1,R2 respectively. Suppose also the prover wants to show that l1=r1 and l2=r2 without revealing them.

The following check is not secure:

L1+L2=R1+R2+πB

where π is the difference in the blinding terms. As a counterexample, consider the case where l1=1,r1=2,l2=2,r2=1. The sums are balanced, but the original claim is incorrect.

Random linear combinations

However, if the prover is required to show that

L1+L2z=R1+R2z+πB

for a random value z they cannot predict, then the scheme is secure.

Specifically, the prover and verifier do the following algorithm:

Randomized proof of equality

Setup

The prover and verifier agree on elliptic curve points G and B, where the discrete logs are unknown.

Prover sends commitments

The prover generates blinding terms α1,α2,β1,β2 and creates the Pedersen commitments

L1=l1G+α1B
R1=r1G+β1B
L2=l2G+α2B
R2=r2G+β2B

and sends (L1,L2,R1,R2) to the verifier.

Verifier picks a random z

The verifier chooses a random field element z and sends it to the prover.

Prover computes the difference in blinding terms

The prover computes π=α1+α2⋅z−β1−β2⋅z and sends π to the verifier.

Final verification check

The verifier checks that

L1+L2z=?R1+R2z+πB

Security analysis

If l1=r1 and l2=r2 then the equation will be balanced regardless of the choice of z, assuming the prover computed π correctly.

Now suppose l1≠r1 or l2≠r2. The prover still will not be able to produce a valid π because doing so would require solving for the discrete logs of G and B.

Generalizing to m checks

If we have m equality checks, L1=R1,L2=R2,...,Lm=Rm, the verifier could send m random elements z1,…,zm and the prover could provide π such that

L1+L2z1+L3z2+...Lmzm−1=?R1+R2z1+R3z2+⋯+Rmzm−1+πB

However, this requires the verifier to send m elements, leading to a linear communication overhead. The communication overhead can be reduced to constant if the verifier only sends z and the prover and verifier separate the commitments by successive powers of z:

L1+L2z+L3z2+...Lmzm−1=?R1+R2z+R3z2⋯+Rmzm−1+πB

Security analysis

The left-hand-side and right-hand-side are both polynomials of degree m−1. If they are unequal to each other, then they intersect in at most m−1 points by the Schwartz Zippel Lemma. If m≪p where p is the order of the finite field, then again the probability of z being an intersection point is negligible.

Random linear combinations of inner products

We can generalize the above technique to combine multiple inner products together.

Suppose we have two inner products

⟨𝐚L,𝐚R⟩=v1 and ⟨𝐚L,𝐚W⟩=v2

Because the two inner products share a common term, it is algebraically possible to combine them as follows:

⟨𝐚L,𝐚R+𝐚W⟩=v1+v2

However, this is not secure from a soundness perspective because it is possible that ⟨𝐚L,𝐚R⟩≠v1 and ⟨𝐚L,𝐚W⟩≠v2 but ⟨𝐚L,𝐚R+𝐚W⟩=v1+v2.

As expected, we can solve this by using a random linear combination.

⟨𝐚L,𝐚R⟩=v1 // first inner productz⟨𝐚L,𝐚W⟩=z⋅v2 // second inner product⟨𝐚L,z⋅𝐚W⟩=z⋅v2 // bring z inside⟨𝐚L,𝐚R+z⋅𝐚W⟩=v1+z⋅v2 // combine into one inner product

We only need to create an inner product proof for a single inner product instead of two. It is crucial that the prover receives z after they have sent the relevant commitments, but we leave the exact details for the next chapter when we see an example of an algorithm using this technique: range proofs.

This tutorial is part of a series on ZK Bulletproofs.