arnaucube
arnaucube/gnark-plonky2-verifierPublic Self-hosted repository
added support to optionally use bit decompose range checker
Kevin Jue kjue235@gmail.com
Thu, 21 Dec 2023 12:23:28 -0800
commit

9be0171580f3634d2326b328238564f759ce8c0f

parent

89b5a01e4b4be8a439e28b864e36e0bb5b512207

2 files changed, 20 insertions(+), 1 deletions(-)

jump to
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"

@@ -86,7 +87,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)) +}