Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
hypernova_verifier.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
8
9namespace bb {
10
11template <typename Flavor_>
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 <typename Flavor_>
31template <size_t N>
33 const RefArray<Commitment, N>& _points, const std::vector<FF>& scalars)
34{
35 std::vector<Commitment> points(N);
36 for (size_t idx = 0; const auto& point : _points) {
37 points[idx++] = point;
38 }
39
40 if constexpr (IsRecursiveFlavor<Flavor>) {
41 return Curve::Group::batch_mul(points, scalars);
42 } else {
43 return batch_mul_native<Curve>(points, scalars);
44 }
45}
46
47template <typename Flavor>
51{
52 BB_BENCH_NAME("HypernovaFoldingVerifier::sumcheck_output_to_accumulator");
53
54 // Generate challenges to batch shifted and unshifted polynomials/commitments/evaluation
55 auto [unshifted_challenges, shifted_challenges] = get_batching_challenges();
56
57 // Batch evaluations
58 FF batched_unshifted_evaluation(0);
59 FF batched_shifted_evaluation(0);
60
61 for (auto [eval, challenge] : zip_view(sumcheck_output.claimed_evaluations.get_unshifted(), unshifted_challenges)) {
62 batched_unshifted_evaluation += eval * challenge;
63 }
64 for (auto [eval, challenge] : zip_view(sumcheck_output.claimed_evaluations.get_shifted(), shifted_challenges)) {
65 batched_shifted_evaluation += eval * challenge;
66 }
67
68 // Batch commitments
69 VerifierCommitments verifier_commitments(instance->get_vk(), instance->witness_commitments);
70
71 Commitment batched_unshifted_commitment = batch_mul(verifier_commitments.get_unshifted(), unshifted_challenges);
72 Commitment batched_shifted_commitment = batch_mul(verifier_commitments.get_to_be_shifted(), shifted_challenges);
73
74 return Accumulator{ .challenge = sumcheck_output.challenge,
75 .non_shifted_evaluation = batched_unshifted_evaluation,
76 .shifted_evaluation = batched_shifted_evaluation,
77 .non_shifted_commitment = batched_unshifted_commitment,
78 .shifted_commitment = batched_shifted_commitment };
79};
80
81template <typename Flavor>
84{
85 BB_BENCH_NAME("HypernovaFoldingVerifier::sumcheck_on_incoming_instance");
86
87 vinfo("HypernovaFoldingVerifier: verifying Oink proof...");
88 // Complete the incoming verifier instance
89 OinkVerifier verifier{ instance, transcript };
90 transcript->load_proof(proof);
91 verifier.verify();
92
93 instance->gate_challenges = transcript->template get_dyadic_powers_of_challenge<FF>(
94 "HypernovaFoldingProver:gate_challenge", Flavor::VIRTUAL_LOG_N);
95
96 // Sumcheck verification
97 vinfo("HypernovaFoldingVerifier: verifying Sumcheck to turn instance into an accumulator...");
98
99 std::vector<FF> padding_indicator_array(Flavor::VIRTUAL_LOG_N, 1);
100 SumcheckVerifier sumcheck(transcript, instance->alpha, Flavor::VIRTUAL_LOG_N);
101 SumcheckOutput<Flavor> sumcheck_output =
102 sumcheck.verify(instance->relation_parameters, instance->gate_challenges, padding_indicator_array);
103
104 return sumcheck_output;
105};
106
107template <typename Flavor>
110 const Proof& proof)
111{
112 BB_BENCH_NAME("HypernovaFoldingVerifier::instance_to_accumulator");
113
114 auto sumcheck_output = sumcheck_on_incoming_instance(instance, proof);
115
116 auto accumulator = sumcheck_output_to_accumulator(sumcheck_output, instance);
117
118 if (sumcheck_output.verified) {
119 vinfo("HypernovaFoldingVerifier: Successfully turned instance into accumulator.");
120 } else {
121 vinfo("HypernovaFoldingVerifier: Failed to recursively verify Sumcheck to turn instance into an accumulator. "
122 "Ignore if generating the VKs");
123 }
124
125 return { sumcheck_output.verified, accumulator };
126};
127
128template <typename Flavor>
132{
133 BB_BENCH_NAME("HypernovaFoldingVerifier::verify_folding_proof");
134
135 vinfo("HypernovaFoldingVerifier: verifying folding proof...");
136
137 auto sumcheck_output = sumcheck_on_incoming_instance(instance, proof);
138
139 // Generate challenges to batch shifted and unshifted polynomials/commitments/evaluation
140 auto [unshifted_challenges, shifted_challenges] = get_batching_challenges();
141
142 VerifierCommitments verifier_commitments(instance->get_vk(), instance->witness_commitments);
143
144 MultilinearBatchingVerifier batching_verifier(transcript);
145 auto [sumcheck_batching_result, new_accumulator] =
146 batching_verifier.verify_proof(sumcheck_output, verifier_commitments, unshifted_challenges, shifted_challenges);
147
148 if (sumcheck_output.verified && sumcheck_batching_result) {
149 vinfo("HypernovaFoldingVerifier: successfully verified folding proof.");
150 } else if (!sumcheck_output.verified) {
151 vinfo("HypernovaFoldingVerifier: Failed to recursively verify Sumcheck to turn instance into an accumulator. "
152 "Ignore if generating the VKs");
153 } else {
154 vinfo("HypernovaFoldingVerifier: Failed to recursively verify Sumcheck to batch two accumulators. Ignore if "
155 "generating the VKs");
156 }
157
158 return { sumcheck_output.verified, sumcheck_batching_result, new_accumulator };
159};
160
163} // namespace bb
std::shared_ptr< Napi::ThreadSafeFunction > instance
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:219
SumcheckOutput< Flavor > sumcheck_on_incoming_instance(const std::shared_ptr< VerifierInstance > &instance, const Proof &proof)
Perform sumcheck on the incoming instance.
std::conditional_t< IsRecursiveFlavor< Flavor >, typename HypernovaRecursiveTypes::Proof, typename HypernovaNativeTypes::Proof > Proof
std::pair< bool, Accumulator > instance_to_accumulator(const std::shared_ptr< VerifierInstance > &instance, const Proof &proof)
Turn an instance into an accumulator by executing sumcheck.
std::conditional_t< IsRecursiveFlavor< Flavor >, typename HypernovaRecursiveTypes::MultilinearBatchingVerifier, typename HypernovaNativeTypes::MultilinearBatchingVerifier > MultilinearBatchingVerifier
Commitment batch_mul(const RefArray< Commitment, N > &_points, const std::vector< FF > &scalars)
Utility to perform batch mul of commitments.
Accumulator sumcheck_output_to_accumulator(MegaSumcheckOutput &sumcheck_output, const std::shared_ptr< VerifierInstance > &instance)
Convert the output of the sumcheck run on the incoming instance into an accumulator.
std::pair< std::vector< FF >, std::vector< FF > > get_batching_challenges()
Generate the challenges required to batch the incoming instance with the accumulator.
Verifier class for all the presumcheck rounds, which are shared between the folding verifier and ultr...
void verify()
Oink Verifier 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
Implementation of the sumcheck Verifier for statements of the form for multilinear polynomials .
Definition sumcheck.hpp:786
SumcheckOutput< Flavor > verify(const bb::RelationParameters< FF > &relation_parameters, const std::vector< FF > &gate_challenges, const std::vector< FF > &padding_indicator_array)
The Sumcheck verification method. First it extracts round univariate, checks sum (the sumcheck univar...
Definition sumcheck.hpp:844
#define vinfo(...)
Definition log.hpp:80
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
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