63 lines
2.0 KiB
Go
Raw Normal View History

2022-10-10 16:41:42 -07:00
package plonky2_verifier
2022-10-10 20:45:34 -07:00
import (
2022-10-10 21:23:30 -07:00
"fmt"
2022-10-10 20:45:34 -07:00
. "gnark-ed25519/field"
"gnark-ed25519/poseidon"
2022-10-10 21:23:30 -07:00
"gnark-ed25519/utils"
2022-10-10 20:45:34 -07:00
"github.com/consensys/gnark/frontend"
)
type VerifierChip struct {
api frontend.API
field frontend.API
poseidonChip poseidon.PoseidonChip
}
func (c *VerifierChip) GetPublicInputsHash(publicInputs []F) Hash {
return c.poseidonChip.HashNoPad(publicInputs)
}
2022-10-10 21:23:30 -07:00
func (c *VerifierChip) GetChallenges(proofWithPis ProofWithPublicInputs, publicInputsHash Hash, commonData CommonCircuitDataRaw) ProofChallenges {
2022-10-10 20:45:34 -07:00
config := commonData.Config
numChallenges := config.NumChallenges
challenger := NewChallengerChip(c.api, c.field, c.poseidonChip)
2022-10-10 21:23:30 -07:00
var circuitDigest Hash
copy(circuitDigest[:], utils.Uint64ArrayToFArray(commonData.CircuitDigest.Elements))
challenger.ObserveHash(circuitDigest)
2022-10-10 20:45:34 -07:00
challenger.ObserveHash(publicInputsHash)
challenger.ObserveCap(proofWithPis.Proof.WiresCap)
plonkBetas := challenger.GetNChallenges(numChallenges)
plonkGammas := challenger.GetNChallenges(numChallenges)
challenger.ObserveCap(proofWithPis.Proof.PlonkZsPartialProductsCap)
plonkAlphas := challenger.GetNChallenges(numChallenges)
challenger.ObserveCap(proofWithPis.Proof.QuotientPolysCap)
plonkZeta := challenger.GetExtensionChallenge()
challenger.ObserveOpenings(proofWithPis.Proof.Openings.ToFriOpenings())
return ProofChallenges{
PlonkBetas: plonkBetas,
PlonkGammas: plonkGammas,
PlonkAlphas: plonkAlphas,
PlonkZeta: plonkZeta,
FriChallenges: challenger.GetFriChallenges(
proofWithPis.Proof.OpeningProof.CommitPhaseMerkleCaps,
proofWithPis.Proof.OpeningProof.FinalPoly,
proofWithPis.Proof.OpeningProof.PowWitness,
2022-10-10 21:23:30 -07:00
commonData.DegreeBits,
config.FriConfig,
2022-10-10 20:45:34 -07:00
),
}
}
2022-10-10 21:23:30 -07:00
func (c *VerifierChip) Verify(proofWithPis ProofWithPublicInputs, verifierData VerifierOnlyCircuitData, commonData CommonCircuitDataRaw) {
2022-10-10 20:45:34 -07:00
publicInputsHash := c.GetPublicInputsHash(proofWithPis.PublicInputs)
2022-10-10 21:23:30 -07:00
proofChallenges := c.GetChallenges(proofWithPis, publicInputsHash, commonData)
fmt.Printf("%+v\n", proofChallenges)
2022-10-10 20:45:34 -07:00
}