Skip to content

Commit 382139f

Browse files
committed
Redefine typeI Groth16 in terms of TypeI instantiation
1 parent b5395ca commit 382139f

3 files changed

Lines changed: 358 additions & 264 deletions

File tree

Lines changed: 52 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Mathlib
22
import CompPoly.Multivariate.CMvPolynomialEvalLemmas
33
import CompPoly.Multivariate.Rename
4-
-- import Mathlib.Algebra.BigOperators.Basic
5-
-- import Mathlib.Data.List.BigOperators.Basic
64

75

86
open scoped BigOperators
@@ -13,30 +11,31 @@ open CPoly
1311
open 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 `π“Ÿ`.
6763
attribute [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. -/
7774
def 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
126123
CMvPolynomial 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

137134
def 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

147139
def 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

156148
def 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

166158
end

0 commit comments

Comments
Β (0)