Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
batch_mul_native.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
10#include <vector>
11
12namespace bb {
17template <typename Commitment, typename FF>
18static Commitment batch_mul_native(const std::vector<Commitment>& _points, const std::vector<FF>& _scalars)
19{
20 std::vector<Commitment> points;
21 std::vector<FF> scalars;
22 for (size_t i = 0; i < _points.size(); ++i) {
23 const auto& point = _points[i];
24 const auto& scalar = _scalars[i];
25
26 // TODO: Special handling of point at infinity here due to incorrect serialization.
27 if (!scalar.is_zero() && !point.is_point_at_infinity() && !point.y.is_zero()) {
28 points.emplace_back(point);
29 scalars.emplace_back(scalar);
30 }
31 }
32
33 if (points.empty()) {
34 return Commitment::infinity();
35 }
36
37 auto result = points[0] * scalars[0];
38 for (size_t idx = 1; idx < scalars.size(); ++idx) {
39 result = result + points[idx] * scalars[idx];
40 }
41 return result;
42}
43
48template <typename FF> static FF linear_combination(const std::vector<FF>& as, const std::vector<FF>& bs)
49{
50 FF result = as[0] * bs[0];
51 for (size_t idx = 1; idx < as.size(); ++idx) {
52 result += as[idx] * bs[idx];
53 }
54 return result;
55}
56
57} // namespace bb
Entry point for Barretenberg command-line interface.