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-only memory table. Table entries must be initialized in the constructor.
15// N.B. Only works with the UltraBuilder at the moment!
16template <typename Builder> class ram_table {
17 private:
19
20 public:
22 ram_table(Builder* builder, const size_t table_size);
23 ram_table(const std::vector<field_pt>& table_entries);
24 ram_table(const ram_table& other);
25 ram_table(ram_table&& other);
26
27 void initialize_table() const;
28
29 ram_table& operator=(const ram_table& other);
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 init = true;
49 for (auto i : _index_initialized) {
50 init = init && i;
51 }
54 }
55
56 private:
58 // Origin Tags for detection of dangerous interactions within stdlib primitives
60 mutable std::vector<bool> _index_initialized;
61 size_t _length = 0;
62 mutable size_t _ram_id = 0; // Builder identifier for this ROM table
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)
Copy assignment operator.
std::vector< bool > _index_initialized
Definition ram_table.hpp:60
bool _ram_table_generated_in_builder
Definition ram_table.hpp:63
field_pt read(const field_pt &index) const
Read a field element from the RAM table at an index value.
Builder * get_context() const
Definition ram_table.hpp:38
std::vector< field_pt > _raw_entries
Definition ram_table.hpp:57
bool _all_entries_written_to_with_constant_index
Definition ram_table.hpp:64
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:82
AluTraceBuilder builder
Definition alu.test.cpp:123
const auto init
Definition fr.bench.cpp:141
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...