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: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
10
11namespace bb {
12
15{
16 std::vector<std::string> labels_unshifted_entities(NUM_UNSHIFTED_ENTITIES);
17 std::vector<std::string> labels_shifted_witnesses(NUM_SHIFTED_ENTITIES);
18 for (size_t idx = 0; idx < NUM_UNSHIFTED_ENTITIES; idx++) {
19 labels_unshifted_entities[idx] = "unshifted_challenge_" + std::to_string(idx);
20 }
21 for (size_t idx = 0; idx < NUM_SHIFTED_ENTITIES; idx++) {
22 labels_shifted_witnesses[idx] = "shifted_challenge_" + std::to_string(idx);
23 }
24 auto unshifted_challenges = transcript->template get_challenges<FF>(labels_unshifted_entities);
25 auto shifted_challenges = transcript->template get_challenges<FF>(labels_shifted_witnesses);
26
27 return { unshifted_challenges, shifted_challenges };
28}
29
30template <size_t N>
32 const std::vector<FF>& scalars)
33{
34 std::vector<Commitment> points(N);
35 for (size_t idx = 0; auto point : _points) {
36 points[idx++] = point;
37 }
38
39 return batch_mul_native<MegaFlavor::Curve>(points, scalars);
40}
41
46{
47 BB_BENCH_NAME("HypernovaFoldingProver::sumcheck_output_to_accumulator");
48
49 // Generate challenges to batch shifted and unshifted polynomials/commitments/evaluation
50 auto [unshifted_challenges, shifted_challenges] = get_batching_challenges();
51
52 // Batch polynomials
53 Polynomial<FF> batched_unshifted_polynomial = batch_polynomials<Flavor::NUM_UNSHIFTED_ENTITIES>(
54 instance->polynomials.get_unshifted(), instance->dyadic_size(), unshifted_challenges);
55 Polynomial<FF> batched_shifted_polynomial = batch_polynomials<Flavor::NUM_SHIFTED_ENTITIES>(
56 instance->polynomials.get_to_be_shifted(), instance->dyadic_size(), shifted_challenges);
57
58 // Batch evaluations
59 FF batched_unshifted_evaluation(0);
60 FF batched_shifted_evaluation(0);
61
62 for (auto [eval, challenge] : zip_view(sumcheck_output.claimed_evaluations.get_unshifted(), unshifted_challenges)) {
63 batched_unshifted_evaluation += eval * challenge;
64 }
65 for (auto [eval, challenge] : zip_view(sumcheck_output.claimed_evaluations.get_shifted(), shifted_challenges)) {
66 batched_shifted_evaluation += eval * challenge;
67 }
68
69 // Batch commitments
70 VerifierCommitments verifier_commitments(honk_vk, instance->commitments);
71
72 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1552): Optimize batch_mul_native
73 Commitment batched_unshifted_commitment = batch_mul(verifier_commitments.get_unshifted(), unshifted_challenges);
74 Commitment batched_shifted_commitment = batch_mul(verifier_commitments.get_to_be_shifted(), shifted_challenges);
75
76 return Accumulator{
77 .challenge = std::move(sumcheck_output.challenge),
78 .non_shifted_evaluation = batched_unshifted_evaluation,
79 .shifted_evaluation = batched_shifted_evaluation,
80 .non_shifted_polynomial = std::move(batched_unshifted_polynomial),
81 .shifted_polynomial = std::move(batched_shifted_polynomial),
82 .non_shifted_commitment = batched_unshifted_commitment,
83 .shifted_commitment = batched_shifted_commitment,
84 .dyadic_size = instance->dyadic_size(),
85 };
86};
87
88template <size_t N>
90 RefArray<Polynomial<FF>, N> polynomials_to_batch,
91 const size_t& full_batched_size,
92 const std::vector<FF>& challenges)
93{
94 BB_BENCH_NAME("HypernovaFoldingProver::batch_polynomials");
95 BB_ASSERT_EQ(full_batched_size,
96 polynomials_to_batch[0].virtual_size(),
97 "The virtual size of the first polynomial is different from the full batched size.");
99 challenges.size(), N, "The number of challenges provided does not match the number of polynomials to batch.");
100
101 size_t challenge_idx = 0;
102
103 for (auto& poly : polynomials_to_batch) {
104 if (challenge_idx == 0) {
105 polynomials_to_batch[0] *= challenges[challenge_idx];
106 } else {
107 polynomials_to_batch[0].add_scaled(poly, challenges[challenge_idx]);
108 }
109 challenge_idx += 1;
110 }
111
112 return polynomials_to_batch[0];
113};
114
117 const std::shared_ptr<VerificationKey>& honk_vk)
118{
119 BB_BENCH_NAME("HypernovaFoldingProver::instance_to_accumulator");
120
121 vinfo("HypernovaFoldingProver: converting instance to accumulator...");
122
123 // Complete the incoming instance
124 auto precomputed_vk = honk_vk ? honk_vk : std::make_shared<VerificationKey>(instance->get_precomputed());
125 MegaOinkProver oink_prover{ instance, precomputed_vk, transcript };
126 oink_prover.prove();
127
128 instance->gate_challenges = transcript->template get_dyadic_powers_of_challenge<FF>(
129 "HypernovaFoldingProver:gate_challenge", Flavor::VIRTUAL_LOG_N);
130
131 // Run Sumcheck with padding
132 MegaSumcheckProver sumcheck(instance->dyadic_size(),
133 instance->polynomials,
135 instance->alpha,
136 instance->gate_challenges,
137 instance->relation_parameters,
139 auto sumcheck_output = sumcheck.prove();
140
141 Accumulator accumulator = sumcheck_output_to_accumulator(sumcheck_output, instance, precomputed_vk);
142
143 vinfo("HypernovaFoldingProver: accumulator constructed.");
144
145 return accumulator;
146}
147
149 const Accumulator& accumulator,
151 const std::shared_ptr<VerificationKey>& honk_vk)
152{
153 Accumulator incoming_accumulator = instance_to_accumulator(instance, honk_vk);
154
155 // Sumcheck
158 transcript);
159
160 HonkProof proof = batching_prover.construct_proof();
161
162 return { proof, batching_prover.compute_new_claim() };
163}
164} // namespace bb
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:77
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
std::pair< HonkProof, Accumulator > fold(const Accumulator &accumulator, const std::shared_ptr< ProverInstance > &instance, const std::shared_ptr< VerificationKey > &honk_vk=nullptr)
Fold an instance into an accumulator. Folding happens in place.
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.
std::pair< std::vector< FF >, std::vector< FF > > get_batching_challenges()
Generate the challenges required to batch the incoming instance with the accumulator.
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...
static constexpr size_t VIRTUAL_LOG_N
BB_PROFILE MultilinearBatchingProverClaim compute_new_claim()
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:398
#define vinfo(...)
Definition log.hpp:80
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
std::string to_string(bb::avm2::ValueTag tag)
Contains the evaluations of multilinear polynomials at the challenge point . These are computed by S...
ClaimedEvaluations claimed_evaluations
std::vector< FF > challenge