Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ram_table.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8#include "../circuit_builders/circuit_builders_fwd.hpp"
9#include "../field/field.hpp"
11
12namespace bb::stdlib {
13
14// A runtime-defined read-write memory table. Table entries must be initialized in the constructor.
15// Works with UltraBuilder and MegaBuilder.
16template <IsUltraOrMegaBuilder Builder> class ram_table {
17 private:
19
20 public:
22 ram_table(Builder* builder, const std::vector<field_pt>& table_entries);
23 ram_table(const std::vector<field_pt>& table_entries);
24 ram_table(const ram_table& other);
26
27 void initialize_table() const;
28
31
32 field_pt read(const field_pt& index) const;
33
34 void write(const field_pt& index, const field_pt& value);
35
36 size_t size() const { return length; }
37
38 Builder* get_context() const { return context; }
39
41 {
43 return true;
44 }
45 if (length == 0) {
46 return false;
47 }
48 bool all_initialized = true;
49 for (auto idx_init : index_initialized) {
50 all_initialized = all_initialized && idx_init;
51 }
54 }
55
56 private:
58 // Origin Tags for detection of dangerous interactions within stdlib primitives
60 mutable std::vector<bool> index_initialized; // Keeps track if the indicies of the RAM table have been initialized
61 size_t length = 0;
62 mutable size_t ram_id = 0; // Identifier of this ROM table for the builder
63 mutable bool ram_table_generated_in_builder = false;
65 mutable Builder* context = nullptr;
66};
67} // namespace bb::stdlib
ram_table & operator=(const ram_table &other)
std::vector< bool > index_initialized
Definition ram_table.hpp:60
ram_table & operator=(ram_table &&other)
field_pt read(const field_pt &index) const
Read a field element from the RAM table at an index value.
std::vector< field_pt > raw_entries
Definition ram_table.hpp:57
Builder * get_context() const
Definition ram_table.hpp:38
ram_table(const ram_table &other)
std::vector< OriginTag > _tags
Definition ram_table.hpp:59
size_t size() const
Definition ram_table.hpp:36
bool check_indices_initialized() const
Definition ram_table.hpp:40
field_t< Builder > field_pt
Definition ram_table.hpp:18
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.
Definition ram_table.cpp:83
bool ram_table_generated_in_builder
Definition ram_table.hpp:63
bool all_entries_written_to_with_constant_index
Definition ram_table.hpp:64
ram_table(ram_table &&other)
AluTraceBuilder builder
Definition alu.test.cpp:124
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
This file contains part of the logic for the Origin Tag mechanism that tracks the use of in-circuit p...