6#include <unordered_map>
9#include "../../types/prover_settings.hpp"
10#include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp"
11#include "barretenberg/plonk/work_queue/work_queue.hpp"
12#include "barretenberg/polynomials/iterate_over_domain.hpp"
14using namespace proof_system;
31#define CHALLENGE_BIT_ALPHA (1 << widget::ChallengeIndex::ALPHA)
32#define CHALLENGE_BIT_BETA (1 << widget::ChallengeIndex::BETA)
33#define CHALLENGE_BIT_GAMMA (1 << widget::ChallengeIndex::GAMMA)
34#define CHALLENGE_BIT_ETA (1 << widget::ChallengeIndex::ETA)
35#define CHALLENGE_BIT_ZETA (1 << widget::ChallengeIndex::ZETA)
39 std::array<Field, ChallengeIndex::MAX_NUM_CHALLENGES> elements;
40 std::array<Field, num_widget_relations> alpha_powers;
43template <
class Field>
using poly_array = std::array<std::pair<Field, Field>, PolynomialIndex::MAX_NUM_POLYNOMIALS>;
46 std::unordered_map<PolynomialIndex, polynomial::pointer> coefficients;
72template <
class Field,
class Transcript,
class Settings,
size_t num_w
idget_relations>
class BaseGetter {
88 const Field& alpha_base,
89 uint8_t required_challenges)
112 auto add_challenge = [transcript,
113 &result](
const auto label,
const auto tag,
const bool required,
const size_t index = 0) {
114 ASSERT(!required || transcript.has_challenge(label));
115 if (transcript.has_challenge(label)) {
116 ASSERT(index < transcript.get_num_challenges(label));
117 result.elements[tag] = transcript.get_challenge_field_element(label, index);
119 result.elements[tag] = barretenberg::fr::random_element();
122 add_challenge(
"alpha", ALPHA, required_challenges & CHALLENGE_BIT_ALPHA);
123 add_challenge(
"beta", BETA, required_challenges & CHALLENGE_BIT_BETA);
124 add_challenge(
"beta", GAMMA, required_challenges & CHALLENGE_BIT_GAMMA, 1);
125 add_challenge(
"eta", ETA, required_challenges & CHALLENGE_BIT_ETA);
126 add_challenge(
"z", ZETA, required_challenges & CHALLENGE_BIT_ZETA);
127 result.alpha_powers[0] = alpha_base;
128 for (
size_t i = 1; i < num_widget_relations; ++i) {
129 result.alpha_powers[i] = result.alpha_powers[i - 1] * result.elements[ALPHA];
134 static Field update_alpha(
const challenge_array& challenges,
const size_t num_independent_relations)
136 if (num_independent_relations == 0) {
137 return challenges.alpha_powers[0];
139 return challenges.alpha_powers[num_independent_relations - 1] * challenges.elements[ALPHA];
152template <
class Field,
class Transcript,
class Settings,
size_t num_w
idget_relations>
155 typedef containers::poly_array<Field> poly_array;
170 template <
bool use_shifted_evaluation, PolynomialIndex
id>
171 inline static const Field&
get_value(
const poly_array& polynomials,
const size_t = 0)
173 if constexpr (use_shifted_evaluation) {
174 return polynomials[id].second;
176 return polynomials[id].first;
186 const Transcript& transcript)
191 const std::string label(info.polynomial_label);
192 result[info.index].first = transcript.get_field_element(label);
194 if (info.requires_shifted_evaluation) {
195 result[info.index].second = transcript.get_field_element(label +
"_omega");
197 result[info.index].second = 0;
214template <
typename Field,
class Transcript,
class Settings,
size_t num_w
idget_relations>
223 std::string label_suffix;
226 label_suffix =
"_fft";
227 result.block_mask = key->large_domain.size - 1;
228 result.index_shift = 4;
231 for (
size_t i = 0; i < key->polynomial_manifest.size(); ++i) {
232 auto info_ = key->polynomial_manifest[i];
233 if (required_polynomial_ids.contains(info_.index)) {
234 std::string label = std::string(info_.polynomial_label) + label_suffix;
235 result.coefficients[info_.index] = key->polynomial_store.get(label).data();
241 template <EvaluationType evaluation_type, PolynomialIndex
id>
242 inline static const Field& get_value(
poly_ptr_map& polynomials,
const size_t index = 0)
244 if constexpr (EvaluationType::SHIFTED == evaluation_type) {
246 .coefficients[id][(ptrdiff_t)((index + polynomials.index_shift) & polynomials.block_mask)];
249 ASSERT(polynomials.coefficients.count(
id) > 0);
250 return polynomials.coefficients[id][(ptrdiff_t)index];
281template <
class Field,
class Settings,
template <
typename,
typename,
typename>
typename KernelBase>
284 static constexpr size_t num_independent_relations = KernelBase<int, int, int>::num_independent_relations;
286 typedef containers::poly_array<Field> poly_array;
294 typedef KernelBase<Field, FFTGetter, poly_ptr_map> FFTKernel;
295 typedef KernelBase<Field, EvaluationGetter, poly_array> EvaluationKernel;
314 Field compute_quotient_contribution(
const Field& alpha_base,
318 ASSERT(key !=
nullptr);
321 auto& required_polynomial_ids = FFTKernel::get_required_polynomial_ids();
324 poly_ptr_map polynomials = FFTGetter::get_polynomials(key, required_polynomial_ids);
329 ITERATE_OVER_DOMAIN_START(key->large_domain);
331 Field& quotient_term =
332 key->quotient_polynomial_parts[i >> key->small_domain.log2_size][i & (key->circuit_size - 1)];
333 FFTKernel::accumulate_contribution(polynomials, challenges, quotient_term, i);
334 ITERATE_OVER_DOMAIN_END;
336 return FFTGetter::update_alpha(challenges, FFTKernel::num_independent_relations);
340template <
class Field,
class Transcript,
class Settings,
template <
typename,
typename,
typename>
typename KernelBase>
343 static constexpr size_t num_independent_relations = KernelBase<int, int, int>::num_independent_relations;
345 typedef containers::poly_array<Field> poly_array;
350 typedef KernelBase<Field, EvaluationGetter, poly_array> EvaluationKernel;
352 static Field compute_quotient_evaluation_contribution(
typename Transcript::Key* key,
353 const Field& alpha_base,
354 const Transcript& transcript,
355 Field& quotient_numerator_eval)
357 poly_array polynomial_evaluations =
363 EvaluationKernel::accumulate_contribution(polynomial_evaluations, challenges, quotient_numerator_eval);
365 return EvaluationGetter::update_alpha(challenges, num_independent_relations);
368 static Field append_scalar_multiplication_inputs(
typename Transcript::Key*,
369 const Field& alpha_base,
370 const Transcript& transcript,
371 std::map<std::string, Field>&)
375 EvaluationKernel::quotient_required_challenges |
376 EvaluationKernel::update_required_challenges);
377 return EvaluationGetter::update_alpha(challenges, num_independent_relations);
Definition: polynomial_manifest.hpp:142
Definition: transcript_wrappers.hpp:13
Definition: widget.bench.cpp:13
Definition: proving_key.hpp:38