Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
biggroup_batch_mul.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8
11#include <cstddef>
13
19template <typename C, class Fq, class Fr, class G>
20template <size_t max_num_bits>
22 const std::vector<Fr>& _scalars)
23{
24 constexpr size_t WNAF_SIZE = 4;
25 BB_ASSERT_EQ(_points.size(), _scalars.size());
26
27 const auto [points, scalars] = handle_points_at_infinity(_points, _scalars);
28
30 for (const auto& point : points) {
31 point_tables.emplace_back(four_bit_table_plookup(point));
32 }
33
35 for (const auto& scalar : scalars) {
36 wnaf_entries.emplace_back(compute_wnaf<max_num_bits>(scalar));
37 }
38
39 constexpr size_t num_bits = (max_num_bits == 0) ? (Fr::modulus.get_msb() + 1) : (max_num_bits);
40 constexpr size_t num_rounds = ((num_bits + WNAF_SIZE - 1) / WNAF_SIZE);
41 const auto offset_generators = compute_offset_generators(num_rounds * 4 - 3);
42
43 element accumulator = offset_generators.first + point_tables[0][wnaf_entries[0][0]];
44 for (size_t i = 1; i < points.size(); ++i) {
45 accumulator += point_tables[i][wnaf_entries[i][0]];
46 }
47
48 for (size_t i = 1; i < num_rounds; ++i) {
49 accumulator = accumulator.dbl();
50 accumulator = accumulator.dbl();
52 for (size_t j = 0; j < points.size(); ++j) {
53 to_add.emplace_back(point_tables[j][wnaf_entries[j][i]]);
54 }
55 accumulator = accumulator.quadruple_and_add(to_add);
56 }
57
58 for (size_t i = 0; i < points.size(); ++i) {
59 element skew = accumulator - points[i];
60 Fq out_x = accumulator.x.conditional_select(skew.x, bool_ct(wnaf_entries[i][num_rounds]));
61 Fq out_y = accumulator.y.conditional_select(skew.y, bool_ct(wnaf_entries[i][num_rounds]));
62 accumulator = element(out_x, out_y);
63 }
64 accumulator -= offset_generators.second;
65 return accumulator;
66}
67} // namespace bb::stdlib::element_default
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:59
Implements boolean logic in-circuit.
Definition bool.hpp:59
element quadruple_and_add(const std::vector< element > &to_add) const
Compute 4.P + to_add[0] + ... + to_add[to_add.size() - 1].
constexpr T get_msb(const T in)
Definition get_msb.hpp:47
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static constexpr uint256_t modulus
#define WNAF_SIZE(x)
Definition wnaf.hpp:16