barretenberg
Loading...
Searching...
No Matches
twin_rom_table.hpp
1#pragma once
2#include "../circuit_builders/circuit_builders_fwd.hpp"
3#include "../field/field.hpp"
4
5namespace proof_system::plonk {
6namespace stdlib {
7
8// A runtime-defined read-only memory table. Table entries must be initialized in the constructor.
9// Each entry contains a pair of values
10// N.B. Only works with the UltraPlonkBuilder at the moment!
11template <typename Builder> class twin_rom_table {
12 private:
14 typedef std::array<field_pt, 2> field_pair_pt;
15
16 public:
18 twin_rom_table(const std::vector<field_pair_pt>& table_entries);
19 twin_rom_table(const twin_rom_table& other);
21
22 void initialize_table() const;
23
24 twin_rom_table& operator=(const twin_rom_table& other);
25 twin_rom_table& operator=(twin_rom_table&& other);
26
27 // read from table with a constant index value. Does not add any gates
28 field_pair_pt operator[](const size_t index) const;
29
30 // read from table with a witness index value. Adds 2 gates
31 field_pair_pt operator[](const field_pt& index) const;
32
33 size_t size() const { return length; }
34
35 Builder* get_context() const { return context; }
36
37 private:
38 std::vector<field_pair_pt> raw_entries;
39 mutable std::vector<field_pair_pt> entries;
40 size_t length = 0;
41 mutable size_t rom_id = 0; // Builder identifier for this ROM table
42 mutable bool initialized = false;
43 mutable Builder* context = nullptr;
44};
45
46EXTERN_STDLIB_ULTRA_TYPE(twin_rom_table);
47
48} // namespace stdlib
49} // namespace proof_system::plonk
Definition: standard_circuit_builder.hpp:12
Definition: field.hpp:10
Definition: twin_rom_table.hpp:11
Definition: widget.bench.cpp:13