Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
fp3_gadgets.hpp
Go to the documentation of this file.
1 
15 #ifndef FP3_GADGETS_HPP_
16 #define FP3_GADGETS_HPP_
17 
19 #include <memory>
20 
21 namespace libsnark
22 {
23 
27 template<typename Fp3T> class Fp3_variable : public gadget<typename Fp3T::my_Fp>
28 {
29 public:
30  typedef typename Fp3T::my_Fp FieldT;
31 
35 
37 
41  const Fp3T &el,
42  const std::string &annotation_prefix);
45  const Fp3T &el,
46  const pb_linear_combination<FieldT> &coeff,
47  const std::string &annotation_prefix);
53  const std::string &annotation_prefix);
54 
55  void generate_r1cs_equals_const_constraints(const Fp3T &el);
56  void generate_r1cs_witness(const Fp3T &el);
57  Fp3T get_element();
58 
59  Fp3_variable<Fp3T> operator*(const FieldT &coeff) const;
61  Fp3_variable<Fp3T> operator+(const Fp3T &other) const;
63  void evaluate() const;
64  bool is_constant() const;
65 
66  static size_t size_in_bits();
67  static size_t num_variables();
68 };
69 
73 template<typename Fp3T>
74 class Fp3_mul_gadget : public gadget<typename Fp3T::my_Fp>
75 {
76 public:
77  typedef typename Fp3T::my_Fp FieldT;
78 
82 
85 
88  const Fp3_variable<Fp3T> &A,
89  const Fp3_variable<Fp3T> &B,
91  const std::string &annotation_prefix);
93  void generate_r1cs_witness();
94 };
95 
100 template<typename Fp3T>
101 class Fp3_mul_by_lc_gadget : public gadget<typename Fp3T::my_Fp>
102 {
103 public:
104  typedef typename Fp3T::my_Fp FieldT;
105 
109 
112  const Fp3_variable<Fp3T> &A,
114  const Fp3_variable<Fp3T> &result,
115  const std::string &annotation_prefix);
117  void generate_r1cs_witness();
118 };
119 
123 template<typename Fp3T>
124 class Fp3_sqr_gadget : public gadget<typename Fp3T::my_Fp>
125 {
126 public:
127  typedef typename Fp3T::my_Fp FieldT;
128 
131 
132  std::shared_ptr<Fp3_mul_gadget<Fp3T>> mul;
133 
136  const Fp3_variable<Fp3T> &A,
137  const Fp3_variable<Fp3T> &result,
138  const std::string &annotation_prefix);
140  void generate_r1cs_witness();
141 };
142 
143 } // namespace libsnark
144 
146 
147 #endif // FP3_GADGETS_HPP_
libsnark::Fp3_variable::c1
pb_linear_combination< FieldT > c1
Definition: fp3_gadgets.hpp:33
libsnark::Fp3_mul_gadget::generate_r1cs_constraints
void generate_r1cs_constraints()
libsnark::Fp3_mul_by_lc_gadget::Fp3_mul_by_lc_gadget
Fp3_mul_by_lc_gadget(protoboard< FieldT > &pb, const Fp3_variable< Fp3T > &A, const pb_linear_combination< FieldT > &lc, const Fp3_variable< Fp3T > &result, const std::string &annotation_prefix)
libsnark::Fp3_mul_gadget
Definition: fp3_gadgets.hpp:74
libsnark::Fp3_mul_by_lc_gadget
Definition: fp3_gadgets.hpp:101
libsnark::Fp3_mul_by_lc_gadget::lc
pb_linear_combination< FieldT > lc
Definition: fp3_gadgets.hpp:107
libsnark::Fp3_sqr_gadget::result
Fp3_variable< Fp3T > result
Definition: fp3_gadgets.hpp:130
libsnark::gadget< Fp3T::my_Fp >::annotation_prefix
const std::string annotation_prefix
Definition: gadget.hpp:20
libsnark::Fp3_sqr_gadget::mul
std::shared_ptr< Fp3_mul_gadget< Fp3T > > mul
Definition: fp3_gadgets.hpp:132
libsnark::Fp3_variable::operator*
Fp3_variable< Fp3T > operator*(const FieldT &coeff) const
libsnark
Definition: accumulation_vector.hpp:18
libsnark::Fp3_mul_gadget::B
Fp3_variable< Fp3T > B
Definition: fp3_gadgets.hpp:80
libsnark::Fp3_mul_gadget::v0
pb_variable< FieldT > v0
Definition: fp3_gadgets.hpp:83
libsnark::Fp3_variable::generate_r1cs_witness
void generate_r1cs_witness(const Fp3T &el)
libsnark::Fp3_variable::num_variables
static size_t num_variables()
libsnark::gadget< Fp3T::my_Fp >::pb
protoboard< Fp3T::my_Fp > & pb
Definition: gadget.hpp:19
libsnark::Fp3_variable::mul_by_X
Fp3_variable< Fp3T > mul_by_X() const
gadget.hpp
fp3_gadgets.tcc
libsnark::Fp3_mul_by_lc_gadget::generate_r1cs_constraints
void generate_r1cs_constraints()
libsnark::Fp3_sqr_gadget::generate_r1cs_witness
void generate_r1cs_witness()
libsnark::gadget
Definition: gadget.hpp:16
libsnark::Fp3_variable::get_element
Fp3T get_element()
libsnark::Fp3_variable::Fp3_variable
Fp3_variable(protoboard< FieldT > &pb, const std::string &annotation_prefix)
libsnark::Fp3_mul_gadget::generate_r1cs_witness
void generate_r1cs_witness()
libsnark::Fp3_mul_gadget::result
Fp3_variable< Fp3T > result
Definition: fp3_gadgets.hpp:81
libsnark::Fp3_sqr_gadget::Fp3_sqr_gadget
Fp3_sqr_gadget(protoboard< FieldT > &pb, const Fp3_variable< Fp3T > &A, const Fp3_variable< Fp3T > &result, const std::string &annotation_prefix)
libsnark::Fp3_variable::operator+
Fp3_variable< Fp3T > operator+(const Fp3_variable< Fp3T > &other) const
libsnark::Fp3_variable::c2
pb_linear_combination< FieldT > c2
Definition: fp3_gadgets.hpp:34
libsnark::pb_linear_combination_array
Definition: pb_variable.hpp:118
libsnark::Fp3_mul_gadget::Fp3_mul_gadget
Fp3_mul_gadget(protoboard< FieldT > &pb, const Fp3_variable< Fp3T > &A, const Fp3_variable< Fp3T > &B, const Fp3_variable< Fp3T > &result, const std::string &annotation_prefix)
libsnark::pb_linear_combination
Definition: pb_variable.hpp:101
libsnark::Fp3_mul_by_lc_gadget::result
Fp3_variable< Fp3T > result
Definition: fp3_gadgets.hpp:108
libsnark::Fp3_sqr_gadget::generate_r1cs_constraints
void generate_r1cs_constraints()
libsnark::pb_variable
Definition: pb_variable.hpp:24
libsnark::Fp3_sqr_gadget::A
Fp3_variable< Fp3T > A
Definition: fp3_gadgets.hpp:129
libsnark::Fp3_sqr_gadget::FieldT
Fp3T::my_Fp FieldT
Definition: fp3_gadgets.hpp:127
libsnark::Fp3_mul_by_lc_gadget::generate_r1cs_witness
void generate_r1cs_witness()
libsnark::Fp3_mul_by_lc_gadget::FieldT
Fp3T::my_Fp FieldT
Definition: fp3_gadgets.hpp:104
libsnark::Fp3_variable::FieldT
Fp3T::my_Fp FieldT
Definition: fp3_gadgets.hpp:30
libsnark::Fp3_mul_gadget::A
Fp3_variable< Fp3T > A
Definition: fp3_gadgets.hpp:79
libsnark::Fp3_variable::is_constant
bool is_constant() const
libsnark::Fp3_mul_gadget::FieldT
Fp3T::my_Fp FieldT
Definition: fp3_gadgets.hpp:77
libsnark::Fp3_variable::generate_r1cs_equals_const_constraints
void generate_r1cs_equals_const_constraints(const Fp3T &el)
libsnark::Fp3_variable::evaluate
void evaluate() const
libsnark::Fp3_variable::all_vars
pb_linear_combination_array< FieldT > all_vars
Definition: fp3_gadgets.hpp:36
libsnark::Fp3_variable
Definition: fp3_gadgets.hpp:27
libsnark::Fp3_variable::c0
pb_linear_combination< FieldT > c0
Definition: fp3_gadgets.hpp:32
libsnark::Fp3_mul_gadget::v4
pb_variable< FieldT > v4
Definition: fp3_gadgets.hpp:84
libsnark::Fp3_sqr_gadget
Definition: fp3_gadgets.hpp:124
libsnark::Fp3_variable::size_in_bits
static size_t size_in_bits()
libsnark::protoboard
Definition: pb_variable.hpp:22
libsnark::Fp3_mul_by_lc_gadget::A
Fp3_variable< Fp3T > A
Definition: fp3_gadgets.hpp:106