systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.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 
26 #ifndef CRYPTO3_R1CS_GG_PPZKSNARK_PROVING_KEY_HPP
27 #define CRYPTO3_R1CS_GG_PPZKSNARK_PROVING_KEY_HPP
28 
32 
33 namespace nil {
34  namespace crypto3 {
35  namespace zk {
36  namespace snark {
37  template<typename CurveType,
38  typename ConstraintSystem = r1cs_constraint_system<typename CurveType::scalar_field_type>>
40  typedef CurveType curve_type;
42 
43  typename CurveType::template g1_type<>::value_type alpha_g1;
44  typename CurveType::template g1_type<>::value_type beta_g1;
45  typename CurveType::template g2_type<>::value_type beta_g2;
46  typename CurveType::template g1_type<>::value_type delta_g1;
47  typename CurveType::template g2_type<>::value_type delta_g2;
48 
49  std::vector<typename CurveType::template g1_type<>::value_type>
50  A_query; // this could be a sparse vector if we had multiexp for those
52  typename CurveType::template g1_type<>>
54  std::vector<typename CurveType::template g1_type<>::value_type> H_query;
55  std::vector<typename CurveType::template g1_type<>::value_type> L_query;
56 
58 
63 
65  const typename CurveType::template g1_type<>::value_type &alpha_g1,
66  const typename CurveType::template g1_type<>::value_type &beta_g1,
67  const typename CurveType::template g2_type<>::value_type &beta_g2,
68  const typename CurveType::template g1_type<>::value_type &delta_g1,
69  const typename CurveType::template g2_type<>::value_type &delta_g2,
70  const std::vector<typename CurveType::template g1_type<>::value_type> &A_query,
71  const knowledge_commitment_vector<typename CurveType::template g2_type<>,
72  typename CurveType::template g1_type<>> &B_query,
73  const std::vector<typename CurveType::template g1_type<>::value_type> &H_query,
74  const std::vector<typename CurveType::template g1_type<>::value_type> &L_query,
79 
81  typename CurveType::template g1_type<>::value_type &&alpha_g1,
82  typename CurveType::template g1_type<>::value_type &&beta_g1,
83  typename CurveType::template g2_type<>::value_type &&beta_g2,
84  typename CurveType::template g1_type<>::value_type &&delta_g1,
85  typename CurveType::template g2_type<>::value_type &&delta_g2,
86  std::vector<typename CurveType::template g1_type<>::value_type> &&A_query,
87  knowledge_commitment_vector<typename CurveType::template g2_type<>,
88  typename CurveType::template g1_type<>> &&B_query,
89  std::vector<typename CurveType::template g1_type<>::value_type> &&H_query,
90  std::vector<typename CurveType::template g1_type<>::value_type> &&L_query,
92  alpha_g1(std::move(alpha_g1)),
93  beta_g1(std::move(beta_g1)), beta_g2(std::move(beta_g2)), delta_g1(std::move(delta_g1)),
94  delta_g2(std::move(delta_g2)), A_query(std::move(A_query)), B_query(std::move(B_query)),
95  H_query(std::move(H_query)), L_query(std::move(L_query)),
97 
98  std::size_t G1_size() const {
99  return 1 + A_query.size() + B_query.domain_size() + H_query.size() + L_query.size();
100  }
101 
102  std::size_t G2_size() const {
103  return 1 + B_query.domain_size();
104  }
105 
106  std::size_t G1_sparse_size() const {
107  return 1 + A_query.size() + B_query.size() + H_query.size() + L_query.size();
108  }
109 
110  std::size_t G2_sparse_size() const {
111  return 1 + B_query.size();
112  }
113 
114  std::size_t size_in_bits() const {
115  using g1_type = typename CurveType::template g1_type<>;
116  using g2_type = typename CurveType::template g2_type<>;
117 
118  return A_query.size() * g1_type::value_bits + B_query.size_in_bits() +
119  H_query.size() * g1_type::value_bits + L_query.size() * g1_type::value_bits +
120  1 * g1_type::value_bits + 1 * g2_type::value_bits;
121  }
122 
123  bool operator==(const r1cs_gg_ppzksnark_proving_key &other) const {
124  return (this->alpha_g1 == other.alpha_g1 && this->beta_g1 == other.beta_g1 &&
125  this->beta_g2 == other.beta_g2 && this->delta_g1 == other.delta_g1 &&
126  this->delta_g2 == other.delta_g2 && this->A_query == other.A_query &&
127  this->B_query == other.B_query && this->H_query == other.H_query &&
128  this->L_query == other.L_query && this->constraint_system == other.constraint_system);
129  }
130  };
131  } // namespace snark
132  } // namespace zk
133  } // namespace crypto3
134 } // namespace nil
135 
136 #endif // CRYPTO3_R1CS_GG_PPZKSNARK_TYPES_POLICY_HPP
vector(T, U...) -> vector< std::enable_if_t<(std::is_same_v< T, U > &&...), T >, 1+sizeof...(U)>
deduction guide for uniform initialization
OutputIterator move(const SinglePassRange &rng, OutputIterator result)
Definition: move.hpp:45
Definition: pair.hpp:31
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:39
CurveType::template g2_type ::value_type delta_g2
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:47
r1cs_gg_ppzksnark_proving_key & operator=(const r1cs_gg_ppzksnark_proving_key &other)=default
r1cs_gg_ppzksnark_proving_key(r1cs_gg_ppzksnark_proving_key &&other)=default
CurveType::template g2_type ::value_type beta_g2
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:45
r1cs_gg_ppzksnark_proving_key(const r1cs_gg_ppzksnark_proving_key &other)=default
r1cs_gg_ppzksnark_proving_key(typename CurveType::template g1_type<>::value_type &&alpha_g1, typename CurveType::template g1_type<>::value_type &&beta_g1, typename CurveType::template g2_type<>::value_type &&beta_g2, typename CurveType::template g1_type<>::value_type &&delta_g1, typename CurveType::template g2_type<>::value_type &&delta_g2, std::vector< typename CurveType::template g1_type<>::value_type > &&A_query, knowledge_commitment_vector< typename CurveType::template g2_type<>, typename CurveType::template g1_type<>> &&B_query, std::vector< typename CurveType::template g1_type<>::value_type > &&H_query, std::vector< typename CurveType::template g1_type<>::value_type > &&L_query, constraint_system_type &&constraint_system)
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:80
bool operator==(const r1cs_gg_ppzksnark_proving_key &other) const
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:123
std::size_t G2_sparse_size() const
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:110
constraint_system_type constraint_system
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:57
std::vector< typename CurveType::template g1_type<>::value_type > A_query
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:50
CurveType::template g1_type ::value_type delta_g1
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:46
std::vector< typename CurveType::template g1_type<>::value_type > H_query
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:54
CurveType curve_type
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:40
r1cs_gg_ppzksnark_proving_key(const typename CurveType::template g1_type<>::value_type &alpha_g1, const typename CurveType::template g1_type<>::value_type &beta_g1, const typename CurveType::template g2_type<>::value_type &beta_g2, const typename CurveType::template g1_type<>::value_type &delta_g1, const typename CurveType::template g2_type<>::value_type &delta_g2, const std::vector< typename CurveType::template g1_type<>::value_type > &A_query, const knowledge_commitment_vector< typename CurveType::template g2_type<>, typename CurveType::template g1_type<>> &B_query, const std::vector< typename CurveType::template g1_type<>::value_type > &H_query, const std::vector< typename CurveType::template g1_type<>::value_type > &L_query, const constraint_system_type &constraint_system)
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:64
std::size_t G1_size() const
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:98
std::size_t size_in_bits() const
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:114
r1cs_constraint_system< typename CurveType::scalar_field_type > constraint_system_type
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:41
r1cs_gg_ppzksnark_proving_key()
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:59
std::vector< typename CurveType::template g1_type<>::value_type > L_query
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:55
std::size_t G1_sparse_size() const
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:106
knowledge_commitment_vector< typename CurveType::template g2_type<>, typename CurveType::template g1_type<> > B_query
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:53
CurveType::template g1_type ::value_type beta_g1
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:44
CurveType::template g1_type ::value_type alpha_g1
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:43
std::size_t G2_size() const
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:102
Definition: sparse_vector.hpp:48