barretenberg
Loading...
Searching...
No Matches
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// N.B. Only works with the UltraPlonkBuilder at the moment!
10template <typename Builder> class rom_table {
11 private:
13
14 public:
15 rom_table(){};
16 rom_table(const std::vector<field_pt>& table_entries);
17 rom_table(const rom_table& other);
18 rom_table(rom_table&& other);
19
20 void initialize_table() const;
21
22 rom_table& operator=(const rom_table& other);
23 rom_table& operator=(rom_table&& other);
24
25 // read from table with a constant index value. Does not add any gates
26 field_pt operator[](const size_t index) const;
27
28 // read from table with a witness index value. Adds 2 gates
29 field_pt operator[](const field_pt& index) const;
30
31 size_t size() const { return length; }
32
33 Builder* get_context() const { return context; }
34
35 private:
36 std::vector<field_pt> raw_entries;
37 mutable std::vector<field_pt> entries;
38 size_t length = 0;
39 mutable size_t rom_id = 0; // Builder identifier for this ROM table
40 mutable bool initialized = false;
41 mutable Builder* context = nullptr;
42};
43
44EXTERN_STDLIB_ULTRA_TYPE(rom_table);
45
46} // namespace stdlib
47} // namespace proof_system::plonk
Definition: standard_circuit_builder.hpp:12
Definition: field.hpp:10
Definition: rom_table.hpp:10
Definition: widget.bench.cpp:13