pairing_checks.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-2021 Nikita Kaskov <nbering@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 // @file Declaration of interfaces for pairing-check components.
26 //
27 // Given that e(.,.) denotes a pairing,
28 // - the component "check_e_equals_e_component" checks the equation "e(P1,Q1)=e(P2,Q2)"; and
29 // - the component "check_e_equals_ee_component" checks the equation "e(P1,Q1)=e(P2,Q2)*e(P3,Q3)".
30 //---------------------------------------------------------------------------//
31 
32 #ifndef CRYPTO3_ZK_BLUEPRINT_PAIRING_CHECKS_HPP
33 #define CRYPTO3_ZK_BLUEPRINT_PAIRING_CHECKS_HPP
34 
35 #include <memory>
36 
39 
42 
43 namespace nil {
44  namespace crypto3 {
45  namespace zk {
46  namespace components {
47 
48  template<typename CurveType>
49  class check_e_equals_e_component : public component<typename CurveType::scalar_field_type> {
50 
52 
53  using Fqk_variable_type = typename component_policy::Fqk_variable_type;
54 
55  public:
56  typedef typename CurveType::scalar_field_type field_type;
57 
58  std::shared_ptr<Fqk_variable_type> ratio;
59  std::shared_ptr<mnt_e_over_e_miller_loop_component<CurveType>> compute_ratio;
60  std::shared_ptr<final_exp_component<CurveType>> check_finexp;
61 
66 
68 
77  ratio.reset(new Fqk_variable_type(bp));
81  }
82 
84  compute_ratio->generate_r1cs_constraints();
85  check_finexp->generate_r1cs_constraints();
86  }
87 
89  compute_ratio->generate_r1cs_witness();
90  check_finexp->generate_r1cs_witness();
91  }
92  };
93 
94  template<typename CurveType>
95  class check_e_equals_ee_component : public component<typename CurveType::scalar_field_type> {
96 
98 
99  using Fqk_variable_type = typename component_policy::Fqk_variable_type;
100 
101  public:
102  typedef typename CurveType::scalar_field_type field_type;
103 
104  std::shared_ptr<Fqk_variable_type> ratio;
105  std::shared_ptr<mnt_e_times_e_over_e_miller_loop_component<CurveType>> compute_ratio;
106  std::shared_ptr<final_exp_component<CurveType>> check_finexp;
107 
114 
116 
128  ratio.reset(new Fqk_variable_type(bp));
132  }
133 
135  compute_ratio->generate_r1cs_constraints();
136  check_finexp->generate_r1cs_constraints();
137  }
138 
140  compute_ratio->generate_r1cs_witness();
141  check_finexp->generate_r1cs_witness();
142  }
143  };
144  } // namespace components
145  } // namespace zk
146  } // namespace crypto3
147 } // namespace nil
148 
149 #endif // CRYPTO3_ZK_BLUEPRINT_PAIRING_CHECKS_HPP
Definition: blueprint.hpp:46
g2_precomputation< CurveType > lhs_G2
Definition: pairing_checks.hpp:63
blueprint_variable< field_type > result
Definition: pairing_checks.hpp:67
std::shared_ptr< final_exp_component< CurveType > > check_finexp
Definition: pairing_checks.hpp:60
g1_precomputation< CurveType > rhs_G1
Definition: pairing_checks.hpp:64
void generate_r1cs_witness()
Definition: pairing_checks.hpp:88
void generate_r1cs_constraints()
Definition: pairing_checks.hpp:83
std::shared_ptr< Fqk_variable_type > ratio
Definition: pairing_checks.hpp:58
g1_precomputation< CurveType > lhs_G1
Definition: pairing_checks.hpp:62
std::shared_ptr< mnt_e_over_e_miller_loop_component< CurveType > > compute_ratio
Definition: pairing_checks.hpp:59
CurveType::scalar_field_type field_type
Definition: pairing_checks.hpp:56
check_e_equals_e_component(blueprint< field_type > &bp, const g1_precomputation< CurveType > &lhs_G1, const g2_precomputation< CurveType > &lhs_G2, const g1_precomputation< CurveType > &rhs_G1, const g2_precomputation< CurveType > &rhs_G2, const blueprint_variable< field_type > &result)
Definition: pairing_checks.hpp:69
g2_precomputation< CurveType > rhs_G2
Definition: pairing_checks.hpp:65
g1_precomputation< CurveType > rhs2_G1
Definition: pairing_checks.hpp:112
g1_precomputation< CurveType > rhs1_G1
Definition: pairing_checks.hpp:110
std::shared_ptr< final_exp_component< CurveType > > check_finexp
Definition: pairing_checks.hpp:106
g2_precomputation< CurveType > lhs_G2
Definition: pairing_checks.hpp:109
g2_precomputation< CurveType > rhs2_G2
Definition: pairing_checks.hpp:113
g2_precomputation< CurveType > rhs1_G2
Definition: pairing_checks.hpp:111
blueprint_variable< field_type > result
Definition: pairing_checks.hpp:115
void generate_r1cs_constraints()
Definition: pairing_checks.hpp:134
CurveType::scalar_field_type field_type
Definition: pairing_checks.hpp:102
check_e_equals_ee_component(blueprint< field_type > &bp, const g1_precomputation< CurveType > &lhs_G1, const g2_precomputation< CurveType > &lhs_G2, const g1_precomputation< CurveType > &rhs1_G1, const g2_precomputation< CurveType > &rhs1_G2, const g1_precomputation< CurveType > &rhs2_G1, const g2_precomputation< CurveType > &rhs2_G2, const blueprint_variable< field_type > &result)
Definition: pairing_checks.hpp:117
std::shared_ptr< Fqk_variable_type > ratio
Definition: pairing_checks.hpp:104
g1_precomputation< CurveType > lhs_G1
Definition: pairing_checks.hpp:108
void generate_r1cs_witness()
Definition: pairing_checks.hpp:139
std::shared_ptr< mnt_e_times_e_over_e_miller_loop_component< CurveType > > compute_ratio
Definition: pairing_checks.hpp:105
Definition: component.hpp:37
blueprint< CurveType::scalar_field_type > & bp
Definition: component.hpp:39
Definition: blueprint/include/nil/crypto3/zk/components/algebra/pairing/detail/mnt4.hpp:46
Definition: precomputation.hpp:59
Definition: precomputation.hpp:189
Definition: pair.hpp:31
Definition: blueprint/include/nil/crypto3/zk/components/algebra/pairing/weierstrass/final_exponentiation.hpp:52