gnark-plonky2-verifier/types/deserialize.go
types/deserialize.goRaw
1package types
2
3import (
4 "encoding/json"
5 "io"
6 "os"
7)
8
9type ProofWithPublicInputsRaw struct {
10 Proof struct {
11 WiresCap []string `json:"wires_cap"`
12 PlonkZsPartialProductsCap []string `json:"plonk_zs_partial_products_cap"`
13 QuotientPolysCap []string `json:"quotient_polys_cap"`
14 Openings struct {
15 Constants [][]uint64 `json:"constants"`
16 PlonkSigmas [][]uint64 `json:"plonk_sigmas"`
17 Wires [][]uint64 `json:"wires"`
18 PlonkZs [][]uint64 `json:"plonk_zs"`
19 PlonkZsNext [][]uint64 `json:"plonk_zs_next"`
20 PartialProducts [][]uint64 `json:"partial_products"`
21 QuotientPolys [][]uint64 `json:"quotient_polys"`
22 } `json:"openings"`
23 OpeningProof struct {
24 CommitPhaseMerkleCaps [][]string `json:"commit_phase_merkle_caps"`
25 QueryRoundProofs []struct {
26 InitialTreesProof struct {
27 EvalsProofs []EvalProofRaw `json:"evals_proofs"`
28 } `json:"initial_trees_proof"`
29 Steps []struct {
30 Evals [][]uint64 `json:"evals"`
31 MerkleProof struct {
32 Siblings []string `json:"siblings"`
33 } `json:"merkle_proof"`
34 } `json:"steps"`
35 } `json:"query_round_proofs"`
36 FinalPoly struct {
37 Coeffs [][]uint64 `json:"coeffs"`
38 } `json:"final_poly"`
39 PowWitness uint64 `json:"pow_witness"`
40 } `json:"opening_proof"`
41 } `json:"proof"`
42 PublicInputs []uint64 `json:"public_inputs"`
43}
44
45type EvalProofRaw struct {
46 LeafElements []uint64
47 MerkleProof MerkleProofRaw
48}
49
50func (e *EvalProofRaw) UnmarshalJSON(data []byte) error {
51 return json.Unmarshal(data, &[]interface{}{&e.LeafElements, &e.MerkleProof})
52}
53
54type MerkleProofRaw struct {
55 Hash []string
56}
57
58func (m *MerkleProofRaw) UnmarshalJSON(data []byte) error {
59 type SiblingObject struct {
60 Siblings []string // "siblings"
61 }
62
63 var siblings SiblingObject
64 if err := json.Unmarshal(data, &siblings); err != nil {
65 panic(err)
66 }
67
68 m.Hash = make([]string, len(siblings.Siblings))
69 copy(m.Hash[:], siblings.Siblings)
70
71 return nil
72}
73
74type ProofChallengesRaw struct {
75 PlonkBetas []uint64 `json:"plonk_betas"`
76 PlonkGammas []uint64 `json:"plonk_gammas"`
77 PlonkAlphas []uint64 `json:"plonk_alphas"`
78 PlonkZeta []uint64 `json:"plonk_zeta"`
79 FriChallenges struct {
80 FriAlpha []uint64 `json:"fri_alpha"`
81 FriBetas [][]uint64 `json:"fri_betas"`
82 FriPowResponse uint64 `json:"fri_pow_response"`
83 FriQueryIndices []uint64 `json:"fri_query_indices"`
84 } `json:"fri_challenges"`
85}
86
87type VerifierOnlyCircuitDataRaw struct {
88 ConstantsSigmasCap []string `json:"constants_sigmas_cap"`
89 CircuitDigest string `json:"circuit_digest"`
90}
91
92func ReadProofWithPublicInputs(path string) ProofWithPublicInputsRaw {
93 jsonFile, err := os.Open(path)
94 if err != nil {
95 panic(err)
96 }
97
98 defer jsonFile.Close()
99 rawBytes, _ := io.ReadAll(jsonFile)
100
101 var raw ProofWithPublicInputsRaw
102 err = json.Unmarshal(rawBytes, &raw)
103 if err != nil {
104 panic(err)
105 }
106
107 return raw
108}
109
110func ReadVerifierOnlyCircuitData(path string) VerifierOnlyCircuitDataRaw {
111 jsonFile, err := os.Open(path)
112 if err != nil {
113 panic(err)
114 }
115
116 defer jsonFile.Close()
117 rawBytes, _ := io.ReadAll(jsonFile)
118
119 var raw VerifierOnlyCircuitDataRaw
120 err = json.Unmarshal(rawBytes, &raw)
121 if err != nil {
122 panic(err)
123 }
124
125 return raw
126}