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
11
12namespace bb {
13
14template <size_t N>
16 const std::vector<FF>& scalars)
17{
18 std::vector<Commitment> points(N);
19 for (size_t idx = 0; idx < N; ++idx) {
20 points[idx] = _points[idx];
21 }
22 return Commitment::batch_mul(points, scalars);
23}
24
29{
30 BB_BENCH_NAME("HypernovaFoldingProver::sumcheck_output_to_accumulator");
31
32 // Generate challenges to batch shifted and unshifted polynomials/commitments/evaluation
33 auto [unshifted_challenges, shifted_challenges] =
34 get_hypernova_batching_challenges<FF>(transcript, NUM_UNSHIFTED_ENTITIES, NUM_SHIFTED_ENTITIES);
35
36 // Batch polynomials
37 Polynomial<FF> batched_unshifted_polynomial = batch_polynomials<Flavor::NUM_UNSHIFTED_ENTITIES>(
38 instance->polynomials.get_unshifted(), instance->dyadic_size(), unshifted_challenges);
39 Polynomial<FF> batched_shifted_polynomial = batch_polynomials<Flavor::NUM_SHIFTED_ENTITIES>(
40 instance->polynomials.get_to_be_shifted(), instance->dyadic_size(), shifted_challenges);
41
42 // Batch evaluations
43 FF batched_unshifted_evaluation(0);
44 FF batched_shifted_evaluation(0);
45
46 for (auto [eval, challenge] : zip_view(sumcheck_output.claimed_evaluations.get_unshifted(), unshifted_challenges)) {
47 batched_unshifted_evaluation += eval * challenge;
48 }
49 for (auto [eval, challenge] : zip_view(sumcheck_output.claimed_evaluations.get_shifted(), shifted_challenges)) {
50 batched_shifted_evaluation += eval * challenge;
51 }
52
53 // Batch commitments
54 VerifierCommitments verifier_commitments(honk_vk, instance->commitments);
55
56 Commitment batched_unshifted_commitment = batch_mul(verifier_commitments.get_unshifted(), unshifted_challenges);
57 Commitment batched_shifted_commitment = batch_mul(verifier_commitments.get_to_be_shifted(), shifted_challenges);
58
59 return Accumulator{
60 .challenge = std::move(sumcheck_output.challenge),
61 .non_shifted_evaluation = batched_unshifted_evaluation,
62 .shifted_evaluation = batched_shifted_evaluation,
63 .non_shifted_polynomial = std::move(batched_unshifted_polynomial),
64 .shifted_polynomial = std::move(batched_shifted_polynomial),
65 .non_shifted_commitment = batched_unshifted_commitment,
66 .shifted_commitment = batched_shifted_commitment,
67 .dyadic_size = instance->dyadic_size(),
68 };
69};
70
71template <size_t N>
73 RefArray<Polynomial<FF>, N> polynomials_to_batch,
74 const size_t& full_batched_size,
75 const std::vector<FF>& challenges)
76{
77 BB_BENCH_NAME("HypernovaFoldingProver::batch_polynomials");
78 BB_ASSERT_EQ(full_batched_size,
79 polynomials_to_batch[0].virtual_size(),
80 "The virtual size of the first polynomial is different from the full batched size.");
82 challenges.size(), N, "The number of challenges provided does not match the number of polynomials to batch.");
83
84 for (size_t idx = 1; idx < N; idx++) {
85 polynomials_to_batch[0].add_scaled(polynomials_to_batch[idx], challenges[idx]);
86 }
87
88 return polynomials_to_batch[0];
89};
90
93 const std::shared_ptr<VerificationKey>& honk_vk)
94{
95 BB_BENCH_NAME("HypernovaFoldingProver::instance_to_accumulator");
96
97 vinfo("HypernovaFoldingProver: converting instance to accumulator...");
98
99 // Complete the incoming instance
100 auto precomputed_vk = honk_vk ? honk_vk : std::make_shared<VerificationKey>(instance->get_precomputed());
101 MegaOinkProver oink_prover{ instance, precomputed_vk, transcript };
102 oink_prover.prove();
103
104 instance->gate_challenges = transcript->template get_dyadic_powers_of_challenge<FF>(
105 "HypernovaFoldingProver:gate_challenge", Flavor::VIRTUAL_LOG_N);
106
107 // Run Sumcheck with padding
108 MegaSumcheckProver sumcheck(instance->dyadic_size(),
109 instance->polynomials,
111 instance->alpha,
112 instance->gate_challenges,
113 instance->relation_parameters,
115 auto sumcheck_output = sumcheck.prove();
116
117 Accumulator accumulator = sumcheck_output_to_accumulator(sumcheck_output, instance, precomputed_vk);
118
119 vinfo("HypernovaFoldingProver: accumulator constructed.");
120
121 return accumulator;
122}
123
125 Accumulator&& accumulator,
127 const std::shared_ptr<VerificationKey>& honk_vk)
128{
129 Accumulator incoming_accumulator = instance_to_accumulator(instance, honk_vk);
130
131 // Sumcheck
132 MultilinearBatchingProver batching_prover(std::move(accumulator), std::move(incoming_accumulator), transcript);
133
134 HonkProof proof = batching_prover.construct_proof();
135
136 return { proof, batching_prover.compute_new_claim() };
137}
138} // 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:219
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.
Commitment batch_mul(const RefArray< Commitment, N > &_points, const std::vector< FF > &scalars)
Utility to perform batch mul of commitments.
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.
Class for all the oink rounds, which are shared between the folding prover and ultra prover.
void prove()
Oink Prover function that runs all the rounds of the verifier.
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:289
SumcheckOutput< Flavor > prove()
Non-ZK version: Compute round univariate, place it in transcript, compute challenge,...
Definition sumcheck.hpp:387
#define vinfo(...)
Definition log.hpp:94
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
std::vector< fr > HonkProof
Definition proof.hpp:15
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