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
18#include "sumcheck_round.hpp"
19
20namespace bb {
21
26template <typename Flavor, bool CommittedSumcheck = UsesCommittedSumcheck<Flavor>> struct RoundUnivariateHandler {
27 using FF = typename Flavor::FF;
31
32 std::shared_ptr<Transcript> transcript;
33
34 RoundUnivariateHandler(std::shared_ptr<Transcript> transcript)
35 : transcript(std::move(transcript))
36 {}
37
38 void process_round_univariate(size_t round_idx,
40 {
41 transcript->send_to_verifier("Sumcheck:univariate_" + std::to_string(round_idx), round_univariate);
42 }
43
44 void finalize_last_round(size_t /*multivariate_d*/,
46 const FF& /*last_challenge*/)
47 {}
48
51};
52
56template <typename Flavor> struct RoundUnivariateHandler<Flavor, true> {
57 using FF = typename Flavor::FF;
61
62 std::shared_ptr<Transcript> transcript;
64 std::vector<FF> eval_domain;
67
68 RoundUnivariateHandler(std::shared_ptr<Transcript> transcript)
69 : transcript(std::move(transcript))
71 {
72 // Compute the vector {0, 1, \ldots, BATCHED_RELATION_PARTIAL_LENGTH-1} needed to transform
73 // the round univariates from Lagrange to monomial basis
74 for (size_t idx = 0; idx < BATCHED_RELATION_PARTIAL_LENGTH; idx++) {
75 eval_domain.push_back(FF(idx));
76 }
77 }
78
79 void process_round_univariate(size_t round_idx,
81 {
82 const std::string idx = std::to_string(round_idx);
83
84 // Transform to monomial form and commit to it
85 Polynomial<FF> round_poly_monomial(
86 eval_domain, std::span<FF>(round_univariate.evaluations), BATCHED_RELATION_PARTIAL_LENGTH);
87 transcript->send_to_verifier("Sumcheck:univariate_comm_" + idx, ck.commit(round_poly_monomial));
88
89 // Store round univariate in monomial, as it is required by Shplemini
90 round_univariates.push_back(std::move(round_poly_monomial));
91
92 // Send the evaluations of the round univariate at 0 and 1
93 transcript->send_to_verifier("Sumcheck:univariate_" + idx + "_eval_0", round_univariate.value_at(0));
94 transcript->send_to_verifier("Sumcheck:univariate_" + idx + "_eval_1", round_univariate.value_at(1));
95
96 // Store the evaluations to be used by ShpleminiProver.
97 round_evaluations.push_back({ round_univariate.value_at(0), round_univariate.value_at(1), FF(0) });
98 if (round_idx > 0) {
99 round_evaluations[round_idx - 1][2] = round_univariate.value_at(0) + round_univariate.value_at(1);
100 }
101 }
102
103 void finalize_last_round(size_t multivariate_d,
105 const FF& last_challenge)
106 {
107 round_evaluations[multivariate_d - 1][2] = round_univariate.evaluate(last_challenge);
108 }
109
110 std::vector<std::array<FF, 3>> get_evaluations() { return round_evaluations; }
111 std::vector<Polynomial<FF>> get_univariates() { return round_univariates; }
112};
113
118template <typename Flavor, bool HasZK = Flavor::HasZK> struct VerifierZKCorrectionHandler {
119 using FF = typename Flavor::FF;
122
123 std::shared_ptr<Transcript> transcript;
126
127 // Construct a handler which will handle all the evaluations/
128 VerifierZKCorrectionHandler(std::shared_ptr<Transcript> transcript)
129 : transcript(std::move(transcript))
130 {}
131
133
134 void apply_zk_corrections(FF& /*full_honk_purported_value*/, const std::vector<FF>& /*multivariate_challenge*/) {}
135
137};
138
142template <typename Flavor> struct VerifierZKCorrectionHandler<Flavor, true> {
143 using FF = typename Flavor::FF;
146
147 std::shared_ptr<Transcript> transcript;
148 FF libra_total_sum = FF{ 0 };
151
152 // If running zero-knowledge sumcheck the target total sum is corrected by the claimed sum of libra masking
153 // multivariate over the hypercube
154 VerifierZKCorrectionHandler(std::shared_ptr<Transcript> transcript)
155 : transcript(std::move(transcript))
156 , libra_total_sum(this->transcript->template receive_from_prover<FF>("Libra:Sum"))
157 , libra_challenge(this->transcript->template get_challenge<FF>("Libra:Challenge"))
158 {}
159
160 void initialize_target_sum(SumcheckRound& round) { round.target_total_sum = libra_total_sum * libra_challenge; }
161
162 void apply_zk_corrections(FF& full_honk_purported_value, std::vector<FF>& multivariate_challenge)
163 {
164 if constexpr (UseRowDisablingPolynomial<Flavor>) {
165 // The row-disabling polynomial 1 - ∏_{i≥2}(1-u_i) is circuit-size
166 // independent. The verifier evaluates it over ALL challenges.
167 full_honk_purported_value *= RowDisablingPolynomial<FF>::evaluate_at_challenge(
168 multivariate_challenge, multivariate_challenge.size());
169 }
170
171 // Get the claimed evaluation of the Libra multivariate evaluated at the sumcheck challenge
172 libra_evaluation = transcript->template receive_from_prover<FF>("Libra:claimed_evaluation");
173
174 // OriginTag false positive: libra_evaluation is PCS-bound (verified by Shplemini opening).
175 // Once commitments are fixed and sumcheck challenges derived, the correct evaluation is determined.
176 if constexpr (IsRecursiveFlavor<Flavor>) {
177 const auto challenge_tag = multivariate_challenge.back().get_origin_tag();
178 libra_evaluation.set_origin_tag(challenge_tag);
179 }
180
181 full_honk_purported_value += libra_evaluation * libra_challenge;
182 }
183
185};
186
293template <typename Flavor> class SumcheckProver {
294 public:
295 using FF = typename Flavor::FF;
296 // PartiallyEvaluatedMultivariates OR ProverPolynomials
297 // both inherit from AllEntities
305
312
313 // this constant specifies the number of coefficients of libra polynomials, and evaluations of round univariate
315
317
318 // The size of the hypercube, i.e. \f$ 2^d\f$.
319 const size_t multivariate_n;
320 // The number of variables
321 const size_t multivariate_d;
322 // A reference to all prover multilinear polynomials.
324
325 std::shared_ptr<Transcript> transcript;
326 // Contains the core sumcheck methods such as `compute_univariate`.
328 // An array of size NUM_SUBRELATIONS-1 containing challenges or consecutive powers of a single challenge that
329 // separate linearly independent subrelation.
331 // pow_β(X₀, ..., X_{d−1}) = ∏ₖ₌₀^{d−1} (1 − Xₖ + Xₖ ⋅ βₖ)
332 std::vector<FF> gate_challenges;
333 // Contains various challenges, such as `beta` and `gamma` used in the Grand Product argument.
335
336 // Determines the number of rounds in the sumcheck (may include padding rounds, i.e. >= multivariate_d).
338
339 std::vector<FF> multivariate_challenge;
340
341 // For computing eq polymomials in Multilinear Batching Flavor
342 std::vector<FF> accumulator_challenge = {};
343 std::vector<FF> instance_challenge = {};
345
347
348 // SumcheckProver constructor for MultilinearBatchingFlavor.
350 ProverPolynomials& prover_polynomials,
351 std::shared_ptr<Transcript> transcript,
352 const FF& relation_separator,
353 const size_t virtual_log_n,
354 const std::vector<FF>& accumulator_challenge,
355 const std::vector<FF>& instance_challenge)
358 , full_polynomials(prover_polynomials)
359 , transcript(std::move(transcript))
361 , alphas(initialize_relation_separator<FF, Flavor::NUM_SUBRELATIONS - 1>(relation_separator))
362 , gate_challenges({})
366
367 // SumcheckProver constructor for the Flavors that generate a single challenge `alpha` and use its powers as
368 // subrelation seperator challenges.
370 ProverPolynomials& prover_polynomials,
371 std::shared_ptr<Transcript> transcript,
372 const FF& alpha,
373 const std::vector<FF>& gate_challenges,
375 const size_t virtual_log_n)
378 , full_polynomials(prover_polynomials)
379 , transcript(std::move(transcript))
381 , alphas(initialize_relation_separator<FF, Flavor::NUM_SUBRELATIONS - 1>(alpha))
392 {
393 vinfo("starting sumcheck rounds...");
394
395 // Given gate challenges β = (β₀, ..., β_{d−1}) and d = `multivariate_d`, compute the evaluations of
396 // GateSeparator_β (X₀, ..., X_{d−1}) = ∏ₖ₌₀^{d−1} (1 − Xₖ + Xₖ · βₖ)
397 // on the boolean hypercube.
399
401 // In the first round, we compute the first univariate polynomial and populate the book-keeping table of
402 // #partially_evaluated_polynomials, which has \f$ n/2 \f$ rows and \f$ N \f$ columns.
403 PartiallyEvaluatedMultivariates partially_evaluated_polynomials = [&] {
404 BB_BENCH_NAME("sumcheck loop 0");
405 auto round_univariate =
406 round.compute_univariate(full_polynomials, relation_parameters, gate_separators, alphas);
407
408 // Place the evaluations of the round univariate into transcript.
409 transcript->send_to_verifier("Sumcheck:univariate_0", round_univariate);
410 FF round_challenge = transcript->template get_challenge<FF>("Sumcheck:u_0");
411 multivariate_challenge.emplace_back(round_challenge);
412
413 // Populate the book-keeping table
414 auto result = partially_evaluate_first_round(full_polynomials, round_challenge);
415 gate_separators.partially_evaluate(round_challenge);
416 round.round_size = round.round_size >> 1;
417 return result;
418 }();
419 for (size_t round_idx = 1; round_idx < multivariate_d; round_idx++) {
420 BB_BENCH_NAME("sumcheck loop");
421
422 // Write the round univariate to the transcript
423 auto round_univariate =
424 round.compute_univariate(partially_evaluated_polynomials, relation_parameters, gate_separators, alphas);
425 // Place evaluations of Sumcheck Round Univariate in the transcript
426 transcript->send_to_verifier("Sumcheck:univariate_" + std::to_string(round_idx), round_univariate);
427 FF round_challenge = transcript->template get_challenge<FF>("Sumcheck:u_" + std::to_string(round_idx));
428 multivariate_challenge.emplace_back(round_challenge);
429 // Prepare sumcheck book-keeping table for the next round.
430 partially_evaluate_in_place(partially_evaluated_polynomials, round_challenge);
431 gate_separators.partially_evaluate(round_challenge);
432 round.round_size = round.round_size >> 1;
433 }
434 vinfo("completed ", multivariate_d, " rounds of sumcheck");
435
437 // If required, extend prover's multilinear polynomials in `multivariate_d` variables by zero to get multilinear
438 // polynomials in `virtual_log_n` variables.
439 for (size_t k = multivariate_d; k < virtual_log_n; ++k) {
440 if constexpr (isMultilinearBatchingFlavor) {
441 // We need to specify the evaluation at index 1 for eq polynomials
442 std::vector<FF> index_1_challenge(virtual_log_n);
443 for (size_t i = 0; i < k; i++) {
444 index_1_challenge[i] = multivariate_challenge[i];
445 }
446 index_1_challenge[k] = FF(1);
447 if (partially_evaluated_polynomials.eq_accumulator.size() == 1) {
448
449 // We need to reallocate the polynomials
450 auto new_polynomial =
451 Polynomial<FF>(2, partially_evaluated_polynomials.eq_accumulator.virtual_size());
452 new_polynomial.at(0) = partially_evaluated_polynomials.eq_accumulator.at(0);
453 partially_evaluated_polynomials.eq_accumulator = new_polynomial;
454 }
455 if (partially_evaluated_polynomials.eq_instance.size() == 1) {
456 // We need to reallocate the polynomials
457 auto new_polynomial = Polynomial<FF>(2, partially_evaluated_polynomials.eq_instance.virtual_size());
458 new_polynomial.at(0) = partially_evaluated_polynomials.eq_instance.at(0);
459 partially_evaluated_polynomials.eq_instance = new_polynomial;
460 }
461 partially_evaluated_polynomials.eq_accumulator.at(1) =
463 partially_evaluated_polynomials.eq_instance.at(1) =
465 index_1_challenge[k] = FF(0);
466 }
467 // Compute the contribution from the extensions by zero. It is sufficient to evaluate the main constraint at
468 // `MAX_PARTIAL_RELATION_LENGTH` points.
469 const auto virtual_round_univariate = round.compute_virtual_contribution(
470 partially_evaluated_polynomials, relation_parameters, virtual_gate_separator, alphas);
471
472 transcript->send_to_verifier("Sumcheck:univariate_" + std::to_string(k), virtual_round_univariate);
473
474 const FF round_challenge = transcript->template get_challenge<FF>("Sumcheck:u_" + std::to_string(k));
475 multivariate_challenge.emplace_back(round_challenge);
476
477 // Update the book-keeping table of partial evaluations of the prover polynomials extended by zero.
478 for (auto& poly : partially_evaluated_polynomials.get_all()) {
479 // Avoid bad access if polynomials are set to be of size 0, which can happen in AVM.
480 if (poly.size() > 0) {
481 if (poly.size() == 1) {
482 poly.at(0) *= (FF(1) - round_challenge);
483 } else if (poly.size() == 2) {
484 // Here we handle the eq polynomial case
485 poly.at(0) = poly.at(0) * (FF(1) - round_challenge) + poly.at(1) * round_challenge;
486 poly.at(1) = 0;
487 } else {
488 BB_ASSERT_EQ(true, false, "Polynomial size is not 1 or 2");
489 }
490 }
491 }
492 virtual_gate_separator.partially_evaluate(round_challenge);
493 }
494
495 ClaimedEvaluations multivariate_evaluations = extract_claimed_evaluations(partially_evaluated_polynomials);
496 transcript->send_to_verifier("Sumcheck:evaluations", multivariate_evaluations.get_all());
497 // For ZK Flavors: the evaluations of Libra univariates are included in the Sumcheck Output
498
499 vinfo("finished sumcheck");
501 .claimed_evaluations = multivariate_evaluations };
502 };
503
511 SumcheckOutput<Flavor> prove(ZKData& zk_sumcheck_data)
512 requires Flavor::HasZK
513 {
515 vinfo("starting sumcheck rounds...");
516 // Given gate challenges β = (β₀, ..., β_{d−1}) and d = `multivariate_d`, compute the evaluations of
517 // GateSeparator_β (X₀, ..., X_{d−1}) = ∏ₖ₌₀^{d−1} (1 − Xₖ + Xₖ · βₖ)
518 // on the boolean hypercube.
520
522 size_t round_idx = 0;
523
524 // In the first round, we compute the first univariate polynomial and populate the book-keeping table of
525 // #partially_evaluated_polynomials, which has \f$ n/2 \f$ rows and \f$ N \f$ columns.
526
527 // Compute the round univariate (excludes disabled rows; handled separately below)
528 auto round_univariate =
529 round.compute_univariate(full_polynomials, relation_parameters, gate_separators, alphas);
530
531 // Add the contribution from the Libra univariates
532 auto hiding_univariate = round.compute_libra_univariate(zk_sumcheck_data, round_idx);
533 round_univariate += hiding_univariate;
534
535 // Handle disabled rows contribution
536 if constexpr (UseRowDisablingPolynomial<Flavor>) {
537 round_univariate += round.compute_disabled_contribution(
539 }
540
541 handler.process_round_univariate(round_idx, round_univariate);
542
543 const FF round_challenge = transcript->template get_challenge<FF>("Sumcheck:u_0");
544 multivariate_challenge.emplace_back(round_challenge);
545
546 // Populate the book-keeping table
547 PartiallyEvaluatedMultivariates partially_evaluated_polynomials =
549
550 // Prepare ZK Sumcheck data for the next round
551 zk_sumcheck_data.update_zk_sumcheck_data(round_challenge, round_idx);
552 row_disabling_polynomial.update_evaluations(round_challenge, round_idx);
553 gate_separators.partially_evaluate(round_challenge);
554 round.round_size = round.round_size >> 1;
555 if constexpr (UseRowDisablingPolynomial<Flavor>) {
556 round.excluded_head_size = 2; // After round 0, disabled zone collapses to 1 edge pair
557 }
558 for (size_t round_idx = 1; round_idx < multivariate_d; round_idx++) {
559 BB_BENCH_NAME("sumcheck loop");
560
561 // Computes the round univariate in two parts: first the contribution necessary to hide the polynomial and
562 // account for having randomness at the end of the trace and then the contribution from the full
563 // relation. Note: we compute the hiding univariate first as the `compute_univariate` method prepares
564 // relevant data structures for the next round
565 round_univariate =
566 round.compute_univariate(partially_evaluated_polynomials, relation_parameters, gate_separators, alphas);
567 hiding_univariate = round.compute_libra_univariate(zk_sumcheck_data, round_idx);
568 // Add the contribution from the Libra univariates
569 round_univariate += hiding_univariate;
570 // Handle disabled rows contribution
571 if constexpr (UseRowDisablingPolynomial<Flavor>) {
572 round_univariate += round.compute_disabled_contribution(partially_evaluated_polynomials,
574 gate_separators,
575 alphas,
577 }
578
579 handler.process_round_univariate(round_idx, round_univariate);
580
581 const FF round_challenge =
582 transcript->template get_challenge<FF>("Sumcheck:u_" + std::to_string(round_idx));
583 multivariate_challenge.emplace_back(round_challenge);
584
585 // Prepare sumcheck book-keeping table for the next round.
586 partially_evaluate_in_place(partially_evaluated_polynomials, round_challenge);
587
588 if constexpr (IsTranslatorFlavor<Flavor>) {
589 if (round_idx == Flavor::LOG_MINI_CIRCUIT_SIZE - 1) {
590 // Send mini-circuit evaluations mid-sumcheck so that they get hashed into the transcript,
591 // ensuring the remaining LOG_N - LOG_MINI_CIRCUIT_SIZE round challenges depend on them.
592 transcript->send_to_verifier("Sumcheck:minicircuit_evaluations",
593 Flavor::get_minicircuit_evaluations(partially_evaluated_polynomials));
594 }
595 }
596
597 // Prepare evaluation masking and libra structures for the next round (for ZK Flavors)
598 zk_sumcheck_data.update_zk_sumcheck_data(round_challenge, round_idx);
599 row_disabling_polynomial.update_evaluations(round_challenge, round_idx);
600
601 gate_separators.partially_evaluate(round_challenge);
602 round.round_size = round.round_size >> 1;
603 }
604
605 handler.finalize_last_round(multivariate_d, round_univariate, multivariate_challenge[multivariate_d - 1]);
606
607 vinfo("completed ", multivariate_d, " rounds of sumcheck");
608
609 // Virtual rounds: unified path for ZK and non-ZK.
610 // The row-disabling polynomial 1-L is circuit-size independent,
611 // so we continue updating it through virtual rounds. The verifier evaluates
612 // 1 - ∏_{i≥2}(1-u_i) over ALL D challenges — no log_n needed.
613 // Libra univariates are generated for ALL D rounds, so compute_libra_univariate works here too.
614 GateSeparatorPolynomial<FF> virtual_gate_separator(gate_challenges, multivariate_challenge);
615 for (size_t idx = multivariate_d; idx < virtual_log_n; idx++) {
616 round_univariate = compute_virtual_round_univariate(round,
617 partially_evaluated_polynomials,
619 virtual_gate_separator,
620 alphas,
622
623 hiding_univariate = round.compute_libra_univariate(zk_sumcheck_data, idx);
624 round_univariate += hiding_univariate;
625
626 handler.process_round_univariate(idx, round_univariate);
627 const FF round_challenge = transcript->template get_challenge<FF>("Sumcheck:u_" + std::to_string(idx));
628 multivariate_challenge.emplace_back(round_challenge);
629
630 fold_for_zero_extension(partially_evaluated_polynomials, round_challenge);
631 zk_sumcheck_data.update_zk_sumcheck_data(round_challenge, idx);
632 row_disabling_polynomial.update_evaluations(round_challenge, idx);
633 virtual_gate_separator.partially_evaluate(round_challenge);
634 }
635
636 // Claimed evaluations of Prover polynomials are extracted and added to the transcript.
637 ClaimedEvaluations multivariate_evaluations = extract_claimed_evaluations(partially_evaluated_polynomials);
638
639 // For Translator: send only the full-circuit evaluations
640 if constexpr (IsTranslatorFlavor<Flavor>) {
641 transcript->send_to_verifier("Sumcheck:evaluations",
642 Flavor::get_full_circuit_evaluations(multivariate_evaluations));
643 } else {
644 transcript->send_to_verifier("Sumcheck:evaluations", multivariate_evaluations.get_all());
645 }
646
647 // Libra evaluation covers all D rounds now (real + virtual).
648 FF libra_evaluation = zk_sumcheck_data.constant_term;
649 for (const auto& libra_eval : zk_sumcheck_data.libra_evaluations) {
650 libra_evaluation += libra_eval;
651 }
652 transcript->send_to_verifier("Libra:claimed_evaluation", libra_evaluation);
653
654 // The sum of the Libra constant term and the evaluations of Libra univariates at corresponding sumcheck
655 // challenges is included in the Sumcheck Output
656 vinfo("finished sumcheck");
657 return SumcheckOutput<Flavor>{ .challenge = multivariate_challenge,
658 .claimed_evaluations = multivariate_evaluations,
659 .claimed_libra_evaluation = libra_evaluation,
660 .round_univariates = handler.get_univariates(),
661 .round_univariate_evaluations = handler.get_evaluations() };
662 };
663
669 static void partially_evaluate(auto& source_polynomials,
670 PartiallyEvaluatedMultivariates& dest_polynomials,
671 const FF& round_challenge)
672 {
673 auto source_view = source_polynomials.get_all();
674 auto dest_view = dest_polynomials.get_all();
675 parallel_for(source_view.size(), [&](size_t j) {
676 BB_BENCH_TRACY_NAME("Sumcheck::partially_evaluate");
677 const auto& poly = source_view[j];
678 size_t limit = poly.end_index();
679 for (size_t i = 0; i < limit; i += 2) {
680 dest_view[j].at(i >> 1) = poly[i] + round_challenge * (poly[i + 1] - poly[i]);
681 }
682 dest_view[j].shrink_end_index((limit / 2) + (limit % 2));
683 });
684 };
685
693 const FF& round_challenge)
694 {
695 PartiallyEvaluatedMultivariates partially_evaluated_polynomials(full_polynomials, multivariate_n);
696 partially_evaluate(full_polynomials, partially_evaluated_polynomials, round_challenge);
697 return partially_evaluated_polynomials;
698 }
699
703 static void partially_evaluate_in_place(PartiallyEvaluatedMultivariates& polynomials, const FF& round_challenge)
704 {
705 partially_evaluate(polynomials, polynomials, round_challenge);
706 };
707
720 {
721 ClaimedEvaluations multivariate_evaluations;
722 for (auto [eval, poly] :
723 zip_view(multivariate_evaluations.get_all(), partially_evaluated_polynomials.get_all())) {
724 eval = poly[0];
725 };
726 return multivariate_evaluations;
727 };
728
735 template <typename PartialEvals, typename Alphas>
738 PartialEvals& partially_evaluated_polynomials,
739 const RelationParameters<FF>& relation_parameters,
740 GateSeparatorPolynomial<FF>& gate_separator,
741 const Alphas& alphas,
742 RowDisablingPolynomial<FF>& row_disabling_polynomial)
743 {
744 auto univariate = round.compute_virtual_contribution(
745 partially_evaluated_polynomials, relation_parameters, gate_separator, alphas);
746 if constexpr (UseRowDisablingPolynomial<Flavor>) {
747 bb::Univariate<FF, 2> one_minus_L(
748 { FF::one() - row_disabling_polynomial.eval_at_0, FF::one() - row_disabling_polynomial.eval_at_1 });
749 univariate *= one_minus_L.template extend_to<Flavor::BATCHED_RELATION_PARTIAL_LENGTH>();
750 }
751 return univariate;
752 }
753
757 static void fold_for_zero_extension(PartiallyEvaluatedMultivariates& pe, const FF& round_challenge)
758 {
759 for (auto& poly : pe.get_all()) {
760 if (poly.end_index() > 0) {
761 poly.at(0) *= (FF(1) - round_challenge);
762 }
763 }
764 }
765};
766
803template <typename Flavor> class SumcheckVerifier {
804
805 public:
807 using FF = typename Flavor::FF;
813 // For ZK Flavors: the verifier obtains a vector of evaluations of \f$ d \f$ univariate polynomials and uses them to
814 // compute full_honk_relation_purported_value
815 using ClaimedLibraEvaluations = typename std::vector<FF>;
819
824 static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = Flavor::BATCHED_RELATION_PARTIAL_LENGTH;
828 static constexpr size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES;
829
830 std::shared_ptr<Transcript> transcript;
832
833 // Determines number of rounds in the sumcheck (may include padding rounds)
835
836 // An array of size NUM_SUBRELATIONS-1 containing challenges or consecutive powers of a single challenge that
837 // separate linearly independent subrelation.
839
840 explicit SumcheckVerifier(std::shared_ptr<Transcript> transcript,
841 const FF& alpha,
842 size_t virtual_log_n,
843 FF target_sum = 0)
844 : transcript(std::move(transcript))
845 , round(target_sum)
846 , virtual_log_n(virtual_log_n)
847 , alphas(initialize_relation_separator<FF, Flavor::NUM_SUBRELATIONS - 1>(alpha)) {};
859 const std::vector<FF>& gate_challenges)
860 {
861 bb::GateSeparatorPolynomial<FF> gate_separators(gate_challenges);
862 // Construct a ZKHandler to handle all the libra related information in the transcript
863 VerifierZKCorrectionHandler<Flavor> zk_correction_handler(transcript);
864
865 // Correct the target sum in the round in the ZK case
866 zk_correction_handler.initialize_target_sum(round);
867
868 std::vector<FF> multivariate_challenge;
869 multivariate_challenge.reserve(virtual_log_n);
870
871 // Process univariate consistancy check rounds
872 // For ECCVM we ensure the consistencies by populating an vector of claimed evaluations that will be checked in
873 // the PCS rounds
874 // For other flavors, we perform the sumcheck univariate consistency check
875
876 bool verified = true;
877 ClaimedEvaluations purported_evaluations;
878 for (size_t round_idx = 0; round_idx < virtual_log_n; round_idx++) {
879 round.process_round(transcript, multivariate_challenge, gate_separators, round_idx);
880 verified = verified && !round.round_failed;
881
882 if constexpr (IsTranslatorFlavor<Flavor>) {
883 if (round_idx == Flavor::LOG_MINI_CIRCUIT_SIZE - 1) {
884 // Receive mini-circuit evaluations mid-sumcheck so that they get hashed into the transcript,
885 // ensuring the remaining LOG_N - LOG_MINI_CIRCUIT_SIZE round challenges depend on them.
886 Flavor::set_minicircuit_evaluations(
887 purported_evaluations,
888 transcript->template receive_from_prover<std::array<FF, Flavor::NUM_MINICIRCUIT_EVALUATIONS>>(
889 "Sumcheck:minicircuit_evaluations"));
890 }
891 }
892 }
893
894 // Populate claimed evaluations at the challenge
895 if constexpr (IsTranslatorFlavor<Flavor>) {
896 // Translator path: receive full-circuit evaluations, set them, and complete
897 // (computable precomputed selectors + L_0 scaling of minicircuit wires already placed above)
898 auto get_full_circuit_evaluations =
899 transcript->template receive_from_prover<std::array<FF, Flavor::NUM_FULL_CIRCUIT_EVALUATIONS>>(
900 "Sumcheck:evaluations");
901 Flavor::complete_full_circuit_evaluations(
902 purported_evaluations, get_full_circuit_evaluations, std::span<const FF>(multivariate_challenge));
903 } else {
904 auto transcript_evaluations =
905 transcript->template receive_from_prover<std::array<FF, NUM_POLYNOMIALS>>("Sumcheck:evaluations");
906 for (auto [eval, transcript_eval] : zip_view(purported_evaluations.get_all(), transcript_evaluations)) {
907 eval = transcript_eval;
908 }
909 }
910
911 // OriginTag false positive: The evaluations are PCS-bound - the prover committed to the
912 // polynomials before challenges were known, and the PCS opening verifies consistency.
913 if constexpr (IsRecursiveFlavor<Flavor>) {
914 const auto challenge_tag = multivariate_challenge.back().get_origin_tag();
915 for (auto& eval : purported_evaluations.get_all()) {
916 eval.set_origin_tag(challenge_tag);
917 }
918 }
919
920 // Evaluate the Honk relation at the point (u_0, ..., u_{d-1}) using claimed evaluations of prover polynomials.
921 // In ZK Flavors, the evaluation is corrected by full_libra_purported_value
922 FF full_honk_purported_value = round.compute_full_relation_purported_value(
923 purported_evaluations, relation_parameters, gate_separators, alphas);
924
925 // For ZK Flavors: compute the evaluation of the Row Disabling Polynomial at the sumcheck challenge and of the
926 // libra univariate used to hide the contribution from the actual Honk relation
927 zk_correction_handler.apply_zk_corrections(full_honk_purported_value, multivariate_challenge);
928
930 bool final_check = round.perform_final_verification(full_honk_purported_value);
931 verified = final_check && verified;
932
933 // For ZK Flavors: the evaluations of Libra univariates are included in the Sumcheck Output
934 return SumcheckOutput<Flavor>{ .challenge = multivariate_challenge,
935 .claimed_evaluations = purported_evaluations,
936 .verified = verified,
937 .claimed_libra_evaluation = zk_correction_handler.get_libra_evaluation(),
938 .round_univariate_commitments = round.get_round_univariate_commitments(),
939 .round_univariate_evaluations = round.get_round_univariate_evaluations() };
940 };
941};
942
943template <typename FF, size_t N> std::array<FF, N> initialize_relation_separator(const FF& alpha)
944{
945 std::array<FF, N> alphas;
946 alphas[0] = alpha;
947 for (size_t i = 1; i < N; ++i) {
948 alphas[i] = alphas[i - 1] * alpha;
949 }
950 return alphas;
951}
952} // 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:264
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:293
SumcheckOutput< Flavor > static 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:669
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
Definition sumcheck.hpp:314
typename Flavor::FF FF
Definition sumcheck.hpp:295
ProverPolynomials & full_polynomials
Definition sumcheck.hpp:323
const size_t multivariate_n
Definition sumcheck.hpp:319
bb::RelationParameters< FF > relation_parameters
Definition sumcheck.hpp:334
typename Flavor::Transcript Transcript
Definition sumcheck.hpp:302
std::vector< FF > accumulator_challenge
Definition sumcheck.hpp:342
std::vector< FF > instance_challenge
Definition sumcheck.hpp:343
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:692
static constexpr bool isMultilinearBatchingFlavor
Definition sumcheck.hpp:306
typename Flavor::ProverPolynomials ProverPolynomials
Definition sumcheck.hpp:298
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:311
std::array< FF, Flavor::NUM_SUBRELATIONS - 1 > SubrelationSeparators
Definition sumcheck.hpp:303
const size_t multivariate_d
Definition sumcheck.hpp:321
static void partially_evaluate_in_place(PartiallyEvaluatedMultivariates &polynomials, const FF &round_challenge)
Evaluate at the round challenge in-place.
Definition sumcheck.hpp:703
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:719
typename Flavor::AllValues ClaimedEvaluations
Definition sumcheck.hpp:300
typename bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > SumcheckRoundUnivariate
Definition sumcheck.hpp:316
static void fold_for_zero_extension(PartiallyEvaluatedMultivariates &pe, const FF &round_challenge)
Fold partially-evaluated polynomials for zero-extension: PE[0] *= (1 - u_k).
Definition sumcheck.hpp:757
std::vector< FF > multivariate_challenge
Definition sumcheck.hpp:339
static bb::Univariate< FF, Flavor::BATCHED_RELATION_PARTIAL_LENGTH > compute_virtual_round_univariate(SumcheckProverRound< Flavor > &round, PartialEvals &partially_evaluated_polynomials, const RelationParameters< FF > &relation_parameters, GateSeparatorPolynomial< FF > &gate_separator, const Alphas &alphas, RowDisablingPolynomial< FF > &row_disabling_polynomial)
Compute the virtual round univariate with the row-disabling polynomial factor applied.
Definition sumcheck.hpp:736
typename Flavor::PartiallyEvaluatedMultivariates PartiallyEvaluatedMultivariates
Definition sumcheck.hpp:299
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:369
RowDisablingPolynomial< FF > row_disabling_polynomial
Definition sumcheck.hpp:346
typename Flavor::CommitmentKey CommitmentKey
Definition sumcheck.hpp:304
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:349
std::vector< FF > gate_challenges
Definition sumcheck.hpp:332
SumcheckProverRound< Flavor > round
Definition sumcheck.hpp:327
std::shared_ptr< Transcript > transcript
Definition sumcheck.hpp:325
SumcheckOutput< Flavor > prove()
Non-ZK version: Compute round univariate, place it in transcript, compute challenge,...
Definition sumcheck.hpp:391
ZKSumcheckData< Flavor > ZKData
Definition sumcheck.hpp:301
SubrelationSeparators alphas
Definition sumcheck.hpp:330
Imlementation of the Sumcheck prover round.
SumcheckRoundUnivariate compute_virtual_contribution(ProverPolynomialsOrPartiallyEvaluatedMultivariates &polynomials, const bb::RelationParameters< FF > &relation_parameters, const GateSeparatorPolynomial< FF > &gate_separator, const SubrelationSeparators &alphas)
Implementation of the sumcheck Verifier for statements of the form for multilinear polynomials .
Definition sumcheck.hpp:803
typename std::vector< FF > ClaimedLibraEvaluations
Definition sumcheck.hpp:815
std::array< FF, Flavor::NUM_SUBRELATIONS - 1 > SubrelationSeparators
Definition sumcheck.hpp:817
typename Flavor::FF FF
Definition sumcheck.hpp:807
typename Flavor::Commitment Commitment
Definition sumcheck.hpp:818
SumcheckOutput< Flavor > verify(const bb::RelationParameters< FF > &relation_parameters, const std::vector< FF > &gate_challenges)
The Sumcheck verification method. First it extracts round univariate, checks sum (the sumcheck univar...
Definition sumcheck.hpp:858
SumcheckVerifierRound< Flavor > round
Definition sumcheck.hpp:831
SumcheckVerifier(std::shared_ptr< Transcript > transcript, const FF &alpha, size_t virtual_log_n, FF target_sum=0)
Definition sumcheck.hpp:840
std::shared_ptr< Transcript > transcript
Definition sumcheck.hpp:830
typename Flavor::AllValues ClaimedEvaluations
Container type for the evaluations of Prover Polynomials at the challenge point .
Definition sumcheck.hpp:812
SubrelationSeparators alphas
Definition sumcheck.hpp:838
typename Flavor::Transcript Transcript
Definition sumcheck.hpp:816
Implementation of the Sumcheck Verifier Round.
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.
void process_round(const std::shared_ptr< Transcript > &transcript, std::vector< FF > &multivariate_challenge, bb::GateSeparatorPolynomial< FF > &gate_separators, size_t round_idx)
Process a single sumcheck round: receive univariate from transcript, verify sum, generate challenge.
std::vector< Commitment > get_round_univariate_commitments()
Get round univariate commitments (only used for Grumpkin flavors).
bool perform_final_verification(const FF &full_honk_purported_value)
Perform final verification: check that the computed target sum matches the full relation evaluation....
A univariate polynomial represented by its values on {0, 1,..., domain_end - 1}.
Fr & value_at(size_t i)
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:50
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:943
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:65
void process_round_univariate(size_t round_idx, bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > &round_univariate)
Definition sumcheck.hpp:79
typename Flavor::CommitmentKey CommitmentKey
Definition sumcheck.hpp:59
std::vector< Polynomial< FF > > round_univariates
Definition sumcheck.hpp:66
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:103
std::vector< Polynomial< FF > > get_univariates()
Definition sumcheck.hpp:111
std::shared_ptr< Transcript > transcript
Definition sumcheck.hpp:62
typename Flavor::Transcript Transcript
Definition sumcheck.hpp:58
std::vector< std::array< FF, 3 > > get_evaluations()
Definition sumcheck.hpp:110
RoundUnivariateHandler(std::shared_ptr< Transcript > transcript)
Definition sumcheck.hpp:68
Handler for processing round univariates in sumcheck. Default implementation: send evaluations direct...
Definition sumcheck.hpp:26
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
Definition sumcheck.hpp:30
typename Flavor::Transcript Transcript
Definition sumcheck.hpp:28
void finalize_last_round(size_t, const bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > &, const FF &)
Definition sumcheck.hpp:44
void process_round_univariate(size_t round_idx, bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > &round_univariate)
Definition sumcheck.hpp:38
std::shared_ptr< Transcript > transcript
Definition sumcheck.hpp:32
typename Flavor::CommitmentKey CommitmentKey
Definition sumcheck.hpp:29
typename Flavor::FF FF
Definition sumcheck.hpp:27
std::vector< Polynomial< FF > > get_univariates()
Definition sumcheck.hpp:50
RoundUnivariateHandler(std::shared_ptr< Transcript > transcript)
Definition sumcheck.hpp:34
std::vector< std::array< FF, 3 > > get_evaluations()
Definition sumcheck.hpp:49
Polynomial for Sumcheck with disabled Rows.
static FF evaluate_at_challenge(std::span< const 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)
void apply_zk_corrections(FF &full_honk_purported_value, std::vector< FF > &multivariate_challenge)
Definition sumcheck.hpp:162
VerifierZKCorrectionHandler(std::shared_ptr< Transcript > transcript)
Definition sumcheck.hpp:154
void initialize_target_sum(SumcheckRound &round)
Definition sumcheck.hpp:160
std::shared_ptr< Transcript > transcript
Definition sumcheck.hpp:147
Handler for ZK-related verification adjustments in sumcheck. Default implementation: no ZK adjustment...
Definition sumcheck.hpp:118
void apply_zk_corrections(FF &, const std::vector< FF > &)
Definition sumcheck.hpp:134
typename Flavor::Transcript Transcript
Definition sumcheck.hpp:120
void initialize_target_sum(SumcheckRound &)
Definition sumcheck.hpp:132
std::shared_ptr< Transcript > transcript
Definition sumcheck.hpp:123
VerifierZKCorrectionHandler(std::shared_ptr< Transcript > transcript)
Definition sumcheck.hpp:128
This structure is created to contain various polynomials and constants required by ZK Sumcheck.