Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
hypernova_prover.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Sergei], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
12
13namespace bb {
14
15template <size_t N>
17 std::vector<FF>& scalars)
18{
19 std::vector<Commitment> points(N);
20 for (size_t idx = 0; idx < N; ++idx) {
21 points[idx] = _points[idx];
22 }
23 return Commitment::batch_mul(points, scalars);
24}
25
30{
31 BB_BENCH_NAME("HypernovaFoldingProver::sumcheck_output_to_accumulator");
32
33 // Generate challenges to batch shifted and unshifted polynomials/commitments/evaluation
34 auto [unshifted_challenges, shifted_challenges] =
35 get_hypernova_batching_challenges<FF>(transcript, NUM_UNSHIFTED_ENTITIES, NUM_SHIFTED_ENTITIES);
36
37 // Batch polynomials
38 Polynomial<FF> batched_unshifted_polynomial = batch_polynomials<Flavor::NUM_UNSHIFTED_ENTITIES>(
39 instance->polynomials.get_unshifted(), instance->dyadic_size(), unshifted_challenges);
40 Polynomial<FF> batched_shifted_polynomial = batch_polynomials<Flavor::NUM_SHIFTED_ENTITIES>(
41 instance->polynomials.get_to_be_shifted(), instance->dyadic_size(), shifted_challenges);
42
43 // Batch evaluations
44 FF batched_unshifted_evaluation(0);
45 FF batched_shifted_evaluation(0);
46
47 for (auto [eval, challenge] : zip_view(sumcheck_output.claimed_evaluations.get_unshifted(), unshifted_challenges)) {
48 batched_unshifted_evaluation += eval * challenge;
49 }
50 for (auto [eval, challenge] : zip_view(sumcheck_output.claimed_evaluations.get_shifted(), shifted_challenges)) {
51 batched_shifted_evaluation += eval * challenge;
52 }
53
54 // Batch commitments
55 VerifierCommitments verifier_commitments(honk_vk, instance->commitments);
56
57 Commitment batched_unshifted_commitment = batch_mul(verifier_commitments.get_unshifted(), unshifted_challenges);
58 Commitment batched_shifted_commitment = batch_mul(verifier_commitments.get_to_be_shifted(), shifted_challenges);
59
60 return Accumulator{
61 .challenge = std::move(sumcheck_output.challenge),
62 .non_shifted_evaluation = batched_unshifted_evaluation,
63 .shifted_evaluation = batched_shifted_evaluation,
64 .non_shifted_polynomial = std::move(batched_unshifted_polynomial),
65 .shifted_polynomial = std::move(batched_shifted_polynomial),
66 .non_shifted_commitment = batched_unshifted_commitment,
67 .shifted_commitment = batched_shifted_commitment,
68 .dyadic_size = instance->dyadic_size(),
69 };
70};
71
72template <size_t N>
74 RefArray<Polynomial<FF>, N> polynomials_to_batch,
75 const size_t& full_batched_size,
76 const std::vector<FF>& challenges)
77{
78 BB_BENCH_NAME("HypernovaFoldingProver::batch_polynomials");
79 BB_ASSERT_EQ(full_batched_size,
80 polynomials_to_batch[0].virtual_size(),
81 "The virtual size of the first polynomial is different from the full batched size.");
83 challenges.size(), N, "The number of challenges provided does not match the number of polynomials to batch.");
84
85 // Ensure the first polynomial has enough backing to accumulate all others (they may have different backing sizes
86 // and/or start indices). add_scaled requires destination start_index <= source start_index.
87 size_t min_start = polynomials_to_batch[0].start_index();
88 size_t max_end = polynomials_to_batch[0].end_index();
89 for (size_t idx = 1; idx < N; idx++) {
90 min_start = std::min(min_start, polynomials_to_batch[idx].start_index());
91 max_end = std::max(max_end, polynomials_to_batch[idx].end_index());
92 }
93
94 // Treat polynomials_to_batch[0] as the destination's starting state (its scalar is implicitly 1).
95 // The remaining N-1 sources are fused into a single parallel_for via add_scaled_batch.
97 sources.reserve(N - 1);
98 for (size_t i = 1; i < N; ++i) {
99 sources.emplace_back(polynomials_to_batch[i]);
100 }
101 auto tail_scalars = std::span<const FF>(challenges).subspan(1);
102
103 auto sources_span = std::span<const PolynomialSpan<const FF>>(sources);
104 if (min_start < polynomials_to_batch[0].start_index() || max_end > polynomials_to_batch[0].end_index()) {
105 Polynomial<FF> result(max_end - min_start, full_batched_size, min_start);
106 result += polynomials_to_batch[0];
107 add_scaled_batch(result, sources_span, tail_scalars);
108 return result;
109 }
110
111 add_scaled_batch(polynomials_to_batch[0], sources_span, tail_scalars);
112
113 return polynomials_to_batch[0];
114};
115
118 const std::shared_ptr<VerificationKey>& honk_vk)
119{
120 BB_BENCH_NAME("HypernovaFoldingProver::instance_to_accumulator");
121
122 vinfo("HypernovaFoldingProver: converting instance to accumulator...");
123
124 // Complete the incoming instance
125 auto precomputed_vk = honk_vk ? honk_vk : std::make_shared<VerificationKey>(instance->get_precomputed());
126 MegaOinkProver oink_prover{ instance, precomputed_vk, transcript };
127 oink_prover.prove();
130 }
131
132 instance->gate_challenges = transcript->template get_dyadic_powers_of_challenge<FF>(
133 "HypernovaFoldingProver:gate_challenge", Flavor::VIRTUAL_LOG_N);
134
135 // Run Sumcheck with padding
136 auto sumcheck_output = [&] {
137 BB_BENCH_NAME("HypernovaFoldingProver::sumcheck");
138 MegaSumcheckProver sumcheck(instance->dyadic_size(),
139 instance->polynomials,
141 instance->alpha,
142 instance->gate_challenges,
143 instance->relation_parameters,
145 return sumcheck.prove();
146 }();
149 }
150
151 Accumulator accumulator = sumcheck_output_to_accumulator(sumcheck_output, instance, precomputed_vk);
152
153 vinfo("HypernovaFoldingProver: accumulator constructed.");
154
155 return accumulator;
156}
157
159 Accumulator&& accumulator,
161 const std::shared_ptr<VerificationKey>& honk_vk)
162{
163 BB_BENCH_NAME("HypernovaFoldingProver::fold");
164 Accumulator incoming_accumulator = instance_to_accumulator(instance, honk_vk);
165
166 // Sumcheck
167 MultilinearBatchingProver batching_prover(std::move(accumulator), std::move(incoming_accumulator), transcript);
168
169 HonkProof proof = batching_prover.construct_proof();
170
171 return { proof, batching_prover.compute_new_claim() };
172}
173} // namespace bb
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:83
std::shared_ptr< Napi::ThreadSafeFunction > instance
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:264
Commitment batch_mul(const RefArray< Commitment, N > &_points, std::vector< FF > &scalars)
Utility to perform batch mul of commitments.
std::shared_ptr< Transcript > transcript
Accumulator sumcheck_output_to_accumulator(MegaSumcheckOutput &sumcheck_output, const std::shared_ptr< ProverInstance > &instance, const std::shared_ptr< VerificationKey > &honk_vk)
Convert the output of the sumcheck run on the incoming instance into an accumulator.
static constexpr size_t NUM_SHIFTED_ENTITIES
static constexpr size_t NUM_UNSHIFTED_ENTITIES
Accumulator instance_to_accumulator(const std::shared_ptr< ProverInstance > &instance, const std::shared_ptr< VerificationKey > &honk_vk=nullptr)
Turn an instance into an accumulator by running Sumcheck.
static Polynomial< FF > batch_polynomials(RefArray< Polynomial< FF >, N > polynomials_to_batch, const size_t &full_batched_size, const std::vector< FF > &challenges)
Batch prover polynomials. Batching happens in place into the first polynomial in the RefArray supplie...
std::pair< HonkProof, Accumulator > fold(Accumulator &&accumulator, const std::shared_ptr< ProverInstance > &instance, const std::shared_ptr< VerificationKey > &honk_vk=nullptr)
Fold an instance into an accumulator.
static constexpr size_t VIRTUAL_LOG_N
Prover for multilinear batching - reduces two polynomial evaluation claims to one via sumcheck.
HonkProof construct_proof()
Construct a multilinear batching proof.
BB_PROFILE MultilinearBatchingProverClaim compute_new_claim()
Compute the batched output claim after sumcheck.
Executes the "Oink" phase of the Honk proving protocol: the initial rounds that commit to witness dat...
void prove(bool emit_alpha=true)
Commit to witnesses, compute relation parameters, and prepare for Sumcheck.
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
A template class for a reference array. Behaves as if std::array<T&, N> was possible.
Definition ref_array.hpp:22
The implementation of the sumcheck Prover for statements of the form for multilinear polynomials .
Definition sumcheck.hpp:294
SumcheckOutput< Flavor > prove()
Non-ZK version: Compute round univariate, place it in transcript, compute challenge,...
Definition sumcheck.hpp:392
#define vinfo(...)
Definition log.hpp:94
bool use_memory_profile
MemoryProfile GLOBAL_MEMORY_PROFILE
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
std::vector< fr > HonkProof
Definition proof.hpp:15
void add_scaled_batch(Polynomial< Fr > &dst, std::span< const PolynomialSpan< const Fr > > sources, std::span< const Fr > scalars)
Fused parallel batched add: dst += sum_i scalars[i] * sources[i].
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Prover's claim for multilinear batching - contains polynomials and their evaluation claims.
Contains the evaluations of multilinear polynomials at the challenge point . These are computed by S...
ClaimedEvaluations claimed_evaluations
std::vector< FF > challenge
void add_checkpoint(const std::string &stage)