Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
tbcs.hpp
Go to the documentation of this file.
1 
17 #ifndef TBCS_HPP_
18 #define TBCS_HPP_
19 
20 #include <libff/common/profiling.hpp>
22 
23 namespace libsnark
24 {
25 
26 /*********************** BACS variable assignment ****************************/
27 
31 typedef std::vector<bool> tbcs_variable_assignment;
32 
33 /**************************** TBCS gate **************************************/
34 
35 typedef size_t tbcs_wire_t;
36 
72 };
73 
74 static const int num_tbcs_gate_types = 16;
75 
87 class tbcs_gate
88 {
89 public:
92 
94 
96 
98 
99  bool evaluate(const tbcs_variable_assignment &input) const;
100  void print(
101  const std::map<size_t, std::string> &variable_annotations =
102  std::map<size_t, std::string>()) const;
103  bool operator==(const tbcs_gate &other) const;
104 
105  friend std::ostream &operator<<(std::ostream &out, const tbcs_gate &g);
106  friend std::istream &operator>>(std::istream &in, tbcs_gate &g);
107 };
108 
109 /****************************** TBCS inputs **********************************/
110 
115 
120 
121 /************************** TBCS circuit *************************************/
122 
134 {
135 public:
138  std::vector<tbcs_gate> gates;
139 
141 
142  size_t num_inputs() const;
143  size_t num_gates() const;
144  size_t num_wires() const;
145 
146  std::vector<size_t> wire_depths() const;
147  size_t depth() const;
148 
149 #ifdef DEBUG
150  std::map<size_t, std::string> gate_annotations;
151  std::map<size_t, std::string> variable_annotations;
152 #endif
153 
154  bool is_valid() const;
155  bool is_satisfied(
156  const tbcs_primary_input &primary_input,
157  const tbcs_auxiliary_input &auxiliary_input) const;
158 
160  const tbcs_primary_input &primary_input,
161  const tbcs_auxiliary_input &auxiliary_input) const;
163  const tbcs_primary_input &primary_input,
164  const tbcs_auxiliary_input &auxiliary_input) const;
165 
166  void add_gate(const tbcs_gate &g);
167  void add_gate(const tbcs_gate &g, const std::string &annotation);
168 
169  bool operator==(const tbcs_circuit &other) const;
170 
171  void print() const;
172  void print_info() const;
173 
174  friend std::ostream &operator<<(
175  std::ostream &out, const tbcs_circuit &circuit);
176  friend std::istream &operator>>(std::istream &in, tbcs_circuit &circuit);
177 };
178 
179 } // namespace libsnark
180 
181 #endif // TBCS_HPP_
libsnark::tbcs_circuit::operator==
bool operator==(const tbcs_circuit &other) const
Definition: tbcs.cpp:281
libsnark::tbcs_circuit::gates
std::vector< tbcs_gate > gates
Definition: tbcs.hpp:138
libsnark::tbcs_circuit::depth
size_t depth() const
Definition: tbcs.cpp:182
libsnark::tbcs_gate::operator<<
friend std::ostream & operator<<(std::ostream &out, const tbcs_gate &g)
Definition: tbcs.cpp:134
libsnark::tbcs_gate::print
void print(const std::map< size_t, std::string > &variable_annotations=std::map< size_t, std::string >()) const
Definition: tbcs.cpp:60
libsnark::TBCS_GATE_X
@ TBCS_GATE_X
Definition: tbcs.hpp:59
libsnark::tbcs_circuit
Definition: tbcs.hpp:133
libsnark::tbcs_gate::output
tbcs_wire_t output
Definition: tbcs.hpp:95
libsnark::tbcs_circuit::get_all_outputs
tbcs_variable_assignment get_all_outputs(const tbcs_primary_input &primary_input, const tbcs_auxiliary_input &auxiliary_input) const
Definition: tbcs.cpp:232
libsnark::TBCS_GATE_NOT_X
@ TBCS_GATE_NOT_X
Definition: tbcs.hpp:68
libsnark::tbcs_gate::left_wire
tbcs_wire_t left_wire
Definition: tbcs.hpp:90
libsnark::tbcs_primary_input
tbcs_variable_assignment tbcs_primary_input
Definition: tbcs.hpp:114
libsnark
Definition: accumulation_vector.hpp:18
libsnark::tbcs_circuit::num_gates
size_t num_gates() const
Definition: tbcs.cpp:178
libsnark::tbcs_circuit::tbcs_circuit
tbcs_circuit()
Definition: tbcs.hpp:140
libsnark::tbcs_circuit::wire_depths
std::vector< size_t > wire_depths() const
Definition: tbcs.cpp:161
libsnark::tbcs_gate::right_wire
tbcs_wire_t right_wire
Definition: tbcs.hpp:91
libsnark::TBCS_GATE_IF_X_THEN_Y
@ TBCS_GATE_IF_X_THEN_Y
Definition: tbcs.hpp:69
libsnark::TBCS_GATE_NOT_X_AND_Y
@ TBCS_GATE_NOT_X_AND_Y
Definition: tbcs.hpp:60
libsnark::TBCS_GATE_X_AND_NOT_Y
@ TBCS_GATE_X_AND_NOT_Y
Definition: tbcs.hpp:58
libsnark::tbcs_circuit::primary_input_size
size_t primary_input_size
Definition: tbcs.hpp:136
libsnark::tbcs_circuit::is_valid
bool is_valid() const
Definition: tbcs.cpp:188
libsnark::tbcs_gate::evaluate
bool evaluate(const tbcs_variable_assignment &input) const
Definition: tbcs.cpp:24
libsnark::tbcs_circuit::add_gate
void add_gate(const tbcs_gate &g)
Definition: tbcs.cpp:264
libsnark::tbcs_circuit::num_wires
size_t num_wires() const
Definition: tbcs.cpp:180
libsnark::tbcs_gate
Definition: tbcs.hpp:87
libsnark::tbcs_circuit::operator>>
friend std::istream & operator>>(std::istream &in, tbcs_circuit &circuit)
Definition: tbcs.cpp:299
libsnark::TBCS_GATE_Y
@ TBCS_GATE_Y
Definition: tbcs.hpp:61
libsnark::tbcs_circuit::is_satisfied
bool is_satisfied(const tbcs_primary_input &primary_input, const tbcs_auxiliary_input &auxiliary_input) const
Definition: tbcs.cpp:249
variable.hpp
libsnark::tbcs_circuit::print_info
void print_info() const
Definition: tbcs.cpp:335
libsnark::tbcs_auxiliary_input
tbcs_variable_assignment tbcs_auxiliary_input
Definition: tbcs.hpp:119
libsnark::TBCS_GATE_NOT_Y
@ TBCS_GATE_NOT_Y
Definition: tbcs.hpp:66
libsnark::tbcs_gate_type
tbcs_gate_type
Definition: tbcs.hpp:55
libsnark::tbcs_circuit::get_all_wires
tbcs_variable_assignment get_all_wires(const tbcs_primary_input &primary_input, const tbcs_auxiliary_input &auxiliary_input) const
Definition: tbcs.cpp:211
libsnark::TBCS_GATE_NOR
@ TBCS_GATE_NOR
Definition: tbcs.hpp:64
libsnark::TBCS_GATE_XOR
@ TBCS_GATE_XOR
Definition: tbcs.hpp:62
libsnark::tbcs_circuit::num_inputs
size_t num_inputs() const
Definition: tbcs.cpp:173
libsnark::TBCS_GATE_AND
@ TBCS_GATE_AND
Definition: tbcs.hpp:57
libsnark::TBCS_GATE_IF_Y_THEN_X
@ TBCS_GATE_IF_Y_THEN_X
Definition: tbcs.hpp:67
libsnark::TBCS_GATE_OR
@ TBCS_GATE_OR
Definition: tbcs.hpp:63
libsnark::tbcs_circuit::operator<<
friend std::ostream & operator<<(std::ostream &out, const tbcs_circuit &circuit)
Definition: tbcs.cpp:289
libsnark::tbcs_circuit::print
void print() const
Definition: tbcs.cpp:311
libsnark::TBCS_GATE_EQUIVALENCE
@ TBCS_GATE_EQUIVALENCE
Definition: tbcs.hpp:65
libsnark::tbcs_gate::operator==
bool operator==(const tbcs_gate &other) const
Definition: tbcs.cpp:125
libsnark::tbcs_gate::type
tbcs_gate_type type
Definition: tbcs.hpp:93
libsnark::tbcs_circuit::auxiliary_input_size
size_t auxiliary_input_size
Definition: tbcs.hpp:137
libsnark::TBCS_GATE_CONSTANT_0
@ TBCS_GATE_CONSTANT_0
Definition: tbcs.hpp:56
libsnark::tbcs_wire_t
size_t tbcs_wire_t
Definition: tbcs.hpp:35
libsnark::tbcs_variable_assignment
std::vector< bool > tbcs_variable_assignment
Definition: tbcs.hpp:31
libsnark::tbcs_gate::is_circuit_output
bool is_circuit_output
Definition: tbcs.hpp:97
libsnark::TBCS_GATE_NAND
@ TBCS_GATE_NAND
Definition: tbcs.hpp:70
libsnark::TBCS_GATE_CONSTANT_1
@ TBCS_GATE_CONSTANT_1
Definition: tbcs.hpp:71
libsnark::tbcs_gate::operator>>
friend std::istream & operator>>(std::istream &in, tbcs_gate &g)
Definition: tbcs.cpp:145