9#include "../circuit_builders/circuit_builders.hpp"
16template <
typename Builder>
21template <
typename Builder>
33template <
typename Builder>
36 , values(input.size())
39 for (
size_t i = 0; i < input.size(); ++i) {
42 value.create_range_constraint(8,
"byte_array: vector entry larger than 1 byte.");
45 set_free_witness_tag();
53template <
typename Builder>
55 :
byte_array(parent_context,
std::vector<uint8_t>(input.begin(), input.end()))
103template <
typename Builder>
105 const size_t num_bytes,
110 static constexpr size_t max_num_bytes = 32;
111 static constexpr size_t midpoint = max_num_bytes / 2;
118 values.resize(num_bytes);
127 for (
size_t i = 0; i < num_bytes; ++i) {
129 size_t bit_start = (num_bytes - i - 1) * 8;
130 size_t bit_end = bit_start + 8;
131 const field_t scaling_factor = one << bit_start;
138 byte.create_range_constraint(8,
"byte_array: byte extraction failed.");
142 accumulator_hi.push_back(scaling_factor *
byte);
144 accumulator_lo.push_back(scaling_factor *
byte);
151 const field_t reconstructed = reconstructed_hi + reconstructed_lo;
157 if (num_bytes == 32) {
166 const field_t diff_lo = -reconstructed_lo + s_lo + shift;
170 const uint256_t diff_lo_hi_value = (diff_lo_value >> 128);
177 const uint256_t lo = diff_lo_value & lo_mask;
185 const field_t overlap = -diff_lo_hi + 1;
187 const field_t diff_hi = (-reconstructed_hi / shift).add_two(s_hi, -overlap);
191 set_origin_tag(input.
tag);
194template <
typename Builder>
200template <
typename Builder>
206template <
typename Builder>
213template <
typename Builder>
216 , values(
std::move(other.values))
241 const size_t bytes = values.size();
246 for (
size_t i = 0; i < bytes; ++i) {
248 scaled_values.push_back(values[i] * scaling_factor);
258 values.insert(values.end(), other.
bytes().begin(), other.
bytes().end());
269 for (
size_t i = 0; i < other.
values.size(); i++) {
270 values[i + index] = other.
values[i];
293 auto start = values.begin() +
static_cast<ptrdiff_t
>(
offset);
294 auto end = values.begin() +
static_cast<ptrdiff_t
>((
offset +
length));
304 size_t offset = bytes.size() - 1;
305 for (
size_t i = 0; i < bytes.size(); i += 1,
offset -= 1) {
306 bytes[
offset] = values[i];
317 const size_t length = values.size();
318 std::vector<uint8_t> bytes(
length, 0);
319 for (
size_t i = 0; i <
length; ++i) {
320 bytes[i] =
static_cast<uint8_t
>(values[i].get_value());
331 auto v = get_value();
332 return std::string(v.begin(), v.end());
#define BB_ASSERT_LTE(left, right,...)
#define BB_ASSERT_LT(left, right,...)
#define ASSERT(expression,...)
constexpr uint256_t slice(uint64_t start, uint64_t end) const
Represents a dynamic array of bytes in-circuit.
byte_array slice(size_t offset) const
Slice bytes from the byte array starting at offset. Does not add any constraints.
byte_array(Builder *parent_context=nullptr)
byte_array reverse() const
Reverse the bytes in the byte array.
byte_array & write_at(byte_array const &other, size_t index)
Overwrites this byte_array starting at index with the contents of other. Asserts that the write does ...
byte_array & write(byte_array const &other)
Appends the contents of another byte_array (other) to the end of this one.
byte_array & operator=(const byte_array &other)
std::vector< uint8_t > get_value() const
A helper converting a byte_array into the vector of its uint8_t values.
bytes_t const & bytes() const
std::string get_string() const
Given a byte_array, compute a vector containing the values of its entries and convert it to a string.
typename std::vector< field_t< Builder > > bytes_t
void assert_equal(const field_t &rhs, std::string const &msg="field_t::assert_equal") const
Copy constraint: constrain that *this field is equal to rhs element.
static field_t accumulate(const std::vector< field_t > &input)
Efficiently compute the sum of vector entries. Using big_add_gate we reduce the number of gates neede...
void create_range_constraint(size_t num_bits, std::string const &msg="field_t::range_constraint") const
Let x = *this.normalize(), constrain x.v < 2^{num_bits}.
Builder * get_context() const
bb::fr get_value() const
Given a := *this, compute its value given by a.v * a.mul + a.add.
StrictMock< MockContext > context
uint8_t const size_t length
Entry point for Barretenberg command-line interface.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static constexpr uint256_t modulus