Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
non_native_group_generator.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Suyash], commit: 553c5eb82901955c638b943065acd3e47fc918c0}
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
8
10
20{
21 std::call_once(init_flag, []() {
22 element base_point = G1::one;
23
24 auto d2 = base_point.dbl();
26 point_table[TABLE_SIZE / 2] = base_point;
27 for (size_t i = 1; i < TABLE_SIZE / 2; ++i) {
28 point_table[i + TABLE_SIZE / 2] = point_table[i + TABLE_SIZE / 2 - 1] + d2;
29 }
30 for (size_t i = 0; i < TABLE_SIZE / 2; ++i) {
31 point_table[TABLE_SIZE / 2 - 1 - i] = -point_table[TABLE_SIZE / 2 + i];
32 }
33 element::batch_normalize(&point_table[0], TABLE_SIZE);
34
35 auto beta = G1::Fq::cube_root_of_unity();
36 for (size_t i = 0; i < TABLE_SIZE; ++i) {
37 uint256_t endo_x = static_cast<uint256_t>(point_table[i].x * beta);
38 uint256_t x = static_cast<uint256_t>(point_table[i].x);
39 uint256_t y = static_cast<uint256_t>(point_table[i].y);
40
41 // Store the values in prime-basis lookup tables
44
45 // Compute x limbs
46 constexpr size_t num_limb_bits = stdlib::NUM_LIMB_BITS_IN_FIELD_SIMULATION;
47 const uint256_t SHIFT = uint256_t(1) << num_limb_bits;
48 const uint256_t MASK = SHIFT - 1;
49 uint256_t x0 = x & MASK;
50 x = x >> num_limb_bits;
51 uint256_t x1 = x & MASK;
52 x = x >> num_limb_bits;
53 uint256_t x2 = x & MASK;
54 x = x >> num_limb_bits;
55 uint256_t x3 = x & MASK;
56
57 // Compute endo x limbs
58 uint256_t endox0 = endo_x & MASK;
59 endo_x = endo_x >> num_limb_bits;
60 uint256_t endox1 = endo_x & MASK;
61 endo_x = endo_x >> num_limb_bits;
62 uint256_t endox2 = endo_x & MASK;
63 endo_x = endo_x >> num_limb_bits;
64 uint256_t endox3 = endo_x & MASK;
65
66 // Compute y limbs
67 uint256_t y0 = y & MASK;
68 y = y >> num_limb_bits;
69 uint256_t y1 = y & MASK;
70 y = y >> num_limb_bits;
71 uint256_t y2 = y & MASK;
72 y = y >> num_limb_bits;
73 uint256_t y3 = y & MASK;
74
75 // Store the limb values in the respective lookup tables
82 }
83 });
84}
85
90{
91 init_generator_tables();
92 const size_t index = static_cast<size_t>(key[0]);
93 BB_ASSERT(index < TABLE_SIZE, "xlo table key out of range");
96}
97
102{
103 init_generator_tables();
104 const size_t index = static_cast<size_t>(key[0]);
105 BB_ASSERT(index < TABLE_SIZE, "xhi table key out of range");
108}
109
113template <typename G1>
115{
116 init_generator_tables();
117 const size_t index = static_cast<size_t>(key[0]);
118 BB_ASSERT(index < TABLE_SIZE, "xlo_endo table key out of range");
121}
122
126template <typename G1>
128{
129 init_generator_tables();
130 const size_t index = static_cast<size_t>(key[0]);
131 BB_ASSERT(index < TABLE_SIZE, "xhi_endo table key out of range");
134}
135
140{
141 init_generator_tables();
142 const size_t index = static_cast<size_t>(key[0]);
143 BB_ASSERT(index < TABLE_SIZE, "ylo table key out of range");
146}
147
152{
153 init_generator_tables();
154 const size_t index = static_cast<size_t>(key[0]);
155 BB_ASSERT(index < TABLE_SIZE, "yhi table key out of range");
158}
159
163template <typename G1>
165{
166 init_generator_tables();
167 const size_t index = static_cast<size_t>(key[0]);
168 BB_ASSERT(index < TABLE_SIZE, "xyprime table key out of range");
171}
172
176template <typename G1>
178{
179 init_generator_tables();
180 const size_t index = static_cast<size_t>(key[0]);
181 BB_ASSERT(index < TABLE_SIZE, "xyprime_endo table key out of range");
184}
185
186template <typename G1> BasicTable ecc_generator_table<G1>::generate_xlo_table(BasicTableId id, const size_t table_index)
187{
188 BasicTable table;
189 table.id = id;
190 table.table_index = table_index;
191 size_t table_size = TABLE_SIZE;
192 table.use_twin_keys = false;
193
194 for (size_t i = 0; i < table_size; ++i) {
195 table.column_1.emplace_back((i));
196 table.column_2.emplace_back(ecc_generator_table<G1>::generator_xlo_table[i].first);
197 table.column_3.emplace_back(ecc_generator_table<G1>::generator_xlo_table[i].second);
198 }
199
200 table.get_values_from_key = &get_xlo_values;
201
202 table.column_1_step_size = 0;
203 table.column_2_step_size = 0;
204 table.column_3_step_size = 0;
205
206 return table;
207}
208
209template <typename G1> BasicTable ecc_generator_table<G1>::generate_xhi_table(BasicTableId id, const size_t table_index)
210{
211 BasicTable table;
212 table.id = id;
213 table.table_index = table_index;
214 size_t table_size = TABLE_SIZE;
215 table.use_twin_keys = false;
216
217 for (size_t i = 0; i < table_size; ++i) {
218 table.column_1.emplace_back((i));
219 table.column_2.emplace_back(ecc_generator_table<G1>::generator_xhi_table[i].first);
220 table.column_3.emplace_back(ecc_generator_table<G1>::generator_xhi_table[i].second);
221 }
222
223 table.get_values_from_key = &get_xhi_values;
224
225 table.column_1_step_size = 0;
226 table.column_2_step_size = 0;
227 table.column_3_step_size = 0;
228
229 return table;
230}
231
232template <typename G1>
234{
235 BasicTable table;
236 table.id = id;
237 table.table_index = table_index;
238 size_t table_size = TABLE_SIZE;
239 table.use_twin_keys = false;
240
241 for (size_t i = 0; i < table_size; ++i) {
242 table.column_1.emplace_back((i));
245 }
246
247 table.get_values_from_key = &get_xlo_endo_values;
248
249 table.column_1_step_size = 0;
250 table.column_2_step_size = 0;
251 table.column_3_step_size = 0;
252
253 return table;
254}
255
256template <typename G1>
258{
259 BasicTable table;
260 table.id = id;
261 table.table_index = table_index;
262 size_t table_size = TABLE_SIZE;
263 table.use_twin_keys = false;
264
265 for (size_t i = 0; i < table_size; ++i) {
266 table.column_1.emplace_back((i));
269 }
270
271 table.get_values_from_key = &get_xhi_endo_values;
272
273 table.column_1_step_size = 0;
274 table.column_2_step_size = 0;
275 table.column_3_step_size = 0;
276
277 return table;
278}
279
280template <typename G1> BasicTable ecc_generator_table<G1>::generate_ylo_table(BasicTableId id, const size_t table_index)
281{
282 BasicTable table;
283 table.id = id;
284 table.table_index = table_index;
285 size_t table_size = TABLE_SIZE;
286 table.use_twin_keys = false;
287
288 for (size_t i = 0; i < table_size; ++i) {
289 table.column_1.emplace_back((i));
290 table.column_2.emplace_back(ecc_generator_table<G1>::generator_ylo_table[i].first);
291 table.column_3.emplace_back(ecc_generator_table<G1>::generator_ylo_table[i].second);
292 }
293
294 table.get_values_from_key = &get_ylo_values;
295
296 table.column_1_step_size = 0;
297 table.column_2_step_size = 0;
298 table.column_3_step_size = 0;
299
300 return table;
301}
302
303template <typename G1> BasicTable ecc_generator_table<G1>::generate_yhi_table(BasicTableId id, const size_t table_index)
304{
305 BasicTable table;
306 table.id = id;
307 table.table_index = table_index;
308 size_t table_size = TABLE_SIZE;
309 table.use_twin_keys = false;
310
311 for (size_t i = 0; i < table_size; ++i) {
312 table.column_1.emplace_back((i));
313 table.column_2.emplace_back(ecc_generator_table<G1>::generator_yhi_table[i].first);
314 table.column_3.emplace_back(ecc_generator_table<G1>::generator_yhi_table[i].second);
315 }
316
317 table.get_values_from_key = &get_yhi_values;
318
319 table.column_1_step_size = 0;
320 table.column_2_step_size = 0;
321 table.column_3_step_size = 0;
322
323 return table;
324}
325
326template <typename G1>
328{
329 BasicTable table;
330 table.id = id;
331 table.table_index = table_index;
332 size_t table_size = TABLE_SIZE;
333 table.use_twin_keys = false;
334
335 for (size_t i = 0; i < table_size; ++i) {
336 table.column_1.emplace_back((i));
339 }
340
341 table.get_values_from_key = &get_xyprime_values;
342
343 table.column_1_step_size = 0;
344 table.column_2_step_size = 0;
345 table.column_3_step_size = 0;
346
347 return table;
348}
349
350template <typename G1>
352{
353 BasicTable table;
354 table.id = id;
355 table.table_index = table_index;
356 size_t table_size = TABLE_SIZE;
357 table.use_twin_keys = false;
358
359 for (size_t i = 0; i < table_size; ++i) {
360 table.column_1.emplace_back((i));
363 }
364
365 table.get_values_from_key = &get_xyprime_endo_values;
366
367 table.column_1_step_size = 0;
368 table.column_2_step_size = 0;
369 table.column_3_step_size = 0;
370
371 return table;
372}
373
374template <typename G1>
376{
377 const size_t num_entries = 1;
378 MultiTable table(TABLE_SIZE, 0, 0, 1);
379
380 table.id = id;
381 for (size_t i = 0; i < num_entries; ++i) {
382 table.slice_sizes.emplace_back(TABLE_SIZE);
383 table.basic_table_ids.emplace_back(basic_id);
384 table.get_table_values.emplace_back(&get_xlo_values);
385 }
386 return table;
387}
388
389template <typename G1>
391{
392 const size_t num_entries = 1;
393 MultiTable table(TABLE_SIZE, 0, 0, 1);
394
395 table.id = id;
396 for (size_t i = 0; i < num_entries; ++i) {
397 table.slice_sizes.emplace_back(TABLE_SIZE);
398 table.basic_table_ids.emplace_back(basic_id);
399 table.get_table_values.emplace_back(&get_xhi_values);
400 }
401 return table;
402}
403
404template <typename G1>
406{
407 const size_t num_entries = 1;
408 MultiTable table(TABLE_SIZE, 0, 0, 1);
409
410 table.id = id;
411 for (size_t i = 0; i < num_entries; ++i) {
412 table.slice_sizes.emplace_back(TABLE_SIZE);
413 table.basic_table_ids.emplace_back(basic_id);
414 table.get_table_values.emplace_back(&get_xlo_endo_values);
415 }
416 return table;
417}
418
419template <typename G1>
421{
422 const size_t num_entries = 1;
423 MultiTable table(TABLE_SIZE, 0, 0, 1);
424
425 table.id = id;
426 for (size_t i = 0; i < num_entries; ++i) {
427 table.slice_sizes.emplace_back(TABLE_SIZE);
428 table.basic_table_ids.emplace_back(basic_id);
429 table.get_table_values.emplace_back(&get_xhi_endo_values);
430 }
431 return table;
432}
433
434template <typename G1>
436{
437 const size_t num_entries = 1;
438 MultiTable table(TABLE_SIZE, 0, 0, 1);
439
440 table.id = id;
441 for (size_t i = 0; i < num_entries; ++i) {
442 table.slice_sizes.emplace_back(TABLE_SIZE);
443 table.basic_table_ids.emplace_back(basic_id);
444 table.get_table_values.emplace_back(&get_ylo_values);
445 }
446 return table;
447}
448
449template <typename G1>
451{
452 const size_t num_entries = 1;
453 MultiTable table(TABLE_SIZE, 0, 0, 1);
454
455 table.id = id;
456 for (size_t i = 0; i < num_entries; ++i) {
457 table.slice_sizes.emplace_back(TABLE_SIZE);
458 table.basic_table_ids.emplace_back(basic_id);
459 table.get_table_values.emplace_back(&get_yhi_values);
460 }
461 return table;
462}
463
464template <typename G1>
466{
467 const size_t num_entries = 1;
468 MultiTable table(TABLE_SIZE, 0, 0, 1);
469
470 table.id = id;
471 for (size_t i = 0; i < num_entries; ++i) {
472 table.slice_sizes.emplace_back(TABLE_SIZE);
473 table.basic_table_ids.emplace_back(basic_id);
474 table.get_table_values.emplace_back(&get_xyprime_values);
475 }
476 return table;
477}
478
479template <typename G1>
481{
482 const size_t num_entries = 1;
483 MultiTable table(TABLE_SIZE, 0, 0, 1);
484
485 table.id = id;
486 for (size_t i = 0; i < num_entries; ++i) {
487 table.slice_sizes.emplace_back(TABLE_SIZE);
488 table.basic_table_ids.emplace_back(basic_id);
489 table.get_table_values.emplace_back(&get_xyprime_endo_values);
490 }
491 return table;
492}
494
495} // namespace bb::plookup::ecc_generator_tables
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
static MultiTable get_yhi_table(const MultiTableId id, const BasicTableId basic_id)
static MultiTable get_xyprime_endo_table(const MultiTableId id, const BasicTableId basic_id)
static BasicTable generate_xlo_table(BasicTableId id, const size_t table_index)
static std::array< fr, 2 > get_xlo_endo_values(const std::array< uint64_t, 2 > key)
static BasicTable generate_xyprime_endo_table(BasicTableId id, const size_t table_index)
static BasicTable generate_yhi_table(BasicTableId id, const size_t table_index)
static BasicTable generate_xlo_endo_table(BasicTableId id, const size_t table_index)
static std::array< fr, 2 > get_xhi_values(const std::array< uint64_t, 2 > key)
static std::array< fr, 2 > get_xyprime_endo_values(const std::array< uint64_t, 2 > key)
static std::array< fr, 2 > get_xlo_values(const std::array< uint64_t, 2 > key)
static BasicTable generate_ylo_table(BasicTableId id, const size_t table_index)
static BasicTable generate_xhi_table(BasicTableId id, const size_t table_index)
static std::array< fr, 2 > get_yhi_values(const std::array< uint64_t, 2 > key)
static MultiTable get_xlo_endo_table(const MultiTableId id, const BasicTableId basic_id)
static std::array< fr, 2 > get_ylo_values(const std::array< uint64_t, 2 > key)
static std::array< fr, 2 > get_xhi_endo_values(const std::array< uint64_t, 2 > key)
static std::array< fr, 2 > get_xyprime_values(const std::array< uint64_t, 2 > key)
static MultiTable get_xyprime_table(const MultiTableId id, const BasicTableId basic_id)
static MultiTable get_xhi_endo_table(const MultiTableId id, const BasicTableId basic_id)
static BasicTable generate_xyprime_table(BasicTableId id, const size_t table_index)
static BasicTable generate_xhi_endo_table(BasicTableId id, const size_t table_index)
static MultiTable get_xhi_table(const MultiTableId id, const BasicTableId basic_id)
static MultiTable get_xlo_table(const MultiTableId id, const BasicTableId basic_id)
static MultiTable get_ylo_table(const MultiTableId id, const BasicTableId basic_id)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
A basic table from which we can perform lookups (for example, an xor table)
Definition types.hpp:305
std::vector< bb::fr > column_3
Definition types.hpp:340
std::vector< bb::fr > column_2
Definition types.hpp:339
std::array< bb::fr, 2 >(* get_values_from_key)(const std::array< uint64_t, 2 >)
Definition types.hpp:348
std::vector< bb::fr > column_1
Definition types.hpp:338
Container for managing multiple BasicTables plus the data needed to combine basic table outputs (e....
Definition types.hpp:167
std::vector< BasicTableId > basic_table_ids
Definition types.hpp:173
std::vector< uint64_t > slice_sizes
Definition types.hpp:174
std::vector< table_out(*)(table_in)> get_table_values
Definition types.hpp:183