-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathr1_constraint.hpp
94 lines (66 loc) · 2 KB
/
r1_constraint.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef MIMC_SNARKBOARD_HPP_
#define MIMC_SNARKBOARD_HPP_
#include "variable.hpp"
#include "common/common.hpp"
namespace snark {
template<typename field_t>
class constraint {
public:
linear_combination< field_t > A, B, C;
constraint();
constraint(const linear_combination<field_t> a,
const linear_combination<field_t> b,
const linear_combination<field_t> c):
A(a), B(b), C(c)
{
}
constraint(const constraint &other):
A(other.A), B(other.B), C(other.C)
{
//set_constraint_type(other.get_constraint_type());
}
void reset_constraint(const linear_combination<field_t> a,
const linear_combination<field_t> b,
const linear_combination<field_t> c);
void clear();
friend std::ostream& operator<< (std::ostream &out, const constraint &constr)
{
out<<constr.A<<" * "<<constr.B<<" = "<<constr.C;
return out;
}
};
template<typename field_t>
class constraint_system {
public:
std::vector<constraint<field_t> > constraints;
constraint_system() {};
constraint_system(const constraint_system &other):
constraints(other.constraints)
{
}
void add_constraint(const constraint<field_t> constr);
constraint<field_t>& operator[](const size_t i);
};
template<typename field_t>
class snarkcs {
public:
constraint_system<field_t> r1_constraints;
std::vector<field_t> witness;
snarkcs();
snarkcs(const snarkcs &other):
r1_constraints(other.r1_constraints), witness(other.witness)
{
}
const size_t constraint_size() const;
const size_t witness_size() const;
void add_constraint(const constraint<field_t> constr);
void add_witness(const field_t w);
void add_witness(std::initializer_list< field_t > l);
void print_constraints() const;
void print_witness() const;
/*removes the last constraint in the system of constraints*/
void pop_constraint();
};
#include "r1_constraint.cpp"
}
#endif