mirror of
https://github.com/logos-storage/gnark-plonky2-verifier.git
synced 2026-01-05 22:53:09 +00:00
Renamed symbol a bunch in goldilocks, goldilocks tests pass
This commit is contained in:
parent
07cf7bd857
commit
1c0235b35a
@ -22,7 +22,7 @@ import (
|
|||||||
|
|
||||||
type BenchmarkPlonky2VerifierCircuit struct {
|
type BenchmarkPlonky2VerifierCircuit struct {
|
||||||
Proof types.Proof
|
Proof types.Proof
|
||||||
PublicInputs []gl.Variable `gnark:",public"`
|
PublicInputs []gl.GoldilocksVariable `gnark:",public"`
|
||||||
|
|
||||||
verifierChip *verifier.VerifierChip `gnark:"-"`
|
verifierChip *verifier.VerifierChip `gnark:"-"`
|
||||||
plonky2CircuitName string `gnark:"-"`
|
plonky2CircuitName string `gnark:"-"`
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
type BenchmarkPlonky2VerifierCircuitPlonk struct {
|
type BenchmarkPlonky2VerifierCircuitPlonk struct {
|
||||||
Proof types.Proof
|
Proof types.Proof
|
||||||
PublicInputs []gl.Variable `gnark:",public"`
|
PublicInputs []gl.GoldilocksVariable `gnark:",public"`
|
||||||
|
|
||||||
verifierChip *verifier.VerifierChip `gnark:"-"`
|
verifierChip *verifier.VerifierChip `gnark:"-"`
|
||||||
plonky2CircuitName string `gnark:"-"`
|
plonky2CircuitName string `gnark:"-"`
|
||||||
|
|||||||
@ -14,15 +14,15 @@ type Chip struct {
|
|||||||
api frontend.API `gnark:"-"`
|
api frontend.API `gnark:"-"`
|
||||||
poseidonChip *poseidon.GoldilocksChip
|
poseidonChip *poseidon.GoldilocksChip
|
||||||
poseidonBN254Chip *poseidon.BN254Chip
|
poseidonBN254Chip *poseidon.BN254Chip
|
||||||
spongeState [poseidon.SPONGE_WIDTH]gl.Variable
|
spongeState [poseidon.SPONGE_WIDTH]gl.GoldilocksVariable
|
||||||
inputBuffer []gl.Variable
|
inputBuffer []gl.GoldilocksVariable
|
||||||
outputBuffer []gl.Variable
|
outputBuffer []gl.GoldilocksVariable
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChip(api frontend.API) *Chip {
|
func NewChip(api frontend.API) *Chip {
|
||||||
var spongeState [poseidon.SPONGE_WIDTH]gl.Variable
|
var spongeState [poseidon.SPONGE_WIDTH]gl.GoldilocksVariable
|
||||||
var inputBuffer []gl.Variable
|
var inputBuffer []gl.GoldilocksVariable
|
||||||
var outputBuffer []gl.Variable
|
var outputBuffer []gl.GoldilocksVariable
|
||||||
for i := 0; i < poseidon.SPONGE_WIDTH; i++ {
|
for i := 0; i < poseidon.SPONGE_WIDTH; i++ {
|
||||||
spongeState[i] = gl.Zero()
|
spongeState[i] = gl.Zero()
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ func NewChip(api frontend.API) *Chip {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Chip) ObserveElement(element gl.Variable) {
|
func (c *Chip) ObserveElement(element gl.GoldilocksVariable) {
|
||||||
c.outputBuffer = clearBuffer(c.outputBuffer)
|
c.outputBuffer = clearBuffer(c.outputBuffer)
|
||||||
c.inputBuffer = append(c.inputBuffer, element)
|
c.inputBuffer = append(c.inputBuffer, element)
|
||||||
if len(c.inputBuffer) == poseidon.SPONGE_RATE {
|
if len(c.inputBuffer) == poseidon.SPONGE_RATE {
|
||||||
@ -46,7 +46,7 @@ func (c *Chip) ObserveElement(element gl.Variable) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Chip) ObserveElements(elements []gl.Variable) {
|
func (c *Chip) ObserveElements(elements []gl.GoldilocksVariable) {
|
||||||
for i := 0; i < len(elements); i++ {
|
for i := 0; i < len(elements); i++ {
|
||||||
c.ObserveElement(elements[i])
|
c.ObserveElement(elements[i])
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ func (c *Chip) ObserveOpenings(openings fri.Openings) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Chip) GetChallenge() gl.Variable {
|
func (c *Chip) GetChallenge() gl.GoldilocksVariable {
|
||||||
if len(c.inputBuffer) != 0 || len(c.outputBuffer) == 0 {
|
if len(c.inputBuffer) != 0 || len(c.outputBuffer) == 0 {
|
||||||
c.duplexing()
|
c.duplexing()
|
||||||
}
|
}
|
||||||
@ -95,8 +95,8 @@ func (c *Chip) GetChallenge() gl.Variable {
|
|||||||
return challenge
|
return challenge
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Chip) GetNChallenges(n uint64) []gl.Variable {
|
func (c *Chip) GetNChallenges(n uint64) []gl.GoldilocksVariable {
|
||||||
challenges := make([]gl.Variable, n)
|
challenges := make([]gl.GoldilocksVariable, n)
|
||||||
for i := uint64(0); i < n; i++ {
|
for i := uint64(0); i < n; i++ {
|
||||||
challenges[i] = c.GetChallenge()
|
challenges[i] = c.GetChallenge()
|
||||||
}
|
}
|
||||||
@ -109,13 +109,13 @@ func (c *Chip) GetExtensionChallenge() gl.QuadraticExtensionVariable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Chip) GetHash() poseidon.GoldilocksHashOut {
|
func (c *Chip) GetHash() poseidon.GoldilocksHashOut {
|
||||||
return [4]gl.Variable{c.GetChallenge(), c.GetChallenge(), c.GetChallenge(), c.GetChallenge()}
|
return [4]gl.GoldilocksVariable{c.GetChallenge(), c.GetChallenge(), c.GetChallenge(), c.GetChallenge()}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Chip) GetFriChallenges(
|
func (c *Chip) GetFriChallenges(
|
||||||
commitPhaseMerkleCaps []types.FriMerkleCap,
|
commitPhaseMerkleCaps []types.FriMerkleCap,
|
||||||
finalPoly types.PolynomialCoeffs,
|
finalPoly types.PolynomialCoeffs,
|
||||||
powWitness gl.Variable,
|
powWitness gl.GoldilocksVariable,
|
||||||
degreeBits uint64,
|
degreeBits uint64,
|
||||||
config types.FriConfig,
|
config types.FriConfig,
|
||||||
) types.FriChallenges {
|
) types.FriChallenges {
|
||||||
@ -142,8 +142,8 @@ func (c *Chip) GetFriChallenges(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func clearBuffer(buffer []gl.Variable) []gl.Variable {
|
func clearBuffer(buffer []gl.GoldilocksVariable) []gl.GoldilocksVariable {
|
||||||
return make([]gl.Variable, 0)
|
return make([]gl.GoldilocksVariable, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Chip) duplexing() {
|
func (c *Chip) duplexing() {
|
||||||
@ -152,7 +152,7 @@ func (c *Chip) duplexing() {
|
|||||||
panic("something went wrong")
|
panic("something went wrong")
|
||||||
}
|
}
|
||||||
|
|
||||||
glApi := gl.NewChip(c.api)
|
glApi := gl.NewGoldilocksApi(c.api)
|
||||||
|
|
||||||
for i := 0; i < len(c.inputBuffer); i++ {
|
for i := 0; i < len(c.inputBuffer); i++ {
|
||||||
c.spongeState[i] = glApi.Reduce(c.inputBuffer[i])
|
c.spongeState[i] = glApi.Reduce(c.inputBuffer[i])
|
||||||
|
|||||||
20
fri/fri.go
20
fri/fri.go
@ -14,8 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Chip struct {
|
type Chip struct {
|
||||||
api frontend.API `gnark:"-"`
|
api frontend.API `gnark:"-"`
|
||||||
gl gl.Chip `gnark:"-"`
|
gl gl.GoldilocksApi `gnark:"-"`
|
||||||
poseidonBN254Chip *poseidon.BN254Chip
|
poseidonBN254Chip *poseidon.BN254Chip
|
||||||
friParams *types.FriParams `gnark:"-"`
|
friParams *types.FriParams `gnark:"-"`
|
||||||
}
|
}
|
||||||
@ -29,11 +29,11 @@ func NewChip(
|
|||||||
api: api,
|
api: api,
|
||||||
poseidonBN254Chip: poseidonBN254Chip,
|
poseidonBN254Chip: poseidonBN254Chip,
|
||||||
friParams: friParams,
|
friParams: friParams,
|
||||||
gl: *gl.NewChip(api),
|
gl: *gl.NewGoldilocksApi(api),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Chip) assertLeadingZeros(powWitness gl.Variable, friConfig types.FriConfig) {
|
func (f *Chip) assertLeadingZeros(powWitness gl.GoldilocksVariable, friConfig types.FriConfig) {
|
||||||
// Asserts that powWitness'es big-endian bit representation has at least `leading_zeros` leading zeros.
|
// Asserts that powWitness'es big-endian bit representation has at least `leading_zeros` 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
|
||||||
@ -58,7 +58,7 @@ func (f *Chip) fromOpeningsAndAlpha(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Chip) verifyMerkleProofToCapWithCapIndex(
|
func (f *Chip) verifyMerkleProofToCapWithCapIndex(
|
||||||
leafData []gl.Variable,
|
leafData []gl.GoldilocksVariable,
|
||||||
leafIndexBits []frontend.Variable,
|
leafIndexBits []frontend.Variable,
|
||||||
capIndexBits []frontend.Variable,
|
capIndexBits []frontend.Variable,
|
||||||
merkleCap types.FriMerkleCap,
|
merkleCap types.FriMerkleCap,
|
||||||
@ -139,7 +139,7 @@ func (f *Chip) assertNoncanonicalIndicesOK() {
|
|||||||
func (f *Chip) expFromBitsConstBase(
|
func (f *Chip) expFromBitsConstBase(
|
||||||
base goldilocks.Element,
|
base goldilocks.Element,
|
||||||
exponentBits []frontend.Variable,
|
exponentBits []frontend.Variable,
|
||||||
) gl.Variable {
|
) gl.GoldilocksVariable {
|
||||||
product := gl.One()
|
product := gl.One()
|
||||||
for i, bit := range exponentBits {
|
for i, bit := range exponentBits {
|
||||||
// If the bit is on, we multiply product by base^pow.
|
// If the bit is on, we multiply product by base^pow.
|
||||||
@ -167,7 +167,7 @@ func (f *Chip) expFromBitsConstBase(
|
|||||||
func (f *Chip) calculateSubgroupX(
|
func (f *Chip) calculateSubgroupX(
|
||||||
xIndexBits []frontend.Variable,
|
xIndexBits []frontend.Variable,
|
||||||
nLog uint64,
|
nLog uint64,
|
||||||
) gl.Variable {
|
) gl.GoldilocksVariable {
|
||||||
// Compute x from its index
|
// Compute x from its index
|
||||||
// `subgroup_x` is `subgroup[x_index]`, i.e., the actual field element in the domain.
|
// `subgroup_x` is `subgroup[x_index]`, i.e., the actual field element in the domain.
|
||||||
// TODO - Make these as global values
|
// TODO - Make these as global values
|
||||||
@ -284,7 +284,7 @@ func (f *Chip) interpolate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Chip) computeEvaluation(
|
func (f *Chip) computeEvaluation(
|
||||||
x gl.Variable,
|
x gl.GoldilocksVariable,
|
||||||
xIndexWithinCosetBits []frontend.Variable,
|
xIndexWithinCosetBits []frontend.Variable,
|
||||||
arityBits uint64,
|
arityBits uint64,
|
||||||
evals []gl.QuadraticExtensionVariable,
|
evals []gl.QuadraticExtensionVariable,
|
||||||
@ -359,7 +359,7 @@ func (f *Chip) verifyQueryRound(
|
|||||||
precomputedReducedEval []gl.QuadraticExtensionVariable,
|
precomputedReducedEval []gl.QuadraticExtensionVariable,
|
||||||
initialMerkleCaps []types.FriMerkleCap,
|
initialMerkleCaps []types.FriMerkleCap,
|
||||||
proof *types.FriProof,
|
proof *types.FriProof,
|
||||||
xIndex gl.Variable,
|
xIndex gl.GoldilocksVariable,
|
||||||
n uint64,
|
n uint64,
|
||||||
nLog uint64,
|
nLog uint64,
|
||||||
roundProof *types.FriQueryRound,
|
roundProof *types.FriQueryRound,
|
||||||
@ -437,7 +437,7 @@ func (f *Chip) verifyQueryRound(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Convert evals (array of QE) to fields by taking their 0th degree coefficients
|
// Convert evals (array of QE) to fields by taking their 0th degree coefficients
|
||||||
fieldEvals := make([]gl.Variable, 0, 2*len(evals))
|
fieldEvals := make([]gl.GoldilocksVariable, 0, 2*len(evals))
|
||||||
for j := 0; j < len(evals); j++ {
|
for j := 0; j < len(evals); j++ {
|
||||||
fieldEvals = append(fieldEvals, evals[j][0])
|
fieldEvals = append(fieldEvals, evals[j][0])
|
||||||
fieldEvals = append(fieldEvals, evals[j][1])
|
fieldEvals = append(fieldEvals, evals[j][1])
|
||||||
|
|||||||
@ -25,7 +25,7 @@ func (circuit *TestFriCircuit) Define(api frontend.API) error {
|
|||||||
commonCircuitData := verifier.DeserializeCommonCircuitData(circuit.commonCircuitDataFilename)
|
commonCircuitData := verifier.DeserializeCommonCircuitData(circuit.commonCircuitDataFilename)
|
||||||
verifierOnlyCircuitData := verifier.DeserializeVerifierOnlyCircuitData(circuit.verifierOnlyCircuitDataFilename)
|
verifierOnlyCircuitData := verifier.DeserializeVerifierOnlyCircuitData(circuit.verifierOnlyCircuitDataFilename)
|
||||||
|
|
||||||
glApi := gl.NewChip(api)
|
glApi := gl.NewGoldilocksApi(api)
|
||||||
poseidonChip := poseidon.NewGoldilocksChip(api)
|
poseidonChip := poseidon.NewGoldilocksChip(api)
|
||||||
friChip := fri.NewChip(api, &commonCircuitData.FriParams)
|
friChip := fri.NewChip(api, &commonCircuitData.FriParams)
|
||||||
challengerChip := challenger.NewChip(api)
|
challengerChip := challenger.NewChip(api)
|
||||||
|
|||||||
@ -178,7 +178,7 @@ func friAllPolys(c *types.CommonCircuitData) []PolynomialInfo {
|
|||||||
return returnArr
|
return returnArr
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetInstance(c *types.CommonCircuitData, glApi *gl.Chip, zeta gl.QuadraticExtensionVariable, degreeBits uint64) InstanceInfo {
|
func GetInstance(c *types.CommonCircuitData, glApi *gl.GoldilocksApi, zeta gl.QuadraticExtensionVariable, degreeBits uint64) InstanceInfo {
|
||||||
zetaBatch := BatchInfo{
|
zetaBatch := BatchInfo{
|
||||||
Point: zeta,
|
Point: zeta,
|
||||||
Polynomials: friAllPolys(c),
|
Polynomials: friAllPolys(c),
|
||||||
|
|||||||
@ -13,13 +13,14 @@ package goldilocks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"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"
|
||||||
"github.com/consensys/gnark/frontend"
|
"github.com/consensys/gnark/frontend"
|
||||||
"github.com/consensys/gnark/std/math/bits"
|
|
||||||
"github.com/consensys/gnark/std/math/emulated"
|
"github.com/consensys/gnark/std/math/emulated"
|
||||||
|
"github.com/consensys/gnark/std/rangecheck"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The multiplicative group generator of the field.
|
// The multiplicative group generator of the field.
|
||||||
@ -45,77 +46,78 @@ func init() {
|
|||||||
solver.RegisterHint(MulAddHint)
|
solver.RegisterHint(MulAddHint)
|
||||||
solver.RegisterHint(ReduceHint)
|
solver.RegisterHint(ReduceHint)
|
||||||
solver.RegisterHint(InverseHint)
|
solver.RegisterHint(InverseHint)
|
||||||
|
solver.RegisterHint(SplitLimbsHint)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A type alias used to represent Goldilocks field elements.
|
// A type alias used to represent Goldilocks field elements.
|
||||||
type Variable struct {
|
type GoldilocksVariable struct {
|
||||||
Limb frontend.Variable
|
Limb frontend.Variable
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new Goldilocks field element from an existing variable. Assumes that the element is
|
// Creates a new Goldilocks field element from an existing variable. Assumes that the element is
|
||||||
// already reduced.
|
// already reduced.
|
||||||
func NewVariable(x frontend.Variable) Variable {
|
func NewVariable(x frontend.Variable) GoldilocksVariable {
|
||||||
return Variable{Limb: x}
|
return GoldilocksVariable{Limb: x}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The zero element in the Golidlocks field.
|
// The zero element in the Golidlocks field.
|
||||||
func Zero() Variable {
|
func Zero() GoldilocksVariable {
|
||||||
return NewVariable(0)
|
return NewVariable(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The one element in the Goldilocks field.
|
// The one element in the Goldilocks field.
|
||||||
func One() Variable {
|
func One() GoldilocksVariable {
|
||||||
return NewVariable(1)
|
return NewVariable(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The negative one element in the Goldilocks field.
|
// The negative one element in the Goldilocks field.
|
||||||
func NegOne() Variable {
|
func NegOne() GoldilocksVariable {
|
||||||
return NewVariable(MODULUS.Uint64() - 1)
|
return NewVariable(MODULUS.Uint64() - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The chip used for Goldilocks field operations.
|
// The chip used for Goldilocks field operations.
|
||||||
type Chip struct {
|
type GoldilocksApi struct {
|
||||||
api frontend.API
|
api frontend.API
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new Goldilocks chip.
|
// Creates a new Goldilocks chip.
|
||||||
func NewChip(api frontend.API) *Chip {
|
func NewGoldilocksApi(api frontend.API) *GoldilocksApi {
|
||||||
return &Chip{api: api}
|
return &GoldilocksApi{api: api}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds two field elements such that x + y = z within the Golidlocks field.
|
// Adds two field elements such that x + y = z within the Golidlocks field.
|
||||||
func (p *Chip) Add(a Variable, b Variable) Variable {
|
func (p *GoldilocksApi) Add(a GoldilocksVariable, b GoldilocksVariable) GoldilocksVariable {
|
||||||
return p.MulAdd(a, NewVariable(1), b)
|
return p.MulAdd(a, NewVariable(1), b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds two field elements such that x + y = z within the Golidlocks field without reducing.
|
// Adds two field elements such that x + y = z within the Golidlocks field without reducing.
|
||||||
func (p *Chip) AddNoReduce(a Variable, b Variable) Variable {
|
func (p *GoldilocksApi) AddNoReduce(a GoldilocksVariable, b GoldilocksVariable) GoldilocksVariable {
|
||||||
return NewVariable(p.api.Add(a.Limb, b.Limb))
|
return NewVariable(p.api.Add(a.Limb, b.Limb))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtracts two field elements such that x + y = z within the Golidlocks field.
|
// Subtracts two field elements such that x + y = z within the Golidlocks field.
|
||||||
func (p *Chip) Sub(a Variable, b Variable) Variable {
|
func (p *GoldilocksApi) Sub(a GoldilocksVariable, b GoldilocksVariable) GoldilocksVariable {
|
||||||
return p.MulAdd(b, NewVariable(MODULUS.Uint64()-1), a)
|
return p.MulAdd(b, NewVariable(MODULUS.Uint64()-1), a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtracts two field elements such that x + y = z within the Golidlocks field without reducing.
|
// Subtracts two field elements such that x + y = z within the Golidlocks field without reducing.
|
||||||
func (p *Chip) SubNoReduce(a Variable, b Variable) Variable {
|
func (p *GoldilocksApi) SubNoReduce(a GoldilocksVariable, b GoldilocksVariable) GoldilocksVariable {
|
||||||
return NewVariable(p.api.Add(a.Limb, p.api.Mul(b.Limb, MODULUS.Uint64()-1)))
|
return NewVariable(p.api.Add(a.Limb, p.api.Mul(b.Limb, MODULUS.Uint64()-1)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiplies two field elements such that x * y = z within the Golidlocks field.
|
// Multiplies two field elements such that x * y = z within the Golidlocks field.
|
||||||
func (p *Chip) Mul(a Variable, b Variable) Variable {
|
func (p *GoldilocksApi) Mul(a GoldilocksVariable, b GoldilocksVariable) GoldilocksVariable {
|
||||||
return p.MulAdd(a, b, Zero())
|
return p.MulAdd(a, b, Zero())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiplies two field elements such that x * y = z within the Golidlocks field without reducing.
|
// Multiplies two field elements such that x * y = z within the Golidlocks field without reducing.
|
||||||
func (p *Chip) MulNoReduce(a Variable, b Variable) Variable {
|
func (p *GoldilocksApi) MulNoReduce(a GoldilocksVariable, b GoldilocksVariable) GoldilocksVariable {
|
||||||
return NewVariable(p.api.Mul(a.Limb, b.Limb))
|
return NewVariable(p.api.Mul(a.Limb, b.Limb))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiplies two field elements and adds a field element such that x * y + z = c within the
|
// Multiplies two field elements and adds a field element such that x * y + z = c within the
|
||||||
// Golidlocks field.
|
// Golidlocks field.
|
||||||
func (p *Chip) MulAdd(a Variable, b Variable, c Variable) Variable {
|
func (p *GoldilocksApi) MulAdd(a GoldilocksVariable, b GoldilocksVariable, c GoldilocksVariable) GoldilocksVariable {
|
||||||
result, err := p.api.Compiler().NewHint(MulAddHint, 2, a.Limb, b.Limb, c.Limb)
|
result, err := p.api.Compiler().NewHint(MulAddHint, 2, a.Limb, b.Limb, c.Limb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -136,7 +138,7 @@ func (p *Chip) MulAdd(a Variable, b Variable, c Variable) Variable {
|
|||||||
|
|
||||||
// Multiplies two field elements and adds a field element such that x * y + z = c within the
|
// Multiplies two field elements and adds a field element such that x * y + z = c within the
|
||||||
// Golidlocks field without reducing.
|
// Golidlocks field without reducing.
|
||||||
func (p *Chip) MulAddNoReduce(a Variable, b Variable, c Variable) Variable {
|
func (p *GoldilocksApi) MulAddNoReduce(a GoldilocksVariable, b GoldilocksVariable, c GoldilocksVariable) GoldilocksVariable {
|
||||||
return p.AddNoReduce(p.MulNoReduce(a, b), c)
|
return p.AddNoReduce(p.MulNoReduce(a, b), c)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +166,7 @@ func MulAddHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reduces a field element x such that x % MODULUS = y.
|
// Reduces a field element x such that x % MODULUS = y.
|
||||||
func (p *Chip) Reduce(x Variable) Variable {
|
func (p *GoldilocksApi) Reduce(x GoldilocksVariable) GoldilocksVariable {
|
||||||
// Witness a `quotient` and `remainder` such that:
|
// Witness a `quotient` and `remainder` such that:
|
||||||
//
|
//
|
||||||
// MODULUS * quotient + remainder = x
|
// MODULUS * quotient + remainder = x
|
||||||
@ -189,7 +191,7 @@ func (p *Chip) Reduce(x Variable) Variable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reduces a field element x such that x % MODULUS = y.
|
// Reduces a field element x such that x % MODULUS = y.
|
||||||
func (p *Chip) ReduceWithMaxBits(x Variable, maxNbBits uint64) Variable {
|
func (p *GoldilocksApi) ReduceWithMaxBits(x GoldilocksVariable, maxNbBits uint64) GoldilocksVariable {
|
||||||
// Witness a `quotient` and `remainder` such that:
|
// Witness a `quotient` and `remainder` such that:
|
||||||
//
|
//
|
||||||
// MODULUS * quotient + remainder = x
|
// MODULUS * quotient + remainder = x
|
||||||
@ -224,7 +226,7 @@ func ReduceHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Computes the inverse of a field element x such that x * x^-1 = 1.
|
// Computes the inverse of a field element x such that x * x^-1 = 1.
|
||||||
func (p *Chip) Inverse(x Variable) Variable {
|
func (p *GoldilocksApi) Inverse(x GoldilocksVariable) GoldilocksVariable {
|
||||||
result, err := p.api.Compiler().NewHint(InverseHint, 1, x.Limb)
|
result, err := p.api.Compiler().NewHint(InverseHint, 1, x.Limb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -258,7 +260,7 @@ func InverseHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Computes a field element raised to some power.
|
// Computes a field element raised to some power.
|
||||||
func (p *Chip) Exp(x Variable, k *big.Int) Variable {
|
func (p *GoldilocksApi) Exp(x GoldilocksVariable, k *big.Int) GoldilocksVariable {
|
||||||
if k.IsUint64() && k.Uint64() == 0 {
|
if k.IsUint64() && k.Uint64() == 0 {
|
||||||
return One()
|
return One()
|
||||||
}
|
}
|
||||||
@ -279,8 +281,31 @@ func (p *Chip) Exp(x Variable, k *big.Int) Variable {
|
|||||||
return z
|
return z
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The hint used to split a GoldilocksVariable into 2 32 bit limbs.
|
||||||
|
func SplitLimbsHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
|
||||||
|
if len(inputs) != 1 {
|
||||||
|
panic("SplitLimbsHint expects 1 input operand")
|
||||||
|
}
|
||||||
|
|
||||||
|
// The Goldilocks field element
|
||||||
|
input := inputs[0]
|
||||||
|
|
||||||
|
if input.Cmp(MODULUS) == 0 || input.Cmp(MODULUS) == 1 {
|
||||||
|
return fmt.Errorf("input is not in the field")
|
||||||
|
}
|
||||||
|
|
||||||
|
two_32 := big.NewInt(int64(math.Pow(2, 32)))
|
||||||
|
|
||||||
|
// The most significant bits
|
||||||
|
results[0] = new(big.Int).Quo(input, two_32)
|
||||||
|
// The least significant bits
|
||||||
|
results[1] = new(big.Int).Rem(input, two_32)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Range checks a field element x to be less than the Golidlocks modulus 2 ^ 64 - 2 ^ 32 + 1.
|
// Range checks a field element x to be less than the Golidlocks modulus 2 ^ 64 - 2 ^ 32 + 1.
|
||||||
func (p *Chip) RangeCheck(x Variable) {
|
func (p *GoldilocksApi) RangeCheck(x GoldilocksVariable) {
|
||||||
// The Goldilocks' modulus is 2^64 - 2^32 + 1, which is:
|
// The Goldilocks' modulus is 2^64 - 2^32 + 1, which is:
|
||||||
//
|
//
|
||||||
// 1111111111111111111111111111111100000000000000000000000000000001
|
// 1111111111111111111111111111111100000000000000000000000000000001
|
||||||
@ -288,47 +313,33 @@ func (p *Chip) RangeCheck(x Variable) {
|
|||||||
// in big endian binary. This function will first verify that x is at most 64 bits wide. Then it
|
// in big endian binary. This function will first verify that x is at most 64 bits wide. Then it
|
||||||
// checks that if the bits[0:31] (in big-endian) are all 1, then bits[32:64] are all zero.
|
// checks that if the bits[0:31] (in big-endian) are all 1, then bits[32:64] are all zero.
|
||||||
|
|
||||||
// First decompose x into 64 bits. The bits will be in little-endian order.
|
// Use the range checker component to range-check the variable.
|
||||||
bits := bits.ToBinary(p.api, x.Limb, bits.WithNbDigits(64))
|
rangeChecker := rangecheck.New(p.api)
|
||||||
|
rangeChecker.Check(x.Limb, 64)
|
||||||
|
|
||||||
// Those bits should compose back to x.
|
result, err := p.api.Compiler().NewHint(SplitLimbsHint, 2, x.Limb)
|
||||||
reconstructedX := frontend.Variable(0)
|
if err != nil {
|
||||||
c := uint64(1)
|
panic(err)
|
||||||
for i := 0; i < 64; i++ {
|
|
||||||
reconstructedX = p.api.Add(reconstructedX, p.api.Mul(bits[i], c))
|
|
||||||
c = c << 1
|
|
||||||
p.api.AssertIsBoolean(bits[i])
|
|
||||||
}
|
|
||||||
p.api.AssertIsEqual(x.Limb, reconstructedX)
|
|
||||||
|
|
||||||
mostSigBits32Sum := frontend.Variable(0)
|
|
||||||
for i := 32; i < 64; i++ {
|
|
||||||
mostSigBits32Sum = p.api.Add(mostSigBits32Sum, bits[i])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
leastSigBits32Sum := frontend.Variable(0)
|
mostSigBits := result[0]
|
||||||
for i := 0; i < 32; i++ {
|
leastSigBits := result[1]
|
||||||
leastSigBits32Sum = p.api.Add(leastSigBits32Sum, bits[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
// If mostSigBits32Sum < 32, then we know that:
|
// If the most significant bits are all 1, then we need to check that the least significant bits are all zero
|
||||||
//
|
// in order for element to be less than the Goldilock's modulus.
|
||||||
// x < (2^63 + ... + 2^32 + 0 * 2^31 + ... + 0 * 2^0)
|
// Otherwise, we don't need to do any checks, since we already know that the element is less than the Goldilocks modulus.
|
||||||
//
|
shouldCheck := p.api.IsZero(p.api.Sub(mostSigBits, uint64(math.Pow(2, 32))-1))
|
||||||
// which equals to 2^64 - 2^32. So in that case, we don't need to do any more checks. If
|
|
||||||
// mostSigBits32Sum == 32, then we need to check that x == 2^64 - 2^32 (max GL value).
|
|
||||||
shouldCheck := p.api.IsZero(p.api.Sub(mostSigBits32Sum, 32))
|
|
||||||
p.api.AssertIsEqual(
|
p.api.AssertIsEqual(
|
||||||
p.api.Select(
|
p.api.Select(
|
||||||
shouldCheck,
|
shouldCheck,
|
||||||
leastSigBits32Sum,
|
leastSigBits,
|
||||||
frontend.Variable(0),
|
frontend.Variable(0),
|
||||||
),
|
),
|
||||||
frontend.Variable(0),
|
frontend.Variable(0),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Chip) AssertIsEqual(x, y Variable) {
|
func (p *GoldilocksApi) AssertIsEqual(x, y GoldilocksVariable) {
|
||||||
p.api.AssertIsEqual(x.Limb, y.Limb)
|
p.api.AssertIsEqual(x.Limb, y.Limb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,8 +15,8 @@ type TestGoldilocksRangeCheckCircuit struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestGoldilocksRangeCheckCircuit) Define(api frontend.API) error {
|
func (c *TestGoldilocksRangeCheckCircuit) Define(api frontend.API) error {
|
||||||
chip := NewChip(api)
|
glApi := NewGoldilocksApi(api)
|
||||||
chip.RangeCheck(NewVariable(c.X))
|
glApi.RangeCheck(NewVariable(c.X))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func TestGoldilocksRangeCheck(t *testing.T) {
|
func TestGoldilocksRangeCheck(t *testing.T) {
|
||||||
@ -45,8 +45,8 @@ type TestGoldilocksMulAddCircuit struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestGoldilocksMulAddCircuit) Define(api frontend.API) error {
|
func (c *TestGoldilocksMulAddCircuit) Define(api frontend.API) error {
|
||||||
chip := NewChip(api)
|
glApi := NewGoldilocksApi(api)
|
||||||
calculateValue := chip.MulAdd(NewVariable(c.X), NewVariable(c.Y), NewVariable(c.Z))
|
calculateValue := glApi.MulAdd(NewVariable(c.X), NewVariable(c.Y), NewVariable(c.Z))
|
||||||
api.AssertIsEqual(calculateValue.Limb, c.ExpectedResult)
|
api.AssertIsEqual(calculateValue.Limb, c.ExpectedResult)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,13 +9,13 @@ import (
|
|||||||
const W uint64 = 7
|
const W uint64 = 7
|
||||||
const DTH_ROOT uint64 = 18446744069414584320
|
const DTH_ROOT uint64 = 18446744069414584320
|
||||||
|
|
||||||
type QuadraticExtensionVariable [2]Variable
|
type QuadraticExtensionVariable [2]GoldilocksVariable
|
||||||
|
|
||||||
func NewQuadraticExtensionVariable(x Variable, y Variable) QuadraticExtensionVariable {
|
func NewQuadraticExtensionVariable(x GoldilocksVariable, y GoldilocksVariable) QuadraticExtensionVariable {
|
||||||
return QuadraticExtensionVariable{x, y}
|
return QuadraticExtensionVariable{x, y}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Variable) ToQuadraticExtension() QuadraticExtensionVariable {
|
func (p GoldilocksVariable) ToQuadraticExtension() QuadraticExtensionVariable {
|
||||||
return NewQuadraticExtensionVariable(p, Zero())
|
return NewQuadraticExtensionVariable(p, Zero())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,35 +28,35 @@ func OneExtension() QuadraticExtensionVariable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Adds two quadratic extension variables in the Goldilocks field.
|
// Adds two quadratic extension variables in the Goldilocks field.
|
||||||
func (p *Chip) AddExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
func (p *GoldilocksApi) AddExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||||
c0 := p.Add(a[0], b[0])
|
c0 := p.Add(a[0], b[0])
|
||||||
c1 := p.Add(a[1], b[1])
|
c1 := p.Add(a[1], b[1])
|
||||||
return NewQuadraticExtensionVariable(c0, c1)
|
return NewQuadraticExtensionVariable(c0, c1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds two quadratic extension variables in the Goldilocks field without reducing.
|
// Adds two quadratic extension variables in the Goldilocks field without reducing.
|
||||||
func (p *Chip) AddExtensionNoReduce(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
func (p *GoldilocksApi) AddExtensionNoReduce(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||||
c0 := p.AddNoReduce(a[0], b[0])
|
c0 := p.AddNoReduce(a[0], b[0])
|
||||||
c1 := p.AddNoReduce(a[1], b[1])
|
c1 := p.AddNoReduce(a[1], b[1])
|
||||||
return NewQuadraticExtensionVariable(c0, c1)
|
return NewQuadraticExtensionVariable(c0, c1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtracts two quadratic extension variables in the Goldilocks field.
|
// Subtracts two quadratic extension variables in the Goldilocks field.
|
||||||
func (p *Chip) SubExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
func (p *GoldilocksApi) SubExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||||
c0 := p.Sub(a[0], b[0])
|
c0 := p.Sub(a[0], b[0])
|
||||||
c1 := p.Sub(a[1], b[1])
|
c1 := p.Sub(a[1], b[1])
|
||||||
return NewQuadraticExtensionVariable(c0, c1)
|
return NewQuadraticExtensionVariable(c0, c1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtracts two quadratic extension variables in the Goldilocks field without reducing.
|
// Subtracts two quadratic extension variables in the Goldilocks field without reducing.
|
||||||
func (p *Chip) SubExtensionNoReduce(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
func (p *GoldilocksApi) SubExtensionNoReduce(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||||
c0 := p.SubNoReduce(a[0], b[0])
|
c0 := p.SubNoReduce(a[0], b[0])
|
||||||
c1 := p.SubNoReduce(a[1], b[1])
|
c1 := p.SubNoReduce(a[1], b[1])
|
||||||
return NewQuadraticExtensionVariable(c0, c1)
|
return NewQuadraticExtensionVariable(c0, c1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiplies quadratic extension variable in the Goldilocks field.
|
// Multiplies quadratic extension variable in the Goldilocks field.
|
||||||
func (p *Chip) MulExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
func (p *GoldilocksApi) MulExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||||
product := p.MulExtensionNoReduce(a, b)
|
product := p.MulExtensionNoReduce(a, b)
|
||||||
product[0] = p.Reduce(product[0])
|
product[0] = p.Reduce(product[0])
|
||||||
product[1] = p.Reduce(product[1])
|
product[1] = p.Reduce(product[1])
|
||||||
@ -64,7 +64,7 @@ func (p *Chip) MulExtension(a, b QuadraticExtensionVariable) QuadraticExtensionV
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Multiplies quadratic extension variable in the Goldilocks field without reducing.
|
// Multiplies quadratic extension variable in the Goldilocks field without reducing.
|
||||||
func (p *Chip) MulExtensionNoReduce(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
func (p *GoldilocksApi) MulExtensionNoReduce(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||||
c0o0 := p.MulNoReduce(a[0], b[0])
|
c0o0 := p.MulNoReduce(a[0], b[0])
|
||||||
c0o1 := p.MulNoReduce(p.MulNoReduce(NewVariable(7), a[1]), b[1])
|
c0o1 := p.MulNoReduce(p.MulNoReduce(NewVariable(7), a[1]), b[1])
|
||||||
c0 := p.AddNoReduce(c0o0, c0o1)
|
c0 := p.AddNoReduce(c0o0, c0o1)
|
||||||
@ -74,7 +74,7 @@ func (p *Chip) MulExtensionNoReduce(a, b QuadraticExtensionVariable) QuadraticEx
|
|||||||
|
|
||||||
// Multiplies two operands a and b and adds to c in the Goldilocks extension field. a * b + c must
|
// Multiplies two operands a and b and adds to c in the Goldilocks extension field. a * b + c must
|
||||||
// be less than RANGE_CHECK_NB_BITS bits.
|
// be less than RANGE_CHECK_NB_BITS bits.
|
||||||
func (p *Chip) MulAddExtension(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable {
|
func (p *GoldilocksApi) MulAddExtension(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||||
product := p.MulExtensionNoReduce(a, b)
|
product := p.MulExtensionNoReduce(a, b)
|
||||||
sum := p.AddExtensionNoReduce(product, c)
|
sum := p.AddExtensionNoReduce(product, c)
|
||||||
sum[0] = p.Reduce(sum[0])
|
sum[0] = p.Reduce(sum[0])
|
||||||
@ -82,7 +82,7 @@ func (p *Chip) MulAddExtension(a, b, c QuadraticExtensionVariable) QuadraticExte
|
|||||||
return sum
|
return sum
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Chip) MulAddExtensionNoReduce(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable {
|
func (p *GoldilocksApi) MulAddExtensionNoReduce(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||||
product := p.MulExtensionNoReduce(a, b)
|
product := p.MulExtensionNoReduce(a, b)
|
||||||
sum := p.AddExtensionNoReduce(product, c)
|
sum := p.AddExtensionNoReduce(product, c)
|
||||||
return sum
|
return sum
|
||||||
@ -90,7 +90,7 @@ func (p *Chip) MulAddExtensionNoReduce(a, b, c QuadraticExtensionVariable) Quadr
|
|||||||
|
|
||||||
// Multiplies two operands a and b and subtracts to c in the Goldilocks extension field. a * b - c must
|
// Multiplies two operands a and b and subtracts to c in the Goldilocks extension field. a * b - c must
|
||||||
// be less than RANGE_CHECK_NB_BITS bits.
|
// be less than RANGE_CHECK_NB_BITS bits.
|
||||||
func (p *Chip) SubMulExtension(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable {
|
func (p *GoldilocksApi) SubMulExtension(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||||
difference := p.SubExtensionNoReduce(a, b)
|
difference := p.SubExtensionNoReduce(a, b)
|
||||||
product := p.MulExtensionNoReduce(difference, c)
|
product := p.MulExtensionNoReduce(difference, c)
|
||||||
product[0] = p.Reduce(product[0])
|
product[0] = p.Reduce(product[0])
|
||||||
@ -99,9 +99,9 @@ func (p *Chip) SubMulExtension(a, b, c QuadraticExtensionVariable) QuadraticExte
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Multiplies quadratic extension variable in the Goldilocks field by a scalar.
|
// Multiplies quadratic extension variable in the Goldilocks field by a scalar.
|
||||||
func (p *Chip) ScalarMulExtension(
|
func (p *GoldilocksApi) ScalarMulExtension(
|
||||||
a QuadraticExtensionVariable,
|
a QuadraticExtensionVariable,
|
||||||
b Variable,
|
b GoldilocksVariable,
|
||||||
) QuadraticExtensionVariable {
|
) QuadraticExtensionVariable {
|
||||||
return NewQuadraticExtensionVariable(
|
return NewQuadraticExtensionVariable(
|
||||||
p.Mul(a[0], b),
|
p.Mul(a[0], b),
|
||||||
@ -110,8 +110,8 @@ func (p *Chip) ScalarMulExtension(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Computes an inner product over quadratic extension variable vectors in the Goldilocks field.
|
// Computes an inner product over quadratic extension variable vectors in the Goldilocks field.
|
||||||
func (p *Chip) InnerProductExtension(
|
func (p *GoldilocksApi) InnerProductExtension(
|
||||||
constant Variable,
|
constant GoldilocksVariable,
|
||||||
startingAcc QuadraticExtensionVariable,
|
startingAcc QuadraticExtensionVariable,
|
||||||
pairs [][2]QuadraticExtensionVariable,
|
pairs [][2]QuadraticExtensionVariable,
|
||||||
) QuadraticExtensionVariable {
|
) QuadraticExtensionVariable {
|
||||||
@ -126,7 +126,7 @@ func (p *Chip) InnerProductExtension(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Computes the inverse of a quadratic extension variable in the Goldilocks field.
|
// Computes the inverse of a quadratic extension variable in the Goldilocks field.
|
||||||
func (p *Chip) InverseExtension(a QuadraticExtensionVariable) QuadraticExtensionVariable {
|
func (p *GoldilocksApi) InverseExtension(a QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||||
a0IsZero := p.api.IsZero(a[0].Limb)
|
a0IsZero := p.api.IsZero(a[0].Limb)
|
||||||
a1IsZero := p.api.IsZero(a[1].Limb)
|
a1IsZero := p.api.IsZero(a[1].Limb)
|
||||||
p.api.AssertIsEqual(p.api.Mul(a0IsZero, a1IsZero), frontend.Variable(0))
|
p.api.AssertIsEqual(p.api.Mul(a0IsZero, a1IsZero), frontend.Variable(0))
|
||||||
@ -139,12 +139,12 @@ func (p *Chip) InverseExtension(a QuadraticExtensionVariable) QuadraticExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Divides two quadratic extension variables in the Goldilocks field.
|
// Divides two quadratic extension variables in the Goldilocks field.
|
||||||
func (p *Chip) DivExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
func (p *GoldilocksApi) DivExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||||
return p.MulExtension(a, p.InverseExtension(b))
|
return p.MulExtension(a, p.InverseExtension(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exponentiates a quadratic extension variable to some exponent in the Golidlocks field.
|
// Exponentiates a quadratic extension variable to some exponent in the Golidlocks field.
|
||||||
func (p *Chip) ExpExtension(
|
func (p *GoldilocksApi) ExpExtension(
|
||||||
a QuadraticExtensionVariable,
|
a QuadraticExtensionVariable,
|
||||||
exponent uint64,
|
exponent uint64,
|
||||||
) QuadraticExtensionVariable {
|
) QuadraticExtensionVariable {
|
||||||
@ -173,12 +173,12 @@ func (p *Chip) ExpExtension(
|
|||||||
return product
|
return product
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Chip) ReduceExtension(x QuadraticExtensionVariable) QuadraticExtensionVariable {
|
func (p *GoldilocksApi) ReduceExtension(x QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||||
return NewQuadraticExtensionVariable(p.Reduce(x[0]), p.Reduce(x[1]))
|
return NewQuadraticExtensionVariable(p.Reduce(x[0]), p.Reduce(x[1]))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduces a list of extension field terms with a scalar power in the Goldilocks field.
|
// Reduces a list of extension field terms with a scalar power in the Goldilocks field.
|
||||||
func (p *Chip) ReduceWithPowers(
|
func (p *GoldilocksApi) ReduceWithPowers(
|
||||||
terms []QuadraticExtensionVariable,
|
terms []QuadraticExtensionVariable,
|
||||||
scalar QuadraticExtensionVariable,
|
scalar QuadraticExtensionVariable,
|
||||||
) QuadraticExtensionVariable {
|
) QuadraticExtensionVariable {
|
||||||
@ -197,14 +197,14 @@ func (p *Chip) ReduceWithPowers(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Outputs whether the quadratic extension variable is zero.
|
// Outputs whether the quadratic extension variable is zero.
|
||||||
func (p *Chip) IsZero(x QuadraticExtensionVariable) frontend.Variable {
|
func (p *GoldilocksApi) IsZero(x QuadraticExtensionVariable) frontend.Variable {
|
||||||
x0IsZero := p.api.IsZero(x[0].Limb)
|
x0IsZero := p.api.IsZero(x[0].Limb)
|
||||||
x1IsZero := p.api.IsZero(x[1].Limb)
|
x1IsZero := p.api.IsZero(x[1].Limb)
|
||||||
return p.api.Mul(x0IsZero, x1IsZero)
|
return p.api.Mul(x0IsZero, x1IsZero)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup is similar to select, but returns the first variable if the bit is zero and vice-versa.
|
// Lookup is similar to select, but returns the first variable if the bit is zero and vice-versa.
|
||||||
func (p *Chip) Lookup(
|
func (p *GoldilocksApi) Lookup(
|
||||||
b frontend.Variable,
|
b frontend.Variable,
|
||||||
x, y QuadraticExtensionVariable,
|
x, y QuadraticExtensionVariable,
|
||||||
) QuadraticExtensionVariable {
|
) QuadraticExtensionVariable {
|
||||||
@ -214,7 +214,7 @@ func (p *Chip) Lookup(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lookup2 is similar to select2, but returns the first variable if the bit is zero and vice-versa.
|
// Lookup2 is similar to select2, but returns the first variable if the bit is zero and vice-versa.
|
||||||
func (p *Chip) Lookup2(
|
func (p *GoldilocksApi) Lookup2(
|
||||||
b0 frontend.Variable,
|
b0 frontend.Variable,
|
||||||
b1 frontend.Variable,
|
b1 frontend.Variable,
|
||||||
qe0, qe1, qe2, qe3 QuadraticExtensionVariable,
|
qe0, qe1, qe2, qe3 QuadraticExtensionVariable,
|
||||||
@ -225,7 +225,7 @@ func (p *Chip) Lookup2(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Asserts that two quadratic extension variables are equal.
|
// Asserts that two quadratic extension variables are equal.
|
||||||
func (p *Chip) AssertIsEqualExtension(
|
func (p *GoldilocksApi) AssertIsEqualExtension(
|
||||||
a QuadraticExtensionVariable,
|
a QuadraticExtensionVariable,
|
||||||
b QuadraticExtensionVariable,
|
b QuadraticExtensionVariable,
|
||||||
) {
|
) {
|
||||||
@ -233,7 +233,7 @@ func (p *Chip) AssertIsEqualExtension(
|
|||||||
p.AssertIsEqual(a[1], b[1])
|
p.AssertIsEqual(a[1], b[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Chip) RangeCheckQE(a QuadraticExtensionVariable) {
|
func (p *GoldilocksApi) RangeCheckQE(a QuadraticExtensionVariable) {
|
||||||
p.RangeCheck(a[0])
|
p.RangeCheck(a[0])
|
||||||
p.RangeCheck(a[1])
|
p.RangeCheck(a[1])
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ func OneExtensionAlgebra() QuadraticExtensionAlgebraVariable {
|
|||||||
return OneExtension().ToQuadraticExtensionAlgebra()
|
return OneExtension().ToQuadraticExtensionAlgebra()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Chip) AddExtensionAlgebra(
|
func (p *GoldilocksApi) AddExtensionAlgebra(
|
||||||
a QuadraticExtensionAlgebraVariable,
|
a QuadraticExtensionAlgebraVariable,
|
||||||
b QuadraticExtensionAlgebraVariable,
|
b QuadraticExtensionAlgebraVariable,
|
||||||
) QuadraticExtensionAlgebraVariable {
|
) QuadraticExtensionAlgebraVariable {
|
||||||
@ -36,7 +36,7 @@ func (p *Chip) AddExtensionAlgebra(
|
|||||||
return sum
|
return sum
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Chip) SubExtensionAlgebra(
|
func (p *GoldilocksApi) SubExtensionAlgebra(
|
||||||
a QuadraticExtensionAlgebraVariable,
|
a QuadraticExtensionAlgebraVariable,
|
||||||
b QuadraticExtensionAlgebraVariable,
|
b QuadraticExtensionAlgebraVariable,
|
||||||
) QuadraticExtensionAlgebraVariable {
|
) QuadraticExtensionAlgebraVariable {
|
||||||
@ -47,7 +47,7 @@ func (p *Chip) SubExtensionAlgebra(
|
|||||||
return diff
|
return diff
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Chip) MulExtensionAlgebra(
|
func (p GoldilocksApi) MulExtensionAlgebra(
|
||||||
a QuadraticExtensionAlgebraVariable,
|
a QuadraticExtensionAlgebraVariable,
|
||||||
b QuadraticExtensionAlgebraVariable,
|
b QuadraticExtensionAlgebraVariable,
|
||||||
) QuadraticExtensionAlgebraVariable {
|
) QuadraticExtensionAlgebraVariable {
|
||||||
@ -74,7 +74,7 @@ func (p Chip) MulExtensionAlgebra(
|
|||||||
return product
|
return product
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Chip) ScalarMulExtensionAlgebra(
|
func (p *GoldilocksApi) ScalarMulExtensionAlgebra(
|
||||||
a QuadraticExtensionVariable,
|
a QuadraticExtensionVariable,
|
||||||
b QuadraticExtensionAlgebraVariable,
|
b QuadraticExtensionAlgebraVariable,
|
||||||
) QuadraticExtensionAlgebraVariable {
|
) QuadraticExtensionAlgebraVariable {
|
||||||
@ -85,7 +85,7 @@ func (p *Chip) ScalarMulExtensionAlgebra(
|
|||||||
return product
|
return product
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Chip) PartialInterpolateExtAlgebra(
|
func (p *GoldilocksApi) PartialInterpolateExtAlgebra(
|
||||||
domain []goldilocks.Element,
|
domain []goldilocks.Element,
|
||||||
values []QuadraticExtensionAlgebraVariable,
|
values []QuadraticExtensionAlgebraVariable,
|
||||||
barycentricWeights []goldilocks.Element,
|
barycentricWeights []goldilocks.Element,
|
||||||
|
|||||||
@ -15,7 +15,7 @@ type TestQuadraticExtensionMulCircuit struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestQuadraticExtensionMulCircuit) Define(api frontend.API) error {
|
func (c *TestQuadraticExtensionMulCircuit) Define(api frontend.API) error {
|
||||||
glApi := NewChip(api)
|
glApi := NewGoldilocksApi(api)
|
||||||
actualRes := glApi.MulExtension(c.Operand1, c.Operand2)
|
actualRes := glApi.MulExtension(c.Operand1, c.Operand2)
|
||||||
glApi.AssertIsEqual(actualRes[0], c.ExpectedResult[0])
|
glApi.AssertIsEqual(actualRes[0], c.ExpectedResult[0])
|
||||||
glApi.AssertIsEqual(actualRes[1], c.ExpectedResult[1])
|
glApi.AssertIsEqual(actualRes[1], c.ExpectedResult[1])
|
||||||
@ -58,7 +58,7 @@ type TestQuadraticExtensionDivCircuit struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestQuadraticExtensionDivCircuit) Define(api frontend.API) error {
|
func (c *TestQuadraticExtensionDivCircuit) Define(api frontend.API) error {
|
||||||
glAPI := NewChip(api)
|
glAPI := NewGoldilocksApi(api)
|
||||||
actualRes := glAPI.DivExtension(c.Operand1, c.Operand2)
|
actualRes := glAPI.DivExtension(c.Operand1, c.Operand2)
|
||||||
glAPI.AssertIsEqual(actualRes[0], c.ExpectedResult[0])
|
glAPI.AssertIsEqual(actualRes[0], c.ExpectedResult[0])
|
||||||
glAPI.AssertIsEqual(actualRes[1], c.ExpectedResult[1])
|
glAPI.AssertIsEqual(actualRes[1], c.ExpectedResult[1])
|
||||||
|
|||||||
@ -24,8 +24,8 @@ func StrArrayToFrontendVariableArray(input []string) []frontend.Variable {
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func Uint64ArrayToVariableArray(input []uint64) []Variable {
|
func Uint64ArrayToVariableArray(input []uint64) []GoldilocksVariable {
|
||||||
var output []Variable
|
var output []GoldilocksVariable
|
||||||
for i := 0; i < len(input); i++ {
|
for i := 0; i < len(input); i++ {
|
||||||
output = append(output, NewVariable(input[i]))
|
output = append(output, NewVariable(input[i]))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,7 +58,7 @@ func (g *ArithmeticExtensionGate) wiresIthOutput(i uint64) Range {
|
|||||||
|
|
||||||
func (g *ArithmeticExtensionGate) EvalUnfiltered(
|
func (g *ArithmeticExtensionGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
const0 := vars.localConstants[0]
|
const0 := vars.localConstants[0]
|
||||||
|
|||||||
@ -59,7 +59,7 @@ func (g *ArithmeticGate) WireIthOutput(i uint64) uint64 {
|
|||||||
|
|
||||||
func (g *ArithmeticGate) EvalUnfiltered(
|
func (g *ArithmeticGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
const0 := vars.localConstants[0]
|
const0 := vars.localConstants[0]
|
||||||
|
|||||||
@ -65,7 +65,7 @@ func (g *BaseSumGate) limbs() []uint64 {
|
|||||||
|
|
||||||
func (g *BaseSumGate) EvalUnfiltered(
|
func (g *BaseSumGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
sum := vars.localWires[BASESUM_GATE_WIRE_SUM]
|
sum := vars.localWires[BASESUM_GATE_WIRE_SUM]
|
||||||
|
|||||||
@ -56,7 +56,7 @@ func (g *ConstantGate) WireOutput(i uint64) uint64 {
|
|||||||
|
|
||||||
func (g *ConstantGate) EvalUnfiltered(
|
func (g *ConstantGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
constraints := []gl.QuadraticExtensionVariable{}
|
constraints := []gl.QuadraticExtensionVariable{}
|
||||||
|
|||||||
@ -147,7 +147,7 @@ func (g *CosetInterpolationGate) wiresShiftedEvaluationPoint() Range {
|
|||||||
|
|
||||||
func (g *CosetInterpolationGate) EvalUnfiltered(
|
func (g *CosetInterpolationGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
constraints := []gl.QuadraticExtensionVariable{}
|
constraints := []gl.QuadraticExtensionVariable{}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ func (g *EvaluateGatesChip) computeFilter(
|
|||||||
s gl.QuadraticExtensionVariable,
|
s gl.QuadraticExtensionVariable,
|
||||||
manySelector bool,
|
manySelector bool,
|
||||||
) gl.QuadraticExtensionVariable {
|
) gl.QuadraticExtensionVariable {
|
||||||
glApi := gl.NewChip(g.api)
|
glApi := gl.NewGoldilocksApi(g.api)
|
||||||
product := gl.OneExtension()
|
product := gl.OneExtension()
|
||||||
for i := groupRange.start; i < groupRange.end; i++ {
|
for i := groupRange.start; i < groupRange.end; i++ {
|
||||||
if i == uint64(row) {
|
if i == uint64(row) {
|
||||||
@ -62,7 +62,7 @@ func (g *EvaluateGatesChip) evalFiltered(
|
|||||||
groupRange Range,
|
groupRange Range,
|
||||||
numSelectors uint64,
|
numSelectors uint64,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
glApi := gl.NewChip(g.api)
|
glApi := gl.NewGoldilocksApi(g.api)
|
||||||
filter := g.computeFilter(row, groupRange, vars.localConstants[selectorIndex], numSelectors > 1)
|
filter := g.computeFilter(row, groupRange, vars.localConstants[selectorIndex], numSelectors > 1)
|
||||||
|
|
||||||
vars.RemovePrefix(numSelectors)
|
vars.RemovePrefix(numSelectors)
|
||||||
@ -75,7 +75,7 @@ func (g *EvaluateGatesChip) evalFiltered(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *EvaluateGatesChip) EvaluateGateConstraints(vars EvaluationVars) []gl.QuadraticExtensionVariable {
|
func (g *EvaluateGatesChip) EvaluateGateConstraints(vars EvaluationVars) []gl.QuadraticExtensionVariable {
|
||||||
glApi := gl.NewChip(g.api)
|
glApi := gl.NewGoldilocksApi(g.api)
|
||||||
constraints := make([]gl.QuadraticExtensionVariable, g.numGateConstraints)
|
constraints := make([]gl.QuadraticExtensionVariable, g.numGateConstraints)
|
||||||
for i := range constraints {
|
for i := range constraints {
|
||||||
constraints[i] = gl.ZeroExtension()
|
constraints[i] = gl.ZeroExtension()
|
||||||
|
|||||||
@ -65,7 +65,7 @@ func (g *ExponentiationGate) wireIntermediateValue(i uint64) uint64 {
|
|||||||
|
|
||||||
func (g *ExponentiationGate) EvalUnfiltered(
|
func (g *ExponentiationGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
base := vars.localWires[g.wireBase()]
|
base := vars.localWires[g.wireBase()]
|
||||||
|
|||||||
@ -12,7 +12,7 @@ type Gate interface {
|
|||||||
Id() string
|
Id() string
|
||||||
EvalUnfiltered(
|
EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable
|
) []gl.QuadraticExtensionVariable
|
||||||
}
|
}
|
||||||
|
|||||||
@ -693,7 +693,7 @@ func (circuit *TestGateCircuit) Define(api frontend.API) error {
|
|||||||
commonCircuitData := verifier.DeserializeCommonCircuitData("../../data/decode_block/common_circuit_data.json")
|
commonCircuitData := verifier.DeserializeCommonCircuitData("../../data/decode_block/common_circuit_data.json")
|
||||||
numSelectors := commonCircuitData.SelectorsInfo.NumSelectors()
|
numSelectors := commonCircuitData.SelectorsInfo.NumSelectors()
|
||||||
|
|
||||||
glApi := gl.NewChip(api)
|
glApi := gl.NewGoldilocksApi(api)
|
||||||
|
|
||||||
vars := gates.NewEvaluationVars(localConstants[numSelectors:], localWires, publicInputsHash)
|
vars := gates.NewEvaluationVars(localConstants[numSelectors:], localWires, publicInputsHash)
|
||||||
|
|
||||||
|
|||||||
@ -54,7 +54,7 @@ func (g *MultiplicationExtensionGate) wiresIthOutput(i uint64) Range {
|
|||||||
|
|
||||||
func (g *MultiplicationExtensionGate) EvalUnfiltered(
|
func (g *MultiplicationExtensionGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
const0 := vars.localConstants[0]
|
const0 := vars.localConstants[0]
|
||||||
|
|||||||
@ -27,7 +27,7 @@ func (g *NoopGate) Id() string {
|
|||||||
|
|
||||||
func (g *NoopGate) EvalUnfiltered(
|
func (g *NoopGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
return []gl.QuadraticExtensionVariable{}
|
return []gl.QuadraticExtensionVariable{}
|
||||||
|
|||||||
@ -91,7 +91,7 @@ func (g *PoseidonGate) WiresEnd() uint64 {
|
|||||||
|
|
||||||
func (g *PoseidonGate) EvalUnfiltered(
|
func (g *PoseidonGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
constraints := []gl.QuadraticExtensionVariable{}
|
constraints := []gl.QuadraticExtensionVariable{}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ func (g *PoseidonMdsGate) mdsRowShfAlgebra(
|
|||||||
v [poseidon.SPONGE_WIDTH]gl.QuadraticExtensionAlgebraVariable,
|
v [poseidon.SPONGE_WIDTH]gl.QuadraticExtensionAlgebraVariable,
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
) gl.QuadraticExtensionAlgebraVariable {
|
) gl.QuadraticExtensionAlgebraVariable {
|
||||||
glApi := gl.NewChip(api)
|
glApi := gl.NewGoldilocksApi(api)
|
||||||
if r >= poseidon.SPONGE_WIDTH {
|
if r >= poseidon.SPONGE_WIDTH {
|
||||||
panic("MDS row index out of range")
|
panic("MDS row index out of range")
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ func (g *PoseidonMdsGate) mdsLayerAlgebra(
|
|||||||
|
|
||||||
func (g *PoseidonMdsGate) EvalUnfiltered(
|
func (g *PoseidonMdsGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
constraints := []gl.QuadraticExtensionVariable{}
|
constraints := []gl.QuadraticExtensionVariable{}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ func (g *PublicInputGate) WiresPublicInputsHash() []uint64 {
|
|||||||
|
|
||||||
func (g *PublicInputGate) EvalUnfiltered(
|
func (g *PublicInputGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
constraints := []gl.QuadraticExtensionVariable{}
|
constraints := []gl.QuadraticExtensionVariable{}
|
||||||
|
|||||||
@ -116,7 +116,7 @@ func (g *RandomAccessGate) WireBit(i uint64, copy uint64) uint64 {
|
|||||||
|
|
||||||
func (g *RandomAccessGate) EvalUnfiltered(
|
func (g *RandomAccessGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
two := gl.NewVariable(2).ToQuadraticExtension()
|
two := gl.NewVariable(2).ToQuadraticExtension()
|
||||||
|
|||||||
@ -76,7 +76,7 @@ func (g *ReducingExtensionGate) wiresAccs(i uint64) Range {
|
|||||||
|
|
||||||
func (g *ReducingExtensionGate) EvalUnfiltered(
|
func (g *ReducingExtensionGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
alpha := vars.GetLocalExtAlgebra(g.wiresAlpha())
|
alpha := vars.GetLocalExtAlgebra(g.wiresAlpha())
|
||||||
|
|||||||
@ -76,7 +76,7 @@ func (g *ReducingGate) wiresAccs(i uint64) Range {
|
|||||||
|
|
||||||
func (g *ReducingGate) EvalUnfiltered(
|
func (g *ReducingGate) EvalUnfiltered(
|
||||||
api frontend.API,
|
api frontend.API,
|
||||||
glApi gl.Chip,
|
glApi gl.GoldilocksApi,
|
||||||
vars EvaluationVars,
|
vars EvaluationVars,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
alpha := vars.GetLocalExtAlgebra(g.wiresAlpha())
|
alpha := vars.GetLocalExtAlgebra(g.wiresAlpha())
|
||||||
|
|||||||
@ -13,8 +13,8 @@ type PlonkChip struct {
|
|||||||
|
|
||||||
commonData types.CommonCircuitData `gnark:"-"`
|
commonData types.CommonCircuitData `gnark:"-"`
|
||||||
|
|
||||||
DEGREE gl.Variable `gnark:"-"`
|
DEGREE gl.GoldilocksVariable `gnark:"-"`
|
||||||
DEGREE_BITS_F gl.Variable `gnark:"-"`
|
DEGREE_BITS_F gl.GoldilocksVariable `gnark:"-"`
|
||||||
DEGREE_QE gl.QuadraticExtensionVariable `gnark:"-"`
|
DEGREE_QE gl.QuadraticExtensionVariable `gnark:"-"`
|
||||||
|
|
||||||
evaluateGatesChip *gates.EvaluateGatesChip
|
evaluateGatesChip *gates.EvaluateGatesChip
|
||||||
@ -44,7 +44,7 @@ func NewPlonkChip(api frontend.API, commonData types.CommonCircuitData) *PlonkCh
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PlonkChip) expPowerOf2Extension(x gl.QuadraticExtensionVariable) gl.QuadraticExtensionVariable {
|
func (p *PlonkChip) expPowerOf2Extension(x gl.QuadraticExtensionVariable) gl.QuadraticExtensionVariable {
|
||||||
glApi := gl.NewChip(p.api)
|
glApi := gl.NewGoldilocksApi(p.api)
|
||||||
for i := uint64(0); i < p.commonData.DegreeBits; i++ {
|
for i := uint64(0); i < p.commonData.DegreeBits; i++ {
|
||||||
x = glApi.MulExtension(x, x)
|
x = glApi.MulExtension(x, x)
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ func (p *PlonkChip) expPowerOf2Extension(x gl.QuadraticExtensionVariable) gl.Qua
|
|||||||
|
|
||||||
func (p *PlonkChip) evalL0(x gl.QuadraticExtensionVariable, xPowN gl.QuadraticExtensionVariable) gl.QuadraticExtensionVariable {
|
func (p *PlonkChip) evalL0(x gl.QuadraticExtensionVariable, xPowN gl.QuadraticExtensionVariable) gl.QuadraticExtensionVariable {
|
||||||
// L_0(x) = (x^n - 1) / (n * (x - 1))
|
// L_0(x) = (x^n - 1) / (n * (x - 1))
|
||||||
glApi := gl.NewChip(p.api)
|
glApi := gl.NewGoldilocksApi(p.api)
|
||||||
evalZeroPoly := glApi.SubExtension(
|
evalZeroPoly := glApi.SubExtension(
|
||||||
xPowN,
|
xPowN,
|
||||||
gl.OneExtension(),
|
gl.OneExtension(),
|
||||||
@ -74,7 +74,7 @@ func (p *PlonkChip) checkPartialProducts(
|
|||||||
challengeNum uint64,
|
challengeNum uint64,
|
||||||
openings types.OpeningSet,
|
openings types.OpeningSet,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
glApi := gl.NewChip(p.api)
|
glApi := gl.NewGoldilocksApi(p.api)
|
||||||
numPartProds := p.commonData.NumPartialProducts
|
numPartProds := p.commonData.NumPartialProducts
|
||||||
quotDegreeFactor := p.commonData.QuotientDegreeFactor
|
quotDegreeFactor := p.commonData.QuotientDegreeFactor
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ func (p *PlonkChip) evalVanishingPoly(
|
|||||||
openings types.OpeningSet,
|
openings types.OpeningSet,
|
||||||
zetaPowN gl.QuadraticExtensionVariable,
|
zetaPowN gl.QuadraticExtensionVariable,
|
||||||
) []gl.QuadraticExtensionVariable {
|
) []gl.QuadraticExtensionVariable {
|
||||||
glApi := gl.NewChip(p.api)
|
glApi := gl.NewGoldilocksApi(p.api)
|
||||||
constraintTerms := p.evaluateGatesChip.EvaluateGateConstraints(vars)
|
constraintTerms := p.evaluateGatesChip.EvaluateGateConstraints(vars)
|
||||||
|
|
||||||
// Calculate the k[i] * x
|
// Calculate the k[i] * x
|
||||||
@ -197,7 +197,7 @@ func (p *PlonkChip) Verify(
|
|||||||
openings types.OpeningSet,
|
openings types.OpeningSet,
|
||||||
publicInputsHash poseidon.GoldilocksHashOut,
|
publicInputsHash poseidon.GoldilocksHashOut,
|
||||||
) {
|
) {
|
||||||
glApi := gl.NewChip(p.api)
|
glApi := gl.NewGoldilocksApi(p.api)
|
||||||
|
|
||||||
// Calculate zeta^n
|
// Calculate zeta^n
|
||||||
zetaPowN := p.expPowerOf2Extension(proofChallenges.PlonkZeta)
|
zetaPowN := p.expPowerOf2Extension(proofChallenges.PlonkZeta)
|
||||||
|
|||||||
@ -20,15 +20,15 @@ const BN254_SPONGE_WIDTH int = 4
|
|||||||
const BN254_SPONGE_RATE int = 3
|
const BN254_SPONGE_RATE int = 3
|
||||||
|
|
||||||
type BN254Chip struct {
|
type BN254Chip struct {
|
||||||
api frontend.API `gnark:"-"`
|
api frontend.API `gnark:"-"`
|
||||||
gl gl.Chip `gnark:"-"`
|
gl gl.GoldilocksApi `gnark:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BN254State = [BN254_SPONGE_WIDTH]frontend.Variable
|
type BN254State = [BN254_SPONGE_WIDTH]frontend.Variable
|
||||||
type BN254HashOut = frontend.Variable
|
type BN254HashOut = frontend.Variable
|
||||||
|
|
||||||
func NewBN254Chip(api frontend.API) *BN254Chip {
|
func NewBN254Chip(api frontend.API) *BN254Chip {
|
||||||
return &BN254Chip{api: api, gl: *gl.NewChip(api)}
|
return &BN254Chip{api: api, gl: *gl.NewGoldilocksApi(api)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BN254Chip) Poseidon(state BN254State) BN254State {
|
func (c *BN254Chip) Poseidon(state BN254State) BN254State {
|
||||||
@ -39,7 +39,7 @@ func (c *BN254Chip) Poseidon(state BN254State) BN254State {
|
|||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BN254Chip) HashNoPad(input []gl.Variable) BN254HashOut {
|
func (c *BN254Chip) HashNoPad(input []gl.GoldilocksVariable) BN254HashOut {
|
||||||
state := BN254State{
|
state := BN254State{
|
||||||
frontend.Variable(0),
|
frontend.Variable(0),
|
||||||
frontend.Variable(0),
|
frontend.Variable(0),
|
||||||
@ -69,7 +69,7 @@ func (c *BN254Chip) HashNoPad(input []gl.Variable) BN254HashOut {
|
|||||||
return BN254HashOut(state[0])
|
return BN254HashOut(state[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BN254Chip) HashOrNoop(input []gl.Variable) BN254HashOut {
|
func (c *BN254Chip) HashOrNoop(input []gl.GoldilocksVariable) BN254HashOut {
|
||||||
if len(input) <= 3 {
|
if len(input) <= 3 {
|
||||||
returnVal := frontend.Variable(0)
|
returnVal := frontend.Variable(0)
|
||||||
|
|
||||||
@ -94,10 +94,10 @@ func (c *BN254Chip) TwoToOne(left BN254HashOut, right BN254HashOut) BN254HashOut
|
|||||||
return state[0]
|
return state[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BN254Chip) ToVec(hash BN254HashOut) []gl.Variable {
|
func (c *BN254Chip) ToVec(hash BN254HashOut) []gl.GoldilocksVariable {
|
||||||
bits := c.api.ToBinary(hash)
|
bits := c.api.ToBinary(hash)
|
||||||
|
|
||||||
returnElements := []gl.Variable{}
|
returnElements := []gl.GoldilocksVariable{}
|
||||||
|
|
||||||
// Split into 7 byte chunks, since 8 byte chunks can result in collisions
|
// Split into 7 byte chunks, since 8 byte chunks can result in collisions
|
||||||
chunkSize := 56
|
chunkSize := 56
|
||||||
|
|||||||
@ -11,17 +11,17 @@ const MAX_WIDTH = 12
|
|||||||
const SPONGE_WIDTH = 12
|
const SPONGE_WIDTH = 12
|
||||||
const SPONGE_RATE = 8
|
const SPONGE_RATE = 8
|
||||||
|
|
||||||
type GoldilocksState = [SPONGE_WIDTH]gl.Variable
|
type GoldilocksState = [SPONGE_WIDTH]gl.GoldilocksVariable
|
||||||
type GoldilocksStateExtension = [SPONGE_WIDTH]gl.QuadraticExtensionVariable
|
type GoldilocksStateExtension = [SPONGE_WIDTH]gl.QuadraticExtensionVariable
|
||||||
type GoldilocksHashOut = [4]gl.Variable
|
type GoldilocksHashOut = [4]gl.GoldilocksVariable
|
||||||
|
|
||||||
type GoldilocksChip struct {
|
type GoldilocksChip struct {
|
||||||
api frontend.API `gnark:"-"`
|
api frontend.API `gnark:"-"`
|
||||||
gl gl.Chip `gnark:"-"`
|
gl gl.GoldilocksApi `gnark:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGoldilocksChip(api frontend.API) *GoldilocksChip {
|
func NewGoldilocksChip(api frontend.API) *GoldilocksChip {
|
||||||
return &GoldilocksChip{api: api, gl: *gl.NewChip(api)}
|
return &GoldilocksChip{api: api, gl: *gl.NewGoldilocksApi(api)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The permutation function.
|
// The permutation function.
|
||||||
@ -38,7 +38,7 @@ func (c *GoldilocksChip) Poseidon(input GoldilocksState) GoldilocksState {
|
|||||||
|
|
||||||
// The input elements MUST have all it's elements be within Goldilocks field.
|
// The input elements MUST have all it's elements be within Goldilocks field.
|
||||||
// The returned slice's elements will all be within Goldilocks field.
|
// The returned slice's elements will all be within Goldilocks field.
|
||||||
func (c *GoldilocksChip) HashNToMNoPad(input []gl.Variable, nbOutputs int) []gl.Variable {
|
func (c *GoldilocksChip) HashNToMNoPad(input []gl.GoldilocksVariable, nbOutputs int) []gl.GoldilocksVariable {
|
||||||
var state GoldilocksState
|
var state GoldilocksState
|
||||||
|
|
||||||
for i := 0; i < SPONGE_WIDTH; i++ {
|
for i := 0; i < SPONGE_WIDTH; i++ {
|
||||||
@ -54,7 +54,7 @@ func (c *GoldilocksChip) HashNToMNoPad(input []gl.Variable, nbOutputs int) []gl.
|
|||||||
state = c.Poseidon(state)
|
state = c.Poseidon(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
var outputs []gl.Variable
|
var outputs []gl.GoldilocksVariable
|
||||||
|
|
||||||
for {
|
for {
|
||||||
for i := 0; i < SPONGE_RATE; i++ {
|
for i := 0; i < SPONGE_RATE; i++ {
|
||||||
@ -69,9 +69,9 @@ func (c *GoldilocksChip) HashNToMNoPad(input []gl.Variable, nbOutputs int) []gl.
|
|||||||
|
|
||||||
// The input elements can be outside of the Goldilocks field.
|
// The input elements can be outside of the Goldilocks field.
|
||||||
// The returned slice's elements will all be within Goldilocks field.
|
// The returned slice's elements will all be within Goldilocks field.
|
||||||
func (c *GoldilocksChip) HashNoPad(input []gl.Variable) GoldilocksHashOut {
|
func (c *GoldilocksChip) HashNoPad(input []gl.GoldilocksVariable) GoldilocksHashOut {
|
||||||
var hash GoldilocksHashOut
|
var hash GoldilocksHashOut
|
||||||
inputVars := []gl.Variable{}
|
inputVars := []gl.GoldilocksVariable{}
|
||||||
|
|
||||||
for i := 0; i < len(input); i++ {
|
for i := 0; i < len(input); i++ {
|
||||||
inputVars = append(inputVars, c.gl.Reduce(input[i]))
|
inputVars = append(inputVars, c.gl.Reduce(input[i]))
|
||||||
@ -85,7 +85,7 @@ func (c *GoldilocksChip) HashNoPad(input []gl.Variable) GoldilocksHashOut {
|
|||||||
return hash
|
return hash
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GoldilocksChip) ToVec(hash GoldilocksHashOut) []gl.Variable {
|
func (c *GoldilocksChip) ToVec(hash GoldilocksHashOut) []gl.GoldilocksVariable {
|
||||||
return hash[:]
|
return hash[:]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ func (c *GoldilocksChip) ConstantLayerExtension(state GoldilocksStateExtension,
|
|||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GoldilocksChip) sBoxMonomial(x gl.Variable) gl.Variable {
|
func (c *GoldilocksChip) sBoxMonomial(x gl.GoldilocksVariable) gl.GoldilocksVariable {
|
||||||
x2 := c.gl.MulNoReduce(x, x)
|
x2 := c.gl.MulNoReduce(x, x)
|
||||||
x3 := c.gl.MulNoReduce(x, x2)
|
x3 := c.gl.MulNoReduce(x, x2)
|
||||||
x3 = c.gl.ReduceWithMaxBits(x3, 192)
|
x3 = c.gl.ReduceWithMaxBits(x3, 192)
|
||||||
@ -169,7 +169,7 @@ func (c *GoldilocksChip) SBoxLayerExtension(state GoldilocksStateExtension) Gold
|
|||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GoldilocksChip) mdsRowShf(r int, v [SPONGE_WIDTH]gl.Variable) gl.Variable {
|
func (c *GoldilocksChip) mdsRowShf(r int, v [SPONGE_WIDTH]gl.GoldilocksVariable) gl.GoldilocksVariable {
|
||||||
res := gl.Zero()
|
res := gl.Zero()
|
||||||
|
|
||||||
for i := 0; i < 12; i++ {
|
for i := 0; i < 12; i++ {
|
||||||
|
|||||||
@ -25,7 +25,7 @@ func (circuit *TestPoseidonCircuit) Define(api frontend.API) error {
|
|||||||
poseidonChip := NewGoldilocksChip(api)
|
poseidonChip := NewGoldilocksChip(api)
|
||||||
output := poseidonChip.Poseidon(input)
|
output := poseidonChip.Poseidon(input)
|
||||||
|
|
||||||
glApi := gl.NewChip(api)
|
glApi := gl.NewGoldilocksApi(api)
|
||||||
|
|
||||||
for i := 0; i < 12; i++ {
|
for i := 0; i < 12; i++ {
|
||||||
glApi.AssertIsEqual(output[i], gl.NewVariable(circuit.Out[i]))
|
glApi.AssertIsEqual(output[i], gl.NewVariable(circuit.Out[i]))
|
||||||
|
|||||||
@ -18,10 +18,10 @@ type TestPublicInputsHashCircuit struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (circuit *TestPublicInputsHashCircuit) Define(api frontend.API) error {
|
func (circuit *TestPublicInputsHashCircuit) Define(api frontend.API) error {
|
||||||
glAPI := gl.NewChip(api)
|
glAPI := gl.NewGoldilocksApi(api)
|
||||||
|
|
||||||
// BN254 -> Binary(64) -> F
|
// BN254 -> Binary(64) -> F
|
||||||
var input [3]gl.Variable
|
var input [3]gl.GoldilocksVariable
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
input[i] = gl.NewVariable(api.FromBinary(api.ToBinary(circuit.In[i], 64)...))
|
input[i] = gl.NewVariable(api.FromBinary(api.ToBinary(circuit.In[i], 64)...))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ type Proof struct {
|
|||||||
|
|
||||||
type ProofWithPublicInputs struct {
|
type ProofWithPublicInputs struct {
|
||||||
Proof Proof
|
Proof Proof
|
||||||
PublicInputs []gl.Variable // Length = CommonCircuitData.NumPublicInputs
|
PublicInputs []gl.GoldilocksVariable // Length = CommonCircuitData.NumPublicInputs
|
||||||
}
|
}
|
||||||
|
|
||||||
type VerifierOnlyCircuitData struct {
|
type VerifierOnlyCircuitData struct {
|
||||||
@ -46,6 +46,6 @@ type CommonCircuitData struct {
|
|||||||
NumGateConstraints uint64
|
NumGateConstraints uint64
|
||||||
NumConstants uint64
|
NumConstants uint64
|
||||||
NumPublicInputs uint64
|
NumPublicInputs uint64
|
||||||
KIs []gl.Variable
|
KIs []gl.GoldilocksVariable
|
||||||
NumPartialProducts uint64
|
NumPartialProducts uint64
|
||||||
}
|
}
|
||||||
|
|||||||
10
types/fri.go
10
types/fri.go
@ -47,11 +47,11 @@ func NewFriMerkleProof(merkleProofLen uint64) FriMerkleProof {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FriEvalProof struct {
|
type FriEvalProof struct {
|
||||||
Elements []gl.Variable // Length = [CommonCircuitData.Constants + CommonCircuitData.NumRoutedWires, CommonCircuitData.NumWires + CommonCircuitData.FriParams.Hiding ? 4 : 0, CommonCircuitData.NumChallenges * (1 + CommonCircuitData.NumPartialProducts) + salt, CommonCircuitData.NumChallenges * CommonCircuitData.QuotientDegreeFactor + salt]
|
Elements []gl.GoldilocksVariable // Length = [CommonCircuitData.Constants + CommonCircuitData.NumRoutedWires, CommonCircuitData.NumWires + CommonCircuitData.FriParams.Hiding ? 4 : 0, CommonCircuitData.NumChallenges * (1 + CommonCircuitData.NumPartialProducts) + salt, CommonCircuitData.NumChallenges * CommonCircuitData.QuotientDegreeFactor + salt]
|
||||||
MerkleProof FriMerkleProof
|
MerkleProof FriMerkleProof
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFriEvalProof(elements []gl.Variable, merkleProof FriMerkleProof) FriEvalProof {
|
func NewFriEvalProof(elements []gl.GoldilocksVariable, merkleProof FriMerkleProof) FriEvalProof {
|
||||||
return FriEvalProof{Elements: elements, MerkleProof: merkleProof}
|
return FriEvalProof{Elements: elements, MerkleProof: merkleProof}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,12 +88,12 @@ type FriProof struct {
|
|||||||
CommitPhaseMerkleCaps []FriMerkleCap // Length = Len(CommonCircuitData.FriParams.ReductionArityBits)
|
CommitPhaseMerkleCaps []FriMerkleCap // Length = Len(CommonCircuitData.FriParams.ReductionArityBits)
|
||||||
QueryRoundProofs []FriQueryRound // Length = CommonCircuitData.FriConfig.FriParams.NumQueryRounds
|
QueryRoundProofs []FriQueryRound // Length = CommonCircuitData.FriConfig.FriParams.NumQueryRounds
|
||||||
FinalPoly PolynomialCoeffs
|
FinalPoly PolynomialCoeffs
|
||||||
PowWitness gl.Variable
|
PowWitness gl.GoldilocksVariable
|
||||||
}
|
}
|
||||||
|
|
||||||
type FriChallenges struct {
|
type FriChallenges struct {
|
||||||
FriAlpha gl.QuadraticExtensionVariable
|
FriAlpha gl.QuadraticExtensionVariable
|
||||||
FriBetas []gl.QuadraticExtensionVariable
|
FriBetas []gl.QuadraticExtensionVariable
|
||||||
FriPowResponse gl.Variable
|
FriPowResponse gl.GoldilocksVariable
|
||||||
FriQueryIndices []gl.Variable
|
FriQueryIndices []gl.GoldilocksVariable
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,9 +25,9 @@ func NewOpeningSet(numConstants uint64, numRoutedWires uint64, numWires uint64,
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ProofChallenges struct {
|
type ProofChallenges struct {
|
||||||
PlonkBetas []gl.Variable
|
PlonkBetas []gl.GoldilocksVariable
|
||||||
PlonkGammas []gl.Variable
|
PlonkGammas []gl.GoldilocksVariable
|
||||||
PlonkAlphas []gl.Variable
|
PlonkAlphas []gl.GoldilocksVariable
|
||||||
PlonkZeta gl.QuadraticExtensionVariable
|
PlonkZeta gl.QuadraticExtensionVariable
|
||||||
FriChallenges FriChallenges
|
FriChallenges FriChallenges
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
type VerifierChip struct {
|
type VerifierChip struct {
|
||||||
api frontend.API `gnark:"-"`
|
api frontend.API `gnark:"-"`
|
||||||
glChip *gl.Chip `gnark:"-"`
|
glChip *gl.GoldilocksApi `gnark:"-"`
|
||||||
poseidonGlChip *poseidon.GoldilocksChip `gnark:"-"`
|
poseidonGlChip *poseidon.GoldilocksChip `gnark:"-"`
|
||||||
poseidonBN254Chip *poseidon.BN254Chip `gnark:"-"`
|
poseidonBN254Chip *poseidon.BN254Chip `gnark:"-"`
|
||||||
plonkChip *plonk.PlonkChip `gnark:"-"`
|
plonkChip *plonk.PlonkChip `gnark:"-"`
|
||||||
@ -20,7 +20,7 @@ type VerifierChip struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewVerifierChip(api frontend.API, commonCircuitData types.CommonCircuitData) *VerifierChip {
|
func NewVerifierChip(api frontend.API, commonCircuitData types.CommonCircuitData) *VerifierChip {
|
||||||
glChip := gl.NewChip(api)
|
glChip := gl.NewGoldilocksApi(api)
|
||||||
friChip := fri.NewChip(api, &commonCircuitData.FriParams)
|
friChip := fri.NewChip(api, &commonCircuitData.FriParams)
|
||||||
plonkChip := plonk.NewPlonkChip(api, commonCircuitData)
|
plonkChip := plonk.NewPlonkChip(api, commonCircuitData)
|
||||||
poseidonGlChip := poseidon.NewGoldilocksChip(api)
|
poseidonGlChip := poseidon.NewGoldilocksChip(api)
|
||||||
@ -35,7 +35,7 @@ func NewVerifierChip(api frontend.API, commonCircuitData types.CommonCircuitData
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *VerifierChip) GetPublicInputsHash(publicInputs []gl.Variable) poseidon.GoldilocksHashOut {
|
func (c *VerifierChip) GetPublicInputsHash(publicInputs []gl.GoldilocksVariable) poseidon.GoldilocksHashOut {
|
||||||
return c.poseidonGlChip.HashNoPad(publicInputs)
|
return c.poseidonGlChip.HashNoPad(publicInputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ func (c *VerifierChip) rangeCheckProof(proof types.Proof) {
|
|||||||
|
|
||||||
func (c *VerifierChip) Verify(
|
func (c *VerifierChip) Verify(
|
||||||
proof types.Proof,
|
proof types.Proof,
|
||||||
publicInputs []gl.Variable,
|
publicInputs []gl.GoldilocksVariable,
|
||||||
verifierData types.VerifierOnlyCircuitData,
|
verifierData types.VerifierOnlyCircuitData,
|
||||||
commonData types.CommonCircuitData,
|
commonData types.CommonCircuitData,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
type TestVerifierCircuit struct {
|
type TestVerifierCircuit struct {
|
||||||
Proof types.Proof
|
Proof types.Proof
|
||||||
PublicInputs []gl.Variable `gnark:",public"`
|
PublicInputs []gl.GoldilocksVariable `gnark:",public"`
|
||||||
|
|
||||||
verifierChip *verifier.VerifierChip `gnark:"-"`
|
verifierChip *verifier.VerifierChip `gnark:"-"`
|
||||||
plonky2CircuitName string `gnark:"-"`
|
plonky2CircuitName string `gnark:"-"`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user