11import Mathlib
22import CompPoly.Multivariate.CMvPolynomialEvalLemmas
33import CompPoly.Multivariate.Rename
4- -- import Mathlib.Algebra.BigOperators.Basic
5- -- import Mathlib.Data.List.BigOperators.Basic
64
75
86open scoped BigOperators
@@ -13,30 +11,31 @@ open CPoly
1311open CPoly.CMvPolynomial
1412
1513
16- -- TODO before all this, finalize the terminology for the various levels of instantiation.
17- -- TODO make a structure that doesn't track components/linear extractor
18- -- then make another structure that returns AGMProofSystemv2
19- -- TODO if dependent is not needed dont use the syntax
20-
21-
2214/--
23- An `AGMProofSystemInstantiationType1` is a SNARK for a particular arithmetic circuit over a
24- particular field
15+ An `AGMProofSystemInstantiationTypeI` is a SNARK for a particular arithmetic circuit over a
16+ particular field, in the Type I (symmetric pairing) setting.
17+
18+ In a symmetric pairing there is a single source group, so unlike
19+ `AGMProofSystemInstantiation` (the Type III model) there is only one collection of SRS
20+ elements and one copy of each proof element. Every SRS element and every proof element can be
21+ used on either side of any pairing; consequently there is no need for the
22+ `Identified_Proof_Elems` field of the Type III model, which existed to identify the G1 and G2
23+ copies of a proof element.
2524-/
26- structure AGMProofSystemInstantiationType1 (F : Type ) [Field F] where
25+ structure AGMProofSystemInstantiationTypeI (F : Type ) [Field F] where
2726 /-- The type of statements -/
2827 Stmt : Type
2928 /-- The type indexing toxic waste elements sampled.
3029 A `FinEnum` instance gives an equivalence `Sample β Fin n`, which is what the computable
3130 multivariate polynomials (`CMvPolynomial n F`) require. -/
3231 Sample : Type
3332 [Sample_FinEnum : FinEnum Sample]
34- /-- The type indexing SRS elements -/
33+ /-- The type indexing SRS elements (all in the single source group) -/
3534 SRSElements : Type
3635 [SRSElements_FinEnum : FinEnum SRSElements]
3736 /-- The SRS elements themselves, described as polynomials in the samples -/
3837 SRSElementValue : SRSElements β CMvPolynomial Sample F
39- /-- A type indexing proof elements in each group -/
38+ /-- A type indexing proof elements -/
4039 Proof : Type
4140 [Proof_FinEnum : FinEnum Proof]
4241 /-- The type indexing equations the verifier checks -/
@@ -46,87 +45,85 @@ structure AGMProofSystemInstantiationType1 (F : Type) [Field F] where
4645 Pairings : EqualityChecks β Type
4746 [Pairings_FinEnum : (k : EqualityChecks) β FinEnum (Pairings k)]
4847
49- /-- The coefficient that the verifier uses for the jth element of the ith component of the SRSI
50- in the left half of the lth paring of the kth equality check -/
51- verificationPairingSRS_G1 : Stmt -> (k : EqualityChecks) β Pairings k β SRSElements β F
52- /-- The coefficient that the verifier uses for the jth element of the ith component of the SRSII
53- in the right half of the lth paring of the kth equality check -/
54- verificationPairingSRS_G2 : Stmt -> (k : EqualityChecks) β Pairings k β SRSElements β F
55- /-- The coefficient that the verifier uses for the jth element of the ith component of the Proof
56- in the left half of the lth paring of the kth equality check -/
57- verificationPairingProof_G1 : Stmt -> (k : EqualityChecks) β Pairings k β Proof β F
58- /-- The coefficient that the verifier uses for the jth element of the ith component of the Proof
59- in the right half of the lth paring of the kth equality check -/
60- verificationPairingProof_G2 : Stmt -> (k : EqualityChecks) β Pairings k β Proof β F
61-
62- /-- Pairs of proof elements that are constrained to be equal -/
63- Identified_Proof_Elems : List (Proof Γ Proof) := []
48+ /-- The coefficient that the verifier uses for the jth SRS element
49+ in the left half of the lth pairing of the kth equality check -/
50+ verificationPairingSRSLeft : Stmt -> (k : EqualityChecks) β Pairings k β SRSElements β F
51+ /-- The coefficient that the verifier uses for the jth SRS element
52+ in the right half of the lth pairing of the kth equality check -/
53+ verificationPairingSRSRight : Stmt -> (k : EqualityChecks) β Pairings k β SRSElements β F
54+ /-- The coefficient that the verifier uses for the jth proof element
55+ in the left half of the lth pairing of the kth equality check -/
56+ verificationPairingProofLeft : Stmt -> (k : EqualityChecks) β Pairings k β Proof β F
57+ /-- The coefficient that the verifier uses for the jth proof element
58+ in the right half of the lth pairing of the kth equality check -/
59+ verificationPairingProofRight : Stmt -> (k : EqualityChecks) β Pairings k β Proof β F
6460
6561-- Register the bundled `FinEnum` fields as instances so that `FinEnum.toList`, the derived
6662-- `Fintype`, and the `β Fin n` equivalences are available from a bare `π`.
6763attribute [instance]
68- AGMProofSystemInstantiationType1 .Sample_FinEnum
69- AGMProofSystemInstantiationType1 .SRSElements_FinEnum
70- AGMProofSystemInstantiationType1 .Proof_FinEnum
71- AGMProofSystemInstantiationType1 .Pairings_FinEnum
64+ AGMProofSystemInstantiationTypeI .Sample_FinEnum
65+ AGMProofSystemInstantiationTypeI .SRSElements_FinEnum
66+ AGMProofSystemInstantiationTypeI .Proof_FinEnum
67+ AGMProofSystemInstantiationTypeI .Pairings_FinEnum
7268
73- namespace AGMProofSystemInstantiationType1
69+ namespace AGMProofSystemInstantiationTypeI
7470
7571/-- The type of possible provers in the AGM model.
76- A prover simply assigns, for each proof element and each SRS element from the group of that proof element, a coefficient. -/
72+ A prover simply assigns, for each proof element and each SRS element, a coefficient.
73+ Since there is a single group, there is a single coefficient function. -/
7774def Prover (F : Type ) [Field F]
78- (π : AGMProofSystemInstantiationType1 F) : Type :=
79- ( π.Proof -> π.SRSElements -> F) Γ (π.Proof -> π.SRSElements -> F)
75+ (π : AGMProofSystemInstantiationTypeI F) : Type :=
76+ π.Proof -> π.SRSElements -> F
8077
81- noncomputable def proof_element_as_poly {F : Type } [Field F] [BEq F] [LawfulBEq F]
82- (π : AGMProofSystemInstantiationType1 F) (prover : π.Prover) (pf_elem : π.Proof) :
78+ def proof_element_as_poly {F : Type } [Field F] [BEq F] [LawfulBEq F]
79+ (π : AGMProofSystemInstantiationTypeI F) (prover : π.Prover) (pf_elem : π.Proof) :
8380 CMvPolynomial (π.Sample) F :=
8481 ((FinEnum.toList π.SRSElements).map fun SRS_elem =>
85- CMvPolynomial.C (prover.fst pf_elem SRS_elem) * (π.SRSElementValue SRS_elem)).sum
82+ CMvPolynomial.C (prover pf_elem SRS_elem) * (π.SRSElementValue SRS_elem)).sum
8683
8784/-- The pairing evaluation, represented as a CMvPolynomial in the samples -/
88- noncomputable def pairing_poly {F : Type } [Field F] [BEq F] [LawfulBEq F]
89- (π : AGMProofSystemInstantiationType1 F) (prover : π.Prover) (stmt : π.Stmt) (check_idx : π.EqualityChecks) (pairing : π.Pairings check_idx) :
85+ def pairing_poly {F : Type } [Field F] [BEq F] [LawfulBEq F]
86+ (π : AGMProofSystemInstantiationTypeI F) (prover : π.Prover) (stmt : π.Stmt) (check_idx : π.EqualityChecks) (pairing : π.Pairings check_idx) :
9087 CMvPolynomial π.Sample F :=
9188 (
92- ( -- G1 input of pairing
89+ ( -- Left input of pairing
9390 -- Proof component
9491 (
9592 ((FinEnum.toList π.Proof).map fun pf_elem => -- Sum over all left proof components
96- C (π.verificationPairingProof_G1 stmt check_idx pairing pf_elem) -- Coefficient of that element
93+ C (π.verificationPairingProofLeft stmt check_idx pairing pf_elem) -- Coefficient of that element
9794 *
9895 -- Times the proof component itself
9996 π.proof_element_as_poly prover pf_elem).sum
10097 )
10198 +
10299 ( -- SRS component
103100 ((FinEnum.toList π.SRSElements).map fun SRS_elem =>
104- C (π.verificationPairingSRS_G1 stmt check_idx pairing SRS_elem) * (π.SRSElementValue SRS_elem)).sum
101+ C (π.verificationPairingSRSLeft stmt check_idx pairing SRS_elem) * (π.SRSElementValue SRS_elem)).sum
105102 )
106103 )
107104 *
108- ( -- G2 input of pairing
105+ ( -- Right input of pairing
109106 -- Proof component
110107 (
111- ((FinEnum.toList π.Proof).map fun pf_elem => -- Sum over all Right proof components
112- C (π.verificationPairingProof_G2 stmt check_idx pairing pf_elem) -- Coefficient of that element
108+ ((FinEnum.toList π.Proof).map fun pf_elem => -- Sum over all right proof components
109+ C (π.verificationPairingProofRight stmt check_idx pairing pf_elem) -- Coefficient of that element
113110 *
114111 -- Times the proof component itself
115112 π.proof_element_as_poly prover pf_elem).sum
116113 )
117114 +
118115 ( -- SRS component
119116 ((FinEnum.toList π.SRSElements).map fun SRS_elem =>
120- C (π.verificationPairingSRS_G2 stmt check_idx pairing SRS_elem) * (π.SRSElementValue SRS_elem)).sum
117+ C (π.verificationPairingSRSRight stmt check_idx pairing SRS_elem) * (π.SRSElementValue SRS_elem)).sum
121118 )
122119 )
123120 )
124121
125122/-- The value that the verifier checks to be equal to 0 for a given equality check, as a
126123CMvPolynomial in the samples.
127124-/
128- noncomputable def check_poly {F : Type } [Field F] [BEq F] [LawfulBEq F]
129- (π : AGMProofSystemInstantiationType1 F) (prover : π.Prover) (stmt : π.Stmt) (check_idx : π.EqualityChecks) :
125+ def check_poly {F : Type } [Field F] [BEq F] [LawfulBEq F]
126+ (π : AGMProofSystemInstantiationTypeI F) (prover : π.Prover) (stmt : π.Stmt) (check_idx : π.EqualityChecks) :
130127 CMvPolynomial π.Sample F :=
131128 (
132129 (FinEnum.toList (π.Pairings check_idx)).map fun pairing =>
@@ -135,17 +132,12 @@ noncomputable def check_poly {F : Type} [Field F] [BEq F] [LawfulBEq F]
135132
136133
137134def verify {F : Type } [Field F] [BEq F] [LawfulBEq F]
138- (π : AGMProofSystemInstantiationType1 F) (prover : π.Prover) (stmt : π.Stmt) : Prop :=
139- (
140- β check_idx : π.EqualityChecks, π.check_poly prover stmt check_idx = 0
141- )
142- β§
143- β pfs β π.Identified_Proof_Elems,
144- π.proof_element_as_poly prover pfs.fst = π.proof_element_as_poly prover pfs.snd
135+ (π : AGMProofSystemInstantiationTypeI F) (prover : π.Prover) (stmt : π.Stmt) : Prop :=
136+ β check_idx : π.EqualityChecks, π.check_poly prover stmt check_idx = 0
145137
146138
147139def soundness (F : Type ) [Field F] [BEq F] [LawfulBEq F]
148- (π : AGMProofSystemInstantiationType1 F)
140+ (π : AGMProofSystemInstantiationTypeI F)
149141 (Wit : Type ) (relation : π.Stmt -> Wit -> Prop )
150142 (extractor : π.Prover -> Wit) : Prop :=
151143 β stmt : π.Stmt,
@@ -154,13 +146,13 @@ def soundness (F : Type) [Field F] [BEq F] [LawfulBEq F]
154146
155147
156148def completeness (F : Type ) [Field F] [BEq F] [LawfulBEq F]
157- (π : AGMProofSystemInstantiationType1 F) (Wit : Type )
149+ (π : AGMProofSystemInstantiationTypeI F) (Wit : Type )
158150 (relation : π.Stmt -> Wit -> Prop )
159151 (prover : π.Stmt -> Wit -> π.Prover) : Prop :=
160152 β stmt : π.Stmt,
161153 β wit : Wit,
162154 relation stmt wit -> π.verify (prover stmt wit) stmt
163155
164- end AGMProofSystemInstantiationType1
156+ end AGMProofSystemInstantiationTypeI
165157
166158end
0 commit comments