Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
sumcheck.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
16#include "sumcheck_round.hpp"
17
18namespace bb {
19
24template <typename Flavor, bool IsGrumpkin = IsGrumpkinFlavor<Flavor>> struct RoundUnivariateHandler {
25 using FF = typename Flavor::FF;
29
30 std::shared_ptr<Transcript> transcript;
31
32 RoundUnivariateHandler(std::shared_ptr<Transcript> transcript)
33 : transcript(std::move(transcript))
34 {}
35
36 void process_round_univariate(size_t round_idx,
38 {
39 transcript->send_to_verifier("Sumcheck:univariate_" + std::to_string(round_idx), round_univariate);
40 }
41
42 void finalize_last_round(size_t /*multivariate_d*/,
44 const FF& /*last_challenge*/)
45 {}
46
49};
50
54template <typename Flavor> struct RoundUnivariateHandler<Flavor, true> {
55 using FF = typename Flavor::FF;
59
60 std::shared_ptr<Transcript> transcript;
62 std::vector<FF> eval_domain;
65
66 RoundUnivariateHandler(std::shared_ptr<Transcript> transcript)
67 : transcript(std::move(transcript))
69 {
70 // Compute the vector {0, 1, \ldots, BATCHED_RELATION_PARTIAL_LENGTH-1} needed to transform
71 // the round univariates from Lagrange to monomial basis
72 for (size_t idx = 0; idx < BATCHED_RELATION_PARTIAL_LENGTH; idx++) {
73 eval_domain.push_back(FF(idx));
74 }
75 }
76
77 void process_round_univariate(size_t round_idx,
79 {
80 const std::string idx = std::to_string(round_idx);
81
82 // Transform to monomial form and commit to it
83 Polynomial<FF> round_poly_monomial(
84 eval_domain, std::span<FF>(round_univariate.evaluations), BATCHED_RELATION_PARTIAL_LENGTH);
85 transcript->send_to_verifier("Sumcheck:univariate_comm_" + idx, ck.commit(round_poly_monomial));
86
87 // Store round univariate in monomial, as it is required by Shplemini
88 round_univariates.push_back(std::move(round_poly_monomial));
89
90 // Send the evaluations of the round univariate at 0 and 1
91 transcript->send_to_verifier("Sumcheck:univariate_" + idx + "_eval_0", round_univariate.value_at(0));
92 transcript->send_to_verifier("Sumcheck:univariate_" + idx + "_eval_1", round_univariate.value_at(1));
93
94 // Store the evaluations to be used by ShpleminiProver.
95 round_evaluations.push_back({ round_univariate.value_at(0), round_univariate.value_at(1), FF(0) });
96 if (round_idx > 0) {
97 round_evaluations[round_idx - 1][2] = round_univariate.value_at(0) + round_univariate.value_at(1);
98 }
99 }
100
101 void finalize_last_round(size_t multivariate_d,
103 const FF& last_challenge)
104 {
105 round_evaluations[multivariate_d - 1][2] = round_univariate.evaluate(last_challenge);
106 }
107
108 std::vector<std::array<FF, 3>> get_evaluations() { return round_evaluations; }
109 std::vector<Polynomial<FF>> get_univariates() { return round_univariates; }
110};
111
116template <typename Flavor, bool HasZK = Flavor::HasZK> struct VerifierZKCorrectionHandler {
117 using FF = typename Flavor::FF;
120
121 std::shared_ptr<Transcript> transcript;
124
125 // Construct a handler which will handle all the evaluations/
126 VerifierZKCorrectionHandler(std::shared_ptr<Transcript> transcript)
127 : transcript(std::move(transcript))
128 {}
129
131
132 void apply_zk_corrections(FF& /*full_honk_purported_value*/,
133 const std::vector<FF>& /*multivariate_challenge*/,
134 const std::vector<FF>& /*padding_indicator_array*/)
135 {}
136
138};
139
143template <typename Flavor> struct VerifierZKCorrectionHandler<Flavor, true> {
144 using FF = typename Flavor::FF;
147
148 std::shared_ptr<Transcript> transcript;
149 FF libra_total_sum = FF{ 0 };
152
153 // If running zero-knowledge sumcheck the target total sum is corrected by the claimed sum of libra masking
154 // multivariate over the hypercube
155 VerifierZKCorrectionHandler(std::shared_ptr<Transcript> transcript)
156 : transcript(std::move(transcript))
157 , libra_total_sum(this->transcript->template receive_from_prover<FF>("Libra:Sum"))
158 , libra_challenge(this->transcript->template get_challenge<FF>("Libra:Challenge"))
159 {}
160
161 void initialize_target_sum(SumcheckRound& round) { round.target_total_sum = libra_total_sum * libra_challenge; }
162
163 void apply_zk_corrections(FF& full_honk_purported_value,
164 std::vector<FF>& multivariate_challenge,
165 const std::vector<FF>& padding_indicator_array)
166 {
167 if constexpr (UseRowDisablingPolynomial<Flavor>) {
168 // Compute the evaluations of the polynomial (1 - \sum L_i) where the sum is for i corresponding to the
169 // rows where all sumcheck relations are disabled
170 // i.e. compute the term $1 - \prod_{i=2}^{d-1} u_i$
171 full_honk_purported_value *=
172 RowDisablingPolynomial<FF>::evaluate_at_challenge(multivariate_challenge, padding_indicator_array);
173 }
174
175 // Get the claimed evaluation of the Libra multivariate evaluated at the sumcheck challenge
176 libra_evaluation = transcript->template receive_from_prover<FF>("Libra:claimed_evaluation");
177 full_honk_purported_value += libra_evaluation * libra_challenge;
178 }
179
181};
182
289template <typename Flavor> class SumcheckProver {
290 public:
291 using FF = typename Flavor::FF;
292 // PartiallyEvaluatedMultivariates OR ProverPolynomials
293 // both inherit from AllEntities
301
308
309 // this constant specifies the number of coefficients of libra polynomials, and evaluations of round univariate
311
313
314 // The size of the hypercube, i.e. \f$ 2^d\f$.
315 const size_t multivariate_n;
316 // The number of variables
317 const size_t multivariate_d;
318 // A reference to all prover multilinear polynomials.
320
321 std::shared_ptr<Transcript> transcript;
322 // Contains the core sumcheck methods such as `compute_univariate`.
324 // An array of size NUM_SUBRELATIONS-1 containing challenges or consecutive powers of a single challenge that
325 // separate linearly independent subrelation.
327 // pow_β(X₀, ..., X_{d−1}) = ∏ₖ₌₀^{d−1} (1 − Xₖ + Xₖ ⋅ βₖ)
328 std::vector<FF> gate_challenges;
329 // Contains various challenges, such as `beta` and `gamma` used in the Grand Product argument.
331
332 // Determines the number of rounds in the sumcheck (may include padding rounds, i.e. >= multivariate_d).
334
335 std::vector<FF> multivariate_challenge;
336
337 // For computing eq polymomials in Multilinear Batching Flavor
338 std::vector<FF> accumulator_challenge = {};
339 std::vector<FF> instance_challenge = {};
341
343
344 // SumcheckProver constructor for MultilinearBatchingFlavor.
346 ProverPolynomials& prover_polynomials,
347 std::shared_ptr<Transcript> transcript,
348 const FF& relation_separator,
349 const size_t virtual_log_n,
350 const std::vector<FF>& accumulator_challenge,
351 const std::vector<FF>& instance_challenge)
354 , full_polynomials(prover_polynomials)
355 , transcript(std::move(transcript))
357 , alphas(initialize_relation_separator<FF, Flavor::NUM_SUBRELATIONS - 1>(relation_separator))
358 , gate_challenges({})
362
363 // SumcheckProver constructor for the Flavors that generate a single challenge `alpha` and use its powers as
364 // subrelation seperator challenges.
366 ProverPolynomials& prover_polynomials,
367 std::shared_ptr<Transcript> transcript,
368 const FF& alpha,
369 const std::vector<FF>& gate_challenges,
371 const size_t virtual_log_n)
374 , full_polynomials(prover_polynomials)
375 , transcript(std::move(transcript))
377 , alphas(initialize_relation_separator<FF, Flavor::NUM_SUBRELATIONS - 1>(alpha))
388 {
389 vinfo("starting sumcheck rounds...");
390
391 // Given gate challenges β = (β₀, ..., β_{d−1}) and d = `multivariate_d`, compute the evaluations of
392 // GateSeparator_β (X₀, ..., X_{d−1}) = ∏ₖ₌₀^{d−1} (1 − Xₖ + Xₖ · βₖ)
393 // on the boolean hypercube.
395
397 // In the first round, we compute the first univariate polynomial and populate the book-keeping table of
398 // #partially_evaluated_polynomials, which has \f$ n/2 \f$ rows and \f$ N \f$ columns.
399 auto round_univariate =
400 round.compute_univariate(full_polynomials, relation_parameters, gate_separators, alphas);
401
402 // Place the evaluations of the round univariate into transcript.
403 transcript->send_to_verifier("Sumcheck:univariate_0", round_univariate);
404 FF round_challenge = transcript->template get_challenge<FF>("Sumcheck:u_0");
405 multivariate_challenge.emplace_back(round_challenge);
406
407 // Populate the book-keeping table
408 PartiallyEvaluatedMultivariates partially_evaluated_polynomials =
410
411 gate_separators.partially_evaluate(round_challenge);
412 round.round_size = round.round_size >> 1;
413 for (size_t round_idx = 1; round_idx < multivariate_d; round_idx++) {
414 BB_BENCH_NAME("sumcheck loop");
415
416 // Write the round univariate to the transcript
417 round_univariate =
418 round.compute_univariate(partially_evaluated_polynomials, relation_parameters, gate_separators, alphas);
419 // Place evaluations of Sumcheck Round Univariate in the transcript
420 transcript->send_to_verifier("Sumcheck:univariate_" + std::to_string(round_idx), round_univariate);
421 FF round_challenge = transcript->template get_challenge<FF>("Sumcheck:u_" + std::to_string(round_idx));
422 multivariate_challenge.emplace_back(round_challenge);
423 // Prepare sumcheck book-keeping table for the next round.
424 partially_evaluate_in_place(partially_evaluated_polynomials, round_challenge);
425 gate_separators.partially_evaluate(round_challenge);
426 round.round_size = round.round_size >> 1;
427 }
428 vinfo("completed ", multivariate_d, " rounds of sumcheck");
429
431 // If required, extend prover's multilinear polynomials in `multivariate_d` variables by zero to get multilinear
432 // polynomials in `virtual_log_n` variables.
433 for (size_t k = multivariate_d; k < virtual_log_n; ++k) {
434 if constexpr (isMultilinearBatchingFlavor) {
435 // We need to specify the evaluation at index 1 for eq polynomials
436 std::vector<FF> index_1_challenge(virtual_log_n);
437 for (size_t i = 0; i < k; i++) {
438 index_1_challenge[i] = multivariate_challenge[i];
439 }
440 index_1_challenge[k] = FF(1);
441 if (partially_evaluated_polynomials.eq_accumulator.size() == 1) {
442
443 // We need to reallocate the polynomials
444 auto new_polynomial =
445 Polynomial<FF>(2, partially_evaluated_polynomials.eq_accumulator.virtual_size());
446 new_polynomial.at(0) = partially_evaluated_polynomials.eq_accumulator.at(0);
447 partially_evaluated_polynomials.eq_accumulator = new_polynomial;
448 }
449 if (partially_evaluated_polynomials.eq_instance.size() == 1) {
450 // We need to reallocate the polynomials
451 auto new_polynomial = Polynomial<FF>(2, partially_evaluated_polynomials.eq_instance.virtual_size());
452 new_polynomial.at(0) = partially_evaluated_polynomials.eq_instance.at(0);
453 partially_evaluated_polynomials.eq_instance = new_polynomial;
454 }
455 partially_evaluated_polynomials.eq_accumulator.at(1) =
457 partially_evaluated_polynomials.eq_instance.at(1) =
459 index_1_challenge[k] = FF(0);
460 }
461 // Compute the contribution from the extensions by zero. It is sufficient to evaluate the main constraint at
462 // `MAX_PARTIAL_RELATION_LENGTH` points.
463 const auto virtual_round_univariate = round.compute_virtual_contribution(
464 partially_evaluated_polynomials, relation_parameters, virtual_gate_separator, alphas);
465
466 transcript->send_to_verifier("Sumcheck:univariate_" + std::to_string(k), virtual_round_univariate);
467
468 const FF round_challenge = transcript->template get_challenge<FF>("Sumcheck:u_" + std::to_string(k));
469 multivariate_challenge.emplace_back(round_challenge);
470
471 // Update the book-keeping table of partial evaluations of the prover polynomials extended by zero.
472 for (auto& poly : partially_evaluated_polynomials.get_all()) {
473 // Avoid bad access if polynomials are set to be of size 0, which can happen in AVM.
474 if (poly.size() > 0) {
475 if (poly.size() == 1) {
476 poly.at(0) *= (FF(1) - round_challenge);
477 } else if (poly.size() == 2) {
478 // Here we handle the eq polynomial case
479 poly.at(0) = poly.at(0) * (FF(1) - round_challenge) + poly.at(1) * round_challenge;
480 poly.at(1) = 0;
481 } else {
482 BB_ASSERT_EQ(true, false, "Polynomial size is not 1 or 2");
483 }
484 }
485 }
486 virtual_gate_separator.partially_evaluate(round_challenge);
487 }
488
489 ClaimedEvaluations multivariate_evaluations = extract_claimed_evaluations(partially_evaluated_polynomials);
490 transcript->send_to_verifier("Sumcheck:evaluations", multivariate_evaluations.get_all());
491 // For ZK Flavors: the evaluations of Libra univariates are included in the Sumcheck Output
492
494 .claimed_evaluations = multivariate_evaluations };
495 vinfo("finished sumcheck");
496 };
497
505 SumcheckOutput<Flavor> prove(ZKData& zk_sumcheck_data)
506 requires Flavor::HasZK
507 {
509 vinfo("starting sumcheck rounds...");
510 // Given gate challenges β = (β₀, ..., β_{d−1}) and d = `multivariate_d`, compute the evaluations of
511 // GateSeparator_β (X₀, ..., X_{d−1}) = ∏ₖ₌₀^{d−1} (1 − Xₖ + Xₖ · βₖ)
512 // on the boolean hypercube.
514
516 size_t round_idx = 0;
517 // In the first round, we compute the first univariate polynomial and populate the book-keeping table of
518 // #partially_evaluated_polynomials, which has \f$ n/2 \f$ rows and \f$ N \f$ columns.
519
520 // Compute the round univariate
521 auto round_univariate =
522 round.compute_univariate(full_polynomials, relation_parameters, gate_separators, alphas);
523
524 // Add the contribution from the Libra univariates
525 auto hiding_univariate = round.compute_libra_univariate(zk_sumcheck_data, round_idx);
526 round_univariate += hiding_univariate;
527
528 // Subtract the contribution from the disabled rows
529 if constexpr (UseRowDisablingPolynomial<Flavor>) {
530 round_univariate -= round.compute_disabled_contribution(
532 }
533
534 handler.process_round_univariate(round_idx, round_univariate);
535 const FF round_challenge = transcript->template get_challenge<FF>("Sumcheck:u_0");
536 multivariate_challenge.emplace_back(round_challenge);
537
538 // Populate the book-keeping table
539 PartiallyEvaluatedMultivariates partially_evaluated_polynomials =
541
542 // Prepare ZK Sumcheck data for the next round
543 zk_sumcheck_data.update_zk_sumcheck_data(round_challenge, round_idx);
544 row_disabling_polynomial.update_evaluations(round_challenge, round_idx);
545 gate_separators.partially_evaluate(round_challenge);
546 round.round_size = round.round_size >> 1;
547 for (size_t round_idx = 1; round_idx < multivariate_d; round_idx++) {
548 BB_BENCH_NAME("sumcheck loop");
549
550 // Computes the round univariate in two parts: first the contribution necessary to hide the polynomial and
551 // account for having randomness at the end of the trace and then the contribution from the full
552 // relation. Note: we compute the hiding univariate first as the `compute_univariate` method prepares
553 // relevant data structures for the next round
554 round_univariate =
555 round.compute_univariate(partially_evaluated_polynomials, relation_parameters, gate_separators, alphas);
556 hiding_univariate = round.compute_libra_univariate(zk_sumcheck_data, round_idx);
557 // Add the contribution from the Libra univariates
558 round_univariate += hiding_univariate;
559 // Subtract the contribution from the disabled rows
560 if constexpr (UseRowDisablingPolynomial<Flavor>) {
561 round_univariate -= round.compute_disabled_contribution(partially_evaluated_polynomials,
563 gate_separators,
564 alphas,
565 round_idx,
567 }
568
569 handler.process_round_univariate(round_idx, round_univariate);
570
571 const FF round_challenge =
572 transcript->template get_challenge<FF>("Sumcheck:u_" + std::to_string(round_idx));
573 multivariate_challenge.emplace_back(round_challenge);
574 // Prepare sumcheck book-keeping table for the next round.
575 partially_evaluate_in_place(partially_evaluated_polynomials, round_challenge);
576 // Prepare evaluation masking and libra structures for the next round (for ZK Flavors)
577 zk_sumcheck_data.update_zk_sumcheck_data(round_challenge, round_idx);
578 row_disabling_polynomial.update_evaluations(round_challenge, round_idx);
579
580 gate_separators.partially_evaluate(round_challenge);
581 round.round_size = round.round_size >> 1;
582 }
583
584 handler.finalize_last_round(multivariate_d, round_univariate, multivariate_challenge[multivariate_d - 1]);
585
586 vinfo("completed ", multivariate_d, " rounds of sumcheck");
587
588 // Zero univariates are used to pad the proof to the fixed size virtual_log_n.
590 for (size_t idx = multivariate_d; idx < virtual_log_n; idx++) {
591 transcript->send_to_verifier("Sumcheck:univariate_" + std::to_string(idx), zero_univariate);
592
593 FF round_challenge = transcript->template get_challenge<FF>("Sumcheck:u_" + std::to_string(idx));
594 multivariate_challenge.emplace_back(round_challenge);
595 }
596
597 // Claimed evaluations of Prover polynomials are extracted and added to the transcript. When Flavor has ZK, the
598 // evaluations of all witnesses are masked.
599 ClaimedEvaluations multivariate_evaluations = extract_claimed_evaluations(partially_evaluated_polynomials);
600 transcript->send_to_verifier("Sumcheck:evaluations", multivariate_evaluations.get_all());
601
602 // The evaluations of Libra uninvariates at \f$ g_0(u_0), \ldots, g_{d-1} (u_{d-1}) \f$ are added to the
603 // transcript.
604 FF libra_evaluation = zk_sumcheck_data.constant_term;
605 for (const auto& libra_eval : zk_sumcheck_data.libra_evaluations) {
606 libra_evaluation += libra_eval;
607 }
608 transcript->send_to_verifier("Libra:claimed_evaluation", libra_evaluation);
609
610 // The sum of the Libra constant term and the evaluations of Libra univariates at corresponding sumcheck
611 // challenges is included in the Sumcheck Output
612 return SumcheckOutput<Flavor>{ .challenge = multivariate_challenge,
613 .claimed_evaluations = multivariate_evaluations,
614 .claimed_libra_evaluation = libra_evaluation,
615 .round_univariates = handler.get_univariates(),
616 .round_univariate_evaluations = handler.get_evaluations() };
617 vinfo("finished sumcheck");
618 };
619
625 void partially_evaluate(auto& source_polynomials,
626 PartiallyEvaluatedMultivariates& dest_polynomials,
627 const FF& round_challenge)
628 {
629 auto source_view = source_polynomials.get_all();
630 auto dest_view = dest_polynomials.get_all();
631 parallel_for(source_view.size(), [&](size_t j) {
632 const auto& poly = source_view[j];
633 size_t limit = poly.end_index();
634 for (size_t i = 0; i < limit; i += 2) {
635 dest_view[j].at(i >> 1) = poly[i] + round_challenge * (poly[i + 1] - poly[i]);
636 }
637 dest_view[j].shrink_end_index((limit / 2) + (limit % 2));
638 });
639 };
647 const FF& round_challenge)
648 {
649 PartiallyEvaluatedMultivariates partially_evaluated_polynomials(full_polynomials, multivariate_n);
650 partially_evaluate(full_polynomials, partially_evaluated_polynomials, round_challenge);
651 return partially_evaluated_polynomials;
652 }
653
657 void partially_evaluate_in_place(PartiallyEvaluatedMultivariates& polynomials, const FF& round_challenge)
658 {
659 partially_evaluate(polynomials, polynomials, round_challenge);
660 };
661
674 {
675 ClaimedEvaluations multivariate_evaluations;
676 for (auto [eval, poly] :
677 zip_view(multivariate_evaluations.get_all(), partially_evaluated_polynomials.get_all())) {
678 eval = poly[0];
679 };
680 return multivariate_evaluations;
681 };
682};
719template <typename Flavor> class SumcheckVerifier {
720
721 public:
723 using FF = typename Flavor::FF;
730 // For ZK Flavors: the verifier obtains a vector of evaluations of \f$ d \f$ univariate polynomials and uses them to
731 // compute full_honk_relation_purported_value
732 using ClaimedLibraEvaluations = typename std::vector<FF>;
736
741 static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = Flavor::BATCHED_RELATION_PARTIAL_LENGTH;
746 static constexpr size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES;
747
748 std::shared_ptr<Transcript> transcript;
750
751 // Determines number of rounds in the sumcheck (may include padding rounds)
753
754 // An array of size NUM_SUBRELATIONS-1 containing challenges or consecutive powers of a single challenge that
755 // separate linearly independent subrelation.
757
758 explicit SumcheckVerifier(std::shared_ptr<Transcript> transcript,
759 const FF& alpha,
760 size_t virtual_log_n,
761 FF target_sum = 0)
762 : transcript(std::move(transcript))
763 , round(target_sum)
764 , virtual_log_n(virtual_log_n)
765 , alphas(initialize_relation_separator<FF, Flavor::NUM_SUBRELATIONS - 1>(alpha)) {};
778 const std::vector<FF>& gate_challenges,
779 const std::vector<FF>& padding_indicator_array)
780 {
781 bb::GateSeparatorPolynomial<FF> gate_separators(gate_challenges);
782 // Construct a ZKHandler to handle all the libra related information in the transcript
783 VerifierZKCorrectionHandler<Flavor> zk_correction_handler(transcript);
784
785 // Correct the target sum in the round in the ZK case
786 zk_correction_handler.initialize_target_sum(round);
787
788 std::vector<FF> multivariate_challenge;
789 multivariate_challenge.reserve(virtual_log_n);
790
791 // Process univariate consistancy check rounds
792 // For ECCVM we ensure the consistencies by populating an vector of claimed evaluations that will be checked in
793 // the PCS rounds
794 // For other flavors, we perform the sumcheck univariate consistency check
795
796 bool verified = true;
797 for (size_t round_idx = 0; round_idx < virtual_log_n; round_idx++) {
798 round.process_round(
799 transcript, multivariate_challenge, gate_separators, padding_indicator_array[round_idx], round_idx);
800 verified = verified && !round.round_failed;
801 }
802
803 // Populate claimed evaluations at the challenge
804 ClaimedEvaluations purported_evaluations;
805 auto transcript_evaluations =
806 transcript->template receive_from_prover<std::array<FF, NUM_POLYNOMIALS>>("Sumcheck:evaluations");
807 for (auto [eval, transcript_eval] : zip_view(purported_evaluations.get_all(), transcript_evaluations)) {
808 eval = transcript_eval;
809 }
810
811 // Evaluate the Honk relation at the point (u_0, ..., u_{d-1}) using claimed evaluations of prover polynomials.
812 // In ZK Flavors, the evaluation is corrected by full_libra_purported_value
813 FF full_honk_purported_value = round.compute_full_relation_purported_value(
814 purported_evaluations, relation_parameters, gate_separators, alphas);
815
816 // For ZK Flavors: compute the evaluation of the Row Disabling Polynomial at the sumcheck challenge and of the
817 // libra univariate used to hide the contribution from the actual Honk relation
818 zk_correction_handler.apply_zk_corrections(
819 full_honk_purported_value, multivariate_challenge, padding_indicator_array);
820
822 verified = round.perform_final_verification(full_honk_purported_value) && verified;
823
824 // For ZK Flavors: the evaluations of Libra univariates are included in the Sumcheck Output
825 return SumcheckOutput<Flavor>{ .challenge = multivariate_challenge,
826 .claimed_evaluations = purported_evaluations,
827 .verified = verified,
828 .claimed_libra_evaluation = zk_correction_handler.get_libra_evaluation(),
829 .round_univariate_commitments = round.get_round_univariate_commitments(),
830 .round_univariate_evaluations = round.get_round_univariate_evaluations() };
831 };
832};
833
834template <typename FF, size_t N> std::array<FF, N> initialize_relation_separator(const FF& alpha)
835{
836 std::array<FF, N> alphas;
837 alphas[0] = alpha;
838 for (size_t i = 1; i < N; ++i) {
839 alphas[i] = alphas[i - 1] * alpha;
840 }
841 return alphas;
842}
843} // namespace bb
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:83
bb::field< bb::Bn254FrParams > FF
Definition field.cpp:24
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:219
A field element for each entity of the flavor. These entities represent the prover polynomials evalua...
A container for the prover polynomials.
static constexpr bool HasZK
typename Curve::ScalarField FF
static constexpr size_t NUM_SUBRELATIONS
static constexpr size_t NUM_ALL_ENTITIES
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH
typename G1::affine_element Commitment
PartiallyEvaluatedMultivariatesBase< AllEntities< Polynomial >, ProverPolynomials, Polynomial > PartiallyEvaluatedMultivariates
A container for storing the partially evaluated multivariates produced by sumcheck.
bb::CommitmentKey< Curve > CommitmentKey
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
BaseTranscript< Codec, HashFunction > Transcript
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
The implementation of the sumcheck Prover for statements of the form for multilinear polynomials .
Definition sumcheck.hpp:289
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
Definition sumcheck.hpp:310
typename Flavor::FF FF
Definition sumcheck.hpp:291
ProverPolynomials & full_polynomials
Definition sumcheck.hpp:319
const size_t multivariate_n
Definition sumcheck.hpp:315
bb::RelationParameters< FF > relation_parameters
Definition sumcheck.hpp:330
typename Flavor::Transcript Transcript
Definition sumcheck.hpp:298
std::vector< FF > accumulator_challenge
Definition sumcheck.hpp:338
std::vector< FF > instance_challenge
Definition sumcheck.hpp:339
PartiallyEvaluatedMultivariates partially_evaluate_first_round(ProverPolynomials &full_polynomials, const FF &round_challenge)
Initialize partially evaluated polynomials and perform first round of partial evaluation.
Definition sumcheck.hpp:646
static constexpr bool isMultilinearBatchingFlavor
Definition sumcheck.hpp:302
typename Flavor::ProverPolynomials ProverPolynomials
Definition sumcheck.hpp:294
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH
The total algebraic degree of the Sumcheck relation as a polynomial in Prover Polynomials .
Definition sumcheck.hpp:307
std::array< FF, Flavor::NUM_SUBRELATIONS - 1 > SubrelationSeparators
Definition sumcheck.hpp:299
const size_t multivariate_d
Definition sumcheck.hpp:317
ClaimedEvaluations extract_claimed_evaluations(PartiallyEvaluatedMultivariates &partially_evaluated_polynomials)
This method takes the book-keeping table containing partially evaluated prover polynomials and create...
Definition sumcheck.hpp:673
typename Flavor::AllValues ClaimedEvaluations
Definition sumcheck.hpp:296
typename bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > SumcheckRoundUnivariate
Definition sumcheck.hpp:312
SumcheckOutput< Flavor > prove(ZKData &zk_sumcheck_data) void partially_evaluate(auto &source_polynomials, PartiallyEvaluatedMultivariates &dest_polynomials, const FF &round_challenge)
ZK-version of prove that runs Sumcheck with disabled rows and masking of Round Univariates....
Definition sumcheck.hpp:625
std::vector< FF > multivariate_challenge
Definition sumcheck.hpp:335
typename Flavor::PartiallyEvaluatedMultivariates PartiallyEvaluatedMultivariates
Definition sumcheck.hpp:295
SumcheckProver(size_t multivariate_n, ProverPolynomials &prover_polynomials, std::shared_ptr< Transcript > transcript, const FF &alpha, const std::vector< FF > &gate_challenges, const RelationParameters< FF > &relation_parameters, const size_t virtual_log_n)
Definition sumcheck.hpp:365
RowDisablingPolynomial< FF > row_disabling_polynomial
Definition sumcheck.hpp:342
typename Flavor::CommitmentKey CommitmentKey
Definition sumcheck.hpp:300
SumcheckProver(size_t multivariate_n, ProverPolynomials &prover_polynomials, std::shared_ptr< Transcript > transcript, const FF &relation_separator, const size_t virtual_log_n, const std::vector< FF > &accumulator_challenge, const std::vector< FF > &instance_challenge)
Definition sumcheck.hpp:345
std::vector< FF > gate_challenges
Definition sumcheck.hpp:328
SumcheckProverRound< Flavor > round
Definition sumcheck.hpp:323
void partially_evaluate_in_place(PartiallyEvaluatedMultivariates &polynomials, const FF &round_challenge)
Evaluate at the round challenge in-place.
Definition sumcheck.hpp:657
std::shared_ptr< Transcript > transcript
Definition sumcheck.hpp:321
SumcheckOutput< Flavor > prove()
Non-ZK version: Compute round univariate, place it in transcript, compute challenge,...
Definition sumcheck.hpp:387
ZKSumcheckData< Flavor > ZKData
Definition sumcheck.hpp:297
SubrelationSeparators alphas
Definition sumcheck.hpp:326
Imlementation of the Sumcheck prover round.
Implementation of the sumcheck Verifier for statements of the form for multilinear polynomials .
Definition sumcheck.hpp:719
typename std::vector< FF > ClaimedLibraEvaluations
Definition sumcheck.hpp:732
std::array< FF, Flavor::NUM_SUBRELATIONS - 1 > SubrelationSeparators
Definition sumcheck.hpp:734
typename Flavor::FF FF
Definition sumcheck.hpp:723
typename Flavor::Commitment Commitment
Definition sumcheck.hpp:735
SumcheckVerifierRound< Flavor > round
Definition sumcheck.hpp:749
SumcheckVerifier(std::shared_ptr< Transcript > transcript, const FF &alpha, size_t virtual_log_n, FF target_sum=0)
Definition sumcheck.hpp:758
std::shared_ptr< Transcript > transcript
Definition sumcheck.hpp:748
typename Flavor::AllValues ClaimedEvaluations
Container type for the evaluations of Prover Polynomials at the challenge point .
Definition sumcheck.hpp:729
SubrelationSeparators alphas
Definition sumcheck.hpp:756
typename Flavor::Transcript Transcript
Definition sumcheck.hpp:733
SumcheckOutput< Flavor > verify(const bb::RelationParameters< FF > &relation_parameters, const std::vector< FF > &gate_challenges, const std::vector< FF > &padding_indicator_array)
The Sumcheck verification method. First it extracts round univariate, checks sum (the sumcheck univar...
Definition sumcheck.hpp:777
Implementation of the Sumcheck Verifier Round.
std::vector< Commitment > get_round_univariate_commitments()
Get round univariate commitments (only used for Grumpkin flavors).
void process_round(const std::shared_ptr< Transcript > &transcript, std::vector< FF > &multivariate_challenge, bb::GateSeparatorPolynomial< FF > &gate_separators, const FF &padding_indicator, size_t round_idx)
Process a single sumcheck round: receive univariate from transcript, verify sum, generate challenge.
bool perform_final_verification(const FF &full_honk_purported_value)
Perform final verification: check that the computed target sum matches the full relation evaluation....
std::vector< std::array< FF, 3 > > get_round_univariate_evaluations()
Get round univariate evaluations (only used for Grumpkin flavors).
FF compute_full_relation_purported_value(const ClaimedEvaluations &purported_evaluations, const bb::RelationParameters< FF > &relation_parameters, const bb::GateSeparatorPolynomial< FF > &gate_separators, const SubrelationSeparators &alphas)
Compute the full relation purported value.
A univariate polynomial represented by its values on {0, 1,..., domain_end - 1}.
Fr & value_at(size_t i)
static Univariate zero()
std::array< Fr, LENGTH > evaluations
Fr evaluate(const Fr &u) const
Evaluate a univariate at a point u not known at compile time and assumed not to be in the domain (els...
#define vinfo(...)
Definition log.hpp:94
constexpr T get_msb(const T in)
Definition get_msb.hpp:47
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
CommitmentKey< Curve > ck
std::array< FF, N > initialize_relation_separator(const FF &alpha)
Definition sumcheck.hpp:834
void parallel_for(size_t num_iterations, const std::function< void(size_t)> &func)
Definition thread.cpp:111
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)
Implementation of the methods for the -polynomials used in in Sumcheck.
void partially_evaluate(FF challenge)
Partially evaluate the -polynomial at the new challenge and update .
Container for parameters used by the grand product (permutation, lookup) Honk relations.
std::vector< std::array< FF, 3 > > round_evaluations
Definition sumcheck.hpp:63
void process_round_univariate(size_t round_idx, bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > &round_univariate)
Definition sumcheck.hpp:77
typename Flavor::CommitmentKey CommitmentKey
Definition sumcheck.hpp:57
std::vector< Polynomial< FF > > round_univariates
Definition sumcheck.hpp:64
void finalize_last_round(size_t multivariate_d, const bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > &round_univariate, const FF &last_challenge)
Definition sumcheck.hpp:101
std::vector< Polynomial< FF > > get_univariates()
Definition sumcheck.hpp:109
std::shared_ptr< Transcript > transcript
Definition sumcheck.hpp:60
typename Flavor::Transcript Transcript
Definition sumcheck.hpp:56
std::vector< std::array< FF, 3 > > get_evaluations()
Definition sumcheck.hpp:108
RoundUnivariateHandler(std::shared_ptr< Transcript > transcript)
Definition sumcheck.hpp:66
Handler for processing round univariates in sumcheck. Default implementation: send evaluations direct...
Definition sumcheck.hpp:24
std::vector< Polynomial< FF > > get_univariates()
Definition sumcheck.hpp:48
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
Definition sumcheck.hpp:28
typename Flavor::CommitmentKey CommitmentKey
Definition sumcheck.hpp:27
void process_round_univariate(size_t round_idx, bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > &round_univariate)
Definition sumcheck.hpp:36
RoundUnivariateHandler(std::shared_ptr< Transcript > transcript)
Definition sumcheck.hpp:32
std::shared_ptr< Transcript > transcript
Definition sumcheck.hpp:30
std::vector< std::array< FF, 3 > > get_evaluations()
Definition sumcheck.hpp:47
typename Flavor::FF FF
Definition sumcheck.hpp:25
void finalize_last_round(size_t, const bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > &, const FF &)
Definition sumcheck.hpp:42
typename Flavor::Transcript Transcript
Definition sumcheck.hpp:26
Polynomial for Sumcheck with disabled Rows.
static FF evaluate_at_challenge(std::vector< FF > multivariate_challenge, const size_t log_circuit_size)
Compute the evaluation of at the sumcheck challenge.
Contains the evaluations of multilinear polynomials at the challenge point . These are computed by S...
std::vector< FF > challenge
static FF eval(std::span< const FF > r_in, std::span< const FF > u)
VerifierZKCorrectionHandler(std::shared_ptr< Transcript > transcript)
Definition sumcheck.hpp:155
void initialize_target_sum(SumcheckRound &round)
Definition sumcheck.hpp:161
std::shared_ptr< Transcript > transcript
Definition sumcheck.hpp:148
void apply_zk_corrections(FF &full_honk_purported_value, std::vector< FF > &multivariate_challenge, const std::vector< FF > &padding_indicator_array)
Definition sumcheck.hpp:163
Handler for ZK-related verification adjustments in sumcheck. Default implementation: no ZK adjustment...
Definition sumcheck.hpp:116
void apply_zk_corrections(FF &, const std::vector< FF > &, const std::vector< FF > &)
Definition sumcheck.hpp:132
typename Flavor::Transcript Transcript
Definition sumcheck.hpp:118
void initialize_target_sum(SumcheckRound &)
Definition sumcheck.hpp:130
std::shared_ptr< Transcript > transcript
Definition sumcheck.hpp:121
VerifierZKCorrectionHandler(std::shared_ptr< Transcript > transcript)
Definition sumcheck.hpp:126
This structure is created to contain various polynomials and constants required by ZK Sumcheck.