barretenberg
Loading...
Searching...
No Matches
polynomial_manifest.hpp
1#pragma once
2
3#include "barretenberg/proof_system/types/circuit_type.hpp"
4#include <array>
5#include <string>
6#include <vector>
7
8namespace proof_system::plonk {
9
10enum PolynomialSource { WITNESS, SELECTOR, PERMUTATION, OTHER };
11
12enum EvaluationType { NON_SHIFTED, SHIFTED };
13
14enum PolynomialIndex {
15 Q_1,
16 Q_2,
17 Q_3,
18 Q_4,
19 Q_5,
20 Q_M,
21 Q_C,
22 Q_ARITHMETIC,
23 Q_FIXED_BASE,
24 Q_RANGE,
25 Q_SORT,
26 TABLE_1,
27 TABLE_2,
28 TABLE_3,
29 TABLE_4,
30 TABLE_INDEX,
31 TABLE_TYPE,
32 Q_ELLIPTIC,
33 Q_AUX,
34 SIGMA_1,
35 SIGMA_2,
36 SIGMA_3,
37 SIGMA_4,
38 ID_1,
39 ID_2,
40 ID_3,
41 ID_4,
42 W_1,
43 W_2,
44 W_3,
45 W_4,
46 S,
47 Z,
48 Z_LOOKUP,
49 LAGRANGE_FIRST,
50 LAGRANGE_LAST,
51 // SUBGROUP_GENERATOR,
52 MAX_NUM_POLYNOMIALS,
53};
54
56 constexpr PolynomialDescriptor(std::string_view commitment_label_ = "",
57 std::string_view polynomial_label_ = "",
58 bool requires_shifted_evaluation_ = false,
59 PolynomialSource source_ = WITNESS,
60 PolynomialIndex index_ = Q_1)
61 : commitment_label(commitment_label_)
62 , polynomial_label(polynomial_label_)
63 , requires_shifted_evaluation(requires_shifted_evaluation_)
64 , source(source_)
65 , index(index_)
66 {}
67 constexpr PolynomialDescriptor(const PolynomialDescriptor& other)
68 : commitment_label(other.commitment_label)
69 , polynomial_label(other.polynomial_label)
70 , requires_shifted_evaluation(other.requires_shifted_evaluation)
71 , source(other.source)
72 , index(other.index)
73 {}
74 constexpr PolynomialDescriptor& operator=(const PolynomialDescriptor& other)
75 {
76 commitment_label = other.commitment_label;
77 polynomial_label = other.polynomial_label;
78 requires_shifted_evaluation = other.requires_shifted_evaluation;
79 source = other.source;
80 index = other.index;
81 return *this;
82 };
83
84 std::string_view commitment_label;
85 std::string_view polynomial_label;
86 bool requires_shifted_evaluation;
87 PolynomialSource source;
88 PolynomialIndex index;
89};
90
91static constexpr size_t STANDARD_MANIFEST_SIZE = 12;
92static constexpr PolynomialDescriptor standard_polynomial_manifest[STANDARD_MANIFEST_SIZE]{
93 PolynomialDescriptor("W_1", "w_1", false, WITNESS, W_1), //
94 PolynomialDescriptor("W_2", "w_2", false, WITNESS, W_2), //
95 PolynomialDescriptor("W_3", "w_3", false, WITNESS, W_3), //
96 PolynomialDescriptor("Z_PERM", "z_perm", true, WITNESS, Z), //
97 PolynomialDescriptor("Q_1", "q_1", false, SELECTOR, Q_1), //
98 PolynomialDescriptor("Q_2", "q_2", false, SELECTOR, Q_2), //
99 PolynomialDescriptor("Q_3", "q_3", false, SELECTOR, Q_3), //
100 PolynomialDescriptor("Q_M", "q_m", false, SELECTOR, Q_M), //
101 PolynomialDescriptor("Q_C", "q_c", false, SELECTOR, Q_C), //
102 PolynomialDescriptor("SIGMA_1", "sigma_1", false, PERMUTATION, SIGMA_1), //
103 PolynomialDescriptor("SIGMA_2", "sigma_2", false, PERMUTATION, SIGMA_2), //
104 PolynomialDescriptor("SIGMA_3", "sigma_3", false, PERMUTATION, SIGMA_3), //
105};
106
107static constexpr size_t ULTRA_MANIFEST_SIZE = 30;
108static constexpr PolynomialDescriptor ultra_polynomial_manifest[ULTRA_MANIFEST_SIZE]{
109 PolynomialDescriptor("W_1", "w_1", true, WITNESS, W_1), //
110 PolynomialDescriptor("W_2", "w_2", true, WITNESS, W_2), //
111 PolynomialDescriptor("W_3", "w_3", true, WITNESS, W_3), //
112 PolynomialDescriptor("W_4", "w_4", true, WITNESS, W_4), //
113 PolynomialDescriptor("S", "s", true, WITNESS, S), //
114 PolynomialDescriptor("Z_PERM", "z_perm", true, WITNESS, Z), //
115 PolynomialDescriptor("Z_LOOKUP", "z_lookup", true, WITNESS, Z_LOOKUP), //
116 PolynomialDescriptor("Q_1", "q_1", false, SELECTOR, Q_1), //
117 PolynomialDescriptor("Q_2", "q_2", false, SELECTOR, Q_2), //
118 PolynomialDescriptor("Q_3", "q_3", false, SELECTOR, Q_3), //
119 PolynomialDescriptor("Q_4", "q_4", false, SELECTOR, Q_4), //
120 PolynomialDescriptor("Q_M", "q_m", false, SELECTOR, Q_M), //
121 PolynomialDescriptor("Q_C", "q_c", false, SELECTOR, Q_C), //
122 PolynomialDescriptor("Q_ARITHMETIC", "q_arith", false, SELECTOR, Q_ARITHMETIC), //
123 PolynomialDescriptor("Q_SORT", "q_sort", false, SELECTOR, Q_SORT), //
124 PolynomialDescriptor("Q_ELLIPTIC", "q_elliptic", false, SELECTOR, Q_ELLIPTIC), //
125 PolynomialDescriptor("Q_AUX", "q_aux", false, SELECTOR, Q_AUX), //
126 PolynomialDescriptor("SIGMA_1", "sigma_1", false, PERMUTATION, SIGMA_1), //
127 PolynomialDescriptor("SIGMA_2", "sigma_2", false, PERMUTATION, SIGMA_2), //
128 PolynomialDescriptor("SIGMA_3", "sigma_3", false, PERMUTATION, SIGMA_3), //
129 PolynomialDescriptor("SIGMA_4", "sigma_4", false, PERMUTATION, SIGMA_4), //
130 PolynomialDescriptor("TABLE_1", "table_value_1", true, SELECTOR, TABLE_1), //
131 PolynomialDescriptor("TABLE_2", "table_value_2", true, SELECTOR, TABLE_2), //
132 PolynomialDescriptor("TABLE_3", "table_value_3", true, SELECTOR, TABLE_3), //
133 PolynomialDescriptor("TABLE_4", "table_value_4", true, SELECTOR, TABLE_4), //
134 PolynomialDescriptor("TABLE_TYPE", "table_type", false, SELECTOR, TABLE_TYPE), //
135 PolynomialDescriptor("ID_1", "id_1", false, PERMUTATION, ID_1), //
136 PolynomialDescriptor("ID_2", "id_2", false, PERMUTATION, ID_2), //
137 PolynomialDescriptor("ID_3", "id_3", false, PERMUTATION, ID_3), //
138 PolynomialDescriptor("ID_4", "id_4", false, PERMUTATION, ID_4), //
139};
140
141// Simple class allowing for access to a polynomial manifest based on composer type
143 // TODO(luke): make this object iterable, i.e. compatible with range-based for loop
144 private:
145 std::vector<PolynomialDescriptor> manifest;
146
147 public:
149
150 PolynomialManifest(CircuitType circuit_type)
151 {
152 switch (circuit_type) {
153 case CircuitType::STANDARD: {
154 std::copy(standard_polynomial_manifest,
155 standard_polynomial_manifest + STANDARD_MANIFEST_SIZE,
156 std::back_inserter(manifest));
157 break;
158 };
159 case CircuitType::ULTRA: {
160 std::copy(ultra_polynomial_manifest,
161 ultra_polynomial_manifest + ULTRA_MANIFEST_SIZE,
162 std::back_inserter(manifest));
163 break;
164 };
165 default: {
166 // TODO(luke): reinstate this. Was getting "use of undeclared identifier" error for 'throw_or_abort'.
167 // throw_or_abort("Received invalid composer type");
168 }
169 };
170 }
171
172 const std::vector<PolynomialDescriptor>& get() const { return manifest; };
173
174 size_t size() const { return manifest.size(); }
175
176 PolynomialDescriptor operator[](size_t index) const { return manifest[index]; }
177};
178
179// This class constructs and provides access to a full list of pre-computed
180// polynomial IDs based on the composer type. This is used, for example, for
181// serialization of the pre-computed portion of the proving key. The list is
182// comprised of IDs corresponding to: the selector polynomials (monomial and
183// coset fft forms) and the permutation polynomials (monomial, coset fft and
184// lagrange forms).
186
187 private:
188 std::vector<std::string> precomputed_poly_ids;
189
190 public:
191 // Upon construction, build the vector of precomputed poly ID strings based on the manifest
192 PrecomputedPolyList(CircuitType circuit_type)
193 {
194 PolynomialManifest manifest(circuit_type);
195
196 for (size_t i = 0; i < manifest.size(); ++i) {
197 std::string label = std::string(manifest[i].polynomial_label);
198 PolynomialSource source = manifest[i].source;
199
200 switch (source) {
201 case PolynomialSource::WITNESS: // no witness polys are precomputed
202 break;
203 case PolynomialSource::SELECTOR: // monomial and fft
204 precomputed_poly_ids.emplace_back(label);
205 precomputed_poly_ids.emplace_back(label + "_fft");
206 // Store all lagrange forms of selector polynomials for ultra
207 if (circuit_type == CircuitType::ULTRA) {
208 precomputed_poly_ids.emplace_back(label + "_lagrange");
209 }
210 break;
211 case PolynomialSource::PERMUTATION: // monomial, fft, and lagrange
212 precomputed_poly_ids.emplace_back(label);
213 precomputed_poly_ids.emplace_back(label + "_fft");
214 precomputed_poly_ids.emplace_back(label + "_lagrange");
215 break;
216 case PolynomialSource::OTHER:
217 break;
218 }
219 }
220 }
221
222 size_t size() const { return precomputed_poly_ids.size(); }
223
224 std::string operator[](size_t index) const { return precomputed_poly_ids[index]; }
225};
226
227} // namespace proof_system::plonk
Definition: polynomial_manifest.hpp:142
Definition: polynomial_manifest.hpp:185
Definition: widget.bench.cpp:13
Definition: polynomial_manifest.hpp:55