Browse Source

Merge pull request #44 from succinctlabs/kevjue/bit_decomp_range_checker

feat: added support to optionally use bit decompose range checker
main
Kevin Jue 1 year ago
committed by GitHub
parent
commit
c82e6f3747
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions
  1. +11
    -1
      goldilocks/base.go
  2. +9
    -0
      goldilocks/utils.go

+ 11
- 1
goldilocks/base.go

@ -18,6 +18,7 @@ import (
"fmt" "fmt"
"math" "math"
"math/big" "math/big"
"os"
"github.com/consensys/gnark-crypto/field/goldilocks" "github.com/consensys/gnark-crypto/field/goldilocks"
"github.com/consensys/gnark/constraint/solver" "github.com/consensys/gnark/constraint/solver"
@ -83,7 +84,16 @@ type Chip struct {
// Creates a new Goldilocks Chip. // Creates a new Goldilocks Chip.
func New(api frontend.API) *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} return &Chip{api: api, rangeChecker: rangeChecker}
} }

+ 9
- 0
goldilocks/utils.go

@ -4,6 +4,7 @@ import (
"math/big" "math/big"
"github.com/consensys/gnark/frontend" "github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/std/math/bits"
) )
func StrArrayToBigIntArray(input []string) []big.Int { func StrArrayToBigIntArray(input []string) []big.Int {
@ -43,3 +44,11 @@ func Uint64ArrayToQuadraticExtensionArray(input [][]uint64) []QuadraticExtension
} }
return output 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))
}

Loading…
Cancel
Save