barretenberg
Loading...
Searching...
No Matches
arithmetization.hpp
1#pragma once
2#include "barretenberg/ecc/curves/bn254/bn254.hpp"
3#include <array>
4#include <barretenberg/common/slab_allocator.hpp>
5#include <cstddef>
6#include <vector>
7
8namespace arithmetization {
9
33// These are not magic numbers and they should not be written with global constants. These parameters are not accessible
34// through clearly named static class members.
35template <typename FF_> class Standard {
36 public:
37 static constexpr size_t NUM_WIRES = 3;
38 static constexpr size_t NUM_SELECTORS = 5;
39 using FF = FF_;
40 using SelectorType = std::vector<FF, barretenberg::ContainerSlabAllocator<FF>>;
41
42 std::vector<SelectorType> selectors;
43
44 SelectorType& q_m() { return selectors[0]; };
45 SelectorType& q_1() { return selectors[1]; };
46 SelectorType& q_2() { return selectors[2]; };
47 SelectorType& q_3() { return selectors[3]; };
48 SelectorType& q_c() { return selectors[4]; };
49
50 const SelectorType& q_m() const { return selectors[0]; };
51 const SelectorType& q_1() const { return selectors[1]; };
52 const SelectorType& q_2() const { return selectors[2]; };
53 const SelectorType& q_3() const { return selectors[3]; };
54 const SelectorType& q_c() const { return selectors[4]; };
55
56 Standard()
57 : selectors(NUM_SELECTORS)
58 {}
59
60 const auto& get() const { return selectors; };
61
62 void reserve(size_t size_hint)
63 {
64 for (auto& p : selectors) {
65 p.reserve(size_hint);
66 }
67 }
68
69 // Note: These are needed for Plonk only (for poly storage in a std::map). Must be in same order as above struct.
70 inline static const std::vector<std::string> selector_names = { "q_m", "q_1", "q_2", "q_3", "q_c" };
71};
72
73template <typename FF_> class Ultra {
74 public:
75 static constexpr size_t NUM_WIRES = 4;
76 static constexpr size_t NUM_SELECTORS = 11;
77 using FF = FF_;
78 using SelectorType = std::vector<FF, barretenberg::ContainerSlabAllocator<FF>>;
79
80 private:
81 std::array<SelectorType, NUM_SELECTORS> selectors;
82
83 public:
84 SelectorType& q_m() { return selectors[0]; };
85 SelectorType& q_c() { return selectors[1]; };
86 SelectorType& q_1() { return selectors[2]; };
87 SelectorType& q_2() { return selectors[3]; };
88 SelectorType& q_3() { return selectors[4]; };
89 SelectorType& q_4() { return selectors[5]; };
90 SelectorType& q_arith() { return selectors[6]; };
91 SelectorType& q_sort() { return selectors[7]; };
92 SelectorType& q_elliptic() { return selectors[8]; };
93 SelectorType& q_aux() { return selectors[9]; };
94 SelectorType& q_lookup_type() { return selectors[10]; };
95
96 const SelectorType& q_m() const { return selectors[0]; };
97 const SelectorType& q_c() const { return selectors[1]; };
98 const SelectorType& q_1() const { return selectors[2]; };
99 const SelectorType& q_2() const { return selectors[3]; };
100 const SelectorType& q_3() const { return selectors[4]; };
101 const SelectorType& q_4() const { return selectors[5]; };
102 const SelectorType& q_arith() const { return selectors[6]; };
103 const SelectorType& q_sort() const { return selectors[7]; };
104 const SelectorType& q_elliptic() const { return selectors[8]; };
105 const SelectorType& q_aux() const { return selectors[9]; };
106 const SelectorType& q_lookup_type() const { return selectors[10]; };
107
108 const auto& get() const { return selectors; };
109
110 void reserve(size_t size_hint)
111 {
112 for (auto& vec : selectors) {
113 vec.reserve(size_hint);
114 }
115 }
116
123
124 // Note: These are needed for Plonk only (for poly storage in a std::map). Must be in same order as above struct.
125 inline static const std::vector<std::string> selector_names = { "q_m", "q_c", "q_1", "q_2",
126 "q_3", "q_4", "q_arith", "q_sort",
127 "q_elliptic", "q_aux", "table_type" };
128};
129
136template <typename FF_> class UltraHonk {
137 public:
138 static constexpr size_t NUM_WIRES = 4;
139 static constexpr size_t NUM_SELECTORS = 14;
140 using FF = FF_;
141 using SelectorType = std::vector<FF, barretenberg::ContainerSlabAllocator<FF>>;
142
143 private:
144 std::array<SelectorType, NUM_SELECTORS> selectors;
145
146 public:
147 SelectorType& q_m() { return selectors[0]; };
148 SelectorType& q_c() { return selectors[1]; };
149 SelectorType& q_1() { return selectors[2]; };
150 SelectorType& q_2() { return selectors[3]; };
151 SelectorType& q_3() { return selectors[4]; };
152 SelectorType& q_4() { return selectors[5]; };
153 SelectorType& q_arith() { return selectors[6]; };
154 SelectorType& q_sort() { return selectors[7]; };
155 SelectorType& q_elliptic() { return selectors[8]; };
156 SelectorType& q_aux() { return selectors[9]; };
157 SelectorType& q_lookup_type() { return selectors[10]; };
158 SelectorType& q_busread() { return selectors[11]; };
159 SelectorType& q_poseidon2_external() { return this->selectors[12]; };
160 SelectorType& q_poseidon2_internal() { return this->selectors[13]; };
161
162 const SelectorType& q_m() const { return selectors[0]; };
163 const SelectorType& q_c() const { return selectors[1]; };
164 const SelectorType& q_1() const { return selectors[2]; };
165 const SelectorType& q_2() const { return selectors[3]; };
166 const SelectorType& q_3() const { return selectors[4]; };
167 const SelectorType& q_4() const { return selectors[5]; };
168 const SelectorType& q_arith() const { return selectors[6]; };
169 const SelectorType& q_sort() const { return selectors[7]; };
170 const SelectorType& q_elliptic() const { return selectors[8]; };
171 const SelectorType& q_aux() const { return selectors[9]; };
172 const SelectorType& q_lookup_type() const { return selectors[10]; };
173 const SelectorType& q_busread() const { return selectors[11]; };
174 const SelectorType& q_poseidon2_external() const { return this->selectors[12]; };
175 const SelectorType& q_poseidon2_internal() const { return this->selectors[13]; };
176
177 const auto& get() const { return selectors; };
178
179 void reserve(size_t size_hint)
180 {
181 for (auto& vec : selectors) {
182 vec.reserve(size_hint);
183 }
184 }
185
193 {
194 q_busread().emplace_back(0);
195 q_poseidon2_external().emplace_back(0);
196 q_poseidon2_internal().emplace_back(0);
197 };
198
199 // Note: Unused. Needed only for consistency with Ultra arith (which is used by Plonk)
200 inline static const std::vector<std::string> selector_names = {};
201};
202
204 public:
205 static constexpr size_t NUM_WIRES = 81;
206 static constexpr size_t NUM_SELECTORS = 0;
207};
208} // namespace arithmetization
Definition: arithmetization.hpp:203
Specify the structure of a CircuitBuilder.
Definition: arithmetization.hpp:35
Ultra Honk arithmetization.
Definition: arithmetization.hpp:136
void pad_additional()
Add zeros to all selectors which are not part of the conventional Ultra arithmetization.
Definition: arithmetization.hpp:192
Definition: arithmetization.hpp:73
void pad_additional()
Add zeros to all selectors which are not part of the conventional Ultra arithmetization.
Definition: arithmetization.hpp:122