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 {
16{
17 BB_BENCH();
18
19 // Generate challenges to batch shifted and unshifted polynomials/commitments/evaluation
22 for (size_t idx = 0; idx < Flavor::NUM_UNSHIFTED_ENTITIES; idx++) {
23 labels_unshifted_entities[idx] = "unshifted_challenge_" + std::to_string(idx);
24 }
25 for (size_t idx = 0; idx < Flavor::NUM_SHIFTED_ENTITIES; idx++) {
26 labels_shifted_witnesses[idx] = "shifted_challenge_" + std::to_string(idx);
27 }
28 auto unshifted_challenges = transcript->template get_challenges<FF>(labels_unshifted_entities);
29 auto shifted_challenges = transcript->template get_challenges<FF>(labels_shifted_witnesses);
30
31 // Batch polynomials
32 auto batched_unshifted_polynomial = batch_polynomials<Flavor::NUM_UNSHIFTED_ENTITIES>(
33 instance->polynomials.get_unshifted(), instance->dyadic_size(), unshifted_challenges);
34 auto batched_shifted_polynomial = batch_polynomials<Flavor::NUM_SHIFTED_ENTITIES>(
35 instance->polynomials.get_to_be_shifted(), instance->dyadic_size(), shifted_challenges);
36
37 // Batch evaluations
38 FF batched_unshifted_evaluation(0);
39 FF batched_shifted_evaluation(0);
40
41 for (auto [eval, challenge] : zip_view(sumcheck_output.claimed_evaluations.get_unshifted(), unshifted_challenges)) {
42 batched_unshifted_evaluation += eval * challenge;
43 }
44 for (auto [eval, challenge] : zip_view(sumcheck_output.claimed_evaluations.get_shifted(), shifted_challenges)) {
45 batched_shifted_evaluation += eval * challenge;
46 }
47
48 // Batch commitments
49 VerifierCommitments verifier_commitments(honk_vk, instance->commitments);
50
51 Commitment batched_unshifted_commitment;
52 Commitment batched_shifted_commitment;
53
54 std::vector<Commitment> points;
55 std::vector<FF> scalars;
56 for (auto [commitment, scalar] : zip_view(verifier_commitments.get_unshifted(), unshifted_challenges)) {
57 points.emplace_back(commitment);
58 scalars.emplace_back(scalar);
59 }
60 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1552): Optimize batch_mul_native
61 batched_unshifted_commitment = batch_mul_native(points, scalars);
62
63 points.clear();
64 scalars.clear();
65 for (auto [commitment, scalar] : zip_view(verifier_commitments.get_to_be_shifted(), shifted_challenges)) {
66 points.emplace_back(commitment);
67 scalars.emplace_back(scalar);
68 }
69 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1552): Optimize batch_mul_native
70 batched_shifted_commitment = batch_mul_native(points, scalars);
71
72 return Accumulator{
73 .challenge = sumcheck_output.challenge,
74 .shifted_evaluation = batched_shifted_evaluation,
75 .non_shifted_evaluation = batched_unshifted_evaluation,
76 .non_shifted_polynomial = batched_unshifted_polynomial,
77 .shifted_polynomial = batched_shifted_polynomial,
78 .non_shifted_commitment = batched_unshifted_commitment,
79 .shifted_commitment = batched_shifted_commitment,
80 .dyadic_size = instance->dyadic_size(),
81 };
82};
83
84template <size_t N>
86 RefArray<Polynomial, N> polynomials_to_batch, const size_t& full_batched_size, const std::array<FF, N>& challenges)
87{
88 BB_BENCH();
89 BB_ASSERT_EQ(full_batched_size,
90 polynomials_to_batch[0].virtual_size(),
91 "The virtual size of the first polynomial is different from the full batched size.");
92
93 size_t challenge_idx = 0;
94
95 for (auto& poly : polynomials_to_batch) {
96 if (challenge_idx == 0) {
97 polynomials_to_batch[0] *= challenges[challenge_idx];
98 } else {
99 polynomials_to_batch[0].add_scaled(poly, challenges[challenge_idx]);
100 }
101 challenge_idx += 1;
102 }
103
104 return polynomials_to_batch[0];
105};
106
109{
110 BB_BENCH();
111
112 vinfo("HypernovaFoldingProver: converting instance to accumulator...");
113
114 // Complete the incoming instance
115 auto honk_vk = std::make_shared<VerificationKey>(instance->get_precomputed());
116 MegaOinkProver oink_prover{ instance, honk_vk, transcript };
117 oink_prover.prove();
118
119 instance->gate_challenges = transcript->template get_powers_of_challenge<FF>(
120 "HypernovaFoldingProver:gate_challenge", Flavor::VIRTUAL_LOG_N);
121
122 // Run Sumcheck with padding
123 MegaSumcheckProver sumcheck(instance->dyadic_size(),
124 instance->polynomials,
126 instance->alphas,
127 instance->gate_challenges,
128 instance->relation_parameters,
130 auto sumcheck_output = sumcheck.prove();
131
132 Accumulator accumulator = sumcheck_output_to_accumulator(sumcheck_output, instance, honk_vk);
133
134 vinfo("HypernovaFoldingProver: accumulator constructed.");
135
136 return accumulator;
137}
138
140 const Accumulator& accumulator, const std::shared_ptr<ProverInstance>& instance)
141{
142 Accumulator incoming_accumulator = instance_to_accumulator(instance);
143
144 // Sumcheck
147 transcript);
148
149 HonkProof proof = batching_prover.construct_proof();
150 batching_prover.compute_new_claim();
151
152 return { proof, batching_prover.get_new_claim() };
153}
154} // namespace bb
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:88
#define BB_BENCH()
Definition bb_bench.hpp:222
std::pair< HonkProof, Accumulator > fold(const Accumulator &accumulator, const std::shared_ptr< ProverInstance > &instance)
Fold an instance into an accumulator. Folding happens in place.
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)
Accumulator instance_to_accumulator(const std::shared_ptr< ProverInstance > &instance)
Turn an instance into an accumulator by running Sumcheck.
static Polynomial batch_polynomials(RefArray< Polynomial, N > polynomials_to_batch, const size_t &full_batched_size, const std::array< FF, N > &challenges)
Batch prover polynomials. Batching happens in place into the first polynomial in the RefArray supplie...
static constexpr size_t NUM_SHIFTED_ENTITIES
static constexpr size_t VIRTUAL_LOG_N
static constexpr size_t NUM_UNSHIFTED_ENTITIES
MultilinearBatchingProverClaim get_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.
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:126
SumcheckOutput< Flavor > prove()
Non-ZK version: Compute round univariate, place it in transcript, compute challenge,...
Definition sumcheck.hpp:246
#define vinfo(...)
Definition log.hpp:79
Entry point for Barretenberg command-line interface.
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