barretenberg
Loading...
Searching...
No Matches
bool.hpp
1#pragma once
2#include "../circuit_builders/circuit_builders_fwd.hpp"
3#include "../witness/witness.hpp"
4
5namespace proof_system::plonk::stdlib {
6
7template <typename Builder> class bool_t {
8 public:
9 bool_t(const bool value = false);
10 bool_t(Builder* parent_context);
11 bool_t(Builder* parent_context, const bool value);
12 bool_t(const witness_t<Builder>& value);
13 bool_t(const bool_t& other);
14 bool_t(bool_t&& other);
15
16 bool_t& operator=(const bool other);
17 bool_t& operator=(const witness_t<Builder>& other);
18 bool_t& operator=(const bool_t& other);
19 bool_t& operator=(bool_t&& other);
20
21 // bitwise operations
22 bool_t operator&(const bool_t& other) const;
23 bool_t operator|(const bool_t& other) const;
24 bool_t operator^(const bool_t& other) const;
25 bool_t operator!() const;
26
27 // equality checks
28 bool_t operator==(const bool_t& other) const;
29
30 bool_t operator!=(const bool_t& other) const;
31
32 // misc bool ops
33 bool_t operator~() const { return operator!(); }
34
35 bool_t operator&&(const bool_t& other) const;
36
37 bool_t operator||(const bool_t& other) const;
38
39 bool_t implies(const bool_t& other) const;
40
41 bool_t implies_both_ways(const bool_t& other) const;
42
43 // self ops
44 void operator|=(const bool_t& other) { *this = operator|(other); }
45
46 void operator&=(const bool_t& other) { *this = operator&(other); }
47
48 void operator^=(const bool_t& other) { *this = operator^(other); }
49
50 // assertions
51 void assert_equal(const bool_t& rhs, std::string const& msg = "bool_t::assert_equal") const;
52
53 static bool_t conditional_assign(const bool_t<Builder>& predicate, const bool_t& lhs, const bool_t& rhs);
54
55 void must_imply(const bool_t& other, std::string const& msg = "bool_t::must_imply") const;
56
57 void must_imply(const std::vector<std::pair<bool_t, std::string>>& conds) const;
58
59 bool get_value() const { return witness_bool ^ witness_inverted; }
60
61 bool is_constant() const { return witness_index == IS_CONSTANT; }
62
63 bool_t normalize() const;
64
65 Builder* get_context() const { return context; }
66
67 mutable Builder* context = nullptr;
68 mutable bool witness_bool = false;
69 mutable bool witness_inverted = false;
70 mutable uint32_t witness_index = IS_CONSTANT;
71};
72
73template <typename T> inline std::ostream& operator<<(std::ostream& os, bool_t<T> const& v)
74{
75 return os << v.get_value();
76}
77
78EXTERN_STDLIB_TYPE(bool_t);
79
80} // namespace proof_system::plonk::stdlib
Definition: standard_circuit_builder.hpp:12
bool_t operator&(const bool_t &other) const
Definition: bool.cpp:104
void must_imply(const bool_t &other, std::string const &msg="bool_t::must_imply") const
Definition: bool.cpp:447
Definition: witness.hpp:10