84 typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariatesNoOptimisticSkipping<DeciderPKs::NUM>;
111 FF& linearly_dependent_contribution)
114 FF linearly_independent_contribution =
std::get<0>(evals)[0];
117 auto scale_by_challenge_and_accumulate =
118 [&]<
size_t relation_idx,
size_t subrelation_idx,
typename Element>(
Element& element) {
119 if constexpr (!(relation_idx == 0 && subrelation_idx == 0)) {
122 const Element contribution = element * challenges[idx++];
123 if constexpr (subrelation_is_linearly_independent<Relation, subrelation_idx>()) {
124 linearly_independent_contribution += contribution;
126 linearly_dependent_contribution += contribution;
131 return linearly_independent_contribution;
154 const size_t polynomial_size = polynomials.get_polynomial_size();
160 std::vector<FF> linearly_dependent_contribution_accumulators(num_threads);
164 num_threads, polynomial_size,
true);
168 for (
size_t idx = range.first; idx < range.second; idx++) {
169 const AllValues row = polynomials.get_row(idx);
176 evals, alphas, linearly_dependent_contribution_accumulators[thread_idx]);
181 aggregated_relation_evaluations.
at(0) +=
sum(linearly_dependent_contribution_accumulators);
183 return aggregated_relation_evaluations;
192 const std::vector<std::vector<FF>>& prev_level_coeffs,
195 if (level ==
betas.size()) {
196 return prev_level_coeffs[0];
199 auto degree = level + 1;
200 auto prev_level_width = prev_level_coeffs.size();
203 prev_level_width / 2,
205 size_t node = parent * 2;
206 std::copy(prev_level_coeffs[node].begin(), prev_level_coeffs[node].end(), level_coeffs[parent].begin());
207 for (
size_t d = 0; d < degree; d++) {
208 level_coeffs[parent][d] += prev_level_coeffs[node + 1][d] *
betas[level];
209 level_coeffs[parent][d + 1] += prev_level_coeffs[node + 1][d] * deltas[level];
230 auto width = full_honk_evaluations.
size();
235 size_t node = parent * 2;
236 first_level_coeffs[parent][0] =
237 full_honk_evaluations[node] + full_honk_evaluations[node + 1] *
betas[0];
238 first_level_coeffs[parent][1] = full_honk_evaluations[node + 1] * deltas[0];
248 const std::vector<FF>& deltas)
251 auto full_honk_evaluations =
253 const auto betas = accumulator->gate_challenges;
255 const size_t log_circuit_size = accumulator->log_dyadic_size();
259 std::span{ deltas.data(), log_circuit_size },
260 full_honk_evaluations);
263 for (
size_t idx = log_circuit_size; idx < CONST_PG_LOG_N; ++idx) {
264 perturbator.emplace_back(
FF(0));
277 template <
size_t skip_count = 0>
280 const size_t row_idx)
285 auto incoming_univariates =
286 keys.template row_to_univariates<ExtendedUnivariate::LENGTH, skip_count>(row_idx);
287 for (
auto [extended_univariate, incoming_univariate] :
288 zip_view(extended_univariates.get_all(), incoming_univariates)) {
289 incoming_univariate.template self_extend_from<NUM_KEYS>();
290 extended_univariate =
std::move(incoming_univariate);
308 template <
size_t relation_
idx = 0>
312 const FF& scaling_factor)
320 extended_univariates,
325 if (!Relation::skip(extended_univariates)) {
327 extended_univariates,
335 accumulate_relation_univariates<relation_idx + 1>(
336 univariate_accumulators, extended_univariates, relation_parameters, scaling_factor);
362 const size_t common_polynomial_size = keys[0]->polynomials.w_l.virtual_size();
382 for (
size_t idx = range.first; idx < range.second; idx++) {
387 extend_univariates<skip_count>(extended_univariates, keys, idx);
389 const FF pow_challenge = gate_separators[idx];
395 extended_univariates,
404 for (
auto& accumulators : thread_univariate_accumulators) {
421 return compute_combiner(keys, gate_separators, relation_parameters, alphas, accumulators);
429 template <
typename TupleOfTuplesOfUnivariatePossiblyOptimistic>
431 const TupleOfTuplesOfUnivariatePossiblyOptimistic& tup)
434 if constexpr (
std::same_as<TupleOfTuplesOfUnivariatePossiblyOptimistic,
439 const auto deoptimize = [&]<
size_t outer_idx,
size_t inner_idx>(
auto& element) {
441 element = element_with_skipping.convert();
455 std::get<0>(
std::get<0>(univariate_accumulators)).template extend_to<DeciderPKs::BATCHED_EXTENDED_LENGTH>();
458 const auto scale_and_sum = [&]<
size_t outer_idx,
size_t inner_idx>(
auto& element) {
459 if constexpr (outer_idx == 0 && inner_idx == 0) {
463 auto extended = element.template extend_to<DeciderPKs::BATCHED_EXTENDED_LENGTH>();
464 extended *= alphas[idx];
478 FF vanishing_polynomial_at_challenge;
483 vanishing_polynomial_at_challenge = challenge * (challenge -
FF(1));
484 lagranges = {
FF(1) - challenge, challenge };
486 vanishing_polynomial_at_challenge = challenge * (challenge -
FF(1)) * (challenge -
FF(2));
487 lagranges = { (
FF(1) - challenge) * (
FF(2) - challenge) * inverse_two,
488 challenge * (
FF(2) - challenge),
489 challenge * (challenge -
FF(1)) /
FF(2) };
492 vanishing_polynomial_at_challenge =
493 challenge * (challenge -
FF(1)) * (challenge -
FF(2)) * (challenge -
FF(3));
494 lagranges = { (
FF(1) - challenge) * (
FF(2) - challenge) * (
FF(3) - challenge) * inverse_six,
495 challenge * (
FF(2) - challenge) * (
FF(3) - challenge) * inverse_two,
496 challenge * (challenge -
FF(1)) * (
FF(3) - challenge) * inverse_two,
497 challenge * (challenge -
FF(1)) * (challenge -
FF(2)) * inverse_six };
501 return { vanishing_polynomial_at_challenge, lagranges };
517 FF vanishing_polynomial;
519 lagrange_0 =
FF(1) -
FF(point);
520 vanishing_polynomial =
FF(point) * (
FF(point) - 1);
522 lagrange_0 = (
FF(1) -
FF(point)) * (
FF(2) -
FF(point)) * inverse_two;
523 vanishing_polynomial =
FF(point) * (
FF(point) - 1) * (
FF(point) - 2);
525 lagrange_0 = (
FF(1) -
FF(point)) * (
FF(2) -
FF(point)) * (
FF(3) -
FF(point)) * inverse_six;
526 vanishing_polynomial =
FF(point) * (
FF(point) - 1) * (
FF(point) - 2) * (
FF(point) - 3);
530 combiner_quotient_evals[idx] =
531 (combiner.
value_at(point) - perturbator_evaluation * lagrange_0) * vanishing_polynomial.
invert();
541 template <
typename ExtendedRelationParameters>
544 using UnivariateParameter =
typename ExtendedRelationParameters::DataType;
545 ExtendedRelationParameters result;
546 size_t param_idx = 0;
547 for (
auto& param : result.get_to_fold()) {
550 for (
auto&
key : keys) {
551 tmp.
value_at(key_idx) =
key->relation_parameters.get_to_fold()[param_idx];
554 param = tmp.template extend_to<UnivariateParameter::LENGTH, UnivariateParameter::SKIP_COUNT>();
567 size_t alpha_idx = 0;
568 for (
auto& alpha : result) {
571 for (
auto&
key : keys) {
575 alpha = tmp.template extend_to<DeciderPKs::BATCHED_EXTENDED_LENGTH>();
591 const size_t min_iterations_per_thread =
593 const size_t desired_num_threads = domain_size / min_iterations_per_thread;
594 size_t num_threads = std::min(desired_num_threads, max_num_threads);
595 num_threads = num_threads > 0 ? num_threads : 1;
#define BB_ASSERT_EQ(actual, expected,...)
A field element for each entity of the flavor. These entities represent the prover polynomials evalua...
A container for the prover polynomials handles.
std::array< FF, NUM_SUBRELATIONS - 1 > SubrelationSeparators
static constexpr size_t MAX_TOTAL_RELATION_LENGTH
static constexpr size_t NUM_SUBRELATIONS
static constexpr size_t NUM_RELATIONS
Relations_< FF > Relations
static constexpr bool USE_SHORT_MONOMIALS
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
Fr & at(size_t index)
Our mutable accessor, unlike operator[]. We abuse precedent a bit to differentiate at() and operator[...
A purely static class (never add state to this!) consisting of functions used by the Protogalaxy prov...
typename Flavor::AllValues AllValues
static Univariate< FF, DeciderPKs::BATCHED_EXTENDED_LENGTH, DeciderPKs::NUM > compute_combiner_quotient(FF perturbator_evaluation, ExtendedUnivariateWithRandomization combiner)
Compute the combiner quotient defined as $K$ polynomial in the paper.
ExtendedUnivariateWithRandomization compute_combiner(const DeciderPKs &keys, const GateSeparatorPolynomial< FF > &gate_separators, const UnivariateRelationParameters &relation_parameters, const UnivariateSubrelationSeparators &alphas, TupleOfTuplesOfUnivariates &univariate_accumulators)
Compute the combiner polynomial $G$ in the Protogalaxy paper.
static std::vector< FF > construct_coefficients_tree(std::span< const FF > betas, std::span< const FF > deltas, const std::vector< std::vector< FF > > &prev_level_coeffs, size_t level=1)
Recursively compute the parent nodes of each level in the tree, starting from the leaves....
static BB_INLINE void accumulate_relation_univariates(TupleOfTuplesOfUnivariates &univariate_accumulators, const ExtendedUnivariatesType &extended_univariates, const UnivariateRelationParameters &relation_parameters, const FF &scaling_factor)
Add the value of each relation over univariates to an appropriate accumulator.
decltype(create_tuple_of_arrays_of_values< typename Flavor::Relations >()) RelationEvaluations
ExecutionTraceUsageTracker trace_usage_tracker
typename Flavor::Relations Relations
static ExtendedUnivariateWithRandomization batch_over_relations(TupleOfTuplesOfUnivariatesNoOptimisticSkipping &univariate_accumulators, const UnivariateSubrelationSeparators &alphas)
typename Flavor::template ProverUnivariatesWithOptimisticSkipping< ExtendedUnivariate::LENGTH, DeciderPKs::NUM - 1 > ExtendedUnivariates
static size_t compute_num_threads(const size_t domain_size)
Determine number of threads for multithreading of perterbator/combiner operations.
typename Flavor::ProverPolynomials ProverPolynomials
static ExtendedRelationParameters compute_extended_relation_parameters(const DeciderPKs &keys)
For each parameter, collect the value in each decider pvogin key in a univariate and extend for use i...
typename Flavor::SubrelationSeparators SubrelationSeparators
std::array< Univariate< FF, DeciderPKs::BATCHED_EXTENDED_LENGTH >, Flavor::NUM_SUBRELATIONS - 1 > UnivariateSubrelationSeparators
static BB_INLINE void extend_univariates(ExtendedUnivariatesType &extended_univariates, const DeciderPKs &keys, const size_t row_idx)
Prepare a univariate polynomial for relation execution in one step of the combiner construction.
Polynomial< FF > compute_perturbator(const std::shared_ptr< const DeciderPK > &accumulator, const std::vector< FF > &deltas)
Construct the power perturbator polynomial F(X) in coefficient form from the accumulator.
typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates< DeciderPKs::NUM > TupleOfTuplesOfUnivariates
typename DeciderPKs::DeciderPK DeciderPK
static constexpr size_t NUM_KEYS
typename DeciderPKs::Flavor Flavor
static std::pair< typename DeciderPKs::FF, std::array< typename DeciderPKs::FF, DeciderPKs::NUM > > compute_vanishing_polynomial_and_lagranges(const FF &challenge)
static UnivariateSubrelationSeparators compute_and_extend_alphas(const DeciderPKs &keys)
Combine the relation batching parameters (alphas) from each decider proving key into a univariate for...
std::conditional_t< Flavor::USE_SHORT_MONOMIALS, ShortUnivariates, ExtendedUnivariates > ExtendedUnivariatesType
static constexpr size_t NUM_SUBRELATIONS
typename Flavor::template ProverUnivariates< DeciderPKs::NUM > ShortUnivariates
ShortUnivariates is an optimisation to improve the evaluation of Flavor relations when the output is ...
ProtogalaxyProverInternal(ExecutionTraceUsageTracker trace_usage_tracker=ExecutionTraceUsageTracker{})
typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariatesNoOptimisticSkipping< DeciderPKs::NUM > TupleOfTuplesOfUnivariatesNoOptimisticSkipping
static FF process_subrelation_evaluations(const RelationEvaluations &evals, const SubrelationSeparators &challenges, FF &linearly_dependent_contribution)
A scale subrelations evaluations by challenges ('alphas') and part of the linearly dependent relation...
static std::vector< FF > construct_perturbator_coefficients(std::span< const FF > betas, std::span< const FF > deltas, const Polynomial< FF > &full_honk_evaluations)
We construct the coefficients of the perturbator polynomial in O(n) time following the technique in C...
ExtendedUnivariateWithRandomization compute_combiner(const DeciderPKs &keys, const GateSeparatorPolynomial< FF > &gate_separators, const UnivariateRelationParameters &relation_parameters, const UnivariateSubrelationSeparators &alphas)
static TupleOfTuplesOfUnivariatesNoOptimisticSkipping deoptimize_univariates(const TupleOfTuplesOfUnivariatePossiblyOptimistic &tup)
Convert univariates from optimized form to regular.
Polynomial< FF > compute_row_evaluations(const ProverPolynomials &polynomials, const SubrelationSeparators &alphas, const RelationParameters< FF > &relation_parameters)
Compute the values of the aggregated relation evaluations at each row in the execution trace,...
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
static void apply_to_tuple_of_arrays_elements(Operation &&operation, const tuple_type &tuple)
Recursive template function to apply a specific operation on each element of several arrays in a tupl...
static void zero_univariates(auto &tuple)
Set all coefficients of Univariates to zero.
static constexpr void add_nested_tuples(Tuple &tuple_1, const Tuple &tuple_2)
Componentwise addition of nested tuples (tuples of tuples)
static void apply_to_tuple_of_tuples(auto &tuple, Operation &&operation)
General purpose method for applying an operation to a tuple of tuples of Univariates.
static RelationEvaluations accumulate_relation_evaluations(const PolynomialEvaluations &evaluations, const Parameters &relation_parameters, const FF &partial_evaluation_result)
Calculate the contribution of each relation to the expected value of the full Honk relation.
A univariate polynomial represented by its values on {domain_start, domain_start + 1,...
static constexpr size_t LENGTH
The templates defined herein facilitate sharing the relation arithmetic between the prover and the ve...
std::vector< FF > betas
The challenges .
constexpr size_t FF_MULTIPLICATION_COST
Entry point for Barretenberg command-line interface.
size_t get_num_cpus_pow2()
Inner sum(Cont< Inner, Args... > const &in)
void parallel_for_heuristic(size_t num_points, const std::function< void(size_t, size_t, size_t)> &func, size_t heuristic_cost)
Split a loop into several loops running in parallel based on operations in 1 iteration.
void parallel_for(size_t num_iterations, const std::function< void(size_t)> &func)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
#define PROFILE_THIS_NAME(name)
static constexpr size_t BATCHED_EXTENDED_LENGTH
Flavor::template ProverUnivariates< 2 > row_to_short_univariates(size_t row_idx) const
static constexpr size_t EXTENDED_LENGTH
DeciderProvingKey_< Flavor > DeciderPK
static constexpr size_t NUM_SUBRELATIONS
static constexpr size_t NUM
Tracks the cumulative usage of the execution trace across a series of circuits.
std::vector< std::vector< Range > > thread_ranges
void construct_thread_ranges(const size_t num_threads, const size_t full_domain_size, bool use_prev_accumulator=false)
Construct ranges of execution trace rows that evenly distribute the active content of the trace acros...
std::pair< size_t, size_t > Range
Implementation of the methods for the -polynomials used in Protogalaxy and -polynomials used in Sumch...
Container for parameters used by the grand product (permutation, lookup) Honk relations.
constexpr field invert() const noexcept