9#include "../circuit_builders/circuit_builders.hpp"
23template <
typename Builder>
25 : raw_entries(table_entries)
26 ,
length(table_entries.size())
36 for (
size_t i = 0; i <
length; i++) {
37 _tags[i] = table_entries[i].get_origin_tag();
48template <
typename Builder>
50 : raw_entries(table_entries)
51 ,
length(raw_entries.size())
53 for (
const auto& entry : table_entries) {
54 if (entry.get_context() !=
nullptr) {
69 for (
size_t i = 0; i <
length; i++) {
70 _tags[i] = table_entries[i].get_origin_tag();
85 if (ram_table_generated_in_builder) {
92 if (raw_entries.size() > 0) {
93 for (
size_t i = 0; i <
length; ++i) {
94 if (!index_initialized[i]) {
96 if (raw_entries[i].is_constant()) {
98 context->put_constant_variable(raw_entries[i].get_value()));
100 entry = raw_entries[i];
103 index_initialized[i] =
true;
110 if (raw_entries.size() > 0) {
111 for (
size_t i = 0; i <
length; i++) {
115 ram_table_generated_in_builder =
true;
120template <
typename Builder>
122 : raw_entries(
std::move(other.raw_entries))
124 , index_initialized(
std::move(other.index_initialized))
126 , ram_id(other.ram_id)
127 , ram_table_generated_in_builder(other.ram_table_generated_in_builder)
128 , all_entries_written_to_with_constant_index(other.all_entries_written_to_with_constant_index)
133 other.ram_table_generated_in_builder =
false;
134 other.all_entries_written_to_with_constant_index =
false;
135 other.context =
nullptr;
142 if (
this != &other) {
143 raw_entries =
std::move(other.raw_entries);
145 index_initialized =
std::move(other.index_initialized);
147 ram_id = other.ram_id;
148 ram_table_generated_in_builder = other.ram_table_generated_in_builder;
149 all_entries_written_to_with_constant_index = other.all_entries_written_to_with_constant_index;
154 other.ram_table_generated_in_builder =
false;
155 other.all_entries_written_to_with_constant_index =
false;
156 other.context =
nullptr;
175 "ram_table: Performing a read operation without providing a context. We cannot initialize the table.");
182 if (native_index >=
length) {
185 context->failure(
"ram_table: RAM array access out of bounds");
188 if (!check_indices_initialized()) {
189 context->failure(
"ram_table must have initialized every RAM entry before the table can be read");
193 if (
index.is_constant()) {
200 const size_t cast_index =
static_cast<size_t>(
static_cast<uint64_t
>(native_index));
202 if (native_index <
length) {
203 element.set_origin_tag(_tags[cast_index]);
224 "ram_table: Performing a write operation without providing a context. We cannot initialize the table.");
233 context->failure(
"ram_table: RAM array access out of bounds");
238 if (
index.is_constant()) {
243 if (!check_indices_initialized()) {
244 context->failure(
"ram_table must have initialized every RAM entry before a write can be performed");
249 auto native_value =
value.get_value();
250 if (
value.is_constant()) {
254 const size_t cast_index =
static_cast<size_t>(
static_cast<uint64_t
>(native_index));
255 if (
index.is_constant() && !index_initialized[cast_index]) {
258 index_initialized[cast_index] =
true;
264 if (native_index <
length) {
265 _tags[cast_index] =
value.get_origin_tag();
#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
OriginTag get_origin_tag() const
void convert_constant_to_fixed_witness(Builder *ctx)
uint32_t get_witness_index() const
Get the witness index of the current field element.
ram_table & operator=(const ram_table &other)
std::vector< bool > index_initialized
field_pt read(const field_pt &index) const
Read a field element from the RAM table at an index value.
std::vector< OriginTag > _tags
void write(const field_pt &index, const field_pt &value)
Write a field element from the RAM table at an index value.
void initialize_table() const
internal method, is used to call Builder methods that will generate RAM table.
StrictMock< MockContext > context
uint8_t const size_t length
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...
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
This file contains part of the logic for the Origin Tag mechanism that tracks the use of in-circuit p...