9#include "../circuit_builders/circuit_builders.hpp"
23template <
typename Builder>
25 : raw_entries(table_entries)
26 , length(raw_entries.size())
34 for (
size_t i = 0; i <
length; ++i) {
47template <
typename Builder>
49 : raw_entries(table_entries)
50 , length(raw_entries.size())
53 for (
const auto& entry : table_entries) {
54 if (entry.get_context() !=
nullptr) {
67 for (
size_t i = 0; i <
length; ++i) {
87 for (
const auto& entry : raw_entries) {
88 if (entry.is_constant()) {
91 fixed_witness.set_origin_tag(entry.get_origin_tag());
92 entries.emplace_back(fixed_witness);
95 entries.emplace_back(entry);
98 rom_id =
context->create_ROM_array(length);
100 for (
size_t i = 0; i < length; ++i) {
101 context->set_ROM_element(rom_id, i, entries[i].get_witness_index());
105 _tags.resize(raw_entries.size());
106 for (
size_t i = 0; i < length; ++i) {
107 _tags[i] = raw_entries[i].get_origin_tag();
114template <
typename Builder>
116 : raw_entries(
std::move(other.raw_entries))
119 , length(other.length)
120 , rom_id(other.rom_id)
121 , initialized(other.initialized)
126 other.initialized =
false;
127 other.context =
nullptr;
134 if (
this != &other) {
135 raw_entries =
std::move(other.raw_entries);
138 length = other.length;
139 rom_id = other.rom_id;
140 initialized = other.initialized;
145 other.initialized =
false;
146 other.context =
nullptr;
153 if (
index >= length) {
155 context->failure(
"rom_table: ROM array access out of bounds");
156 return raw_entries[0];
159 return raw_entries[
index];
169 "rom_table: Performing a read operation without providing a context. We cannot initialize the table.");
175 if (
index.is_constant()) {
180 if (native_index >= length) {
182 context->failure(
"rom_table: ROM array access out of bounds");
186 uint32_t output_idx =
context->read_ROM_array(rom_id,
index.get_witness_index());
189 const size_t cast_index =
static_cast<size_t>(
static_cast<uint64_t
>(native_index));
192 if (native_index < length) {
193 element.set_origin_tag(_tags[cast_index]);
#define BB_ASSERT(expression,...)
#define BB_ASSERT_NEQ(actual, expected,...)
static field_t from_witness_index(Builder *ctx, uint32_t witness_index)
Builder * get_context() const
std::vector< OriginTag > _tags
void initialize_table() const
Initialize the table once we perform a read.
rom_table & operator=(const rom_table &other)
std::vector< field_pt > raw_entries
field_pt operator[](const size_t index) const
StrictMock< MockContext > context
std::conditional_t< IsGoblinBigGroup< C, Fq, Fr, G >, element_goblin::goblin_element< C, goblin_field< C >, Fr, G >, element_default::element< C, Fq, Fr, G > > element
element wraps either element_default::element or element_goblin::goblin_element depending on parametr...
Entry point for Barretenberg command-line interface.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept