mirror of
https://github.com/arnaucube/gnark-plonky2-verifier.git
synced 2026-01-12 00:51:33 +01:00
Moved to variables
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user