2#include "barretenberg/common/thread.hpp"
3#include "barretenberg/common/thread_utils.hpp"
5#include "barretenberg/polynomials/pow.hpp"
6#include "barretenberg/relations/relation_parameters.hpp"
7#include "barretenberg/relations/relation_types.hpp"
8#include "barretenberg/relations/utils.hpp"
10namespace proof_system::honk::sumcheck {
56 using Relations =
typename Flavor::Relations;
57 using SumcheckTupleOfTuplesOfUnivariates =
typename Flavor::SumcheckTupleOfTuplesOfUnivariates;
65 static constexpr size_t NUM_RELATIONS = Flavor::NUM_RELATIONS;
66 static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = Flavor::MAX_PARTIAL_RELATION_LENGTH;
67 static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = Flavor::BATCHED_RELATION_PARTIAL_LENGTH;
69 SumcheckTupleOfTuplesOfUnivariates univariate_accumulators;
73 : round_size(initial_round_size)
86 template <
typename ProverPolynomialsOrPartiallyEvaluatedMultivariates>
88 const ProverPolynomialsOrPartiallyEvaluatedMultivariates& multivariates,
91 for (
auto [extended_edge, multivariate] :
zip_view(extended_edges.get_all(), multivariates.get_all())) {
93 extended_edge = edge.template extend_to<MAX_PARTIAL_RELATION_LENGTH>();
102 template <
typename ProverPolynomialsOrPartiallyEvaluatedMultivariates>
104 ProverPolynomialsOrPartiallyEvaluatedMultivariates& polynomials,
111 std::vector<FF> pow_challenges(round_size >> 1);
112 pow_challenges[0] = pow_univariate.partial_evaluation_constant;
113 for (
size_t i = 1; i < (round_size >> 1); ++i) {
114 pow_challenges[i] = pow_challenges[i - 1] * pow_univariate.zeta_pow_sqr;
121 size_t min_iterations_per_thread = 1 << 6;
123 barretenberg::thread_utils::calculate_num_threads_pow2(round_size, min_iterations_per_thread);
124 size_t iterations_per_thread = round_size / num_threads;
127 std::vector<SumcheckTupleOfTuplesOfUnivariates> thread_univariate_accumulators(num_threads);
128 for (
auto& accum : thread_univariate_accumulators) {
133 std::vector<ExtendedEdges> extended_edges;
134 extended_edges.resize(num_threads);
137 parallel_for(num_threads, [&](
size_t thread_idx) {
138 size_t start = thread_idx * iterations_per_thread;
139 size_t end = (thread_idx + 1) * iterations_per_thread;
143 for (
size_t edge_idx = start; edge_idx < end; edge_idx += 2) {
144 extend_edges(extended_edges[thread_idx], polynomials, edge_idx);
147 FF pow_challenge = pow_challenges[edge_idx >> 1];
152 accumulate_relation_univariates(thread_univariate_accumulators[thread_idx],
153 extended_edges[thread_idx],
160 for (
auto& accumulators : thread_univariate_accumulators) {
164 return batch_over_relations<barretenberg::Univariate<FF, BATCHED_RELATION_PARTIAL_LENGTH>>(
165 univariate_accumulators, alpha, pow_univariate);
172 template <
typename ExtendedUnivariate,
typename ContainerOverSubrelations>
177 auto running_challenge = FF(1);
180 auto result = ExtendedUnivariate(0);
196 template <
typename ExtendedUnivariate,
typename TupleOfTuplesOfUnivariates>
198 ExtendedUnivariate& result,
201 ExtendedUnivariate extended_random_polynomial;
204 extended_random_polynomial = random_polynomial.template extend_to<ExtendedUnivariate::LENGTH>();
206 auto extend_and_sum = [&]<
size_t relation_idx,
size_t subrelation_idx,
typename Element>(Element& element) {
207 auto extended = element.template extend_to<ExtendedUnivariate::LENGTH>();
209 using Relation =
typename std::tuple_element_t<relation_idx, Relations>;
210 const bool is_subrelation_linearly_independent =
211 proof_system::subrelation_is_linearly_independent<Relation, subrelation_idx>();
215 if (!is_subrelation_linearly_independent) {
218 result += extended * extended_random_polynomial;
240 template <
size_t relation_
idx = 0>
241 void accumulate_relation_univariates(SumcheckTupleOfTuplesOfUnivariates& univariate_accumulators,
242 const auto& extended_edges,
244 const FF& scaling_factor)
246 using Relation = std::tuple_element_t<relation_idx, Relations>;
247 Relation::accumulate(
248 std::get<relation_idx>(univariate_accumulators), extended_edges, relation_parameters, scaling_factor);
251 if constexpr (relation_idx + 1 < NUM_RELATIONS) {
252 accumulate_relation_univariates<relation_idx + 1>(
253 univariate_accumulators, extended_edges, relation_parameters, scaling_factor);
260 using Relations =
typename Flavor::Relations;
261 using TupleOfArraysOfValues =
typename Flavor::TupleOfArraysOfValues;
267 bool round_failed =
false;
269 static constexpr size_t NUM_RELATIONS = Flavor::NUM_RELATIONS;
270 static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = Flavor::BATCHED_RELATION_PARTIAL_LENGTH;
272 FF target_total_sum = 0;
274 TupleOfArraysOfValues relation_evaluations;
283 FF total_sum = univariate.value_at(0) + univariate.value_at(1);
287 bool sumcheck_round_failed(
false);
289 target_total_sum.assert_equal(total_sum);
290 sumcheck_round_failed = (target_total_sum != total_sum).get_value();
292 sumcheck_round_failed = (target_total_sum != total_sum);
295 round_failed = round_failed || sumcheck_round_failed;
296 return !sumcheck_round_failed;
311 target_total_sum = univariate.
evaluate(round_challenge);
312 return target_total_sum;
329 Utils::template accumulate_relation_evaluations<>(purported_evaluations,
330 relation_evaluations,
332 pow_univariate.partial_evaluation_constant);
334 auto running_challenge = FF(1);
static void zero_elements(auto &tuple)
Set each element in a tuple of arrays to zero.
Definition: utils.hpp:154
static void zero_univariates(auto &tuple)
Set all coefficients of Univariates to zero.
Definition: utils.hpp:53
static void scale_and_batch_elements(auto &tuple, const FF &challenge, FF current_scalar, FF &result)
Scale elements by consecutive powers of the challenge then sum.
Definition: utils.hpp:164
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.
Definition: utils.hpp:29
static void scale_univariates(auto &tuple, const FF &challenge, FF ¤t_scalar)
Scale Univaraites by consecutive powers of the provided challenge.
Definition: utils.hpp:68
static constexpr void add_nested_tuples(Tuple &tuple_1, const Tuple &tuple_2)
Componentwise addition of nested tuples (tuples of tuples)
Definition: utils.hpp:109
A univariate polynomial represented by its values on {domain_start, domain_start + 1,...
Definition: univariate.hpp:23
Fr evaluate(const Fr &u)
Evaluate a univariate at a point u not known at compile time and assumed not to be in the domain (els...
Definition: univariate.hpp:311
The templates defined herein facilitate sharing the relation arithmetic between the prover and the ve...
Definition: relation_types.hpp:121
A field element for each entity of the flavor. These entities represent the prover polynomials evalua...
Definition: goblin_translator.hpp:947
ProverUnivariates< MAX_PARTIAL_RELATION_LENGTH > ExtendedEdges
A container for univariates produced during the hot loop in sumcheck.
Definition: goblin_translator.hpp:1014
Definition: sumcheck_round.hpp:53
void extend_edges(ExtendedEdges &extended_edges, const ProverPolynomialsOrPartiallyEvaluatedMultivariates &multivariates, size_t edge_idx)
Extend each edge in the edge group at to max-relation-length-many values.
Definition: sumcheck_round.hpp:87
static void extend_and_batch_univariates(const TupleOfTuplesOfUnivariates &tuple, ExtendedUnivariate &result, const barretenberg::PowUnivariate< FF > &pow_univariate)
Extend Univariates to specified size then sum them.
Definition: sumcheck_round.hpp:197
barretenberg::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > compute_univariate(ProverPolynomialsOrPartiallyEvaluatedMultivariates &polynomials, const proof_system::RelationParameters< FF > &relation_parameters, const barretenberg::PowUnivariate< FF > &pow_univariate, const FF alpha)
Return the evaluations of the univariate restriction (S_l(X_l) in the thesis) at num_multivariates-ma...
Definition: sumcheck_round.hpp:103
static ExtendedUnivariate batch_over_relations(ContainerOverSubrelations &univariate_accumulators, const FF &challenge, const barretenberg::PowUnivariate< FF > &pow_univariate)
Given a tuple t = (t_0, t_1, ..., t_{NUM_SUBRELATIONS-1}) and a challenge α, return t_0 + αt_1 + ....
Definition: sumcheck_round.hpp:173
Definition: sumcheck_round.hpp:258
FF compute_full_honk_relation_purported_value(ClaimedEvaluations purported_evaluations, const proof_system::RelationParameters< FF > &relation_parameters, const barretenberg::PowUnivariate< FF > &pow_univariate, const FF alpha)
General purpose method for applying a tuple of arrays (of FFs)
Definition: sumcheck_round.hpp:324
FF compute_next_target_sum(barretenberg::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > &univariate, FF &round_challenge)
After checking that the univariate is good for this round, compute the next target sum.
Definition: sumcheck_round.hpp:307
Definition: zip_view.hpp:159
Definition: flavor.hpp:300
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
Container for parameters used by the grand product (permutation, lookup) Honk relations.
Definition: relation_parameters.hpp:12