r1cs_gg_ppzksnark/ipp2/generator.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-2021 Ilias Khairullin <ilias@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_ZK_R1CS_GG_PPZKSNARK_IPP2_GENERATOR_HPP
27 #define CRYPTO3_ZK_R1CS_GG_PPZKSNARK_IPP2_GENERATOR_HPP
28 
31 
32 namespace nil {
33  namespace crypto3 {
34  namespace zk {
35  namespace snark {
36  template<typename CurveType>
40 
41  typedef typename CurveType::scalar_field_type scalar_field_type;
42  typedef typename CurveType::template g1_type<> g1_type;
43  typedef typename CurveType::template g2_type<> g2_type;
44 
45  public:
49  typedef typename policy_type::srs_type srs_type;
52 
53  template<typename DistributionType =
54  boost::random::uniform_int_distribution<typename scalar_field_type::integral_type>,
55  typename GeneratorType = boost::random::mt19937>
56  static inline keypair_type process(const constraint_system_type &constraint_system) {
57 
58  auto [alpha_g1,
59  beta_g1,
60  beta_g2,
61  delta_g1,
62  delta_g2,
63  gamma_g2,
64  A_query,
65  B_query,
66  H_query,
67  L_query,
68  r1cs_copy,
69  alpha_g1_beta_g2,
70  gamma_ABC_g1,
71  gamma_g1] = std::move(basic_generator::basic_process(constraint_system));
72 
73  verification_key_type vk(alpha_g1, beta_g2, gamma_g2, delta_g2, gamma_ABC_g1);
74 
75  proving_key_type pk(std::move(alpha_g1),
76  std::move(beta_g1),
77  std::move(beta_g2),
78  std::move(delta_g1),
79  std::move(delta_g2),
80  std::move(A_query),
81  std::move(B_query),
82  std::move(H_query),
83  std::move(L_query),
84  std::move(r1cs_copy));
85 
86  return {std::move(pk), std::move(vk)};
87  }
88 
89  template<typename DistributionType =
90  boost::random::uniform_int_distribution<typename scalar_field_type::integral_type>,
91  typename GeneratorType = boost::random::mt19937>
92  static inline srs_pair_type process(std::size_t num_proofs) {
93 
94  srs_type srs(num_proofs,
95  random_element<scalar_field_type, DistributionType, GeneratorType>(),
96  random_element<scalar_field_type, DistributionType, GeneratorType>());
97  return srs.specialize(num_proofs);
98  }
99  };
100  } // namespace snark
101  } // namespace zk
102  } // namespace crypto3
103 } // namespace nil
104 
105 #endif // CRYPTO3_ZK_R1CS_GG_PPZKSNARK_IPP2_GENERATOR_HPP
policy_type::srs_type srs_type
Definition: r1cs_gg_ppzksnark/ipp2/generator.hpp:49
static srs_pair_type process(std::size_t num_proofs)
Definition: r1cs_gg_ppzksnark/ipp2/generator.hpp:92
policy_type::srs_pair_type srs_pair_type
Definition: r1cs_gg_ppzksnark/ipp2/generator.hpp:51
static keypair_type process(const constraint_system_type &constraint_system)
Definition: r1cs_gg_ppzksnark/ipp2/generator.hpp:56
policy_type::verification_key_type verification_key_type
Definition: r1cs_gg_ppzksnark/ipp2/generator.hpp:48
policy_type::proving_key_type proving_key_type
Definition: r1cs_gg_ppzksnark/ipp2/generator.hpp:47
policy_type::keypair_type keypair_type
Definition: r1cs_gg_ppzksnark/ipp2/generator.hpp:50
policy_type::constraint_system_type constraint_system_type
Definition: r1cs_gg_ppzksnark/ipp2/generator.hpp:46
Definition: r1cs_gg_ppzksnark/generator.hpp:49
OutputIterator move(const SinglePassRange &rng, OutputIterator result)
Definition: move.hpp:45
ProvingMode
Definition: modes.hpp:33
Definition: pair.hpp:31
Definition: zk/include/nil/crypto3/zk/snark/systems/ppzksnark/r1cs_gg_ppzksnark/detail/basic_policy.hpp:168
r1cs_gg_ppzksnark_keypair< proving_key_type, verification_key_type > keypair_type
Definition: zk/include/nil/crypto3/zk/snark/systems/ppzksnark/r1cs_gg_ppzksnark/detail/basic_policy.hpp:204
srs_type::srs_pair_type srs_pair_type
Definition: zk/include/nil/crypto3/zk/snark/systems/ppzksnark/r1cs_gg_ppzksnark/detail/basic_policy.hpp:233
srs_pair_type specialize(std::size_t num_proofs)
Definition: srs.hpp:157
Definition: zk/include/nil/crypto3/zk/snark/systems/ppzksnark/r1cs_gg_ppzksnark/ipp2/verification_key.hpp:38
Definition: systems/ppzksnark/r1cs_gg_ppzksnark/proving_key.hpp:39