systems/ppzksnark/r1cs_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_PPZKSNARK_PROVING_KEY_HPP
27 #define CRYPTO3_R1CS_PPZKSNARK_PROVING_KEY_HPP
28 
29 #ifdef MULTICORE
30 #include <omp.h>
31 #endif
32 
36 
38 
39 namespace nil {
40  namespace crypto3 {
41  namespace zk {
42  namespace snark {
46  template<typename CurveType, typename ConstraintSystemType>
48  using g1_type = typename CurveType::template g1_type<>;
49  using g2_type = typename CurveType::template g2_type<>;
50  using g1_value_type = typename g1_type::value_type;
51  using g2_value_type = typename g2_type::value_type;
52 
53  public:
54  typedef CurveType curve_type;
55  typedef ConstraintSystemType constraint_system_type;
56 
60  std::vector<g1_value_type> H_query;
61  std::vector<g1_value_type> K_query;
62 
64 
72  typename std::vector<g1_value_type> &&H_query,
73  typename std::vector<g1_value_type> &&K_query,
75  A_query(std::move(A_query)),
76  B_query(std::move(B_query)), C_query(std::move(C_query)), H_query(std::move(H_query)),
78 
79  std::size_t G1_size() const {
80  return 2 * (A_query.domain_size() + C_query.domain_size()) + B_query.domain_size() +
81  H_query.size() + K_query.size();
82  }
83 
84  std::size_t G2_size() const {
85  return B_query.domain_size();
86  }
87 
88  std::size_t G1_sparse_size() const {
89  return 2 * (A_query.size() + C_query.size()) + B_query.size() + H_query.size() + K_query.size();
90  }
91 
92  std::size_t G2_sparse_size() const {
93  return B_query.size();
94  }
95 
96  std::size_t size_in_bits() const {
97  return A_query.size_in_bits() + B_query.size_in_bits() + C_query.size_in_bits() +
98  H_query.size() * CurveType::g1_type::value_bits +
99  K_query.size() * CurveType::g1_type::value_bits;
100  }
101 
102  bool operator==(const r1cs_ppzksnark_proving_key &other) const {
103  return (this->A_query == other.A_query && this->B_query == other.B_query &&
104  this->C_query == other.C_query && this->H_query == other.H_query &&
105  this->K_query == other.K_query && this->constraint_system == other.constraint_system);
106  }
107  };
108  } // namespace snark
109  } // namespace zk
110  } // namespace crypto3
111 } // namespace nil
112 
113 #endif // CRYPTO3_R1CS_PPZKSNARK_BASIC_PROVER_HPP
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:47
std::vector< g1_value_type > H_query
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:60
std::size_t G2_size() const
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:84
std::size_t G2_sparse_size() const
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:92
knowledge_commitment_vector< g1_type, g1_type > A_query
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:57
constraint_system_type constraint_system
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:63
ConstraintSystemType constraint_system_type
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:55
knowledge_commitment_vector< g2_type, g1_type > B_query
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:58
std::size_t G1_sparse_size() const
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:88
r1cs_ppzksnark_proving_key(knowledge_commitment_vector< g1_type, g1_type > &&A_query, knowledge_commitment_vector< g2_type, g1_type > &&B_query, knowledge_commitment_vector< g1_type, g1_type > &&C_query, typename std::vector< g1_value_type > &&H_query, typename std::vector< g1_value_type > &&K_query, constraint_system_type &&constraint_system)
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:69
r1cs_ppzksnark_proving_key(const r1cs_ppzksnark_proving_key &other)=default
r1cs_ppzksnark_proving_key & operator=(const r1cs_ppzksnark_proving_key &other)=default
bool operator==(const r1cs_ppzksnark_proving_key &other) const
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:102
std::size_t size_in_bits() const
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:96
std::size_t G1_size() const
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:79
std::vector< g1_value_type > K_query
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:61
r1cs_ppzksnark_proving_key()
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:65
r1cs_ppzksnark_proving_key(r1cs_ppzksnark_proving_key &&other)=default
knowledge_commitment_vector< g1_type, g1_type > C_query
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:59
CurveType curve_type
Definition: systems/ppzksnark/r1cs_ppzksnark/proving_key.hpp:54
OutputIterator move(const SinglePassRange &rng, OutputIterator result)
Definition: move.hpp:45
Definition: pair.hpp:31
Definition: sparse_vector.hpp:48