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: Complete, auditors: [Raju], commit: 05a381f8b31ae4648e480f1369e911b148216e8b}
3// external_1: { status: Complete, auditors: [Sherlock], commit: e6694849223 }
4// external_2: { status: not started, auditors: [], commit: }
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.
15template <typename Builder> class ram_table {
16 private:
18
19 public:
21 ram_table(Builder* builder, const std::vector<field_pt>& table_entries);
22 ram_table(const std::vector<field_pt>& table_entries);
23 ram_table(const ram_table& other);
24 ram_table(ram_table&& other) noexcept;
25
26 void initialize_table() const;
27
29 ram_table& operator=(ram_table&& other) noexcept;
30
31 field_pt read(const field_pt& index) const;
32
33 void write(const field_pt& index, const field_pt& value);
34
35 size_t size() const { return length; }
36
37 Builder* get_context() const { return context; }
38
40 {
42 return true;
43 }
44 if (length == 0) {
45 return false;
46 }
47 bool all_initialized = true;
48 for (auto idx_init : index_initialized) {
49 all_initialized = all_initialized && idx_init;
50 }
53 }
54
55 private:
57 // Origin Tags for detection of dangerous interactions within stdlib primitives
59 mutable std::vector<bool> index_initialized; // Keeps track if the indicies of the RAM table have been initialized
60 size_t length = 0;
61 mutable size_t ram_id = 0; // Identifier of this ROM table for the builder
62 mutable bool ram_table_generated_in_builder = false;
64 mutable Builder* context = nullptr;
65};
66} // namespace bb::stdlib
ram_table & operator=(const ram_table &other)
std::vector< bool > index_initialized
Definition ram_table.hpp:59
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:56
Builder * get_context() const
Definition ram_table.hpp:37
ram_table(const ram_table &other)
std::vector< OriginTag > _tags
Definition ram_table.hpp:58
size_t size() const
Definition ram_table.hpp:35
bool check_indices_initialized() const
Definition ram_table.hpp:39
field_t< Builder > field_pt
Definition ram_table.hpp:17
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:62
bool all_entries_written_to_with_constant_index
Definition ram_table.hpp:63
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...