2 *****************************************************************************
4 Implementation of interfaces for pairing-check gadgets.
6 See pairing_checks.hpp .
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 *****************************************************************************/
14 #ifndef PAIRING_CHECKS_TCC_
15 #define PAIRING_CHECKS_TCC_
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)
36 ratio.reset(new Fqk_variable<ppT>(pb, FMT(annotation_prefix, " ratio")));
37 compute_ratio.reset(new e_over_e_miller_loop_gadget<ppT>(
44 FMT(annotation_prefix, " compute_ratio")));
45 check_finexp.reset(new final_exp_gadget<ppT>(
46 pb, *ratio, result, FMT(annotation_prefix, " check_finexp")));
49 template<typename ppT>
50 void check_e_equals_e_gadget<ppT>::generate_r1cs_constraints()
52 compute_ratio->generate_r1cs_constraints();
53 check_finexp->generate_r1cs_constraints();
56 template<typename ppT>
57 void check_e_equals_e_gadget<ppT>::generate_r1cs_witness()
59 compute_ratio->generate_r1cs_witness();
60 check_finexp->generate_r1cs_witness();
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)
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>(
93 FMT(annotation_prefix, " compute_ratio")));
94 check_finexp.reset(new final_exp_gadget<ppT>(
95 pb, *ratio, result, FMT(annotation_prefix, " check_finexp")));
98 template<typename ppT>
99 void check_e_equals_ee_gadget<ppT>::generate_r1cs_constraints()
101 compute_ratio->generate_r1cs_constraints();
102 check_finexp->generate_r1cs_constraints();
105 template<typename ppT>
106 void check_e_equals_ee_gadget<ppT>::generate_r1cs_witness()
108 compute_ratio->generate_r1cs_witness();
109 check_finexp->generate_r1cs_witness();
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)
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>(
148 FMT(annotation_prefix, " compute_ratio")));
149 check_finexp.reset(new final_exp_gadget<ppT>(
150 pb, *ratio, result, FMT(annotation_prefix, " check_finexp")));
153 template<typename ppT>
154 void check_e_equals_eee_gadget<ppT>::generate_r1cs_constraints()
156 compute_ratio->generate_r1cs_constraints();
157 check_finexp->generate_r1cs_constraints();
160 template<typename ppT>
161 void check_e_equals_eee_gadget<ppT>::generate_r1cs_witness()
163 compute_ratio->generate_r1cs_witness();
164 check_finexp->generate_r1cs_witness();
167 } // namespace libsnark
169 #endif // PAIRING_CHECKS_TCC_