2#include "../circuit_builders/circuit_builders_fwd.hpp"
3#include "../witness/witness.hpp"
4#include "barretenberg/common/assert.hpp"
7namespace proof_system::plonk::stdlib {
9template <
typename Builder>
class bool_t;
10template <
typename Builder>
class field_t {
26 field_t(
const unsigned long long value)
34 field_t(
const unsigned int value)
43 field_t(
const unsigned long value)
68 : context(other.context)
70 , multiplicative_constant(other.multiplicative_constant)
75 : context(other.context)
77 , multiplicative_constant(other.multiplicative_constant)
85 static constexpr bool is_composite =
false;
86 static constexpr uint256_t modulus = barretenberg::fr::modulus;
98 multiplicative_constant = other.multiplicative_constant;
100 context = (other.context ==
nullptr ? nullptr : other.context);
107 multiplicative_constant = other.multiplicative_constant;
109 context = (other.context ==
nullptr ? nullptr : other.context);
116 result.assert_equal(other,
"field_t::copy_as_new_witness, assert_equal");
133 *
this = *
this + other;
138 *
this = *
this - other;
143 *
this = *
this * other;
148 *
this = *
this / other;
165 return this_before_operation;
170 static field_t coset_generator(
const size_t generator_idx)
172 return field_t(barretenberg::fr::coset_generator(generator_idx));
175 static field_t external_coset_generator() {
return field_t(barretenberg::fr::external_coset_generator()); }
180 result.multiplicative_constant = -multiplicative_constant;
188 void assert_equal(
const field_t& rhs, std::string
const& msg =
"field_t::assert_equal")
const;
190 void assert_not_equal(
const field_t& rhs, std::string
const& msg =
"field_t::assert_not_equal")
const;
192 void assert_is_in_set(
const std::vector<field_t>& set, std::string
const& msg =
"field_t::assert_not_in_set")
const;
196 static std::array<field_t, 4> preprocess_two_bit_table(
const field_t& T0,
200 static field_t select_from_two_bit_table(
const std::array<field_t, 4>& table,
204 static std::array<field_t, 8> preprocess_three_bit_table(
const field_t& T0,
212 static field_t select_from_three_bit_table(
const std::array<field_t, 8>& table,
250 Builder* get_context()
const {
return context; }
256 std::array<field_t, 3>
slice(uint8_t msb, uint8_t lsb)
const;
264 void create_range_constraint(
size_t num_bits, std::string
const& msg =
"field_t::range_constraint")
const;
265 void assert_is_not_zero(std::string
const& msg =
"field_t::assert_is_not_zero")
const;
266 void assert_is_zero(std::string
const& msg =
"field_t::assert_is_zero")
const;
267 bool is_constant()
const {
return witness_index == IS_CONSTANT; }
293 auto context = get_context();
294 ASSERT(context !=
nullptr);
301 size_t num_bits = 256,
320 const auto& a = (*this);
321 const auto& b = other;
322 auto* ctx = a.context ? a.context : b.context;
323 if (a.is_constant() && b.is_constant()) {
337 field_t predicate_valid = b.add_two(-(a) + range_constant - 1, -
field_t(predicate) * range_constant);
338 predicate_valid.create_range_constraint(num_bits);
342 mutable Builder* context =
nullptr;
426template <
typename Builder>
inline std::ostream& operator<<(std::ostream& os,
field_t<Builder> const& v)
428 return os << v.get_value();
Definition: uint256.hpp:25
virtual void set_public_input(const uint32_t witness_index)
Definition: circuit_builder_base.hpp:290
Definition: standard_circuit_builder.hpp:12
field_t operator*(const field_t &other) const
Definition: field.cpp:141
std::array< field_t, 3 > slice(uint8_t msb, uint8_t lsb) const
Definition: field.cpp:1033
static field_t accumulate(const std::vector< field_t > &to_add)
Definition: field.cpp:936
barretenberg::fr additive_constant
Definition: field.hpp:379
uint32_t witness_index
Definition: field.hpp:423
std::vector< bool_t< Builder > > decompose_into_bits(size_t num_bits=256, std::function< witness_t< Builder >(Builder *ctx, uint64_t, uint256_t)> get_bit=[](Builder *ctx, uint64_t j, const uint256_t &val) { return witness_t< Builder >(ctx, val.get_bit(j));}) const
Build a circuit allowing a user to prove that they have deomposed this into bits.
Definition: field.cpp:1090
void fix_witness()
Definition: field.hpp:290
void convert_constant_to_fixed_witness(Builder *ctx)
Definition: field.hpp:274
bool_t< Builder > ranged_less_than(const field_t< Builder > &other) const
Return (a < b) as bool circuit type. This method assumes that both a and b are < 2^{input_bits} - 1 i...
Definition: field.hpp:318
field_t normalize() const
Definition: field.cpp:482
void assert_equal(const field_t &rhs, std::string const &msg="field_t::assert_equal") const
Constrain that this field is equal to the given field.
Definition: field.cpp:749
bool_t< Builder > is_zero() const
Definition: field.cpp:588
field_t madd(const field_t &to_mul, const field_t &to_add) const
Definition: field.cpp:384
field_t pow(const field_t &exponent) const
raise a field_t to a power of an exponent (field_t). Note that the exponent must not exceed 32 bits a...
Definition: field.cpp:346
Definition: witness.hpp:10