mirror of
https://github.com/logos-storage/gnark-plonky2-verifier.git
synced 2026-01-04 06:03:12 +00:00
added support to optionally use bit decompose range checker
This commit is contained in:
parent
89b5a01e4b
commit
9be0171580
@ -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"
|
||||||
@ -86,7 +87,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}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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…
x
Reference in New Issue
Block a user