-
Notifications
You must be signed in to change notification settings - Fork 152
/
vector.go
717 lines (586 loc) · 18.1 KB
/
vector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
// Copyright 2020 ConsenSys Software Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by consensys/gnark-crypto DO NOT EDIT
package plookup
import (
"crypto/sha256"
"errors"
"math/big"
"math/bits"
"sort"
"github.com/consensys/gnark-crypto/ecc/bls12-378/fr"
"github.com/consensys/gnark-crypto/ecc/bls12-378/fr/fft"
"github.com/consensys/gnark-crypto/ecc/bls12-378/fr/kzg"
fiatshamir "github.com/consensys/gnark-crypto/fiat-shamir"
)
var (
ErrNotInTable = errors.New("some value in the vector is not in the lookup table")
ErrPlookupVerification = errors.New("plookup verification failed")
ErrGenerator = errors.New("wrong generator")
)
// Proof Plookup proof, containing opening proofs
type ProofLookupVector struct {
// size of the system
size uint64
// generator of the fft domain, used for shifting the evaluation point
g fr.Element
// Commitments to h1, h2, t, z, f, h
h1, h2, t, z, f, h kzg.Digest
// Batch opening proof of h1, h2, z, t
BatchedProof kzg.BatchOpeningProof
// Batch opening proof of h1, h2, z shifted by g
BatchedProofShifted kzg.BatchOpeningProof
}
// evaluateAccumulationPolynomial computes Z, in Lagrange basis. Z is the accumulation of the partial
// ratios of 2 fully split polynomials (cf https://eprint.iacr.org/2020/315.pdf)
// * lf is the list of values that should be in lt
// * lt is the lookup table
// * lh1, lh2 is lf sorted by lt split in 2 overlapping slices
// * beta, gamma are challenges (Schwartz-zippel: they are the random evaluations point)
func evaluateAccumulationPolynomial(lf, lt, lh1, lh2 []fr.Element, beta, gamma fr.Element) []fr.Element {
z := make([]fr.Element, len(lt))
n := len(lt)
d := make([]fr.Element, n-1)
var u, c fr.Element
c.SetOne().
Add(&c, &beta).
Mul(&c, &gamma)
for i := 0; i < n-1; i++ {
d[i].Mul(&beta, &lh1[i+1]).
Add(&d[i], &lh1[i]).
Add(&d[i], &c)
u.Mul(&beta, &lh2[i+1]).
Add(&u, &lh2[i]).
Add(&u, &c)
d[i].Mul(&d[i], &u)
}
d = fr.BatchInvert(d)
z[0].SetOne()
var a, b, e fr.Element
e.SetOne().Add(&e, &beta)
for i := 0; i < n-1; i++ {
a.Add(&gamma, &lf[i])
b.Mul(&beta, <[i+1]).
Add(&b, <[i]).
Add(&b, &c)
a.Mul(&a, &b).
Mul(&a, &e)
z[i+1].Mul(&z[i], &a).
Mul(&z[i+1], &d[i])
}
return z
}
// evaluateNumBitReversed computes the evaluation (shifted, bit reversed) of h where
// h = (x-1)*z*(1+\beta)*(\gamma+f)*(\gamma(1+\beta) + t+ \beta*t(gX)) -
//
// (x-1)*z(gX)*(\gamma(1+\beta) + h_{1} + \beta*h_{1}(gX))*(\gamma(1+\beta) + h_{2} + \beta*h_{2}(gX) )
//
// * cz, ch1, ch2, ct, cf are the polynomials z, h1, h2, t, f in canonical basis
// * _lz, _lh1, _lh2, _lt, _lf are the polynomials z, h1, h2, t, f in shifted Lagrange basis (domainBig)
// * beta, gamma are the challenges
// * it returns h in canonical basis
func evaluateNumBitReversed(_lz, _lh1, _lh2, _lt, _lf []fr.Element, beta, gamma fr.Element, domainBig *fft.Domain) []fr.Element {
// result
s := int(domainBig.Cardinality)
num := make([]fr.Element, domainBig.Cardinality)
var u, onePlusBeta, GammaTimesOnePlusBeta, m, n, one fr.Element
one.SetOne()
onePlusBeta.Add(&one, &beta)
GammaTimesOnePlusBeta.Mul(&onePlusBeta, &gamma)
g := make([]fr.Element, s)
g[0].Set(&domainBig.FrMultiplicativeGen)
for i := 1; i < s; i++ {
g[i].Mul(&g[i-1], &domainBig.Generator)
}
var gg fr.Element
expo := big.NewInt(int64(domainBig.Cardinality>>1 - 1))
gg.Square(&domainBig.Generator).Exp(gg, expo)
nn := uint64(64 - bits.TrailingZeros64(domainBig.Cardinality))
for i := 0; i < s; i++ {
_i := int(bits.Reverse64(uint64(i)) >> nn)
_is := int(bits.Reverse64(uint64((i+2)%s)) >> nn)
// m = z*(1+\beta)*(\gamma+f)*(\gamma(1+\beta) + t+ \beta*t(gX))
m.Mul(&onePlusBeta, &_lz[_i])
u.Add(&gamma, &_lf[_i])
m.Mul(&m, &u)
u.Mul(&beta, &_lt[_is]).
Add(&u, &_lt[_i]).
Add(&u, &GammaTimesOnePlusBeta)
m.Mul(&m, &u)
// n = z(gX)*(\gamma(1+\beta) + h_{1} + \beta*h_{1}(gX))*(\gamma(1+\beta) + h_{2} + \beta*h_{2}(gX)
n.Mul(&beta, &_lh1[_is]).
Add(&n, &_lh1[_i]).
Add(&n, &GammaTimesOnePlusBeta)
u.Mul(&beta, &_lh2[_is]).
Add(&u, &_lh2[_i]).
Add(&u, &GammaTimesOnePlusBeta)
n.Mul(&n, &u).
Mul(&n, &_lz[_is])
// (x-gg**(n-1))*(m-n)
num[_i].Sub(&m, &n)
u.Sub(&g[i], &gg)
num[_i].Mul(&num[_i], &u)
}
return num
}
// evaluateXnMinusOneDomainBig returns the evaluation of (x^{n}-1) on FrMultiplicativeGen*< g >
func evaluateXnMinusOneDomainBig(domainBig *fft.Domain) [2]fr.Element {
sizeDomainSmall := domainBig.Cardinality / 2
var one fr.Element
one.SetOne()
// x^{n}-1 on FrMultiplicativeGen*< g >
var res [2]fr.Element
var shift fr.Element
shift.Exp(domainBig.FrMultiplicativeGen, big.NewInt(int64(sizeDomainSmall)))
res[0].Sub(&shift, &one)
res[1].Add(&shift, &one).Neg(&res[1])
return res
}
// evaluateL0DomainBig returns the evaluation of (x^{n}-1)/(x-1) on
// x^{n}-1 on FrMultiplicativeGen*< g >
func evaluateL0DomainBig(domainBig *fft.Domain) ([2]fr.Element, []fr.Element) {
var one fr.Element
one.SetOne()
// x^{n}-1 on FrMultiplicativeGen*< g >
xnMinusOne := evaluateXnMinusOneDomainBig(domainBig)
// 1/(x-1) on FrMultiplicativeGen*< g >
var acc fr.Element
denL0 := make([]fr.Element, domainBig.Cardinality)
acc.Set(&domainBig.FrMultiplicativeGen)
for i := 0; i < int(domainBig.Cardinality); i++ {
denL0[i].Sub(&acc, &one)
acc.Mul(&acc, &domainBig.Generator)
}
denL0 = fr.BatchInvert(denL0)
return xnMinusOne, denL0
}
// evaluationLnDomainBig returns the evaluation of (x^{n}-1)/(x-g^{n-1}) on
// x^{n}-1 on FrMultiplicativeGen*< g >
func evaluationLnDomainBig(domainBig *fft.Domain) ([2]fr.Element, []fr.Element) {
sizeDomainSmall := domainBig.Cardinality / 2
var one fr.Element
one.SetOne()
// x^{n}-1 on FrMultiplicativeGen*< g >
numLn := evaluateXnMinusOneDomainBig(domainBig)
// 1/(x-g^{n-1}) on FrMultiplicativeGen*< g >
var gg, acc fr.Element
gg.Square(&domainBig.Generator).Exp(gg, big.NewInt(int64(sizeDomainSmall-1)))
denLn := make([]fr.Element, domainBig.Cardinality)
acc.Set(&domainBig.FrMultiplicativeGen)
for i := 0; i < int(domainBig.Cardinality); i++ {
denLn[i].Sub(&acc, &gg)
acc.Mul(&acc, &domainBig.Generator)
}
denLn = fr.BatchInvert(denLn)
return numLn, denLn
}
// evaluateZStartsByOneBitReversed returns l0 * (z-1), in Lagrange basis and bit reversed order
func evaluateZStartsByOneBitReversed(lsZBitReversed []fr.Element, domainBig *fft.Domain) []fr.Element {
var one fr.Element
one.SetOne()
res := make([]fr.Element, domainBig.Cardinality)
nn := uint64(64 - bits.TrailingZeros64(domainBig.Cardinality))
xnMinusOne, denL0 := evaluateL0DomainBig(domainBig)
for i := 0; i < len(lsZBitReversed); i++ {
_i := int(bits.Reverse64(uint64(i)) >> nn)
res[_i].Sub(&lsZBitReversed[_i], &one).
Mul(&res[_i], &xnMinusOne[i%2]).
Mul(&res[_i], &denL0[i])
}
return res
}
// evaluateZEndsByOneBitReversed returns ln * (z-1), in Lagrange basis and bit reversed order
func evaluateZEndsByOneBitReversed(lsZBitReversed []fr.Element, domainBig *fft.Domain) []fr.Element {
var one fr.Element
one.SetOne()
numLn, denLn := evaluationLnDomainBig(domainBig)
res := make([]fr.Element, len(lsZBitReversed))
nn := uint64(64 - bits.TrailingZeros64(domainBig.Cardinality))
for i := 0; i < len(lsZBitReversed); i++ {
_i := int(bits.Reverse64(uint64(i)) >> nn)
res[_i].Sub(&lsZBitReversed[_i], &one).
Mul(&res[_i], &numLn[i%2]).
Mul(&res[_i], &denLn[i])
}
return res
}
// evaluateOverlapH1h2BitReversed returns ln * (h1 - h2(g.x)), in Lagrange basis and bit reversed order
func evaluateOverlapH1h2BitReversed(_lh1, _lh2 []fr.Element, domainBig *fft.Domain) []fr.Element {
var one fr.Element
one.SetOne()
numLn, denLn := evaluationLnDomainBig(domainBig)
res := make([]fr.Element, len(_lh1))
nn := uint64(64 - bits.TrailingZeros64(domainBig.Cardinality))
s := len(_lh1)
for i := 0; i < s; i++ {
_i := int(bits.Reverse64(uint64(i)) >> nn)
_is := int(bits.Reverse64(uint64((i+2)%s)) >> nn)
res[_i].Sub(&_lh1[_i], &_lh2[_is]).
Mul(&res[_i], &numLn[i%2]).
Mul(&res[_i], &denLn[i])
}
return res
}
// computeQuotientCanonical computes the full quotient of the plookup protocol.
// * alpha is the challenge to fold the numerator
// * lh, lh0, lhn, lh1h2 are the various pieces of the numerator (Lagrange shifted form, bit reversed order)
// * domainBig fft domain
// It returns the quotient, in canonical basis
func computeQuotientCanonical(alpha fr.Element, lh, lh0, lhn, lh1h2 []fr.Element, domainBig *fft.Domain) []fr.Element {
sizeDomainBig := int(domainBig.Cardinality)
res := make([]fr.Element, sizeDomainBig)
var one fr.Element
one.SetOne()
numLn := evaluateXnMinusOneDomainBig(domainBig)
numLn[0].Inverse(&numLn[0])
numLn[1].Inverse(&numLn[1])
nn := uint64(64 - bits.TrailingZeros64(domainBig.Cardinality))
for i := 0; i < sizeDomainBig; i++ {
_i := int(bits.Reverse64(uint64(i)) >> nn)
res[_i].Mul(&lh1h2[_i], &alpha).
Add(&res[_i], &lhn[_i]).
Mul(&res[_i], &alpha).
Add(&res[_i], &lh0[_i]).
Mul(&res[_i], &alpha).
Add(&res[_i], &lh[_i]).
Mul(&res[_i], &numLn[i%2])
}
domainBig.FFTInverse(res, fft.DIT, fft.OnCoset())
return res
}
// ProveLookupVector returns proof that the values in f are in t.
//
// /!\IMPORTANT/!\
//
// If the table t is already commited somewhere (which is the normal workflow
// before generating a lookup proof), the commitment needs to be done on the
// table sorted. Otherwise the commitment in proof.t will not be the same as
// the public commitment: it will contain the same values, but permuted.
func ProveLookupVector(srs *kzg.SRS, f, t fr.Vector) (ProofLookupVector, error) {
// res
var proof ProofLookupVector
var err error
// hash function used for Fiat Shamir
hFunc := sha256.New()
// transcript to derive the challenge
fs := fiatshamir.NewTranscript(hFunc, "beta", "gamma", "alpha", "nu")
// create domains
var domainSmall *fft.Domain
if len(t) <= len(f) {
domainSmall = fft.NewDomain(uint64(len(f) + 1))
} else {
domainSmall = fft.NewDomain(uint64(len(t)))
}
sizeDomainSmall := int(domainSmall.Cardinality)
// set the size
proof.size = domainSmall.Cardinality
// set the generator
proof.g.Set(&domainSmall.Generator)
// resize f and t
// note: the last element of lf does not matter
lf := make([]fr.Element, sizeDomainSmall)
lt := make([]fr.Element, sizeDomainSmall)
cf := make([]fr.Element, sizeDomainSmall)
ct := make([]fr.Element, sizeDomainSmall)
copy(lt, t)
copy(lf, f)
for i := len(f); i < sizeDomainSmall; i++ {
lf[i] = f[len(f)-1]
}
for i := len(t); i < sizeDomainSmall; i++ {
lt[i] = t[len(t)-1]
}
sort.Sort(fr.Vector(lt))
copy(ct, lt)
copy(cf, lf)
domainSmall.FFTInverse(ct, fft.DIF)
domainSmall.FFTInverse(cf, fft.DIF)
fft.BitReverse(ct)
fft.BitReverse(cf)
proof.t, err = kzg.Commit(ct, srs)
if err != nil {
return proof, err
}
proof.f, err = kzg.Commit(cf, srs)
if err != nil {
return proof, err
}
// write f sorted by t
lfSortedByt := make(fr.Vector, 2*domainSmall.Cardinality-1)
copy(lfSortedByt, lt)
copy(lfSortedByt[domainSmall.Cardinality:], lf)
sort.Sort(lfSortedByt)
// compute h1, h2, commit to them
lh1 := make([]fr.Element, sizeDomainSmall)
lh2 := make([]fr.Element, sizeDomainSmall)
ch1 := make([]fr.Element, sizeDomainSmall)
ch2 := make([]fr.Element, sizeDomainSmall)
copy(lh1, lfSortedByt[:sizeDomainSmall])
copy(lh2, lfSortedByt[sizeDomainSmall-1:])
copy(ch1, lfSortedByt[:sizeDomainSmall])
copy(ch2, lfSortedByt[sizeDomainSmall-1:])
domainSmall.FFTInverse(ch1, fft.DIF)
domainSmall.FFTInverse(ch2, fft.DIF)
fft.BitReverse(ch1)
fft.BitReverse(ch2)
proof.h1, err = kzg.Commit(ch1, srs)
if err != nil {
return proof, err
}
proof.h2, err = kzg.Commit(ch2, srs)
if err != nil {
return proof, err
}
// derive beta, gamma
beta, err := deriveRandomness(&fs, "beta", &proof.t, &proof.f, &proof.h1, &proof.h2)
if err != nil {
return proof, err
}
gamma, err := deriveRandomness(&fs, "gamma")
if err != nil {
return proof, err
}
// Compute to Z
lz := evaluateAccumulationPolynomial(lf, lt, lh1, lh2, beta, gamma)
cz := make([]fr.Element, len(lz))
copy(cz, lz)
domainSmall.FFTInverse(cz, fft.DIF)
fft.BitReverse(cz)
proof.z, err = kzg.Commit(cz, srs)
if err != nil {
return proof, err
}
// prepare data for computing the quotient
// compute the numerator
s := domainSmall.Cardinality
domainBig := fft.NewDomain(uint64(2 * s))
_lz := make([]fr.Element, 2*s)
_lh1 := make([]fr.Element, 2*s)
_lh2 := make([]fr.Element, 2*s)
_lt := make([]fr.Element, 2*s)
_lf := make([]fr.Element, 2*s)
copy(_lz, cz)
copy(_lh1, ch1)
copy(_lh2, ch2)
copy(_lt, ct)
copy(_lf, cf)
domainBig.FFT(_lz, fft.DIF, fft.OnCoset())
domainBig.FFT(_lh1, fft.DIF, fft.OnCoset())
domainBig.FFT(_lh2, fft.DIF, fft.OnCoset())
domainBig.FFT(_lt, fft.DIF, fft.OnCoset())
domainBig.FFT(_lf, fft.DIF, fft.OnCoset())
// compute h
lh := evaluateNumBitReversed(_lz, _lh1, _lh2, _lt, _lf, beta, gamma, domainBig)
// compute l0*(z-1)
lh0 := evaluateZStartsByOneBitReversed(_lz, domainBig)
// compute ln(z-1)
lhn := evaluateZEndsByOneBitReversed(_lz, domainBig)
// compute ln*(h1-h2(g*X))
lh1h2 := evaluateOverlapH1h2BitReversed(_lh1, _lh2, domainBig)
// compute the quotient
alpha, err := deriveRandomness(&fs, "alpha", &proof.z)
if err != nil {
return proof, err
}
ch := computeQuotientCanonical(alpha, lh, lh0, lhn, lh1h2, domainBig)
proof.h, err = kzg.Commit(ch, srs)
if err != nil {
return proof, err
}
// build the opening proofs
nu, err := deriveRandomness(&fs, "nu", &proof.h)
if err != nil {
return proof, err
}
proof.BatchedProof, err = kzg.BatchOpenSinglePoint(
[][]fr.Element{
ch1,
ch2,
ct,
cz,
cf,
ch,
},
[]kzg.Digest{
proof.h1,
proof.h2,
proof.t,
proof.z,
proof.f,
proof.h,
},
nu,
hFunc,
srs,
)
if err != nil {
return proof, err
}
nu.Mul(&nu, &domainSmall.Generator)
proof.BatchedProofShifted, err = kzg.BatchOpenSinglePoint(
[][]fr.Element{
ch1,
ch2,
ct,
cz,
},
[]kzg.Digest{
proof.h1,
proof.h2,
proof.t,
proof.z,
},
nu,
hFunc,
srs,
)
if err != nil {
return proof, err
}
return proof, nil
}
// VerifyLookupVector verifies that a ProofLookupVector proof is correct
func VerifyLookupVector(srs *kzg.SRS, proof ProofLookupVector) error {
// hash function that is used for Fiat Shamir
hFunc := sha256.New()
// transcript to derive the challenge
fs := fiatshamir.NewTranscript(hFunc, "beta", "gamma", "alpha", "nu")
// derive the various challenges
beta, err := deriveRandomness(&fs, "beta", &proof.t, &proof.f, &proof.h1, &proof.h2)
if err != nil {
return err
}
gamma, err := deriveRandomness(&fs, "gamma")
if err != nil {
return err
}
alpha, err := deriveRandomness(&fs, "alpha", &proof.z)
if err != nil {
return err
}
nu, err := deriveRandomness(&fs, "nu", &proof.h)
if err != nil {
return err
}
// check opening proofs
err = kzg.BatchVerifySinglePoint(
[]kzg.Digest{
proof.h1,
proof.h2,
proof.t,
proof.z,
proof.f,
proof.h,
},
&proof.BatchedProof,
nu,
hFunc,
srs,
)
if err != nil {
return err
}
// shift the point and verify shifted proof
var shiftedNu fr.Element
shiftedNu.Mul(&nu, &proof.g)
err = kzg.BatchVerifySinglePoint(
[]kzg.Digest{
proof.h1,
proof.h2,
proof.t,
proof.z,
},
&proof.BatchedProofShifted,
shiftedNu,
hFunc,
srs,
)
if err != nil {
return err
}
// check the generator is correct
var checkOrder, one fr.Element
one.SetOne()
checkOrder.Exp(proof.g, big.NewInt(int64(proof.size/2)))
if checkOrder.Equal(&one) {
return ErrGenerator
}
checkOrder.Square(&checkOrder)
if !checkOrder.Equal(&one) {
return ErrGenerator
}
// check polynomial relation using Schwartz Zippel
var lhs, rhs, nun, g, _g, a, v, w fr.Element
g.Exp(proof.g, big.NewInt(int64(proof.size-1)))
v.Add(&one, &beta)
w.Mul(&v, &gamma)
// h(ν) where
// h = (xⁿ⁻¹-1)*z*(1+β)*(γ+f)*(γ(1+β) + t+ β*t(gX)) -
// (xⁿ⁻¹-1)*z(gX)*(γ(1+β) + h₁ + β*h₁(gX))*(γ(1+β) + h₂ + β*h₂(gX) )
lhs.Sub(&nu, &g). // (ν-gⁿ⁻¹)
Mul(&lhs, &proof.BatchedProof.ClaimedValues[3]).
Mul(&lhs, &v)
a.Add(&gamma, &proof.BatchedProof.ClaimedValues[4])
lhs.Mul(&lhs, &a)
a.Mul(&beta, &proof.BatchedProofShifted.ClaimedValues[2]).
Add(&a, &proof.BatchedProof.ClaimedValues[2]).
Add(&a, &w)
lhs.Mul(&lhs, &a)
rhs.Sub(&nu, &g).
Mul(&rhs, &proof.BatchedProofShifted.ClaimedValues[3])
a.Mul(&beta, &proof.BatchedProofShifted.ClaimedValues[0]).
Add(&a, &proof.BatchedProof.ClaimedValues[0]).
Add(&a, &w)
rhs.Mul(&rhs, &a)
a.Mul(&beta, &proof.BatchedProofShifted.ClaimedValues[1]).
Add(&a, &proof.BatchedProof.ClaimedValues[1]).
Add(&a, &w)
rhs.Mul(&rhs, &a)
lhs.Sub(&lhs, &rhs)
// check consistancy of bounds
var l0, ln, d1, d2 fr.Element
l0.Exp(nu, big.NewInt(int64(proof.size))).Sub(&l0, &one)
ln.Set(&l0)
d1.Sub(&nu, &one)
d2.Sub(&nu, &g)
l0.Div(&l0, &d1) // (νⁿ-1)/(ν-1)
ln.Div(&ln, &d2) // (νⁿ-1)/(ν-gⁿ⁻¹)
// l₀*(z-1) = (νⁿ-1)/(ν-1)*(z-1)
var l0z fr.Element
l0z.Sub(&proof.BatchedProof.ClaimedValues[3], &one).
Mul(&l0z, &l0)
// lₙ*(z-1) = (νⁿ-1)/(ν-gⁿ⁻¹)*(z-1)
var lnz fr.Element
lnz.Sub(&proof.BatchedProof.ClaimedValues[3], &one).
Mul(&ln, &lnz)
// lₙ*(h1 - h₂(g.x))
var lnh1h2 fr.Element
lnh1h2.Sub(&proof.BatchedProof.ClaimedValues[0], &proof.BatchedProofShifted.ClaimedValues[1]).
Mul(&lnh1h2, &ln)
// fold the numerator
lnh1h2.Mul(&lnh1h2, &alpha).
Add(&lnh1h2, &lnz).
Mul(&lnh1h2, &alpha).
Add(&lnh1h2, &l0z).
Mul(&lnh1h2, &alpha).
Add(&lnh1h2, &lhs)
// (xⁿ-1) * h(x) evaluated at ν
nun.Exp(nu, big.NewInt(int64(proof.size)))
_g.Sub(&nun, &one)
_g.Mul(&proof.BatchedProof.ClaimedValues[5], &_g)
if !lnh1h2.Equal(&_g) {
return ErrPlookupVerification
}
return nil
}