Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
twin_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// Each entry contains a pair of values
16// N.B. Only works with the UltraBuilder at the moment!
17template <typename Builder> class twin_rom_table {
18 private:
21
22 public:
24 twin_rom_table(const std::vector<field_pair_pt>& table_entries);
25 twin_rom_table(const twin_rom_table& other);
27
28 void initialize_table() const;
29
32
33 // read from table with a constant index value. Does not add any gates
34 field_pair_pt operator[](const size_t index) const;
35
36 // read from table with a witness index value. Adds 2 gates
37 field_pair_pt operator[](const field_pt& index) const;
38
39 size_t size() const { return length; }
40
41 Builder* get_context() const { return context; }
42
43 private:
44 std::vector<field_pair_pt> raw_entries;
45 mutable std::vector<field_pair_pt> entries;
46
47 // Origin Tags used for tracking dangerous interactions in stdlib primtives
49 size_t length = 0;
50 mutable size_t rom_id = 0; // Builder identifier for this ROM table
51 mutable bool initialized = false;
52 mutable Builder* context = nullptr;
53};
54} // namespace bb::stdlib
std::vector< field_pair_pt > entries
field_pair_pt operator[](const size_t index) const
std::vector< std::array< OriginTag, 2 > > tags
field_t< Builder > field_pt
twin_rom_table & operator=(const twin_rom_table &other)
Builder * get_context() const
twin_rom_table(const std::vector< field_pair_pt > &table_entries)
std::array< field_pt, 2 > field_pair_pt
std::vector< field_pair_pt > raw_entries
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...