Try   HackMD

Multiset checks in PLONK and Plookup

Grand Products

PLONK at its technical heart is based on the following primitive -
The grand product check: given commitments to polynomials

f,g over a finite field
F
, and a subset
H={x1,,xn}F
check that the product of values of
f
and
g
over
H
agree.
That is, whether
i[n]ai=?i[n]bi,

where
ai=f(xi)
and
bi=g(xi)
. The PLONK paper shows this check can be performed with great efficiency when
H
is a multiplicative subgroup.

Polynomials and Vectors

Throughout this post, whenever we discuss a vector

a of length
n
, we assume in the actual protocol the prover has sent a commitment to a polynomial
f
with
f(xi)=ai
as above. Thus, we can allow operations like adding vectors coordinate wise, that will be emulated in the real protocol by applying the same operation on the polynomial commitments.

Grand products to multiset checks

One reason a grand product check is useful, is that with a little randomness it translates to a more powerful primitive - the multiset equality check:
Given two vectors

a=(a1,,an),b=(b1,,bn) check they contain the same elements, counting repetitions, possibly in different order.

For example,

(1,1,2,3) is multiset-equal to
(2,1,1,3)
but not multiset-equal to
(1,2,3,3)
or
(1,1,2,4)
.

Let's see the reduction from multiset equality to grand product. The verifier simply chooses a random

γF, and runs the grand product check on the randomly shifted vectors
aa+γ,bb+γ
(
γ
is added to all coordinates).
This grand product check corresponds to
i[n](ai+γ)=?i[n](bi+γ)

Thinking of both sides as polynomials in

γ, the Schwarz-Zippel Lemma implies that the grand product check fails with high probability unless
a,b
are mutliset-equal.

Permutations via Multiset checks

Given a permutation

σ:[n][n] suppose we want to check that
b=σ(a)
, in the sense that for each
i
,
bi=aσ(i)
. See the PLONK paper (and other SNARK papers) as to why permutation checks are central to SNARKs. To reduce this to a multiset check, look first at the vectors of pairs
((ai,i))i[n],((bi,σ(i))i[n]

Thinking about it for a minute, you can see that they are multiset-equal if and only if

b=σ(a). But we wish to reduce to a mutliset check on vectors of elements, rather than vectors of pairs.
For this we choose random
β
, and define vectors
a,b
by
aiai+βi,bibi+βσ(i)

If the above vectors of pairs are not multiset equal, then with high probability

a and
b
aren't either. Thus, it suffices to do the multiset check between
a
and
b
.

Table lookups via Multiset checks

The XOR example

Another very useful operation for zk-SNARKs is the table lookup operation. For example, suppose we had three vectors of field elements

a=(a1,,an),b=(b1,,bn),c=(c1,,cn);
and we want to check that for each
i[n]
,
ai,bi,ci
correspond to
8
-bit strings, and
ci=aibi
where
is a bitwise XOR. A traditional SNARK approach would require many arithmetic constraints for each tuple
(ai,bi,ci)
to decompose the inputs into bits and perform the bitwise XORs.

Lookup tables are an alternative approach to operations requiring many constraints. We start by precomputting the truth table

T corresponding to the XOR operation. So
T
consists of three vectors/columns
T1,T2,T3
of length
216
such that the rows of
T
,
(T1,i,T2,i,T3,i)
, go over all legal input/output combinations for 8-bit XOR.

Remark: In the SNARK context,

a,b,c typically correspond to witness polynomials for which only for some
i
's we wish to check a XOR relation; combining different tables and gates can be achieved with "selectors", see e.g. Section 4.1 of the plookup paper.

Reducing tuples to single elements

We thus wish to show that each tuple

(ai,bi,ci) is equal to some row of
T
. The first thing we do is use randomness to reduce checking tuples to checking single elements: We choose a random
α
and look at the vector
f
with
fi=ai+αbi+α2ci
for each
i[n]
. We similarly create a randomly compressed version
t
of the table
T
with
ti=T1,i+αT2,i+α2T3,i
. The Schwarz-Zippel Lemma can show that if some tuple
(ai,bi,ci)
was not in
T
, then with very high probability
fi
is not an element of
t
.

The plookup protocol - sort and compare differences

So it now suffices to check that every element of

f is an element of
t
. Let's denote this by
ft
. The plookup protocol reduces this to one multiset equality check. The protocol is based on the following observation: Suppose we have sorted versions of two vectors, and further know they start at the same element. Then, they contain the same distinct elements if and only if they contain the same sequence of non-zero differences between adjacent elements.

Let's describe this on a concrete example:

f=(2,2,1,1,5),t=(1,2,5). The prover will create an additional vector
s
- which is a "sorted by
t
" version of the concatenation
(f,t)
of
f
and
t
. Sorted by
t
means elements appear in
s
in the same order they appear in
t
.
In our example, we have
s=(1,1,1,2,2,2,5,5)
.

Now the point is to look at the difference vectors

s,t of
s
and
t
; i.e. the vectors consisting of the differences of adjacent elements. We have
s=(0,0,1,0,0,3,0),t=(1,3)
.

Note that when

ft,
s
contains exactly the same non-zero elements as
t
. Let us denote by
t
the vector
t
concatenated with
|f|
zeroes. At this point, let's first describe a simpler reduction using two multiset checks:

  1. Between
    s
    and
    (f,t)
    .
  2. Between
    s
    and
    t
    .

We claim these two checks suffice:
The first check implies in particular that

fs. Thus, after the first check it suffices to verify that
st
.

The first check also implies that

ts. Thus, if
s
contained a value outside of
t
, it would have to contain more than
|t|
distinct values. But the second check implies
s
has at most
|t|1
non-zeroes, and so
s
has at most
|t|
distinct values.

A more efficient version using randomness

Now, let's see the plookup reduction that uses only one multiset check. The verifier chooses random

β, and we define
s,t
to be the "randomized difference vectors" of
s
and
t
. That is
si=si+βsi+1
, and
t
is defined analogously.
We now claim that it suffices to do a single multiset check between
s
and
((1+β)f,t)
. To see this most easily, it will be convenient to think of our elements as formal polynomials in
β
, rather than field elements.
Using this viewpoint, the elements of
s
are the degree one polynomials
si+si+1β
.
When
sisi+1
this cannot match with an element of
(1+β)f
which will have the same coefficient for
1
and
β
, and so this element must match with one from
t
of the form
tj+tj+1β
. This means that whenever
s
"changes" the new value
si+1
is contained in
t
, and so
st
.
From the other side, each polynomial
fi+fiβ
must match with an element of
s
. It can only match with an element
sj+sj+1β
with
sj=sj+1
. So, for some
j
,
sj=sj+1=fi
; hence
fs
, and so
ft
.

Finally, the Schwarz-Zippel Lemma tells us that these comparisons between formal polynomials in

β with high probability will not differ from the comparisons of the actual elements for the random choice of
β
.

Summary:

Describing protocols via primitives like multiset checks abstracts away many details and let's us more easily see what's going on at a high level.

References/Acknowledgements: The reduction from permutations to grand products appeared first in a paper by Bayer and Groth. We thank Tom Walton-Pocock for a review and suggestions