Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
pairing_checks.tcc
Go to the documentation of this file.
1 /** @file
2  *****************************************************************************
3 
4  Implementation of interfaces for pairing-check gadgets.
5 
6  See pairing_checks.hpp .
7 
8  *****************************************************************************
9  * @author This file is part of libsnark, developed by SCIPR Lab
10  * and contributors (see AUTHORS).
11  * @copyright MIT license (see LICENSE file)
12  *****************************************************************************/
13 
14 #ifndef PAIRING_CHECKS_TCC_
15 #define PAIRING_CHECKS_TCC_
16 
17 namespace libsnark
18 {
19 
20 template<typename ppT>
21 check_e_equals_e_gadget<ppT>::check_e_equals_e_gadget(
22  protoboard<FieldT> &pb,
23  const G1_precomputation<ppT> &lhs_G1,
24  const G2_precomputation<ppT> &lhs_G2,
25  const G1_precomputation<ppT> &rhs_G1,
26  const G2_precomputation<ppT> &rhs_G2,
27  const pb_variable<FieldT> &result,
28  const std::string &annotation_prefix)
29  : gadget<FieldT>(pb, annotation_prefix)
30  , lhs_G1(lhs_G1)
31  , lhs_G2(lhs_G2)
32  , rhs_G1(rhs_G1)
33  , rhs_G2(rhs_G2)
34  , result(result)
35 {
36  ratio.reset(new Fqk_variable<ppT>(pb, FMT(annotation_prefix, " ratio")));
37  compute_ratio.reset(new e_over_e_miller_loop_gadget<ppT>(
38  pb,
39  lhs_G1,
40  lhs_G2,
41  rhs_G1,
42  rhs_G2,
43  *ratio,
44  FMT(annotation_prefix, " compute_ratio")));
45  check_finexp.reset(new final_exp_gadget<ppT>(
46  pb, *ratio, result, FMT(annotation_prefix, " check_finexp")));
47 }
48 
49 template<typename ppT>
50 void check_e_equals_e_gadget<ppT>::generate_r1cs_constraints()
51 {
52  compute_ratio->generate_r1cs_constraints();
53  check_finexp->generate_r1cs_constraints();
54 }
55 
56 template<typename ppT>
57 void check_e_equals_e_gadget<ppT>::generate_r1cs_witness()
58 {
59  compute_ratio->generate_r1cs_witness();
60  check_finexp->generate_r1cs_witness();
61 }
62 
63 template<typename ppT>
64 check_e_equals_ee_gadget<ppT>::check_e_equals_ee_gadget(
65  protoboard<FieldT> &pb,
66  const G1_precomputation<ppT> &lhs_G1,
67  const G2_precomputation<ppT> &lhs_G2,
68  const G1_precomputation<ppT> &rhs1_G1,
69  const G2_precomputation<ppT> &rhs1_G2,
70  const G1_precomputation<ppT> &rhs2_G1,
71  const G2_precomputation<ppT> &rhs2_G2,
72  const pb_variable<FieldT> &result,
73  const std::string &annotation_prefix)
74  : gadget<FieldT>(pb, annotation_prefix)
75  , lhs_G1(lhs_G1)
76  , lhs_G2(lhs_G2)
77  , rhs1_G1(rhs1_G1)
78  , rhs1_G2(rhs1_G2)
79  , rhs2_G1(rhs2_G1)
80  , rhs2_G2(rhs2_G2)
81  , result(result)
82 {
83  ratio.reset(new Fqk_variable<ppT>(pb, FMT(annotation_prefix, " ratio")));
84  compute_ratio.reset(new e_times_e_over_e_miller_loop_gadget<ppT>(
85  pb,
86  rhs1_G1,
87  rhs1_G2,
88  rhs2_G1,
89  rhs2_G2,
90  lhs_G1,
91  lhs_G2,
92  *ratio,
93  FMT(annotation_prefix, " compute_ratio")));
94  check_finexp.reset(new final_exp_gadget<ppT>(
95  pb, *ratio, result, FMT(annotation_prefix, " check_finexp")));
96 }
97 
98 template<typename ppT>
99 void check_e_equals_ee_gadget<ppT>::generate_r1cs_constraints()
100 {
101  compute_ratio->generate_r1cs_constraints();
102  check_finexp->generate_r1cs_constraints();
103 }
104 
105 template<typename ppT>
106 void check_e_equals_ee_gadget<ppT>::generate_r1cs_witness()
107 {
108  compute_ratio->generate_r1cs_witness();
109  check_finexp->generate_r1cs_witness();
110 }
111 
112 template<typename ppT>
113 check_e_equals_eee_gadget<ppT>::check_e_equals_eee_gadget(
114  protoboard<FieldT> &pb,
115  const G1_precomputation<ppT> &lhs_G1,
116  const G2_precomputation<ppT> &lhs_G2,
117  const G1_precomputation<ppT> &rhs1_G1,
118  const G2_precomputation<ppT> &rhs1_G2,
119  const G1_precomputation<ppT> &rhs2_G1,
120  const G2_precomputation<ppT> &rhs2_G2,
121  const G1_precomputation<ppT> &rhs3_G1,
122  const G2_precomputation<ppT> &rhs3_G2,
123  const pb_variable<FieldT> &result,
124  const std::string &annotation_prefix)
125  : gadget<FieldT>(pb, annotation_prefix)
126  , lhs_G1(lhs_G1)
127  , lhs_G2(lhs_G2)
128  , rhs1_G1(rhs1_G1)
129  , rhs1_G2(rhs1_G2)
130  , rhs2_G1(rhs2_G1)
131  , rhs2_G2(rhs2_G2)
132  , rhs3_G1(rhs3_G1)
133  , rhs3_G2(rhs3_G2)
134  , result(result)
135 {
136  ratio.reset(new Fqk_variable<ppT>(pb, FMT(annotation_prefix, " ratio")));
137  compute_ratio.reset(new e_times_e_times_e_over_e_miller_loop_gadget<ppT>(
138  pb,
139  rhs1_G1,
140  rhs1_G2,
141  rhs2_G1,
142  rhs2_G2,
143  rhs3_G1,
144  rhs3_G2,
145  lhs_G1,
146  lhs_G2,
147  *ratio,
148  FMT(annotation_prefix, " compute_ratio")));
149  check_finexp.reset(new final_exp_gadget<ppT>(
150  pb, *ratio, result, FMT(annotation_prefix, " check_finexp")));
151 }
152 
153 template<typename ppT>
154 void check_e_equals_eee_gadget<ppT>::generate_r1cs_constraints()
155 {
156  compute_ratio->generate_r1cs_constraints();
157  check_finexp->generate_r1cs_constraints();
158 }
159 
160 template<typename ppT>
161 void check_e_equals_eee_gadget<ppT>::generate_r1cs_witness()
162 {
163  compute_ratio->generate_r1cs_witness();
164  check_finexp->generate_r1cs_witness();
165 }
166 
167 } // namespace libsnark
168 
169 #endif // PAIRING_CHECKS_TCC_