Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
powersoftau_utils.hpp
Go to the documentation of this file.
1 // Copyright (c) 2015-2022 Clearmatics Technologies Ltd
2 //
3 // SPDX-License-Identifier: LGPL-3.0+
4 
5 #ifndef __ZETH_MPC_GROTH16_POWERSOFTAU_UTILS_HPP__
6 #define __ZETH_MPC_GROTH16_POWERSOFTAU_UTILS_HPP__
7 
9 
10 #include <istream>
11 
12 namespace libzeth
13 {
14 
18 template<typename ppT> class srs_powersoftau
19 {
20 public:
22  const libff::G1_vector<ppT> tau_powers_g1;
23 
25  const libff::G2_vector<ppT> tau_powers_g2;
26 
28  const libff::G1_vector<ppT> alpha_tau_powers_g1;
29 
31  const libff::G1_vector<ppT> beta_tau_powers_g1;
32 
34  const libff::G2<ppT> beta_g2;
35 
37  libff::G1_vector<ppT> &&tau_powers_g1,
38  libff::G2_vector<ppT> &&tau_powers_g2,
39  libff::G1_vector<ppT> &&alpha_tau_powers_g1,
40  libff::G1_vector<ppT> &&beta_tau_g1,
41  const libff::G2<ppT> &beta_g2);
42 
43  bool is_well_formed() const;
44 };
45 
48 template<typename ppT> class srs_lagrange_evaluations
49 {
50 public:
51  const size_t degree;
52 
54  std::vector<libff::G1<ppT>> lagrange_g1;
55 
57  std::vector<libff::G2<ppT>> lagrange_g2;
58 
60  std::vector<libff::G1<ppT>> alpha_lagrange_g1;
61 
63  std::vector<libff::G1<ppT>> beta_lagrange_g1;
64 
66  size_t degree,
67  std::vector<libff::G1<ppT>> &&lagrange_g1,
68  std::vector<libff::G2<ppT>> &&lagrange_g2,
69  std::vector<libff::G1<ppT>> &&alpha_lagrange_g1,
70  std::vector<libff::G1<ppT>> &&beta_lagrange_g1);
71 
72  bool is_well_formed() const;
73  void write(std::ostream &out) const;
74  static srs_lagrange_evaluations read(std::istream &in);
75 };
76 
79 template<typename ppT>
81  const libff::Fr<ppT> &tau,
82  const libff::Fr<ppT> &alpha,
83  const libff::Fr<ppT> &beta,
84  size_t n);
85 
88 template<typename ppT> srs_powersoftau<ppT> dummy_powersoftau(size_t n);
89 
90 // Utility functions for reading and writing data as formatted by the
91 // powersoftau process.
92 
93 template<typename ppT>
94 void read_powersoftau_fr(std::istream &in, libff::Fr<ppT> &fr_out);
95 template<typename ppT>
96 void read_powersoftau_g1(std::istream &in, libff::G1<ppT> &out);
97 template<typename ppT>
98 void read_powersoftau_g2(std::istream &in, libff::G2<ppT> &out);
99 
100 template<typename ppT>
101 void write_powersoftau_fr(std::ostream &out, const libff::Fr<ppT> &fr);
102 template<typename ppT>
103 void write_powersoftau_g1(std::ostream &out, const libff::G1<ppT> &g1);
104 template<typename ppT>
105 void write_powersoftau_g2(std::ostream &out, const libff::G2<ppT> &g2);
106 
112 template<typename ppT>
113 srs_powersoftau<ppT> powersoftau_load(std::istream &in, size_t n);
114 
117 template<typename ppT>
118 void powersoftau_write(std::ostream &out, const srs_powersoftau<ppT> &pot);
119 
123 template<typename ppT>
124 bool same_ratio(
125  const libff::G1<ppT> &a1,
126  const libff::G1<ppT> &b1,
127  const libff::G2<ppT> &a2,
128  const libff::G2<ppT> &b2);
129 
139 template<typename ppT>
140 bool same_ratio_vectors(
141  const std::vector<libff::G1<ppT>> &a1s,
142  const std::vector<libff::G1<ppT>> &b1s,
143  const libff::G2<ppT> &a2,
144  const libff::G2<ppT> &b2);
145 
147 template<typename ppT>
148 bool same_ratio_vectors(
149  const libff::G1<ppT> &a1,
150  const libff::G1<ppT> &b1,
151  const std::vector<libff::G2<ppT>> &a2s,
152  const std::vector<libff::G2<ppT>> &b2s);
153 
156 template<typename ppT>
158  const std::vector<libff::G1<ppT>> &a1s,
159  const libff::G2<ppT> &a2,
160  const libff::G2<ppT> &b2);
161 
163 template<typename ppT>
165  const libff::G1<ppT> &a1,
166  const libff::G1<ppT> &b1,
167  const std::vector<libff::G2<ppT>> &a2s);
168 
170 template<typename ppT>
172 
176 template<typename ppT>
178  const srs_powersoftau<ppT> &pot, const size_t n);
179 
180 } // namespace libzeth
181 
183 
184 #endif // __ZETH_MPC_GROTH16_POWERSOFTAU_UTILS_HPP__
powersoftau_utils.tcc
groth16_snark.hpp
libzeth::srs_lagrange_evaluations::is_well_formed
bool is_well_formed() const
libzeth::dummy_powersoftau
srs_powersoftau< ppT > dummy_powersoftau(size_t n)
libzeth::same_ratio_consecutive
bool same_ratio_consecutive(const std::vector< libff::G1< ppT >> &a1s, const libff::G2< ppT > &a2, const libff::G2< ppT > &b2)
libzeth::srs_powersoftau::alpha_tau_powers_g1
const libff::G1_vector< ppT > alpha_tau_powers_g1
{ [ alpha . x^i ]_1 } i = 0 .. n-1
Definition: powersoftau_utils.hpp:28
libzeth
Definition: binary_operation.hpp:15
libzeth::srs_powersoftau::tau_powers_g2
const libff::G2_vector< ppT > tau_powers_g2
{ [ x^i ]_2 } i = 0 .. n-1
Definition: powersoftau_utils.hpp:25
libzeth::srs_powersoftau::tau_powers_g1
const libff::G1_vector< ppT > tau_powers_g1
{ [ x^i ]_1 } i = 0 .. 2n-2
Definition: powersoftau_utils.hpp:22
libzeth::read_powersoftau_fr
void read_powersoftau_fr(std::istream &in, libff::Fr< ppT > &fr_out)
libzeth::srs_lagrange_evaluations
Definition: mpc_utils.hpp:32
libzeth::srs_lagrange_evaluations::alpha_lagrange_g1
std::vector< libff::G1< ppT > > alpha_lagrange_g1
${ [ alpha . L_i(x) ]_1 }"$
Definition: powersoftau_utils.hpp:60
libzeth::read_powersoftau_g2
void read_powersoftau_g2(std::istream &in, libff::G2< ppT > &out)
libzeth::powersoftau_load
srs_powersoftau< ppT > powersoftau_load(std::istream &in, size_t n)
libzeth::srs_lagrange_evaluations::lagrange_g1
std::vector< libff::G1< ppT > > lagrange_g1
${ [ L_i(x) ]_1 }_i$
Definition: powersoftau_utils.hpp:54
libzeth::srs_lagrange_evaluations::degree
const size_t degree
Definition: powersoftau_utils.hpp:51
libzeth::read_powersoftau_g1
void read_powersoftau_g1(std::istream &in, libff::G1< ppT > &out)
libzeth::same_ratio
bool same_ratio(const libff::G1< ppT > &a1, const libff::G1< ppT > &b1, const libff::G2< ppT > &a2, const libff::G2< ppT > &b2)
libzeth::srs_powersoftau::srs_powersoftau
srs_powersoftau(libff::G1_vector< ppT > &&tau_powers_g1, libff::G2_vector< ppT > &&tau_powers_g2, libff::G1_vector< ppT > &&alpha_tau_powers_g1, libff::G1_vector< ppT > &&beta_tau_g1, const libff::G2< ppT > &beta_g2)
libzeth::srs_lagrange_evaluations::lagrange_g2
std::vector< libff::G2< ppT > > lagrange_g2
${ [ L_i(x) ]_2 }_i$
Definition: powersoftau_utils.hpp:57
libzeth::srs_powersoftau::beta_tau_powers_g1
const libff::G1_vector< ppT > beta_tau_powers_g1
{ [ beta . x^i ]_1 } i = 0 .. n-1
Definition: powersoftau_utils.hpp:31
libzeth::srs_lagrange_evaluations::beta_lagrange_g1
std::vector< libff::G1< ppT > > beta_lagrange_g1
${ [ beta . L_i(x) ]_1 }"$
Definition: powersoftau_utils.hpp:63
libzeth::dummy_powersoftau_from_secrets
srs_powersoftau< ppT > dummy_powersoftau_from_secrets(const libff::Fr< ppT > &tau, const libff::Fr< ppT > &alpha, const libff::Fr< ppT > &beta, size_t n)
libzeth::srs_powersoftau::is_well_formed
bool is_well_formed() const
libzeth::srs_powersoftau
Definition: mpc_utils.hpp:31
libzeth::srs_lagrange_evaluations::srs_lagrange_evaluations
srs_lagrange_evaluations(size_t degree, std::vector< libff::G1< ppT >> &&lagrange_g1, std::vector< libff::G2< ppT >> &&lagrange_g2, std::vector< libff::G1< ppT >> &&alpha_lagrange_g1, std::vector< libff::G1< ppT >> &&beta_lagrange_g1)
libzeth::write_powersoftau_g2
void write_powersoftau_g2(std::ostream &out, const libff::G2< ppT > &g2)
libzeth::write_powersoftau_g1
void write_powersoftau_g1(std::ostream &out, const libff::G1< ppT > &g1)
libzeth::srs_lagrange_evaluations::read
static srs_lagrange_evaluations read(std::istream &in)
libzeth::write_powersoftau_fr
void write_powersoftau_fr(std::ostream &out, const libff::Fr< ppT > &fr)
libzeth::powersoftau_compute_lagrange_evaluations
srs_lagrange_evaluations< ppT > powersoftau_compute_lagrange_evaluations(const srs_powersoftau< ppT > &pot, const size_t n)
libzeth::powersoftau_write
void powersoftau_write(std::ostream &out, const srs_powersoftau< ppT > &pot)
libzeth::powersoftau_is_well_formed
bool powersoftau_is_well_formed(const srs_powersoftau< ppT > &pot)
Verify that the pot data is well formed.
libzeth::srs_lagrange_evaluations::write
void write(std::ostream &out) const
libzeth::same_ratio_vectors
bool same_ratio_vectors(const std::vector< libff::G1< ppT >> &a1s, const std::vector< libff::G1< ppT >> &b1s, const libff::G2< ppT > &a2, const libff::G2< ppT > &b2)
libzeth::srs_powersoftau::beta_g2
const libff::G2< ppT > beta_g2
[ beta ]_2
Definition: powersoftau_utils.hpp:34