Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
circuit_base.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <limits>
4#include <sstream>
5#include <string>
6#include <unordered_map>
7
11
13
14namespace smt_circuit {
15using namespace smt_solver;
16using namespace smt_terms;
17using namespace smt_circuit_schema;
18
19enum class SubcircuitType { XOR, AND, RANGE, ROR, SHL, SHR };
20
29 public:
30 std::vector<bb::fr> variables; // circuit witness
31 std::unordered_set<uint32_t> public_inps; // public inputs from the circuit
32 std::unordered_map<uint32_t, std::string> variable_names; // names of the variables
33 std::unordered_map<std::string, uint32_t> variable_names_inverse; // inverse map of the previous member
34 std::unordered_map<uint32_t, STerm> symbolic_vars; // all the symbolic variables from the circuit
35 std::vector<uint32_t> real_variable_index; // indexes for assert_equal'd wires
36 std::vector<uint32_t> real_variable_tags; // tags of the variables in the circuit
37 std::unordered_map<uint32_t, bool> optimized; // keeps track of the variables that were excluded from symbolic
38 // circuit during optimizations
39 bool enable_optimizations; // flags to turn on circuit optimizations
41 post_process; // Values idxs that should be post processed after the solver returns a witness.
42 // Basically it affects only optimized out variables.
43 // Because in BitVector case we can't collect negative values since they will not be
44 // the same in the field. That's why we store the expression and calculate it after the witness is
45 // obtained.
46
47 Solver* solver; // pointer to the solver
48 TermType type; // Type of the underlying Symbolic Terms
49
50 std::string tag; // tag of the symbolic circuit.
51 // If not empty, will be added to the names
52 // of symbolic variables to prevent collisions.
53
54 CircuitBase(std::unordered_map<uint32_t, std::string>& variable_names,
56 std::vector<uint32_t>& public_inps,
57 std::vector<uint32_t>& real_variable_index,
58 std::vector<uint32_t>& real_variable_tags,
61 const std::string& tag = "",
62 bool enable_optimizations = true);
63
64 STerm operator[](const std::string& name);
65 STerm operator[](const uint32_t& idx) { return this->symbolic_vars[this->real_variable_index[idx]]; };
66 inline size_t get_num_real_vars() const { return symbolic_vars.size(); };
67 inline size_t get_num_vars() const { return variables.size(); };
68
69 void init();
70 virtual bool simulate_circuit_eval(std::vector<bb::fr>& witness) const = 0;
71
72 CircuitBase(const CircuitBase& other) = default;
73 CircuitBase(CircuitBase&& other) noexcept = default;
74 CircuitBase& operator=(const CircuitBase& other) = default;
75 CircuitBase& operator=(CircuitBase&& other) noexcept = default;
76 virtual ~CircuitBase() = default;
77};
78
79}; // namespace smt_circuit
Base class for symbolic circuits.
CircuitBase & operator=(const CircuitBase &other)=default
std::vector< uint32_t > real_variable_index
STerm operator[](const uint32_t &idx)
std::unordered_set< uint32_t > public_inps
virtual bool simulate_circuit_eval(std::vector< bb::fr > &witness) const =0
size_t get_num_real_vars() const
CircuitBase(const CircuitBase &other)=default
virtual ~CircuitBase()=default
std::vector< uint32_t > real_variable_tags
std::unordered_map< uint32_t, bool > optimized
std::vector< bb::fr > variables
size_t get_num_vars() const
CircuitBase & operator=(CircuitBase &&other) noexcept=default
STerm operator[](const std::string &name)
Returns a previously named symbolic variable.
std::unordered_map< uint32_t, std::string > variable_names
CircuitBase(CircuitBase &&other) noexcept=default
std::unordered_map< uint32_t, std::vector< bb::fr > > post_process
std::unordered_map< std::string, uint32_t > variable_names_inverse
std::unordered_map< uint32_t, STerm > symbolic_vars
Class for the solver.
Definition solver.hpp:80
Symbolic term element class.
Definition term.hpp:114
TermType
Allows to define three types of symbolic terms STerm - Symbolic Variables acting like a Finte Field e...
Definition term.hpp:15
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13