81 typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariatesNoOptimisticSkipping<NUM_INSTANCES>;
103 using ContainerType =
105 typename Flavor::template ProverUnivariates<2>,
108 std::array<
decltype(instances[0]->polynomials.get_all()), NUM_INSTANCES> views;
109 views[0] = instances[0]->polynomials.get_all();
110 views[1] = instances[1]->polynomials.get_all();
112 ContainerType results;
115 for (
size_t inst_idx = 0;
auto& get_all : views) {
120 for (
auto [result, poly_ptr] :
zip_view(results.get_all(), get_all)) {
121 result.evaluations[inst_idx] = poly_ptr[row_idx];
124 for (
auto [result, poly_ptr] :
zip_view(results, get_all)) {
125 result.evaluations[inst_idx] = poly_ptr[row_idx];
148 FF& linearly_dependent_contribution)
151 FF linearly_independent_contribution =
std::get<0>(evals)[0];
154 auto scale_by_challenge_and_accumulate =
155 [&]<
size_t relation_idx,
size_t subrelation_idx,
typename Element>(
Element& element) {
156 if constexpr (!(relation_idx == 0 && subrelation_idx == 0)) {
159 const Element contribution = element * challenges[idx++];
160 if constexpr (subrelation_is_linearly_independent<Relation, subrelation_idx>()) {
161 linearly_independent_contribution += contribution;
163 linearly_dependent_contribution += contribution;
168 return linearly_independent_contribution;
189 BB_BENCH_NAME(
"ProtogalaxyProver_::compute_row_evaluations");
191 const size_t polynomial_size = polynomials.get_polynomial_size();
197 std::vector<FF> linearly_dependent_contribution_accumulators(num_threads);
204 for (
size_t idx = range.first; idx < range.second; idx++) {
205 const AllValues row = polynomials.get_row(idx);
212 evals, alphas, linearly_dependent_contribution_accumulators[thread_idx]);
217 aggregated_relation_evaluations.
at(0) +=
sum(linearly_dependent_contribution_accumulators);
219 return aggregated_relation_evaluations;
267 std::vector<FF>& current_level_buffer,
268 size_t current_width,
269 size_t current_degree)
271 if (betas.size() == 1) {
272 return std::vector<FF>(current_level_buffer.begin(),
273 current_level_buffer.begin() +
static_cast<std::ptrdiff_t>(current_degree));
276 size_t num_levels = betas.size();
281 size_t max_next_buffer_size = 0;
282 size_t temp_width = current_width;
283 for (
size_t level = 1; level < num_levels; ++level) {
285 size_t degree = level + 1;
286 max_next_buffer_size =
std::max(max_next_buffer_size, temp_width * (degree + 1));
289 std::vector<FF> next_level_buffer(max_next_buffer_size);
292 for (
size_t level = 1; level < num_levels; ++level) {
293 size_t next_degree = level + 1;
294 size_t next_width = current_width / 2;
295 size_t next_stride = next_degree + 1;
296 size_t current_stride = current_degree;
302 size_t node = parent * 2;
303 size_t parent_offset = parent * next_stride;
304 size_t left_child_offset = node * current_stride;
305 size_t right_child_offset = (node + 1) * current_stride;
308 for (
size_t d = 0; d < current_stride; d++) {
309 next_level_buffer[parent_offset + d] = current_level_buffer[left_child_offset + d];
311 for (
size_t d = current_stride; d < next_stride; d++) {
312 next_level_buffer[parent_offset + d] =
FF(0);
316 for (
size_t d = 0; d < current_stride; d++) {
317 next_level_buffer[parent_offset + d] +=
318 current_level_buffer[right_child_offset + d] * betas[level];
319 next_level_buffer[parent_offset + d + 1] +=
320 current_level_buffer[right_child_offset + d] * deltas[level];
326 std::swap(current_level_buffer, next_level_buffer);
327 current_width = next_width;
328 current_degree = next_stride;
332 return std::vector<FF>(current_level_buffer.begin(),
333 current_level_buffer.begin() +
static_cast<std::ptrdiff_t>(current_degree));
396 auto width = full_honk_evaluations.
size();
400 size_t first_level_width = width / 2;
401 std::vector<FF> first_level_buffer(first_level_width * 2);
406 size_t node = parent * 2;
407 size_t offset = parent * 2;
408 first_level_buffer[
offset] = full_honk_evaluations[node] + full_honk_evaluations[node + 1] * betas[0];
409 first_level_buffer[
offset + 1] = full_honk_evaluations[node + 1] * deltas[0];
422 const std::vector<FF>& deltas)
425 auto full_honk_evaluations =
427 const auto betas = accumulator->gate_challenges;
429 const size_t log_circuit_size = accumulator->log_dyadic_size();
433 std::span{ deltas.data(), log_circuit_size },
434 full_honk_evaluations);
437 for (
size_t idx = log_circuit_size; idx < CONST_PG_LOG_N; ++idx) {
438 perturbator.emplace_back(
FF(0));
443 accumulator->target_sum,
444 "ProtogalaxyProver: the zeroth coefficient of the perturbator is different from the target sum "
445 "stored in the accumulator.");
456 template <
size_t skip_count = 0>
459 const size_t row_idx)
464 auto incoming_univariates = row_to_univariates<skip_count>(instances, row_idx);
465 for (
auto [extended_univariate, incoming_univariate] :
466 zip_view(extended_univariates.get_all(), incoming_univariates)) {
467 incoming_univariate.template self_extend_from<NUM_INSTANCES>();
468 extended_univariate =
std::move(incoming_univariate);
486 template <
size_t relation_
idx = 0>
490 const FF& scaling_factor)
498 extended_univariates,
503 if (!Relation::skip(extended_univariates)) {
505 extended_univariates,
513 accumulate_relation_univariates<relation_idx + 1>(
514 univariate_accumulators, extended_univariates, relation_parameters, scaling_factor);
543 const size_t common_polynomial_size = instances[0]->polynomials.w_l.virtual_size();
561 for (
size_t idx = range.first; idx < range.second; idx++) {
574 extend_univariates<SKIP_COUNT>(extended_univariates, instances, idx);
576 const FF pow_challenge = gate_separators[idx];
582 extended_univariates,
591 for (
auto& accumulators : thread_univariate_accumulators) {
607 template <
typename TupleOfTuplesOfUnivariatePossiblyOptimistic>
609 const TupleOfTuplesOfUnivariatePossiblyOptimistic& tup)
612 if constexpr (
std::same_as<TupleOfTuplesOfUnivariatePossiblyOptimistic,
617 const auto deoptimize = [&]<
size_t outer_idx,
size_t inner_idx>(
auto& element) {
619 element = element_with_skipping.convert();
644 auto result =
std::get<0>(
std::get<0>(univariate_accumulators)).template extend_to<BATCHED_EXTENDED_LENGTH>();
647 const auto scale_and_sum = [&]<
size_t outer_idx,
size_t inner_idx>(
auto& element) {
648 if constexpr (outer_idx == 0 && inner_idx == 0) {
653 auto extended = element.template extend_to<BATCHED_EXTENDED_LENGTH>();
654 extended *= alphas[idx];
672 FF vanishing_polynomial_at_challenge;
674 vanishing_polynomial_at_challenge = challenge * (challenge -
FF(1));
675 lagranges = {
FF(1) - challenge, challenge };
677 return { vanishing_polynomial_at_challenge, lagranges };
695 for (
size_t point = NUM_INSTANCES; point < combiner.
size(); point++) {
696 auto idx = point - NUM_INSTANCES;
697 FF lagrange_0 =
FF(1) -
FF(point);
698 FF vanishing_polynomial =
FF(point) * (
FF(point) - 1);
699 combiner_quotient_evals[idx] =
700 (combiner.
value_at(point) - perturbator_evaluation * lagrange_0) * vanishing_polynomial.
invert();
719 template <
typename ExtendedRelationParameters>
722 using UnivariateParameter =
typename ExtendedRelationParameters::DataType;
723 ExtendedRelationParameters result;
724 size_t param_idx = 0;
725 for (
auto& param : result.get_to_fold()) {
727 tmp.
value_at(0) = instances[0]->relation_parameters.get_to_fold()[param_idx];
728 tmp.
value_at(1) = instances[1]->relation_parameters.get_to_fold()[param_idx];
729 param = tmp.template extend_to<UnivariateParameter::LENGTH, UnivariateParameter::SKIP_COUNT>();
751 size_t alpha_idx = 0;
752 for (
auto& alpha : result) {
754 tmp.
value_at(0) = instances[0]->alphas[alpha_idx];
755 tmp.
value_at(1) = instances[1]->alphas[alpha_idx];
756 alpha = tmp.template extend_to<BATCHED_EXTENDED_LENGTH>();
772 const size_t min_iterations_per_thread =
774 const size_t desired_num_threads = domain_size / min_iterations_per_thread;
775 size_t num_threads = std::min(desired_num_threads, max_num_threads);
776 num_threads = num_threads > 0 ? num_threads : 1;
#define BB_ASSERT_EQ(actual, expected,...)
#define BB_BENCH_NAME(name)
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 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...
std::conditional_t< Flavor::USE_SHORT_MONOMIALS, ShortUnivariates, ExtendedUnivariates > ExtendedUnivariatesType
ExtendedUnivariateWithRandomization compute_combiner(const ProverInstances &instances, const GateSeparatorPolynomial< FF > &gate_separators, const UnivariateRelationParameters &relation_parameters, const UnivariateSubrelationSeparators &alphas, TupleOfTuplesOfUnivariates &univariate_accumulators)
Compute the combiner polynomial in the Protogalaxy paper.
Polynomial< FF > compute_perturbator(const std::shared_ptr< const ProverInstance > &accumulator, const std::vector< FF > &deltas)
Construct the perturbator polynomial F(X) in coefficient form from the accumulator resulted from a pr...
static BB_INLINE void extend_univariates(ExtendedUnivariatesType &extended_univariates, const ProverInstances &instances, const size_t row_idx)
Prepare a univariate polynomial for relation execution in one step of the combiner construction.
static auto row_to_univariates(const ProverInstances &instances, size_t row_idx)
Constructs univariates that interpolate the values of each instance across a given row.
std::array< Univariate< FF, BATCHED_EXTENDED_LENGTH >, NUM_SUBRELATIONS - 1 > UnivariateSubrelationSeparators
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,...
static std::pair< typename ProverInstance::FF, std::array< typename ProverInstance::FF, NUM_INSTANCES > > compute_vanishing_polynomial_and_lagranges(const FF &challenge)
Compute the vanishing polynomial and Lagranges at the challenge.
static size_t compute_num_threads(const size_t domain_size)
Determine number of threads for multithreading of perterbator/combiner operations.
static std::vector< FF > construct_coefficients_tree(std::span< const FF > betas, std::span< const FF > deltas, std::vector< FF > ¤t_level_buffer, size_t current_width, size_t current_degree)
Non-recursively compute the parent nodes of each level in the tree, starting from the leaves.
static UnivariateSubrelationSeparators compute_and_extend_alphas(const ProverInstances &instances)
Combine the relation batching parameters (alphas) from each prover instance into a univariate for the...
static TupleOfTuplesOfUnivariatesNoOptimisticSkipping deoptimize_univariates(const TupleOfTuplesOfUnivariatePossiblyOptimistic &tup)
Convert univariates from optimized form to regular.
typename Flavor::AllValues AllValues
typename Flavor::template ProverUnivariates< NUM_INSTANCES > ShortUnivariates
ShortUnivariates is an optimisation to improve the evaluation of Flavor relations when the output is ...
static FF process_subrelation_evaluations(const RelationEvaluations &evals, const SubrelationSeparators &challenges, FF &linearly_dependent_contribution)
Scale all linearly independent subrelations evaluations by challenges ('alphas').
ExecutionTraceUsageTracker trace_usage_tracker
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.
typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates< NUM_INSTANCES > TupleOfTuplesOfUnivariates
typename ProverInstance::Flavor Flavor
ProtogalaxyProverInternal(ExecutionTraceUsageTracker trace_usage_tracker=ExecutionTraceUsageTracker{})
static std::vector< FF > construct_perturbator_coefficients(std::span< const FF > betas, std::span< const FF > deltas, const Polynomial< FF > &full_honk_evaluations)
Construct the perturbator polynomial F(X) coefficients in O(n) time using binary tree reduction.
typename Flavor::Relations Relations
static constexpr size_t BATCHED_EXTENDED_LENGTH
decltype(create_tuple_of_arrays_of_values< typename Flavor::Relations >()) RelationEvaluations
static Univariate< FF, BATCHED_EXTENDED_LENGTH, NUM_INSTANCES > compute_combiner_quotient(FF perturbator_evaluation, ExtendedUnivariateWithRandomization combiner)
Compute the combiner quotient defined as $K$ polynomial in the paper specialised for only folding two...
typename Flavor::SubrelationSeparators SubrelationSeparators
static ExtendedRelationParameters compute_extended_relation_parameters(const ProverInstances &instances)
For each parameter, collect the value in each ProverInstance in a univariate and extend for use in th...
static ExtendedUnivariateWithRandomization batch_over_relations(TupleOfTuplesOfUnivariatesNoOptimisticSkipping &univariate_accumulators, const UnivariateSubrelationSeparators &alphas)
Given the univariate accumulators and the batching challenges, compute the combiner by batching the s...
static constexpr size_t EXTENDED_LENGTH
typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariatesNoOptimisticSkipping< NUM_INSTANCES > TupleOfTuplesOfUnivariatesNoOptimisticSkipping
typename Flavor::template ProverUnivariatesWithOptimisticSkipping< ExtendedUnivariate::LENGTH, SKIP_COUNT > ExtendedUnivariates
static constexpr size_t NUM_SUBRELATIONS
typename Flavor::ProverPolynomials ProverPolynomials
std::array< std::shared_ptr< ProverInstance >, NUM_INSTANCES > ProverInstances
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 RelationEvaluations accumulate_relation_evaluations(const PolynomialEvaluations &evaluations, const Parameters &relation_parameters, const FF &scaling_factor)
Calculate the contribution of each relation to the expected value of the full Honk relation.
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.
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...
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
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 in Sumcheck.
Container for parameters used by the grand product (permutation, lookup) Honk relations.
constexpr field invert() const noexcept