fix for V-SCT-VUL-027
Kevin Jue kjue235@gmail.com
Tue, 19 Dec 2023 12:22:19 -0800
6 files changed,
23 insertions(+),
16 deletions(-)
M
fri/fri.go
→
fri/fri.go
@@ -73,11 +73,15 @@ return Openings{Batches: []OpeningBatch{zetaBatch, zetaNextBatch}}
} func (f *Chip) assertLeadingZeros(powWitness gl.Variable, friConfig types.FriConfig) { - // Asserts that powWitness'es big-endian bit representation has at least `leading_zeros` leading zeros. + // Asserts that powWitness'es big-endian bit representation has at least friConfig.ProofOfWorkBits leading zeros. // Note that this is assuming that the Goldilocks field is being used. Specfically that the // field is 64 bits long maxPowWitness := uint64(math.Pow(2, float64(64-friConfig.ProofOfWorkBits))) - 1 + + // TODO: This does an un-nessary reduce, since powWitness is already range checked to be within GL field. reducedPowWitness := f.gl.Reduce(powWitness) + + // TODO: Can replace with with std.rangecheck.Check. Will probably be less contraints. f.api.AssertIsLessOrEqual(reducedPowWitness.Limb, frontend.Variable(maxPowWitness)) }
M
goldilocks/base.go
→
goldilocks/base.go
@@ -87,38 +87,41 @@ rangeChecker := rangecheck.New(api)
return &Chip{api: api, rangeChecker: rangeChecker} } -// Adds two field elements such that x + y = z within the Golidlocks field. +// Adds two goldilocks field elements and returns a value within the goldilocks field. func (p *Chip) Add(a Variable, b Variable) Variable { return p.MulAdd(a, NewVariable(1), b) } -// Adds two field elements such that x + y = z within the Golidlocks field without reducing. +// Adds two goldilocks field elements and returns a value that may not be within the goldilocks field +// (e.g. the sum is not reduced). func (p *Chip) AddNoReduce(a Variable, b Variable) Variable { return NewVariable(p.api.Add(a.Limb, b.Limb)) } -// Subtracts two field elements such that x + y = z within the Golidlocks field. +// Subracts two goldilocks field elements and returns a value within the goldilocks field. func (p *Chip) Sub(a Variable, b Variable) Variable { return p.MulAdd(b, NegOne(), a) } -// Subtracts two field elements such that x + y = z within the Golidlocks field without reducing. +// Subracts two goldilocks field elements and returns a value that may not be within the goldilocks field +// (e.g. the difference is not reduced). func (p *Chip) SubNoReduce(a Variable, b Variable) Variable { return NewVariable(p.api.Add(a.Limb, p.api.Mul(b.Limb, NegOne().Limb))) } -// Multiplies two field elements such that x * y = z within the Golidlocks field. +// Multiplies two goldilocks field elements and returns a value within the goldilocks field. func (p *Chip) Mul(a Variable, b Variable) Variable { return p.MulAdd(a, b, Zero()) } -// Multiplies two field elements such that x * y = z within the Golidlocks field without reducing. +// Multiplies two goldilocks field elements and returns a value that may not be within the goldilocks field +// (e.g. the product is not reduced). func (p *Chip) MulNoReduce(a Variable, b Variable) Variable { return NewVariable(p.api.Mul(a.Limb, b.Limb)) } -// Multiplies two field elements and adds a field element such that x * y + z = c within the -// Golidlocks field. +// Multiplies two field elements and adds a field element (e.g. computes a * b + c). The returned value +// will be within the goldilocks field. func (p *Chip) MulAdd(a Variable, b Variable, c Variable) Variable { result, err := p.api.Compiler().NewHint(MulAddHint, 2, a.Limb, b.Limb, c.Limb) if err != nil {@@ -138,8 +141,8 @@ p.RangeCheck(remainder)
return remainder } -// Multiplies two field elements and adds a field element such that x * y + z = c within the -// Golidlocks field without reducing. +// Multiplies two field elements and adds a field element (e.g. computes a * b + c). The returned value +// may no be within the goldilocks field (e.g. the result is not reduced). func (p *Chip) MulAddNoReduce(a Variable, b Variable, c Variable) Variable { cLimbCopy := p.api.Mul(c.Limb, 1) return NewVariable(p.api.MulAcc(cLimbCopy, a.Limb, b.Limb))
M
goldilocks/quadratic_extension.go
→
goldilocks/quadratic_extension.go
@@ -84,7 +84,7 @@ sum := p.AddExtensionNoReduce(product, c)
return sum } -// Multiplies two operands a and b and subtracts to c in the Goldilocks extension field. a * b - c must +// Subtracts two operands a and b and multiplies the diff by c in the Goldilocks extension field. (a - b) * c must // be less than RANGE_CHECK_NB_BITS bits. func (p *Chip) SubMulExtension(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable { difference := p.SubExtensionNoReduce(a, b)@@ -209,7 +209,7 @@ c1 := p.api.Select(b, y[1].Limb, x[1].Limb)
return NewQuadraticExtensionVariable(NewVariable(c0), NewVariable(c1)) } -// Lookup2 is similar to select2, but returns the first variable if the bit is zero and vice-versa. +// Lookup2 is similar to Lookup2. It returns the ith qe value (0 indexed) where i is bit decomposed to b0,b1 (little endian). func (p *Chip) Lookup2( b0 frontend.Variable, b1 frontend.Variable,
M
plonk/gates/random_access_gate.go
→
plonk/gates/random_access_gate.go
@@ -151,7 +151,7 @@ x := listItems[i]
y := listItems[i+1] // This is computing `if b { x } else { y }` - // i.e. `bx - (by-y)`. + // i.e. `by - (bx - x)`. mul1 := glApi.MulExtension(b, x) sub1 := glApi.SubExtension(mul1, x)
M
plonk/gates/reducing_extension_gate.go
→
plonk/gates/reducing_extension_gate.go
@@ -12,7 +12,7 @@
var reducingExtensionGateRegex = regexp.MustCompile("ReducingExtensionGate { num_coeffs: (?P<numCoeffs>[0-9]+) }") func deserializeReducingExtensionGate(parameters map[string]string) Gate { - // Has the format "ReducingGate { num_coeffs: 33 }" + // Has the format "ReducingExtensionGate { num_coeffs: 33 }" numCoeffs, hasNumCoeffs := parameters["numCoeffs"] if !hasNumCoeffs { panic("Missing field num_coeffs in ReducingExtensionGate")