mirror of
https://github.com/arnaucube/gnark-plonky2-verifier.git
synced 2026-01-12 09:01:32 +01:00
got plonk.evalVanishingPoly working
This commit is contained in:
@@ -2,18 +2,32 @@ package plonky2_verifier
|
||||
|
||||
import (
|
||||
. "gnark-ed25519/field"
|
||||
|
||||
"github.com/consensys/gnark/frontend"
|
||||
)
|
||||
|
||||
type PlonkChip struct {
|
||||
api frontend.API
|
||||
field frontend.API
|
||||
qe *QuadraticExtensionAPI
|
||||
qe *QuadraticExtensionAPI
|
||||
|
||||
commonData CommonCircuitData
|
||||
proofChallenges ProofChallenges
|
||||
openings OpeningSet
|
||||
|
||||
DEGREE F
|
||||
DEGREE_BITS_F F
|
||||
DEGREE_QE QuadraticExtension
|
||||
}
|
||||
|
||||
func NewPlonkChip(qe *QuadraticExtensionAPI, commonData CommonCircuitData) *PlonkChip {
|
||||
// TODO: Should degreeBits be verified that it fits within the field and that degree is within uint64?
|
||||
|
||||
return &PlonkChip{
|
||||
qe: qe,
|
||||
|
||||
commonData: commonData,
|
||||
|
||||
DEGREE: NewFieldElement(1 << commonData.DegreeBits),
|
||||
DEGREE_BITS_F: NewFieldElement(commonData.DegreeBits),
|
||||
DEGREE_QE: QuadraticExtension{NewFieldElement(1 << commonData.DegreeBits), NewFieldElement(0)},
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PlonkChip) expPowerOf2Extension(x QuadraticExtension) QuadraticExtension {
|
||||
@@ -31,8 +45,8 @@ func (p *PlonkChip) evalL0(x QuadraticExtension, xPowN QuadraticExtension) Quadr
|
||||
p.qe.ONE,
|
||||
)
|
||||
denominator := p.qe.SubExtension(
|
||||
p.qe.ScalarMulExtension(x, p.qe.DEGREE_BITS_F),
|
||||
p.qe.DEGREE_BITS_QE,
|
||||
p.qe.ScalarMulExtension(x, p.DEGREE),
|
||||
p.DEGREE_QE,
|
||||
)
|
||||
return p.qe.DivExtension(
|
||||
evalZeroPoly,
|
||||
@@ -55,7 +69,7 @@ func (p *PlonkChip) checkPartialProducts(
|
||||
|
||||
partialProductChecks := make([]QuadraticExtension, 0, numPartProds)
|
||||
|
||||
for i := uint64(0); i < numPartProds; i += 1 {
|
||||
for i := uint64(0); i <= numPartProds; i += 1 {
|
||||
ppStartIdx := i * quotDegreeFactor
|
||||
numeProduct := numerators[ppStartIdx]
|
||||
denoProduct := denominators[ppStartIdx]
|
||||
@@ -92,10 +106,9 @@ func (p *PlonkChip) evalVanishingPoly() []QuadraticExtension {
|
||||
vanishingPartialProductsTerms := make([]QuadraticExtension, 0, p.commonData.Config.NumChallenges*p.commonData.NumPartialProducts)
|
||||
for i := uint64(0); i < p.commonData.Config.NumChallenges; i++ {
|
||||
// L_0(zeta) (Z(zeta) - 1) = 0
|
||||
z1_term := p.qe.SubExtension(
|
||||
p.qe.MulExtension(l0Zeta, p.openings.PlonkZs[i]),
|
||||
z1_term := p.qe.MulExtension(
|
||||
l0Zeta,
|
||||
)
|
||||
p.qe.SubExtension(p.openings.PlonkZs[i], p.qe.ONE))
|
||||
vanishingZ1Terms = append(vanishingZ1Terms, z1_term)
|
||||
|
||||
numeratorValues := make([]QuadraticExtension, 0, p.commonData.Config.NumRoutedWires)
|
||||
@@ -135,9 +148,16 @@ func (p *PlonkChip) evalVanishingPoly() []QuadraticExtension {
|
||||
)
|
||||
}
|
||||
|
||||
return vanishingPartialProductsTerms
|
||||
return append(vanishingZ1Terms, vanishingPartialProductsTerms...)
|
||||
}
|
||||
|
||||
func (p *PlonkChip) Verify() {
|
||||
p.evalVanishingPoly()
|
||||
|
||||
/*
|
||||
vanishingPolys := p.evalVanishingPoly()
|
||||
|
||||
for _, vp := range vanishingPolys {
|
||||
//fmt.Println(vp)
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -37,14 +37,9 @@ func (circuit *TestPlonkCircuit) Define(api frontend.API) error {
|
||||
},
|
||||
}
|
||||
|
||||
plonkChip := PlonkChip{
|
||||
api: api,
|
||||
field: field,
|
||||
qe: qe,
|
||||
commonData: commonCircuitData,
|
||||
proofChallenges: proofChallenges,
|
||||
openings: proofWithPis.Proof.Openings,
|
||||
}
|
||||
plonkChip := NewPlonkChip(qe, commonCircuitData)
|
||||
plonkChip.proofChallenges = proofChallenges
|
||||
plonkChip.openings = proofWithPis.Proof.Openings
|
||||
|
||||
plonkChip.Verify()
|
||||
return nil
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package plonky2_verifier
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
. "gnark-ed25519/field"
|
||||
|
||||
"github.com/consensys/gnark/frontend"
|
||||
@@ -9,28 +10,24 @@ import (
|
||||
type QuadraticExtensionAPI struct {
|
||||
field frontend.API
|
||||
|
||||
W F
|
||||
DTH_ROOT F
|
||||
ZERO_F F
|
||||
DEGREE_BITS_F F
|
||||
W F
|
||||
DTH_ROOT F
|
||||
ZERO_F F
|
||||
|
||||
ONE QuadraticExtension
|
||||
DEGREE_BITS_QE QuadraticExtension
|
||||
ONE QuadraticExtension
|
||||
}
|
||||
|
||||
func NewQuadraticExtensionAPI(field frontend.API, degreeBits uint64) *QuadraticExtensionAPI {
|
||||
// TODO: Should degreeBits be verified that it fits within the field?
|
||||
// TODO: Should degreeBits be verified that it fits within the field and that degree is within uint64?
|
||||
|
||||
return &QuadraticExtensionAPI{
|
||||
field: field,
|
||||
|
||||
W: NewFieldElement(7),
|
||||
DTH_ROOT: NewFieldElement(18446744069414584320),
|
||||
ZERO_F: NewFieldElement(0),
|
||||
DEGREE_BITS_F: NewFieldElement(degreeBits),
|
||||
W: NewFieldElement(7),
|
||||
DTH_ROOT: NewFieldElement(18446744069414584320),
|
||||
ZERO_F: NewFieldElement(0),
|
||||
|
||||
ONE: QuadraticExtension{NewFieldElement(1), NewFieldElement(0)},
|
||||
DEGREE_BITS_QE: QuadraticExtension{NewFieldElement(degreeBits), NewFieldElement(0)},
|
||||
ONE: QuadraticExtension{NewFieldElement(1), NewFieldElement(0)},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,3 +79,11 @@ func (c *QuadraticExtensionAPI) ScalarMulExtension(a QuadraticExtension, scalar
|
||||
func (c *QuadraticExtensionAPI) FieldToQE(a F) QuadraticExtension {
|
||||
return QuadraticExtension{a, c.ZERO_F}
|
||||
}
|
||||
|
||||
func (c *QuadraticExtensionAPI) Println(a QuadraticExtension) {
|
||||
fmt.Print("Degree 0 coefficient")
|
||||
c.field.Println(a[0])
|
||||
|
||||
fmt.Print("Degree 1 coefficient")
|
||||
c.field.Println(a[1])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user