constraint optimizations for assertLeadingZeros
Kevin Jue kjue235@gmail.com
Fri, 22 Dec 2023 11:42:53 -0800
2 files changed,
7 insertions(+),
8 deletions(-)
M
fri/fri.go
→
fri/fri.go
@@ -75,14 +75,8 @@
func (f *Chip) assertLeadingZeros(powWitness gl.Variable, friConfig types.FriConfig) { // 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)) + // field is 64 bits long. + f.gl.RangeCheckWithMaxBits(powWitness, 64-friConfig.ProofOfWorkBits) } func (f *Chip) fromOpeningsAndAlpha(
M
goldilocks/base.go
→
goldilocks/base.go
@@ -333,6 +333,11 @@ frontend.Variable(0),
) } +// This function will assert that the field element x is less than 2^maxNbBits. +func (p *Chip) RangeCheckWithMaxBits(x Variable, maxNbBits uint64) { + p.rangeChecker.Check(x.Limb, int(maxNbBits)) +} + func (p *Chip) AssertIsEqual(x, y Variable) { p.api.AssertIsEqual(x.Limb, y.Limb) }