arnaucube
arnaucube/gnark-plonky2-verifierPublic Self-hosted repository
gnark-plonky2-verifier/plonky2_verifier/verifier.go
plonky2_verifier/verifier.goRaw
 1package plonky2_verifier
 2
 3import (
 4	. "gnark-ed25519/goldilocks"
 5	"gnark-ed25519/poseidon"
 6	"gnark-ed25519/utils"
 7
 8	"github.com/consensys/gnark/frontend"
 9)
10
11type VerifierChip struct {
12	api          frontend.API
13	field        frontend.API
14	poseidonChip poseidon.PoseidonChip
15}
16
17func (c *VerifierChip) GetPublicInputsHash(publicInputs []GoldilocksElement) poseidon.HashOutput {
18	return c.poseidonChip.HashNoPad(publicInputs)
19}
20
21func (c *VerifierChip) GetChallenges(proofWithPis ProofWithPublicInputs, publicInputsHash Hash, commonData CommonCircuitData) {
22	config := commonData.Config
23	numChallenges := int(config.NumChallenges)
24	challenger := NewChallengerChip(c.api, c.field, c.poseidonChip)
25
26	var circuitDigest Hash
27	copy(circuitDigest[:], utils.Uint64ArrayToGoldilocksElementArray(commonData.CircuitDigest.Elements))
28
29	challenger.ObserveHash(circuitDigest)
30	challenger.ObserveHash(publicInputsHash)
31	challenger.ObserveCap(proofWithPis.Proof.WiresCap)
32	plonkBetas := challenger.GetNChallenges(numChallenges)
33	plonkGammas := challenger.GetNChallenges(numChallenges)
34
35	challenger.ObserveCap(proofWithPis.Proof.PlonkZsPartialProductsCap)
36	plonkAlphas := challenger.GetNChallenges(numChallenges)
37
38	challenger.ObserveCap(proofWithPis.Proof.QuotientPolysCap)
39	plonkZeta := challenger.GetNChallenges(numChallenges)
40
41	challenger.ObserveOpenings(proofWithPis.Proof.Openings)
42}
43
44func (c *VerifierChip) Verify(proofWithPis ProofWithPublicInputs, verifierData VerifierOnlyCircuitData, commonData CommonCircuitData) {
45	publicInputsHash := c.GetPublicInputsHash(proofWithPis.PublicInputs)
46	challenges := c.GetChallenges(proofWithPis, publicInputsHash, commonData)
47}