Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
rom_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// Works with UltraBuilder and MegaBuilder.
16template <IsUltraOrMegaBuilder Builder> class rom_table {
17 private:
19
20 public:
22 rom_table(const std::vector<field_pt>& table_entries);
23 rom_table(Builder* builder, const std::vector<field_pt>& table_entries);
24 rom_table(const rom_table& other);
26
27 void initialize_table() const;
28
31
32 // read from table with a constant index value. Does not add any gates
33 field_pt operator[](const size_t index) const;
34
35 // read from table with a witness index value. Adds 2 gates
36 field_pt operator[](const field_pt& index) const;
37
38 size_t size() const { return length; }
39
40 Builder* get_context() const { return context; }
41
42 private:
43 std::vector<field_pt> raw_entries; // the entries of the ROM table
44 mutable std::vector<field_pt> entries; // processed version of `raw_entries`, where circuit constants are explicitly
45 // turned into constant witnesses.
46 // Origin Tags for detecting problematic interactions of stdlib primitives
48 size_t length = 0;
49 mutable size_t rom_id = 0; // Identifier of this ROM table for the builder.
50 mutable bool initialized = false;
51 mutable Builder* context = nullptr;
52};
53} // namespace bb::stdlib
rom_table(const rom_table &other)
std::vector< field_pt > entries
Definition rom_table.hpp:44
std::vector< OriginTag > _tags
Definition rom_table.hpp:47
size_t size() const
Definition rom_table.hpp:38
rom_table & operator=(rom_table &&other)
rom_table(rom_table &&other)
void initialize_table() const
Initialize the table once we perform a read.
Definition rom_table.cpp:80
rom_table & operator=(const rom_table &other)
std::vector< field_pt > raw_entries
Definition rom_table.hpp:43
Builder * get_context() const
Definition rom_table.hpp:40
field_pt operator[](const size_t index) const
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...