Merge pull request #44 from succinctlabs/kevjue/bit_decomp_range_checker feat: added support to optionally use bit decompose range checker
Kevin Jue kjue235@gmail.com
Tue, 02 Jan 2024 14:37:00 -0800
2 files changed,
20 insertions(+),
1 deletions(-)
M
goldilocks/base.go
→
goldilocks/base.go
@@ -18,6 +18,7 @@ import (
"fmt" "math" "math/big" + "os" "github.com/consensys/gnark-crypto/field/goldilocks" "github.com/consensys/gnark/constraint/solver"@@ -83,7 +84,16 @@ }
// Creates a new Goldilocks Chip. func New(api frontend.API) *Chip { - rangeChecker := rangecheck.New(api) + use_bit_decomp := os.Getenv("USE_BIT_DECOMPOSITION_RANGE_CHECK") + + var rangeChecker frontend.Rangechecker + + // If USE_BIT_DECOMPOSITION_RANGE_CHECK is not set, then use the std.rangecheck New function + if use_bit_decomp == "" { + rangeChecker = rangecheck.New(api) + } else { + rangeChecker = bitDecompChecker{api: api} + } return &Chip{api: api, rangeChecker: rangeChecker} }
M
goldilocks/utils.go
→
goldilocks/utils.go
@@ -4,6 +4,7 @@ import (
"math/big" "github.com/consensys/gnark/frontend" + "github.com/consensys/gnark/std/math/bits" ) func StrArrayToBigIntArray(input []string) []big.Int {@@ -43,3 +44,11 @@ output = append(output, NewQuadraticExtensionVariable(NewVariable(input[i][0]), NewVariable(input[i][1])))
} return output } + +type bitDecompChecker struct { + api frontend.API +} + +func (pl bitDecompChecker) Check(v frontend.Variable, nbBits int) { + bits.ToBinary(pl.api, v, bits.WithNbDigits(nbBits)) +}