mirror of
https://github.com/logos-storage/gnark-plonky2-verifier.git
synced 2026-01-02 13:13:06 +00:00
Moved to variables
This commit is contained in:
parent
3b8611c6ac
commit
5d53737841
@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/types"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/variables"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/verifier"
|
||||
|
||||
"github.com/consensys/gnark-crypto/ecc"
|
||||
@ -21,7 +21,7 @@ import (
|
||||
)
|
||||
|
||||
type BenchmarkPlonky2VerifierCircuit struct {
|
||||
Proof types.Proof
|
||||
Proof variables.Proof
|
||||
PublicInputs []gl.Variable `gnark:",public"`
|
||||
|
||||
verifierChip *verifier.VerifierChip `gnark:"-"`
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/types"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/variables"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/verifier"
|
||||
|
||||
"github.com/consensys/gnark-crypto/ecc"
|
||||
@ -22,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
type BenchmarkPlonky2VerifierCircuitPlonk struct {
|
||||
Proof types.Proof
|
||||
Proof variables.Proof
|
||||
PublicInputs []gl.Variable `gnark:",public"`
|
||||
|
||||
verifierChip *verifier.VerifierChip `gnark:"-"`
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/fri"
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/poseidon"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/types"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/variables"
|
||||
)
|
||||
|
||||
type Chip struct {
|
||||
@ -113,12 +113,12 @@ func (c *Chip) GetHash() poseidon.GoldilocksHashOut {
|
||||
}
|
||||
|
||||
func (c *Chip) GetFriChallenges(
|
||||
commitPhaseMerkleCaps []types.FriMerkleCap,
|
||||
finalPoly types.PolynomialCoeffs,
|
||||
commitPhaseMerkleCaps []variables.FriMerkleCap,
|
||||
finalPoly variables.PolynomialCoeffs,
|
||||
powWitness gl.Variable,
|
||||
degreeBits uint64,
|
||||
config types.FriConfig,
|
||||
) types.FriChallenges {
|
||||
config variables.FriConfig,
|
||||
) variables.FriChallenges {
|
||||
numFriQueries := config.NumQueryRounds
|
||||
friAlpha := c.GetExtensionChallenge()
|
||||
|
||||
@ -134,7 +134,7 @@ func (c *Chip) GetFriChallenges(
|
||||
friPowResponse := c.GetChallenge()
|
||||
friQueryIndices := c.GetNChallenges(numFriQueries)
|
||||
|
||||
return types.FriChallenges{
|
||||
return variables.FriChallenges{
|
||||
FriAlpha: friAlpha,
|
||||
FriBetas: friBetas,
|
||||
FriPowResponse: friPowResponse,
|
||||
@ -152,7 +152,7 @@ func (c *Chip) duplexing() {
|
||||
panic("something went wrong")
|
||||
}
|
||||
|
||||
glApi := gl.NewGoldilocksApi(c.api)
|
||||
glApi := gl.New(c.api)
|
||||
|
||||
for i := 0; i < len(c.inputBuffer); i++ {
|
||||
c.spongeState[i] = glApi.Reduce(c.inputBuffer[i])
|
||||
|
||||
38
fri/fri.go
38
fri/fri.go
@ -10,30 +10,30 @@ import (
|
||||
"github.com/consensys/gnark/frontend"
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/poseidon"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/types"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/variables"
|
||||
)
|
||||
|
||||
type Chip struct {
|
||||
api frontend.API `gnark:"-"`
|
||||
gl gl.GoldilocksApi `gnark:"-"`
|
||||
api frontend.API `gnark:"-"`
|
||||
gl gl.Chip `gnark:"-"`
|
||||
poseidonBN254Chip *poseidon.BN254Chip
|
||||
friParams *types.FriParams `gnark:"-"`
|
||||
friParams *variables.FriParams `gnark:"-"`
|
||||
}
|
||||
|
||||
func NewChip(
|
||||
api frontend.API,
|
||||
friParams *types.FriParams,
|
||||
friParams *variables.FriParams,
|
||||
) *Chip {
|
||||
poseidonBN254Chip := poseidon.NewBN254Chip(api)
|
||||
return &Chip{
|
||||
api: api,
|
||||
poseidonBN254Chip: poseidonBN254Chip,
|
||||
friParams: friParams,
|
||||
gl: *gl.NewGoldilocksApi(api),
|
||||
gl: *gl.New(api),
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Chip) assertLeadingZeros(powWitness gl.Variable, friConfig types.FriConfig) {
|
||||
func (f *Chip) assertLeadingZeros(powWitness gl.Variable, friConfig variables.FriConfig) {
|
||||
// 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
|
||||
// field is 64 bits long
|
||||
@ -61,8 +61,8 @@ func (f *Chip) verifyMerkleProofToCapWithCapIndex(
|
||||
leafData []gl.Variable,
|
||||
leafIndexBits []frontend.Variable,
|
||||
capIndexBits []frontend.Variable,
|
||||
merkleCap types.FriMerkleCap,
|
||||
proof *types.FriMerkleProof,
|
||||
merkleCap variables.FriMerkleCap,
|
||||
proof *variables.FriMerkleProof,
|
||||
) {
|
||||
currentDigest := f.poseidonBN254Chip.HashOrNoop(leafData)
|
||||
for i, sibling := range proof.Siblings {
|
||||
@ -100,7 +100,7 @@ func (f *Chip) verifyMerkleProofToCapWithCapIndex(
|
||||
f.api.AssertIsEqual(currentDigest, merkleCapEntry)
|
||||
}
|
||||
|
||||
func (f *Chip) verifyInitialProof(xIndexBits []frontend.Variable, proof *types.FriInitialTreeProof, initialMerkleCaps []types.FriMerkleCap, capIndexBits []frontend.Variable) {
|
||||
func (f *Chip) verifyInitialProof(xIndexBits []frontend.Variable, proof *variables.FriInitialTreeProof, initialMerkleCaps []variables.FriMerkleCap, capIndexBits []frontend.Variable) {
|
||||
if len(proof.EvalsProofs) != len(initialMerkleCaps) {
|
||||
panic("length of eval proofs in fri proof should equal length of initial merkle caps")
|
||||
}
|
||||
@ -187,7 +187,7 @@ func (f *Chip) calculateSubgroupX(
|
||||
|
||||
func (f *Chip) friCombineInitial(
|
||||
instance InstanceInfo,
|
||||
proof types.FriInitialTreeProof,
|
||||
proof variables.FriInitialTreeProof,
|
||||
friAlpha gl.QuadraticExtensionVariable,
|
||||
subgroupX_QE gl.QuadraticExtensionVariable,
|
||||
precomputedReducedEval []gl.QuadraticExtensionVariable,
|
||||
@ -228,7 +228,7 @@ func (f *Chip) friCombineInitial(
|
||||
return sum
|
||||
}
|
||||
|
||||
func (f *Chip) finalPolyEval(finalPoly types.PolynomialCoeffs, point gl.QuadraticExtensionVariable) gl.QuadraticExtensionVariable {
|
||||
func (f *Chip) finalPolyEval(finalPoly variables.PolynomialCoeffs, point gl.QuadraticExtensionVariable) gl.QuadraticExtensionVariable {
|
||||
ret := gl.ZeroExtension()
|
||||
for i := len(finalPoly.Coeffs) - 1; i >= 0; i-- {
|
||||
ret = f.gl.MulAddExtension(ret, point, finalPoly.Coeffs[i])
|
||||
@ -355,14 +355,14 @@ func (f *Chip) computeEvaluation(
|
||||
|
||||
func (f *Chip) verifyQueryRound(
|
||||
instance InstanceInfo,
|
||||
challenges *types.FriChallenges,
|
||||
challenges *variables.FriChallenges,
|
||||
precomputedReducedEval []gl.QuadraticExtensionVariable,
|
||||
initialMerkleCaps []types.FriMerkleCap,
|
||||
proof *types.FriProof,
|
||||
initialMerkleCaps []variables.FriMerkleCap,
|
||||
proof *variables.FriProof,
|
||||
xIndex gl.Variable,
|
||||
n uint64,
|
||||
nLog uint64,
|
||||
roundProof *types.FriQueryRound,
|
||||
roundProof *variables.FriQueryRound,
|
||||
) {
|
||||
f.assertNoncanonicalIndicesOK()
|
||||
xIndex = f.gl.Reduce(xIndex)
|
||||
@ -468,9 +468,9 @@ func (f *Chip) verifyQueryRound(
|
||||
func (f *Chip) VerifyFriProof(
|
||||
instance InstanceInfo,
|
||||
openings Openings,
|
||||
friChallenges *types.FriChallenges,
|
||||
initialMerkleCaps []types.FriMerkleCap,
|
||||
friProof *types.FriProof,
|
||||
friChallenges *variables.FriChallenges,
|
||||
initialMerkleCaps []variables.FriMerkleCap,
|
||||
friProof *variables.FriProof,
|
||||
) {
|
||||
// TODO: Check fri config
|
||||
/* if let Some(max_arity_bits) = params.max_arity_bits() {
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/fri"
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/poseidon"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/types"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/variables"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/verifier"
|
||||
)
|
||||
|
||||
@ -25,7 +25,7 @@ func (circuit *TestFriCircuit) Define(api frontend.API) error {
|
||||
commonCircuitData := verifier.DeserializeCommonCircuitData(circuit.commonCircuitDataFilename)
|
||||
verifierOnlyCircuitData := verifier.DeserializeVerifierOnlyCircuitData(circuit.verifierOnlyCircuitDataFilename)
|
||||
|
||||
glApi := gl.NewGoldilocksApi(api)
|
||||
glApi := gl.New(api)
|
||||
poseidonChip := poseidon.NewGoldilocksChip(api)
|
||||
friChip := fri.NewChip(api, &commonCircuitData.FriParams)
|
||||
challengerChip := challenger.NewChip(api)
|
||||
@ -67,7 +67,7 @@ func (circuit *TestFriCircuit) Define(api frontend.API) error {
|
||||
x = 11890500485816111017
|
||||
api.AssertIsEqual(friChallenges.FriQueryIndices[0].Limb, x)
|
||||
|
||||
initialMerkleCaps := []types.FriMerkleCap{
|
||||
initialMerkleCaps := []variables.FriMerkleCap{
|
||||
verifierOnlyCircuitData.ConstantSigmasCap,
|
||||
proofWithPis.Proof.WiresCap,
|
||||
proofWithPis.Proof.PlonkZsPartialProductsCap,
|
||||
|
||||
@ -2,7 +2,7 @@ package fri
|
||||
|
||||
import (
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/types"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/variables"
|
||||
)
|
||||
|
||||
type OpeningBatch struct {
|
||||
@ -13,7 +13,7 @@ type Openings struct {
|
||||
Batches []OpeningBatch
|
||||
}
|
||||
|
||||
func ToOpenings(c types.OpeningSet) Openings {
|
||||
func ToOpenings(c variables.OpeningSet) Openings {
|
||||
values := c.Constants // num_constants + 1
|
||||
values = append(values, c.PlonkSigmas...) // num_routed_wires
|
||||
values = append(values, c.Wires...) // num_wires
|
||||
@ -70,7 +70,7 @@ var QUOTIENT = PlonkOracle{
|
||||
blinding: true,
|
||||
}
|
||||
|
||||
func polynomialInfoFromRange(c *types.CommonCircuitData, oracleIdx uint64, startPolyIdx uint64, endPolyIdx uint64) []PolynomialInfo {
|
||||
func polynomialInfoFromRange(c *variables.CommonCircuitData, oracleIdx uint64, startPolyIdx uint64, endPolyIdx uint64) []PolynomialInfo {
|
||||
returnArr := make([]PolynomialInfo, 0)
|
||||
for i := startPolyIdx; i < endPolyIdx; i++ {
|
||||
returnArr = append(returnArr,
|
||||
@ -84,7 +84,7 @@ func polynomialInfoFromRange(c *types.CommonCircuitData, oracleIdx uint64, start
|
||||
}
|
||||
|
||||
// Range of the sigma polynomials in the `constants_sigmas_commitment`.
|
||||
func sigmasRange(c *types.CommonCircuitData) []uint64 {
|
||||
func sigmasRange(c *variables.CommonCircuitData) []uint64 {
|
||||
returnArr := make([]uint64, 0)
|
||||
for i := c.NumConstants; i <= c.NumConstants+c.Config.NumRoutedWires; i++ {
|
||||
returnArr = append(returnArr, i)
|
||||
@ -93,20 +93,20 @@ func sigmasRange(c *types.CommonCircuitData) []uint64 {
|
||||
return returnArr
|
||||
}
|
||||
|
||||
func numPreprocessedPolys(c *types.CommonCircuitData) uint64 {
|
||||
func numPreprocessedPolys(c *variables.CommonCircuitData) uint64 {
|
||||
sigmasRange := sigmasRange(c)
|
||||
return sigmasRange[len(sigmasRange)-1]
|
||||
}
|
||||
|
||||
func numZSPartialProductsPolys(c *types.CommonCircuitData) uint64 {
|
||||
func numZSPartialProductsPolys(c *variables.CommonCircuitData) uint64 {
|
||||
return c.Config.NumChallenges * (1 + c.NumPartialProducts)
|
||||
}
|
||||
|
||||
func numQuotientPolys(c *types.CommonCircuitData) uint64 {
|
||||
func numQuotientPolys(c *variables.CommonCircuitData) uint64 {
|
||||
return c.Config.NumChallenges * c.QuotientDegreeFactor
|
||||
}
|
||||
|
||||
func friPreprocessedPolys(c *types.CommonCircuitData) []PolynomialInfo {
|
||||
func friPreprocessedPolys(c *variables.CommonCircuitData) []PolynomialInfo {
|
||||
return polynomialInfoFromRange(
|
||||
c,
|
||||
CONSTANTS_SIGMAS.index,
|
||||
@ -115,12 +115,12 @@ func friPreprocessedPolys(c *types.CommonCircuitData) []PolynomialInfo {
|
||||
)
|
||||
}
|
||||
|
||||
func friWirePolys(c *types.CommonCircuitData) []PolynomialInfo {
|
||||
func friWirePolys(c *variables.CommonCircuitData) []PolynomialInfo {
|
||||
numWirePolys := c.Config.NumWires
|
||||
return polynomialInfoFromRange(c, WIRES.index, 0, numWirePolys)
|
||||
}
|
||||
|
||||
func friZSPartialProductsPolys(c *types.CommonCircuitData) []PolynomialInfo {
|
||||
func friZSPartialProductsPolys(c *variables.CommonCircuitData) []PolynomialInfo {
|
||||
return polynomialInfoFromRange(
|
||||
c,
|
||||
ZS_PARTIAL_PRODUCTS.index,
|
||||
@ -129,7 +129,7 @@ func friZSPartialProductsPolys(c *types.CommonCircuitData) []PolynomialInfo {
|
||||
)
|
||||
}
|
||||
|
||||
func friQuotientPolys(c *types.CommonCircuitData) []PolynomialInfo {
|
||||
func friQuotientPolys(c *variables.CommonCircuitData) []PolynomialInfo {
|
||||
return polynomialInfoFromRange(
|
||||
c,
|
||||
QUOTIENT.index,
|
||||
@ -138,7 +138,7 @@ func friQuotientPolys(c *types.CommonCircuitData) []PolynomialInfo {
|
||||
)
|
||||
}
|
||||
|
||||
func friZSPolys(c *types.CommonCircuitData) []PolynomialInfo {
|
||||
func friZSPolys(c *variables.CommonCircuitData) []PolynomialInfo {
|
||||
return polynomialInfoFromRange(
|
||||
c,
|
||||
ZS_PARTIAL_PRODUCTS.index,
|
||||
@ -147,7 +147,7 @@ func friZSPolys(c *types.CommonCircuitData) []PolynomialInfo {
|
||||
)
|
||||
}
|
||||
|
||||
func friOracles(c *types.CommonCircuitData) []OracleInfo {
|
||||
func friOracles(c *variables.CommonCircuitData) []OracleInfo {
|
||||
return []OracleInfo{
|
||||
{
|
||||
NumPolys: numPreprocessedPolys(c),
|
||||
@ -168,7 +168,7 @@ func friOracles(c *types.CommonCircuitData) []OracleInfo {
|
||||
}
|
||||
}
|
||||
|
||||
func friAllPolys(c *types.CommonCircuitData) []PolynomialInfo {
|
||||
func friAllPolys(c *variables.CommonCircuitData) []PolynomialInfo {
|
||||
returnArr := make([]PolynomialInfo, 0)
|
||||
returnArr = append(returnArr, friPreprocessedPolys(c)...)
|
||||
returnArr = append(returnArr, friWirePolys(c)...)
|
||||
@ -178,7 +178,7 @@ func friAllPolys(c *types.CommonCircuitData) []PolynomialInfo {
|
||||
return returnArr
|
||||
}
|
||||
|
||||
func GetInstance(c *types.CommonCircuitData, glApi *gl.GoldilocksApi, zeta gl.QuadraticExtensionVariable, degreeBits uint64) InstanceInfo {
|
||||
func GetInstance(c *variables.CommonCircuitData, glApi *gl.Chip, zeta gl.QuadraticExtensionVariable, degreeBits uint64) InstanceInfo {
|
||||
zetaBatch := BatchInfo{
|
||||
Point: zeta,
|
||||
Polynomials: friAllPolys(c),
|
||||
|
||||
@ -11,6 +11,9 @@ package goldilocks
|
||||
// be very beneficial to use the no reduction methods and keep track of the maximum number of bits
|
||||
// your computation uses.
|
||||
|
||||
// This implementation is based on the following plonky2 implementation of Goldilocks
|
||||
// Available here: https://github.com/0xPolygonZero/plonky2/blob/main/field/src/goldilocks_field.rs#L70
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
@ -76,50 +79,50 @@ func NegOne() Variable {
|
||||
}
|
||||
|
||||
// The chip used for Goldilocks field operations.
|
||||
type GoldilocksApi struct {
|
||||
type Chip struct {
|
||||
api frontend.API
|
||||
rangeChecker frontend.Rangechecker
|
||||
}
|
||||
|
||||
// Creates a new Goldilocks chip.
|
||||
func NewGoldilocksApi(api frontend.API) *GoldilocksApi {
|
||||
// Creates a new Goldilocks Chip.
|
||||
func New(api frontend.API) *Chip {
|
||||
rangeChecker := rangecheck.New(api)
|
||||
return &GoldilocksApi{api: api, rangeChecker: rangeChecker}
|
||||
return &Chip{api: api, rangeChecker: rangeChecker}
|
||||
}
|
||||
|
||||
// Adds two field elements such that x + y = z within the Golidlocks field.
|
||||
func (p *GoldilocksApi) Add(a Variable, b Variable) Variable {
|
||||
func (p *Chip) Add(a Variable, b Variable) Variable {
|
||||
return p.MulAdd(a, NewVariable(1), b)
|
||||
}
|
||||
|
||||
// Adds two field elements such that x + y = z within the Golidlocks field without reducing.
|
||||
func (p *GoldilocksApi) AddNoReduce(a Variable, b Variable) Variable {
|
||||
func (p *Chip) AddNoReduce(a Variable, b Variable) Variable {
|
||||
return NewVariable(p.api.Add(a.Limb, b.Limb))
|
||||
}
|
||||
|
||||
// Subtracts two field elements such that x + y = z within the Golidlocks field.
|
||||
func (p *GoldilocksApi) Sub(a Variable, b Variable) Variable {
|
||||
func (p *Chip) Sub(a Variable, b Variable) Variable {
|
||||
return p.MulAdd(b, NewVariable(MODULUS.Uint64()-1), a)
|
||||
}
|
||||
|
||||
// Subtracts two field elements such that x + y = z within the Golidlocks field without reducing.
|
||||
func (p *GoldilocksApi) SubNoReduce(a Variable, b Variable) Variable {
|
||||
func (p *Chip) SubNoReduce(a Variable, b Variable) Variable {
|
||||
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.
|
||||
func (p *GoldilocksApi) Mul(a Variable, b Variable) Variable {
|
||||
func (p *Chip) Mul(a Variable, b Variable) Variable {
|
||||
return p.MulAdd(a, b, Zero())
|
||||
}
|
||||
|
||||
// Multiplies two field elements such that x * y = z within the Golidlocks field without reducing.
|
||||
func (p *GoldilocksApi) MulNoReduce(a Variable, b Variable) Variable {
|
||||
func (p *Chip) MulNoReduce(a Variable, b Variable) Variable {
|
||||
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
|
||||
// Golidlocks field.
|
||||
func (p *GoldilocksApi) MulAdd(a Variable, b Variable, c Variable) Variable {
|
||||
func (p *Chip) MulAdd(a Variable, b Variable, c Variable) Variable {
|
||||
result, err := p.api.Compiler().NewHint(MulAddHint, 2, a.Limb, b.Limb, c.Limb)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -140,7 +143,7 @@ func (p *GoldilocksApi) 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
|
||||
// Golidlocks field without reducing.
|
||||
func (p *GoldilocksApi) MulAddNoReduce(a Variable, b Variable, c Variable) Variable {
|
||||
func (p *Chip) MulAddNoReduce(a Variable, b Variable, c Variable) Variable {
|
||||
return p.AddNoReduce(p.MulNoReduce(a, b), c)
|
||||
}
|
||||
|
||||
@ -168,7 +171,7 @@ func MulAddHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
|
||||
}
|
||||
|
||||
// Reduces a field element x such that x % MODULUS = y.
|
||||
func (p *GoldilocksApi) Reduce(x Variable) Variable {
|
||||
func (p *Chip) Reduce(x Variable) Variable {
|
||||
// Witness a `quotient` and `remainder` such that:
|
||||
//
|
||||
// MODULUS * quotient + remainder = x
|
||||
@ -192,7 +195,7 @@ func (p *GoldilocksApi) Reduce(x Variable) Variable {
|
||||
}
|
||||
|
||||
// Reduces a field element x such that x % MODULUS = y.
|
||||
func (p *GoldilocksApi) ReduceWithMaxBits(x Variable, maxNbBits uint64) Variable {
|
||||
func (p *Chip) ReduceWithMaxBits(x Variable, maxNbBits uint64) Variable {
|
||||
// Witness a `quotient` and `remainder` such that:
|
||||
//
|
||||
// MODULUS * quotient + remainder = x
|
||||
@ -227,7 +230,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.
|
||||
func (p *GoldilocksApi) Inverse(x Variable) Variable {
|
||||
func (p *Chip) Inverse(x Variable) Variable {
|
||||
result, err := p.api.Compiler().NewHint(InverseHint, 1, x.Limb)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -261,7 +264,7 @@ func InverseHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
|
||||
}
|
||||
|
||||
// Computes a field element raised to some power.
|
||||
func (p *GoldilocksApi) Exp(x Variable, k *big.Int) Variable {
|
||||
func (p *Chip) Exp(x Variable, k *big.Int) Variable {
|
||||
if k.IsUint64() && k.Uint64() == 0 {
|
||||
return One()
|
||||
}
|
||||
@ -306,7 +309,7 @@ func SplitLimbsHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error {
|
||||
}
|
||||
|
||||
// Range checks a field element x to be less than the Golidlocks modulus 2 ^ 64 - 2 ^ 32 + 1.
|
||||
func (p *GoldilocksApi) RangeCheck(x Variable) {
|
||||
func (p *Chip) RangeCheck(x Variable) {
|
||||
// The Goldilocks' modulus is 2^64 - 2^32 + 1, which is:
|
||||
//
|
||||
// 1111111111111111111111111111111100000000000000000000000000000001
|
||||
@ -350,7 +353,7 @@ func (p *GoldilocksApi) RangeCheck(x Variable) {
|
||||
)
|
||||
}
|
||||
|
||||
func (p *GoldilocksApi) AssertIsEqual(x, y Variable) {
|
||||
func (p *Chip) AssertIsEqual(x, y Variable) {
|
||||
p.api.AssertIsEqual(x.Limb, y.Limb)
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ type TestGoldilocksRangeCheckCircuit struct {
|
||||
}
|
||||
|
||||
func (c *TestGoldilocksRangeCheckCircuit) Define(api frontend.API) error {
|
||||
glApi := NewGoldilocksApi(api)
|
||||
glApi := New(api)
|
||||
glApi.RangeCheck(NewVariable(c.X))
|
||||
return nil
|
||||
}
|
||||
@ -48,7 +48,7 @@ type TestGoldilocksRangeCheckBenchmarkCircuit struct {
|
||||
}
|
||||
|
||||
func (c *TestGoldilocksRangeCheckBenchmarkCircuit) Define(api frontend.API) error {
|
||||
glApi := NewGoldilocksApi(api)
|
||||
glApi := New(api)
|
||||
for _, x := range c.X {
|
||||
glApi.RangeCheck(NewVariable(x))
|
||||
glApi.Reduce(NewVariable(x))
|
||||
@ -88,7 +88,7 @@ type TestGoldilocksMulAddCircuit struct {
|
||||
}
|
||||
|
||||
func (c *TestGoldilocksMulAddCircuit) Define(api frontend.API) error {
|
||||
glApi := NewGoldilocksApi(api)
|
||||
glApi := New(api)
|
||||
calculateValue := glApi.MulAdd(NewVariable(c.X), NewVariable(c.Y), NewVariable(c.Z))
|
||||
api.AssertIsEqual(calculateValue.Limb, c.ExpectedResult)
|
||||
return nil
|
||||
|
||||
@ -28,35 +28,35 @@ func OneExtension() QuadraticExtensionVariable {
|
||||
}
|
||||
|
||||
// Adds two quadratic extension variables in the Goldilocks field.
|
||||
func (p *GoldilocksApi) AddExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
func (p *Chip) AddExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
c0 := p.Add(a[0], b[0])
|
||||
c1 := p.Add(a[1], b[1])
|
||||
return NewQuadraticExtensionVariable(c0, c1)
|
||||
}
|
||||
|
||||
// Adds two quadratic extension variables in the Goldilocks field without reducing.
|
||||
func (p *GoldilocksApi) AddExtensionNoReduce(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
func (p *Chip) AddExtensionNoReduce(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
c0 := p.AddNoReduce(a[0], b[0])
|
||||
c1 := p.AddNoReduce(a[1], b[1])
|
||||
return NewQuadraticExtensionVariable(c0, c1)
|
||||
}
|
||||
|
||||
// Subtracts two quadratic extension variables in the Goldilocks field.
|
||||
func (p *GoldilocksApi) SubExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
func (p *Chip) SubExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
c0 := p.Sub(a[0], b[0])
|
||||
c1 := p.Sub(a[1], b[1])
|
||||
return NewQuadraticExtensionVariable(c0, c1)
|
||||
}
|
||||
|
||||
// Subtracts two quadratic extension variables in the Goldilocks field without reducing.
|
||||
func (p *GoldilocksApi) SubExtensionNoReduce(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
func (p *Chip) SubExtensionNoReduce(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
c0 := p.SubNoReduce(a[0], b[0])
|
||||
c1 := p.SubNoReduce(a[1], b[1])
|
||||
return NewQuadraticExtensionVariable(c0, c1)
|
||||
}
|
||||
|
||||
// Multiplies quadratic extension variable in the Goldilocks field.
|
||||
func (p *GoldilocksApi) MulExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
func (p *Chip) MulExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
product := p.MulExtensionNoReduce(a, b)
|
||||
product[0] = p.Reduce(product[0])
|
||||
product[1] = p.Reduce(product[1])
|
||||
@ -64,7 +64,7 @@ func (p *GoldilocksApi) MulExtension(a, b QuadraticExtensionVariable) QuadraticE
|
||||
}
|
||||
|
||||
// Multiplies quadratic extension variable in the Goldilocks field without reducing.
|
||||
func (p *GoldilocksApi) MulExtensionNoReduce(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
func (p *Chip) MulExtensionNoReduce(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
c0o0 := p.MulNoReduce(a[0], b[0])
|
||||
c0o1 := p.MulNoReduce(p.MulNoReduce(NewVariable(7), a[1]), b[1])
|
||||
c0 := p.AddNoReduce(c0o0, c0o1)
|
||||
@ -74,7 +74,7 @@ func (p *GoldilocksApi) MulExtensionNoReduce(a, b QuadraticExtensionVariable) Qu
|
||||
|
||||
// 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.
|
||||
func (p *GoldilocksApi) MulAddExtension(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
func (p *Chip) MulAddExtension(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
product := p.MulExtensionNoReduce(a, b)
|
||||
sum := p.AddExtensionNoReduce(product, c)
|
||||
sum[0] = p.Reduce(sum[0])
|
||||
@ -82,7 +82,7 @@ func (p *GoldilocksApi) MulAddExtension(a, b, c QuadraticExtensionVariable) Quad
|
||||
return sum
|
||||
}
|
||||
|
||||
func (p *GoldilocksApi) MulAddExtensionNoReduce(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
func (p *Chip) MulAddExtensionNoReduce(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
product := p.MulExtensionNoReduce(a, b)
|
||||
sum := p.AddExtensionNoReduce(product, c)
|
||||
return sum
|
||||
@ -90,7 +90,7 @@ func (p *GoldilocksApi) MulAddExtensionNoReduce(a, b, c QuadraticExtensionVariab
|
||||
|
||||
// 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.
|
||||
func (p *GoldilocksApi) SubMulExtension(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
func (p *Chip) SubMulExtension(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
difference := p.SubExtensionNoReduce(a, b)
|
||||
product := p.MulExtensionNoReduce(difference, c)
|
||||
product[0] = p.Reduce(product[0])
|
||||
@ -99,7 +99,7 @@ func (p *GoldilocksApi) SubMulExtension(a, b, c QuadraticExtensionVariable) Quad
|
||||
}
|
||||
|
||||
// Multiplies quadratic extension variable in the Goldilocks field by a scalar.
|
||||
func (p *GoldilocksApi) ScalarMulExtension(
|
||||
func (p *Chip) ScalarMulExtension(
|
||||
a QuadraticExtensionVariable,
|
||||
b Variable,
|
||||
) QuadraticExtensionVariable {
|
||||
@ -110,7 +110,7 @@ func (p *GoldilocksApi) ScalarMulExtension(
|
||||
}
|
||||
|
||||
// Computes an inner product over quadratic extension variable vectors in the Goldilocks field.
|
||||
func (p *GoldilocksApi) InnerProductExtension(
|
||||
func (p *Chip) InnerProductExtension(
|
||||
constant Variable,
|
||||
startingAcc QuadraticExtensionVariable,
|
||||
pairs [][2]QuadraticExtensionVariable,
|
||||
@ -126,7 +126,7 @@ func (p *GoldilocksApi) InnerProductExtension(
|
||||
}
|
||||
|
||||
// Computes the inverse of a quadratic extension variable in the Goldilocks field.
|
||||
func (p *GoldilocksApi) InverseExtension(a QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
func (p *Chip) InverseExtension(a QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
a0IsZero := p.api.IsZero(a[0].Limb)
|
||||
a1IsZero := p.api.IsZero(a[1].Limb)
|
||||
p.api.AssertIsEqual(p.api.Mul(a0IsZero, a1IsZero), frontend.Variable(0))
|
||||
@ -139,12 +139,12 @@ func (p *GoldilocksApi) InverseExtension(a QuadraticExtensionVariable) Quadratic
|
||||
}
|
||||
|
||||
// Divides two quadratic extension variables in the Goldilocks field.
|
||||
func (p *GoldilocksApi) DivExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
func (p *Chip) DivExtension(a, b QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
return p.MulExtension(a, p.InverseExtension(b))
|
||||
}
|
||||
|
||||
// Exponentiates a quadratic extension variable to some exponent in the Golidlocks field.
|
||||
func (p *GoldilocksApi) ExpExtension(
|
||||
func (p *Chip) ExpExtension(
|
||||
a QuadraticExtensionVariable,
|
||||
exponent uint64,
|
||||
) QuadraticExtensionVariable {
|
||||
@ -173,12 +173,12 @@ func (p *GoldilocksApi) ExpExtension(
|
||||
return product
|
||||
}
|
||||
|
||||
func (p *GoldilocksApi) ReduceExtension(x QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
func (p *Chip) ReduceExtension(x QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
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.
|
||||
func (p *GoldilocksApi) ReduceWithPowers(
|
||||
func (p *Chip) ReduceWithPowers(
|
||||
terms []QuadraticExtensionVariable,
|
||||
scalar QuadraticExtensionVariable,
|
||||
) QuadraticExtensionVariable {
|
||||
@ -197,14 +197,14 @@ func (p *GoldilocksApi) ReduceWithPowers(
|
||||
}
|
||||
|
||||
// Outputs whether the quadratic extension variable is zero.
|
||||
func (p *GoldilocksApi) IsZero(x QuadraticExtensionVariable) frontend.Variable {
|
||||
func (p *Chip) IsZero(x QuadraticExtensionVariable) frontend.Variable {
|
||||
x0IsZero := p.api.IsZero(x[0].Limb)
|
||||
x1IsZero := p.api.IsZero(x[1].Limb)
|
||||
return p.api.Mul(x0IsZero, x1IsZero)
|
||||
}
|
||||
|
||||
// Lookup is similar to select, but returns the first variable if the bit is zero and vice-versa.
|
||||
func (p *GoldilocksApi) Lookup(
|
||||
func (p *Chip) Lookup(
|
||||
b frontend.Variable,
|
||||
x, y QuadraticExtensionVariable,
|
||||
) QuadraticExtensionVariable {
|
||||
@ -214,7 +214,7 @@ func (p *GoldilocksApi) Lookup(
|
||||
}
|
||||
|
||||
// Lookup2 is similar to select2, but returns the first variable if the bit is zero and vice-versa.
|
||||
func (p *GoldilocksApi) Lookup2(
|
||||
func (p *Chip) Lookup2(
|
||||
b0 frontend.Variable,
|
||||
b1 frontend.Variable,
|
||||
qe0, qe1, qe2, qe3 QuadraticExtensionVariable,
|
||||
@ -225,7 +225,7 @@ func (p *GoldilocksApi) Lookup2(
|
||||
}
|
||||
|
||||
// Asserts that two quadratic extension variables are equal.
|
||||
func (p *GoldilocksApi) AssertIsEqualExtension(
|
||||
func (p *Chip) AssertIsEqualExtension(
|
||||
a QuadraticExtensionVariable,
|
||||
b QuadraticExtensionVariable,
|
||||
) {
|
||||
@ -233,7 +233,7 @@ func (p *GoldilocksApi) AssertIsEqualExtension(
|
||||
p.AssertIsEqual(a[1], b[1])
|
||||
}
|
||||
|
||||
func (p *GoldilocksApi) RangeCheckQE(a QuadraticExtensionVariable) {
|
||||
func (p *Chip) RangeCheckQE(a QuadraticExtensionVariable) {
|
||||
p.RangeCheck(a[0])
|
||||
p.RangeCheck(a[1])
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ func OneExtensionAlgebra() QuadraticExtensionAlgebraVariable {
|
||||
return OneExtension().ToQuadraticExtensionAlgebra()
|
||||
}
|
||||
|
||||
func (p *GoldilocksApi) AddExtensionAlgebra(
|
||||
func (p *Chip) AddExtensionAlgebra(
|
||||
a QuadraticExtensionAlgebraVariable,
|
||||
b QuadraticExtensionAlgebraVariable,
|
||||
) QuadraticExtensionAlgebraVariable {
|
||||
@ -36,7 +36,7 @@ func (p *GoldilocksApi) AddExtensionAlgebra(
|
||||
return sum
|
||||
}
|
||||
|
||||
func (p *GoldilocksApi) SubExtensionAlgebra(
|
||||
func (p *Chip) SubExtensionAlgebra(
|
||||
a QuadraticExtensionAlgebraVariable,
|
||||
b QuadraticExtensionAlgebraVariable,
|
||||
) QuadraticExtensionAlgebraVariable {
|
||||
@ -47,7 +47,7 @@ func (p *GoldilocksApi) SubExtensionAlgebra(
|
||||
return diff
|
||||
}
|
||||
|
||||
func (p GoldilocksApi) MulExtensionAlgebra(
|
||||
func (p Chip) MulExtensionAlgebra(
|
||||
a QuadraticExtensionAlgebraVariable,
|
||||
b QuadraticExtensionAlgebraVariable,
|
||||
) QuadraticExtensionAlgebraVariable {
|
||||
@ -74,7 +74,7 @@ func (p GoldilocksApi) MulExtensionAlgebra(
|
||||
return product
|
||||
}
|
||||
|
||||
func (p *GoldilocksApi) ScalarMulExtensionAlgebra(
|
||||
func (p *Chip) ScalarMulExtensionAlgebra(
|
||||
a QuadraticExtensionVariable,
|
||||
b QuadraticExtensionAlgebraVariable,
|
||||
) QuadraticExtensionAlgebraVariable {
|
||||
@ -85,7 +85,7 @@ func (p *GoldilocksApi) ScalarMulExtensionAlgebra(
|
||||
return product
|
||||
}
|
||||
|
||||
func (p *GoldilocksApi) PartialInterpolateExtAlgebra(
|
||||
func (p *Chip) PartialInterpolateExtAlgebra(
|
||||
domain []goldilocks.Element,
|
||||
values []QuadraticExtensionAlgebraVariable,
|
||||
barycentricWeights []goldilocks.Element,
|
||||
|
||||
@ -15,7 +15,7 @@ type TestQuadraticExtensionMulCircuit struct {
|
||||
}
|
||||
|
||||
func (c *TestQuadraticExtensionMulCircuit) Define(api frontend.API) error {
|
||||
glApi := NewGoldilocksApi(api)
|
||||
glApi := New(api)
|
||||
actualRes := glApi.MulExtension(c.Operand1, c.Operand2)
|
||||
glApi.AssertIsEqual(actualRes[0], c.ExpectedResult[0])
|
||||
glApi.AssertIsEqual(actualRes[1], c.ExpectedResult[1])
|
||||
@ -58,7 +58,7 @@ type TestQuadraticExtensionDivCircuit struct {
|
||||
}
|
||||
|
||||
func (c *TestQuadraticExtensionDivCircuit) Define(api frontend.API) error {
|
||||
glAPI := NewGoldilocksApi(api)
|
||||
glAPI := New(api)
|
||||
actualRes := glAPI.DivExtension(c.Operand1, c.Operand2)
|
||||
glAPI.AssertIsEqual(actualRes[0], c.ExpectedResult[0])
|
||||
glAPI.AssertIsEqual(actualRes[1], c.ExpectedResult[1])
|
||||
|
||||
@ -58,7 +58,7 @@ func (g *ArithmeticExtensionGate) wiresIthOutput(i uint64) Range {
|
||||
|
||||
func (g *ArithmeticExtensionGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
const0 := vars.localConstants[0]
|
||||
|
||||
@ -59,7 +59,7 @@ func (g *ArithmeticGate) WireIthOutput(i uint64) uint64 {
|
||||
|
||||
func (g *ArithmeticGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
const0 := vars.localConstants[0]
|
||||
|
||||
@ -65,7 +65,7 @@ func (g *BaseSumGate) limbs() []uint64 {
|
||||
|
||||
func (g *BaseSumGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
sum := vars.localWires[BASESUM_GATE_WIRE_SUM]
|
||||
|
||||
@ -56,7 +56,7 @@ func (g *ConstantGate) WireOutput(i uint64) uint64 {
|
||||
|
||||
func (g *ConstantGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
constraints := []gl.QuadraticExtensionVariable{}
|
||||
|
||||
@ -147,7 +147,7 @@ func (g *CosetInterpolationGate) wiresShiftedEvaluationPoint() Range {
|
||||
|
||||
func (g *CosetInterpolationGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
constraints := []gl.QuadraticExtensionVariable{}
|
||||
|
||||
@ -36,7 +36,7 @@ func (g *EvaluateGatesChip) computeFilter(
|
||||
s gl.QuadraticExtensionVariable,
|
||||
manySelector bool,
|
||||
) gl.QuadraticExtensionVariable {
|
||||
glApi := gl.NewGoldilocksApi(g.api)
|
||||
glApi := gl.New(g.api)
|
||||
product := gl.OneExtension()
|
||||
for i := groupRange.start; i < groupRange.end; i++ {
|
||||
if i == uint64(row) {
|
||||
@ -62,7 +62,7 @@ func (g *EvaluateGatesChip) evalFiltered(
|
||||
groupRange Range,
|
||||
numSelectors uint64,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
glApi := gl.NewGoldilocksApi(g.api)
|
||||
glApi := gl.New(g.api)
|
||||
filter := g.computeFilter(row, groupRange, vars.localConstants[selectorIndex], numSelectors > 1)
|
||||
|
||||
vars.RemovePrefix(numSelectors)
|
||||
@ -75,7 +75,7 @@ func (g *EvaluateGatesChip) evalFiltered(
|
||||
}
|
||||
|
||||
func (g *EvaluateGatesChip) EvaluateGateConstraints(vars EvaluationVars) []gl.QuadraticExtensionVariable {
|
||||
glApi := gl.NewGoldilocksApi(g.api)
|
||||
glApi := gl.New(g.api)
|
||||
constraints := make([]gl.QuadraticExtensionVariable, g.numGateConstraints)
|
||||
for i := range constraints {
|
||||
constraints[i] = gl.ZeroExtension()
|
||||
|
||||
@ -65,7 +65,7 @@ func (g *ExponentiationGate) wireIntermediateValue(i uint64) uint64 {
|
||||
|
||||
func (g *ExponentiationGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
base := vars.localWires[g.wireBase()]
|
||||
|
||||
@ -12,7 +12,7 @@ type Gate interface {
|
||||
Id() string
|
||||
EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable
|
||||
}
|
||||
|
||||
@ -693,7 +693,7 @@ func (circuit *TestGateCircuit) Define(api frontend.API) error {
|
||||
commonCircuitData := verifier.DeserializeCommonCircuitData("../../data/decode_block/common_circuit_data.json")
|
||||
numSelectors := commonCircuitData.SelectorsInfo.NumSelectors()
|
||||
|
||||
glApi := gl.NewGoldilocksApi(api)
|
||||
glApi := gl.New(api)
|
||||
|
||||
vars := gates.NewEvaluationVars(localConstants[numSelectors:], localWires, publicInputsHash)
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ func (g *MultiplicationExtensionGate) wiresIthOutput(i uint64) Range {
|
||||
|
||||
func (g *MultiplicationExtensionGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
const0 := vars.localConstants[0]
|
||||
|
||||
@ -27,7 +27,7 @@ func (g *NoopGate) Id() string {
|
||||
|
||||
func (g *NoopGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
return []gl.QuadraticExtensionVariable{}
|
||||
|
||||
@ -91,7 +91,7 @@ func (g *PoseidonGate) WiresEnd() uint64 {
|
||||
|
||||
func (g *PoseidonGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
constraints := []gl.QuadraticExtensionVariable{}
|
||||
|
||||
@ -45,7 +45,7 @@ func (g *PoseidonMdsGate) mdsRowShfAlgebra(
|
||||
v [poseidon.SPONGE_WIDTH]gl.QuadraticExtensionAlgebraVariable,
|
||||
api frontend.API,
|
||||
) gl.QuadraticExtensionAlgebraVariable {
|
||||
glApi := gl.NewGoldilocksApi(api)
|
||||
glApi := gl.New(api)
|
||||
if r >= poseidon.SPONGE_WIDTH {
|
||||
panic("MDS row index out of range")
|
||||
}
|
||||
@ -75,7 +75,7 @@ func (g *PoseidonMdsGate) mdsLayerAlgebra(
|
||||
|
||||
func (g *PoseidonMdsGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
constraints := []gl.QuadraticExtensionVariable{}
|
||||
|
||||
@ -31,7 +31,7 @@ func (g *PublicInputGate) WiresPublicInputsHash() []uint64 {
|
||||
|
||||
func (g *PublicInputGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
constraints := []gl.QuadraticExtensionVariable{}
|
||||
|
||||
@ -116,7 +116,7 @@ func (g *RandomAccessGate) WireBit(i uint64, copy uint64) uint64 {
|
||||
|
||||
func (g *RandomAccessGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
two := gl.NewVariable(2).ToQuadraticExtension()
|
||||
|
||||
@ -76,7 +76,7 @@ func (g *ReducingExtensionGate) wiresAccs(i uint64) Range {
|
||||
|
||||
func (g *ReducingExtensionGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
alpha := vars.GetLocalExtAlgebra(g.wiresAlpha())
|
||||
|
||||
@ -76,7 +76,7 @@ func (g *ReducingGate) wiresAccs(i uint64) Range {
|
||||
|
||||
func (g *ReducingGate) EvalUnfiltered(
|
||||
api frontend.API,
|
||||
glApi gl.GoldilocksApi,
|
||||
glApi gl.Chip,
|
||||
vars EvaluationVars,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
alpha := vars.GetLocalExtAlgebra(g.wiresAlpha())
|
||||
|
||||
@ -5,13 +5,13 @@ import (
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/plonk/gates"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/poseidon"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/types"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/variables"
|
||||
)
|
||||
|
||||
type PlonkChip struct {
|
||||
api frontend.API `gnark:"-"`
|
||||
|
||||
commonData types.CommonCircuitData `gnark:"-"`
|
||||
commonData variables.CommonCircuitData `gnark:"-"`
|
||||
|
||||
DEGREE gl.Variable `gnark:"-"`
|
||||
DEGREE_BITS_F gl.Variable `gnark:"-"`
|
||||
@ -20,7 +20,7 @@ type PlonkChip struct {
|
||||
evaluateGatesChip *gates.EvaluateGatesChip
|
||||
}
|
||||
|
||||
func NewPlonkChip(api frontend.API, commonData types.CommonCircuitData) *PlonkChip {
|
||||
func NewPlonkChip(api frontend.API, commonData variables.CommonCircuitData) *PlonkChip {
|
||||
// TODO: Should degreeBits be verified that it fits within the field and that degree is within uint64?
|
||||
|
||||
evaluateGatesChip := gates.NewEvaluateGatesChip(
|
||||
@ -44,7 +44,7 @@ func NewPlonkChip(api frontend.API, commonData types.CommonCircuitData) *PlonkCh
|
||||
}
|
||||
|
||||
func (p *PlonkChip) expPowerOf2Extension(x gl.QuadraticExtensionVariable) gl.QuadraticExtensionVariable {
|
||||
glApi := gl.NewGoldilocksApi(p.api)
|
||||
glApi := gl.New(p.api)
|
||||
for i := uint64(0); i < p.commonData.DegreeBits; i++ {
|
||||
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 {
|
||||
// L_0(x) = (x^n - 1) / (n * (x - 1))
|
||||
glApi := gl.NewGoldilocksApi(p.api)
|
||||
glApi := gl.New(p.api)
|
||||
evalZeroPoly := glApi.SubExtension(
|
||||
xPowN,
|
||||
gl.OneExtension(),
|
||||
@ -72,9 +72,9 @@ func (p *PlonkChip) checkPartialProducts(
|
||||
numerators []gl.QuadraticExtensionVariable,
|
||||
denominators []gl.QuadraticExtensionVariable,
|
||||
challengeNum uint64,
|
||||
openings types.OpeningSet,
|
||||
openings variables.OpeningSet,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
glApi := gl.NewGoldilocksApi(p.api)
|
||||
glApi := gl.New(p.api)
|
||||
numPartProds := p.commonData.NumPartialProducts
|
||||
quotDegreeFactor := p.commonData.QuotientDegreeFactor
|
||||
|
||||
@ -106,11 +106,11 @@ func (p *PlonkChip) checkPartialProducts(
|
||||
|
||||
func (p *PlonkChip) evalVanishingPoly(
|
||||
vars gates.EvaluationVars,
|
||||
proofChallenges types.ProofChallenges,
|
||||
openings types.OpeningSet,
|
||||
proofChallenges variables.ProofChallenges,
|
||||
openings variables.OpeningSet,
|
||||
zetaPowN gl.QuadraticExtensionVariable,
|
||||
) []gl.QuadraticExtensionVariable {
|
||||
glApi := gl.NewGoldilocksApi(p.api)
|
||||
glApi := gl.New(p.api)
|
||||
constraintTerms := p.evaluateGatesChip.EvaluateGateConstraints(vars)
|
||||
|
||||
// Calculate the k[i] * x
|
||||
@ -193,11 +193,11 @@ func (p *PlonkChip) evalVanishingPoly(
|
||||
}
|
||||
|
||||
func (p *PlonkChip) Verify(
|
||||
proofChallenges types.ProofChallenges,
|
||||
openings types.OpeningSet,
|
||||
proofChallenges variables.ProofChallenges,
|
||||
openings variables.OpeningSet,
|
||||
publicInputsHash poseidon.GoldilocksHashOut,
|
||||
) {
|
||||
glApi := gl.NewGoldilocksApi(p.api)
|
||||
glApi := gl.New(p.api)
|
||||
|
||||
// Calculate zeta^n
|
||||
zetaPowN := p.expPowerOf2Extension(proofChallenges.PlonkZeta)
|
||||
|
||||
@ -20,15 +20,15 @@ const BN254_SPONGE_WIDTH int = 4
|
||||
const BN254_SPONGE_RATE int = 3
|
||||
|
||||
type BN254Chip struct {
|
||||
api frontend.API `gnark:"-"`
|
||||
gl gl.GoldilocksApi `gnark:"-"`
|
||||
api frontend.API `gnark:"-"`
|
||||
gl gl.Chip `gnark:"-"`
|
||||
}
|
||||
|
||||
type BN254State = [BN254_SPONGE_WIDTH]frontend.Variable
|
||||
type BN254HashOut = frontend.Variable
|
||||
|
||||
func NewBN254Chip(api frontend.API) *BN254Chip {
|
||||
return &BN254Chip{api: api, gl: *gl.NewGoldilocksApi(api)}
|
||||
return &BN254Chip{api: api, gl: *gl.New(api)}
|
||||
}
|
||||
|
||||
func (c *BN254Chip) Poseidon(state BN254State) BN254State {
|
||||
|
||||
@ -16,12 +16,12 @@ type GoldilocksStateExtension = [SPONGE_WIDTH]gl.QuadraticExtensionVariable
|
||||
type GoldilocksHashOut = [4]gl.Variable
|
||||
|
||||
type GoldilocksChip struct {
|
||||
api frontend.API `gnark:"-"`
|
||||
gl gl.GoldilocksApi `gnark:"-"`
|
||||
api frontend.API `gnark:"-"`
|
||||
gl gl.Chip `gnark:"-"`
|
||||
}
|
||||
|
||||
func NewGoldilocksChip(api frontend.API) *GoldilocksChip {
|
||||
return &GoldilocksChip{api: api, gl: *gl.NewGoldilocksApi(api)}
|
||||
return &GoldilocksChip{api: api, gl: *gl.New(api)}
|
||||
}
|
||||
|
||||
// The permutation function.
|
||||
|
||||
@ -25,7 +25,7 @@ func (circuit *TestPoseidonCircuit) Define(api frontend.API) error {
|
||||
poseidonChip := NewGoldilocksChip(api)
|
||||
output := poseidonChip.Poseidon(input)
|
||||
|
||||
glApi := gl.NewGoldilocksApi(api)
|
||||
glApi := gl.New(api)
|
||||
|
||||
for i := 0; i < 12; i++ {
|
||||
glApi.AssertIsEqual(output[i], gl.NewVariable(circuit.Out[i]))
|
||||
|
||||
@ -18,7 +18,7 @@ type TestPublicInputsHashCircuit struct {
|
||||
}
|
||||
|
||||
func (circuit *TestPublicInputsHashCircuit) Define(api frontend.API) error {
|
||||
glAPI := gl.NewGoldilocksApi(api)
|
||||
glAPI := gl.New(api)
|
||||
|
||||
// BN254 -> Binary(64) -> F
|
||||
var input [3]gl.Variable
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package types
|
||||
package variables
|
||||
|
||||
import (
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
@ -1,4 +1,4 @@
|
||||
package types
|
||||
package variables
|
||||
|
||||
import (
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
@ -1,4 +1,4 @@
|
||||
package types
|
||||
package variables
|
||||
|
||||
import gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/plonk/gates"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/poseidon"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/types"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/variables"
|
||||
)
|
||||
|
||||
type ProofWithPublicInputsRaw struct {
|
||||
@ -146,7 +146,7 @@ type VerifierOnlyCircuitDataRaw struct {
|
||||
CircuitDigest string `json:"circuit_digest"`
|
||||
}
|
||||
|
||||
func DeserializeMerkleCap(merkleCapRaw []string) types.FriMerkleCap {
|
||||
func DeserializeMerkleCap(merkleCapRaw []string) variables.FriMerkleCap {
|
||||
n := len(merkleCapRaw)
|
||||
merkleCap := make([]poseidon.BN254HashOut, n)
|
||||
for i := 0; i < n; i++ {
|
||||
@ -156,9 +156,9 @@ func DeserializeMerkleCap(merkleCapRaw []string) types.FriMerkleCap {
|
||||
return merkleCap
|
||||
}
|
||||
|
||||
func DeserializeMerkleProof(merkleProofRaw struct{ Siblings []interface{} }) types.FriMerkleProof {
|
||||
func DeserializeMerkleProof(merkleProofRaw struct{ Siblings []interface{} }) variables.FriMerkleProof {
|
||||
n := len(merkleProofRaw.Siblings)
|
||||
var mp types.FriMerkleProof
|
||||
var mp variables.FriMerkleProof
|
||||
mp.Siblings = make([]poseidon.BN254HashOut, n)
|
||||
for i := 0; i < n; i++ {
|
||||
element := merkleProofRaw.Siblings[i].(struct{ Elements []uint64 })
|
||||
@ -175,8 +175,8 @@ func DeserializeOpeningSet(openingSetRaw struct {
|
||||
PlonkZsNext [][]uint64
|
||||
PartialProducts [][]uint64
|
||||
QuotientPolys [][]uint64
|
||||
}) types.OpeningSet {
|
||||
return types.OpeningSet{
|
||||
}) variables.OpeningSet {
|
||||
return variables.OpeningSet{
|
||||
Constants: gl.Uint64ArrayToQuadraticExtensionArray(openingSetRaw.Constants),
|
||||
PlonkSigmas: gl.Uint64ArrayToQuadraticExtensionArray(openingSetRaw.PlonkSigmas),
|
||||
Wires: gl.Uint64ArrayToQuadraticExtensionArray(openingSetRaw.Wires),
|
||||
@ -216,29 +216,29 @@ func DeserializeFriProof(openingProofRaw struct {
|
||||
Coeffs [][]uint64
|
||||
}
|
||||
PowWitness uint64
|
||||
}) types.FriProof {
|
||||
var openingProof types.FriProof
|
||||
}) variables.FriProof {
|
||||
var openingProof variables.FriProof
|
||||
openingProof.PowWitness = gl.NewVariable(openingProofRaw.PowWitness)
|
||||
openingProof.FinalPoly.Coeffs = gl.Uint64ArrayToQuadraticExtensionArray(openingProofRaw.FinalPoly.Coeffs)
|
||||
|
||||
openingProof.CommitPhaseMerkleCaps = make([]types.FriMerkleCap, len(openingProofRaw.CommitPhaseMerkleCaps))
|
||||
openingProof.CommitPhaseMerkleCaps = make([]variables.FriMerkleCap, len(openingProofRaw.CommitPhaseMerkleCaps))
|
||||
for i := 0; i < len(openingProofRaw.CommitPhaseMerkleCaps); i++ {
|
||||
openingProof.CommitPhaseMerkleCaps[i] = StringArrayToHashBN254Array(openingProofRaw.CommitPhaseMerkleCaps[i])
|
||||
}
|
||||
|
||||
numQueryRoundProofs := len(openingProofRaw.QueryRoundProofs)
|
||||
openingProof.QueryRoundProofs = make([]types.FriQueryRound, numQueryRoundProofs)
|
||||
openingProof.QueryRoundProofs = make([]variables.FriQueryRound, numQueryRoundProofs)
|
||||
|
||||
for i := 0; i < numQueryRoundProofs; i++ {
|
||||
numEvalProofs := len(openingProofRaw.QueryRoundProofs[i].InitialTreesProof.EvalsProofs)
|
||||
openingProof.QueryRoundProofs[i].InitialTreesProof.EvalsProofs = make([]types.FriEvalProof, numEvalProofs)
|
||||
openingProof.QueryRoundProofs[i].InitialTreesProof.EvalsProofs = make([]variables.FriEvalProof, numEvalProofs)
|
||||
for j := 0; j < numEvalProofs; j++ {
|
||||
openingProof.QueryRoundProofs[i].InitialTreesProof.EvalsProofs[j].Elements = gl.Uint64ArrayToVariableArray(openingProofRaw.QueryRoundProofs[i].InitialTreesProof.EvalsProofs[j].LeafElements)
|
||||
openingProof.QueryRoundProofs[i].InitialTreesProof.EvalsProofs[j].MerkleProof.Siblings = StringArrayToHashBN254Array(openingProofRaw.QueryRoundProofs[i].InitialTreesProof.EvalsProofs[j].MerkleProof.Hash)
|
||||
}
|
||||
|
||||
numSteps := len(openingProofRaw.QueryRoundProofs[i].Steps)
|
||||
openingProof.QueryRoundProofs[i].Steps = make([]types.FriQueryStep, numSteps)
|
||||
openingProof.QueryRoundProofs[i].Steps = make([]variables.FriQueryStep, numSteps)
|
||||
for j := 0; j < numSteps; j++ {
|
||||
openingProof.QueryRoundProofs[i].Steps[j].Evals = gl.Uint64ArrayToQuadraticExtensionArray(openingProofRaw.QueryRoundProofs[i].Steps[j].Evals)
|
||||
openingProof.QueryRoundProofs[i].Steps[j].MerkleProof.Siblings = StringArrayToHashBN254Array(openingProofRaw.QueryRoundProofs[i].Steps[j].MerkleProof.Siblings)
|
||||
@ -248,7 +248,7 @@ func DeserializeFriProof(openingProofRaw struct {
|
||||
return openingProof
|
||||
}
|
||||
|
||||
func DeserializeProofWithPublicInputs(path string) types.ProofWithPublicInputs {
|
||||
func DeserializeProofWithPublicInputs(path string) variables.ProofWithPublicInputs {
|
||||
jsonFile, err := os.Open(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -263,7 +263,7 @@ func DeserializeProofWithPublicInputs(path string) types.ProofWithPublicInputs {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var proofWithPis types.ProofWithPublicInputs
|
||||
var proofWithPis variables.ProofWithPublicInputs
|
||||
proofWithPis.Proof.WiresCap = DeserializeMerkleCap(raw.Proof.WiresCap)
|
||||
proofWithPis.Proof.PlonkZsPartialProductsCap = DeserializeMerkleCap(raw.Proof.PlonkZsPartialProductsCap)
|
||||
proofWithPis.Proof.QuotientPolysCap = DeserializeMerkleCap(raw.Proof.QuotientPolysCap)
|
||||
@ -297,7 +297,7 @@ func DeserializeProofWithPublicInputs(path string) types.ProofWithPublicInputs {
|
||||
return proofWithPis
|
||||
}
|
||||
|
||||
func DeserializeProofChallenges(path string) types.ProofChallenges {
|
||||
func DeserializeProofChallenges(path string) variables.ProofChallenges {
|
||||
jsonFile, err := os.Open(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -312,7 +312,7 @@ func DeserializeProofChallenges(path string) types.ProofChallenges {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var proofChallenges types.ProofChallenges
|
||||
var proofChallenges variables.ProofChallenges
|
||||
proofChallenges.PlonkBetas = gl.Uint64ArrayToVariableArray(raw.PlonkBetas)
|
||||
proofChallenges.PlonkGammas = gl.Uint64ArrayToVariableArray(raw.PlonkGammas)
|
||||
proofChallenges.PlonkAlphas = gl.Uint64ArrayToVariableArray(raw.PlonkAlphas)
|
||||
@ -345,7 +345,7 @@ func ReductionArityBits(
|
||||
return returnArr
|
||||
}
|
||||
|
||||
func DeserializeCommonCircuitData(path string) types.CommonCircuitData {
|
||||
func DeserializeCommonCircuitData(path string) variables.CommonCircuitData {
|
||||
jsonFile, err := os.Open(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -360,7 +360,7 @@ func DeserializeCommonCircuitData(path string) types.CommonCircuitData {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var commonCircuitData types.CommonCircuitData
|
||||
var commonCircuitData variables.CommonCircuitData
|
||||
commonCircuitData.Config.NumWires = raw.Config.NumWires
|
||||
commonCircuitData.Config.NumRoutedWires = raw.Config.NumRoutedWires
|
||||
commonCircuitData.Config.NumConstants = raw.Config.NumConstants
|
||||
@ -411,7 +411,7 @@ func DeserializeCommonCircuitData(path string) types.CommonCircuitData {
|
||||
return commonCircuitData
|
||||
}
|
||||
|
||||
func DeserializeVerifierOnlyCircuitData(path string) types.VerifierOnlyCircuitData {
|
||||
func DeserializeVerifierOnlyCircuitData(path string) variables.VerifierOnlyCircuitData {
|
||||
jsonFile, err := os.Open(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -426,7 +426,7 @@ func DeserializeVerifierOnlyCircuitData(path string) types.VerifierOnlyCircuitDa
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var verifierOnlyCircuitData types.VerifierOnlyCircuitData
|
||||
var verifierOnlyCircuitData variables.VerifierOnlyCircuitData
|
||||
verifierOnlyCircuitData.ConstantSigmasCap = DeserializeMerkleCap(raw.ConstantsSigmasCap)
|
||||
circuitDigestBigInt, _ := new(big.Int).SetString(raw.CircuitDigest, 10)
|
||||
circuitDigestVar := frontend.Variable(circuitDigestBigInt)
|
||||
|
||||
@ -7,20 +7,20 @@ import (
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/plonk"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/poseidon"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/types"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/variables"
|
||||
)
|
||||
|
||||
type VerifierChip struct {
|
||||
api frontend.API `gnark:"-"`
|
||||
glChip *gl.GoldilocksApi `gnark:"-"`
|
||||
glChip *gl.Chip `gnark:"-"`
|
||||
poseidonGlChip *poseidon.GoldilocksChip `gnark:"-"`
|
||||
poseidonBN254Chip *poseidon.BN254Chip `gnark:"-"`
|
||||
plonkChip *plonk.PlonkChip `gnark:"-"`
|
||||
friChip *fri.Chip `gnark:"-"`
|
||||
}
|
||||
|
||||
func NewVerifierChip(api frontend.API, commonCircuitData types.CommonCircuitData) *VerifierChip {
|
||||
glChip := gl.NewGoldilocksApi(api)
|
||||
func NewVerifierChip(api frontend.API, commonCircuitData variables.CommonCircuitData) *VerifierChip {
|
||||
glChip := gl.New(api)
|
||||
friChip := fri.NewChip(api, &commonCircuitData.FriParams)
|
||||
plonkChip := plonk.NewPlonkChip(api, commonCircuitData)
|
||||
poseidonGlChip := poseidon.NewGoldilocksChip(api)
|
||||
@ -40,11 +40,11 @@ func (c *VerifierChip) GetPublicInputsHash(publicInputs []gl.Variable) poseidon.
|
||||
}
|
||||
|
||||
func (c *VerifierChip) GetChallenges(
|
||||
proof types.Proof,
|
||||
proof variables.Proof,
|
||||
publicInputsHash poseidon.GoldilocksHashOut,
|
||||
commonData types.CommonCircuitData,
|
||||
verifierData types.VerifierOnlyCircuitData,
|
||||
) types.ProofChallenges {
|
||||
commonData variables.CommonCircuitData,
|
||||
verifierData variables.VerifierOnlyCircuitData,
|
||||
) variables.ProofChallenges {
|
||||
config := commonData.Config
|
||||
numChallenges := config.NumChallenges
|
||||
challenger := challenger.NewChip(c.api)
|
||||
@ -65,7 +65,7 @@ func (c *VerifierChip) GetChallenges(
|
||||
|
||||
challenger.ObserveOpenings(fri.ToOpenings(proof.Openings))
|
||||
|
||||
return types.ProofChallenges{
|
||||
return variables.ProofChallenges{
|
||||
PlonkBetas: plonkBetas,
|
||||
PlonkGammas: plonkGammas,
|
||||
PlonkAlphas: plonkAlphas,
|
||||
@ -147,7 +147,7 @@ func (c *VerifierChip) generateProofInput(commonData common.CommonCircuitData) c
|
||||
}
|
||||
*/
|
||||
|
||||
func (c *VerifierChip) rangeCheckProof(proof types.Proof) {
|
||||
func (c *VerifierChip) rangeCheckProof(proof variables.Proof) {
|
||||
// Need to verify the plonky2 proof's openings, openings proof (other than the sibling elements), fri's final poly, pow witness.
|
||||
|
||||
// Note that this is NOT range checking the public inputs (first 32 elements should be no more than 8 bits and the last 4 elements should be no more than 64 bits). Since this is currently being inputted via the smart contract,
|
||||
@ -205,10 +205,10 @@ func (c *VerifierChip) rangeCheckProof(proof types.Proof) {
|
||||
}
|
||||
|
||||
func (c *VerifierChip) Verify(
|
||||
proof types.Proof,
|
||||
proof variables.Proof,
|
||||
publicInputs []gl.Variable,
|
||||
verifierData types.VerifierOnlyCircuitData,
|
||||
commonData types.CommonCircuitData,
|
||||
verifierData variables.VerifierOnlyCircuitData,
|
||||
commonData variables.CommonCircuitData,
|
||||
) {
|
||||
c.rangeCheckProof(proof)
|
||||
|
||||
@ -218,7 +218,7 @@ func (c *VerifierChip) Verify(
|
||||
|
||||
c.plonkChip.Verify(proofChallenges, proof.Openings, publicInputsHash)
|
||||
|
||||
initialMerkleCaps := []types.FriMerkleCap{
|
||||
initialMerkleCaps := []variables.FriMerkleCap{
|
||||
verifierData.ConstantSigmasCap,
|
||||
proof.WiresCap,
|
||||
proof.PlonkZsPartialProductsCap,
|
||||
|
||||
@ -9,12 +9,12 @@ import (
|
||||
"github.com/consensys/gnark/std/math/emulated"
|
||||
"github.com/consensys/gnark/test"
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/types"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/variables"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/verifier"
|
||||
)
|
||||
|
||||
type TestVerifierCircuit struct {
|
||||
Proof types.Proof
|
||||
Proof variables.Proof
|
||||
PublicInputs []gl.Variable `gnark:",public"`
|
||||
|
||||
verifierChip *verifier.VerifierChip `gnark:"-"`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user