Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
claim_batcher.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Khashayar], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
10#include <optional>
11
12namespace bb {
13
26template <typename Curve> struct ClaimBatcher_ {
27 using Fr = typename Curve::ScalarField;
29
30 struct Batch {
33 // scalar used for batching the claims, excluding the power of batching challenge \rho
35 };
36
37 std::optional<Batch> unshifted; // commitments and evaluations of unshifted polynomials
38 std::optional<Batch> shifted; // commitments of to-be-shifted-by-1 polys, evals of their shifts
39
41 Batch get_shifted() { return (shifted) ? *shifted : Batch{}; }
42
43 Fr get_unshifted_batch_scalar() const { return unshifted ? unshifted->scalar : Fr{ 0 }; }
44
69 const Fr& nu_challenge,
70 const Fr& r_challenge)
71 {
72 const Fr& inverse_vanishing_eval_pos = inverted_vanishing_evals[0];
73 const Fr& inverse_vanishing_eval_neg = inverted_vanishing_evals[1];
74
75 if (unshifted) {
76 // (1/(z−r) + ν/(z+r))
77 unshifted->scalar = inverse_vanishing_eval_pos + nu_challenge * inverse_vanishing_eval_neg;
78 }
79 if (shifted) {
80 // r⁻¹ ⋅ (1/(z−r) − ν/(z+r))
81 shifted->scalar =
82 r_challenge.invert() * (inverse_vanishing_eval_pos - nu_challenge * inverse_vanishing_eval_neg);
83 }
84 }
95 void update_batch_mul_inputs_and_batched_evaluation(std::vector<Commitment>& commitments,
96 std::vector<Fr>& scalars,
97 Fr& batched_evaluation,
98 const Fr& rho)
99 {
100 size_t num_powers = 0;
101 num_powers += unshifted.has_value() ? unshifted->commitments.size() : 0;
102 num_powers += shifted.has_value() ? shifted->commitments.size() : 0;
103
104 Fr rho_power = Fr(1);
105 size_t power_idx = 0;
106
107 // Append the commitments/scalars from a given batch to the corresponding containers; update the batched
108 // evaluation and the running batching challenge in place
109 auto aggregate_claim_data_and_update_batched_evaluation = [&](const Batch& batch) {
110 for (auto [commitment, evaluation] : zip_view(batch.commitments, batch.evaluations)) {
111 commitments.emplace_back(std::move(commitment));
112 scalars.emplace_back(-batch.scalar * rho_power);
113 batched_evaluation += evaluation * rho_power;
114 power_idx++;
115 if (power_idx < num_powers) {
116 rho_power *= rho;
117 }
118 }
119 };
120
121 // Incorporate the claim data from each batch of claims that is present in the vectors of commitments and
122 // scalars for the batch mul
123 if (unshifted) {
124 // i-th Unshifted commitment will be multiplied by ρ^i and (1/(z−r) + ν/(z+r))
125 aggregate_claim_data_and_update_batched_evaluation(*unshifted);
126 }
127 if (shifted) {
128 // i-th shifted commitments will be multiplied by ρ^{num_unshifted + i} and r⁻¹ ⋅ (1/(z−r) − ν/(z+r))
129 aggregate_claim_data_and_update_batched_evaluation(*shifted);
130 }
131
132 BB_ASSERT_EQ(power_idx, num_powers);
133 }
134};
135
136} // namespace bb
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:83
A template class for a reference vector. Behaves as if std::vector<T&> was possible.
typename Group::affine_element AffineElement
Definition grumpkin.hpp:65
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
RefVector< Commitment > commitments
RefVector< Fr > evaluations
Logic to support batching opening claims for unshifted and shifted polynomials in Shplemini.
std::optional< Batch > unshifted
void update_batch_mul_inputs_and_batched_evaluation(std::vector< Commitment > &commitments, std::vector< Fr > &scalars, Fr &batched_evaluation, const Fr &rho)
Append the commitments and scalars from each batch of claims to the Shplemini vectors which subsequen...
std::optional< Batch > shifted
void compute_scalars_for_each_batch(std::span< const Fr > inverted_vanishing_evals, const Fr &nu_challenge, const Fr &r_challenge)
Compute scalars used to batch each set of claims, excluding contribution from batching challenge \rho...
typename Curve::ScalarField Fr
Fr get_unshifted_batch_scalar() const
typename Curve::AffineElement Commitment