mirror of
https://github.com/arnaucube/gnark-plonky2-verifier.git
synced 2026-01-11 16:41:32 +01:00
Merge pull request #45 from succinctlabs/kevjue/assert_leading_zeros_optimizations
perf: assertLeadingZeros constraint optimizations
This commit is contained in:
10
fri/fri.go
10
fri/fri.go
@@ -75,14 +75,8 @@ func (f *Chip) ToOpenings(c variables.OpeningSet) Openings {
|
|||||||
func (f *Chip) assertLeadingZeros(powWitness gl.Variable, friConfig types.FriConfig) {
|
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.
|
// 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
|
// Note that this is assuming that the Goldilocks field is being used. Specfically that the
|
||||||
// field is 64 bits long
|
// field is 64 bits long.
|
||||||
maxPowWitness := uint64(math.Pow(2, float64(64-friConfig.ProofOfWorkBits))) - 1
|
f.gl.RangeCheckWithMaxBits(powWitness, 64-friConfig.ProofOfWorkBits)
|
||||||
|
|
||||||
// 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))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Chip) fromOpeningsAndAlpha(
|
func (f *Chip) fromOpeningsAndAlpha(
|
||||||
|
|||||||
@@ -328,6 +328,11 @@ func (p *Chip) RangeCheck(x Variable) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
func (p *Chip) AssertIsEqual(x, y Variable) {
|
||||||
p.api.AssertIsEqual(x.Limb, y.Limb)
|
p.api.AssertIsEqual(x.Limb, y.Limb)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user