8#include "../circuit_builders/circuit_builders.hpp"
19template <
typename Builder>
27template <
typename Builder>
36template <
typename Builder>
41 "bool_t: witness value is not 0 or 1");
52template <
typename Builder>
61template <
typename Builder>
64 , witness_bool(other.witness_bool)
65 , witness_inverted(other.witness_inverted)
66 , witness_index(other.witness_index)
73template <
typename Builder>
76 , witness_bool(other.witness_bool)
77 , witness_inverted(other.witness_inverted)
78 , witness_index(other.witness_index)
88 witness_index = IS_CONSTANT;
90 witness_inverted =
false;
113 witness_index = other.witness_index;
114 witness_bool = other.witness_bool;
115 witness_inverted = other.witness_inverted;
129 witness_inverted =
false;
131 context->create_bool_gate(witness_index);
132 set_free_witness_tag();
142 bool left = witness_inverted ^ witness_bool;
179 int i_a(
static_cast<int>(witness_inverted));
182 fr q_m{ 1 - 2 * i_b - 2 * i_a + 4 * i_a * i_b };
183 fr q_l{ i_b * (1 - 2 * i_a) };
184 fr q_r{ i_a * (1 - 2 * i_b) };
190 }
else if (!is_constant() && other.
is_constant()) {
196 }
else if (is_constant() && !other.
is_constant()) {
197 ASSERT(!witness_inverted);
200 result = witness_bool ? other : *
this;
229 const int lhs_inverted =
static_cast<int>(witness_inverted);
231 bb::fr q_m{ -(1 - 2 * rhs_inverted) * (1 - 2 * lhs_inverted) };
232 bb::fr q_l{ (1 - 2 * lhs_inverted) * (1 - rhs_inverted) };
233 bb::fr q_r{ (1 - lhs_inverted) * (1 - 2 * rhs_inverted) };
235 bb::fr q_c{ rhs_inverted + lhs_inverted - rhs_inverted * lhs_inverted };
242 }
else if (!is_constant() && other.
is_constant()) {
249 }
else if (is_constant() && !other.
is_constant()) {
253 result = witness_bool ? *this : other;
282 const int lhs_inverted =
static_cast<int>(witness_inverted);
284 const int aux_prod = (1 - 2 * rhs_inverted) * (1 - 2 * lhs_inverted);
286 bb::fr q_m{ -2 * aux_prod };
290 bb::fr q_c{ lhs_inverted + rhs_inverted - 2 * rhs_inverted * lhs_inverted };
296 { witness_index, other.
witness_index, result.witness_index, q_m, q_l, q_r, q_o, q_c });
297 }
else if (!is_constant() && other.
is_constant()) {
302 }
else if (is_constant() && !other.
is_constant()) {
304 result = witness_bool ? !other : other;
316 ASSERT(!witness_inverted);
349 const int lhs_inverted =
static_cast<int>(witness_inverted);
351 const int aux_prod = (1 - 2 * rhs_inverted) * (1 - 2 * lhs_inverted);
352 bb::fr q_m{ 2 * aux_prod };
356 bb::fr q_c{ 1 - lhs_inverted - rhs_inverted + 2 * rhs_inverted * lhs_inverted };
361 }
else if (!is_constant() && (other.
is_constant())) {
366 }
else if (is_constant() && !other.
is_constant()) {
369 result = witness_bool ? other : !other;
380 return operator^(other);
385 return operator&(other);
390 return operator|(other);
407 ctx->assert_equal_constant(rhs.
witness_index, lhs_value, msg);
412 ctx->assert_equal_constant(lhs.
witness_index, rhs_value, msg);
428template <
typename Builder>
442 if (witness_same || const_same) {
445 return (predicate && lhs) || (!predicate && rhs);
454 return (!(*
this) || other);
470 return !((*this) ^ other);
481 ASSERT(!witness_inverted);
485 if (!witness_inverted) {
492 const bool value = witness_bool ^ witness_inverted;
496 const int inverted =
static_cast<int>(witness_inverted);
497 bb::fr q_l{ 1 - 2 * inverted };
502 context->create_poly_gate({ witness_index, witness_index, new_witness, q_m, q_l, q_r, q_o, q_c });
504 witness_index = new_witness;
505 witness_bool =
value;
506 witness_inverted =
false;
#define BB_ASSERT_EQ(actual, expected,...)
#define ASSERT(expression,...)
Implements boolean logic in-circuit.
void set_origin_tag(const OriginTag &new_tag) const
bool_t implies(const bool_t &other) const
Implements implication operator in circuit.
bool_t normalize() const
A bool_t element is normalized if witness_inverted == false. For a given *this, output its normalized...
bool_t operator&(const bool_t &other) const
Implements AND in circuit.
void set_free_witness_tag()
bool_t operator!() const
Implements negation in circuit.
static bool_t conditional_assign(const bool_t< Builder > &predicate, const bool_t &lhs, const bool_t &rhs)
Implements the ternary operator - if predicate == true then return lhs, else return rhs.
bool_t operator!=(const bool_t &other) const
Implements the not equal operator in circuit.
Builder * get_context() const
bool_t operator&&(const bool_t &other) const
bool_t(const bool value=false)
Construct a constant bool_t object from a bool value.
bool_t operator||(const bool_t &other) const
void must_imply(const bool_t &other, std::string const &msg="bool_t::must_imply") const
Constrains the (a => b) == true.
bool_t & operator=(const bool other)
Assigns a native bool to bool_t object.
void assert_equal(const bool_t &rhs, std::string const &msg="bool_t::assert_equal") const
Implements copy constraint for bool_t elements.
bool_t operator|(const bool_t &other) const
Implements OR in circuit.
bool_t implies_both_ways(const bool_t &other) const
Implements a "double-implication" (<=>), a.k.a "iff", a.k.a. "biconditional".
OriginTag get_origin_tag() const
bool_t operator^(const bool_t &other) const
Implements XOR in circuit.
bool_t operator==(const bool_t &other) const
Implements equality operator in circuit.
StrictMock< MockContext > context
Entry point for Barretenberg command-line interface.
This file contains part of the logic for the Origin Tag mechanism that tracks the use of in-circuit p...
static constexpr field neg_one()
static constexpr field one()
static constexpr field zero()