Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
verifier.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Completed, auditors: [Federico], commit: 0e37cb8}
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
7
8#include "barretenberg/aztec/aztec_constants.hpp"
14#include <numeric>
15
16namespace bb::avm2 {
17
19 : key(std::move(other.key))
20 , transcript(std::move(other.transcript))
21{}
22
24{
25 key = other.key;
26 transcript = other.transcript;
27 return *this;
28}
29
43 const std::vector<FF>& challenges)
44{
45 Polynomial<FF> polynomial(points, MAX_AVM_TRACE_SIZE);
46 return polynomial.evaluate_mle(challenges);
47}
48
53bool AvmVerifier::verify_proof(const HonkProof& proof, const std::vector<std::vector<FF>>& public_inputs)
54{
55 using PCS = Flavor::PCS;
56 using Curve = Flavor::Curve;
57 using VerifierCommitments = Flavor::VerifierCommitments;
59 using ClaimBatcher = ClaimBatcher_<Curve>;
60 using ClaimBatch = ClaimBatcher::Batch;
61 using Challenges = Flavor::AllEntities<FF>;
62
63 RelationParameters<FF> relation_parameters;
64
65 if (proof.size() != static_cast<size_t>(AVM_V2_PROOF_LENGTH_IN_FIELDS)) {
66 vinfo("Proof length mismatch: got ",
67 proof.size(),
68 " fields, expected ",
69 static_cast<size_t>(AVM_V2_PROOF_LENGTH_IN_FIELDS));
70 return false;
71 }
72
73 transcript->load_proof(proof);
74
75 // ========== Execute preamble round ==========
76
77 // Add vk hash to transcript
78 FF vk_hash = key->get_hash();
79 transcript->add_to_hash_buffer("avm_vk_hash", vk_hash);
80 vinfo("AVM vk hash in verifier: ", vk_hash);
81
82 // ========== Execute public inputs round ==========
83
84 // Validate number of public input columns
85 if (public_inputs.size() != AVM_NUM_PUBLIC_INPUT_COLUMNS) {
86 vinfo("Public inputs size mismatch");
87 return false;
88 }
89
90 // Add public inputs to transcript. This ensures that the Sumcheck challenge depends both on the public inputs sent
91 // in the clear and on the committed columns.
92 for (size_t i = 0; i < AVM_NUM_PUBLIC_INPUT_COLUMNS; i++) {
93 // Validate public input column size
94 if (public_inputs[i].size() != AVM_PUBLIC_INPUTS_COLUMN_LENGTHS[i]) {
95 vinfo("Public input size mismatch");
96 return false;
97 }
98 for (size_t j = 0; j < public_inputs[i].size(); j++) {
99 transcript->add_to_hash_buffer("public_input_" + std::to_string(i) + "_" + std::to_string(j),
100 public_inputs[i][j]);
101 }
102 }
103
104 // ========== Execute wire commitments round ==========
105
106 // Receive commitments to all polynomials except the logderivate ones
107 VerifierCommitments commitments{ key };
108 for (auto [comm, label] : zip_view(commitments.get_wires(), commitments.get_wires_labels())) {
109 comm = transcript->template receive_from_prover<Commitment>(label);
110 }
111
112 // ========== Execute log derivative inverse round ==========
113
114 // Generate randomness required by Lookup and Permutation relations
115 auto [beta, gamma] = transcript->template get_challenges<FF>(std::array<std::string, 2>{ "beta", "gamma" });
116 relation_parameters.beta = beta;
117 relation_parameters.gamma = gamma;
118
119 // Receive commitments to all logderivative inverse polynomials
120 for (auto [commitment, label] : zip_view(commitments.get_derived(), commitments.get_derived_labels())) {
121 commitment = transcript->template receive_from_prover<Commitment>(label);
122 }
123
124 // ========== Execute relation check rounds ==========
125
126 // Multiply each linearly independent subrelation contribution by `alpha^i` for i = 0, ..., NUM_SUBRELATIONS - 1.
127 const FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");
128
130
131 // Get the gate challenges for sumcheck computation
132 std::vector<FF> gate_challenges =
133 transcript->template get_dyadic_powers_of_challenge<FF>("Sumcheck:gate_challenge", MAX_AVM_TRACE_LOG_SIZE);
134 SumcheckOutput<Flavor> output = sumcheck.verify(relation_parameters, gate_challenges);
135
136 // If Sumcheck did not verify, return false
137 if (!output.verified) {
138 vinfo("Sumcheck verification failed");
139 return false;
140 }
141
142 // Validate that the public inputs committed in the public input columns match the public inputs sent in the clear
143 // by the Prover
144 using C = ColumnAndShifts;
146 output.claimed_evaluations.get(C::public_inputs_cols_0_),
147 output.claimed_evaluations.get(C::public_inputs_cols_1_),
148 output.claimed_evaluations.get(C::public_inputs_cols_2_),
149 output.claimed_evaluations.get(C::public_inputs_cols_3_),
150 };
151 for (size_t idx = 0;
152 const auto& [public_input_column, claimed_evaluation] : zip_view(public_inputs, claimed_evaluations)) {
153 FF public_input_evaluation = evaluate_public_input_column(public_input_column, output.challenge);
154 if (public_input_evaluation != claimed_evaluation) {
155 vinfo("public_input_evaluation failed, public inputs col ", idx);
156 return false;
157 }
158 idx++;
159 }
160
161 // ========== Execute PCS verification ==========
162
163 // Batch commitments and evaluations using short scalars to reduce ECCVM circuit size
164 std::span<const Commitment> unshifted_comms = commitments.get_unshifted();
165 std::span<const FF> unshifted_evals = output.claimed_evaluations.get_unshifted();
166 std::span<const Commitment> shifted_comms = commitments.get_to_be_shifted();
167 std::span<const FF> shifted_evals = output.claimed_evaluations.get_shifted();
168
169 // Get short batching challenges from transcript
170 Challenges challenges;
171 auto unshifted_challenges_vec = transcript->template get_short_challenges<FF>(challenges.get_unshifted_labels());
172 std::ranges::move(unshifted_challenges_vec, challenges.get_unshifted().begin());
173 auto unshifted_challenges = challenges.get_unshifted();
174 auto shifted_challenges = challenges.get_to_be_shifted();
175
176 // Batch shifted commitments
177 Commitment batched_shifted = Commitment::batch_mul(shifted_comms, shifted_challenges);
178
179 // Batch unshifted commitments: We reuse the calculation performed for shifted commitments.
180 Commitment batched_unshifted =
181 batched_shifted +
182 Commitment::batch_mul(unshifted_comms.subspan(0, WIRES_TO_BE_SHIFTED_START_IDX),
183 unshifted_challenges.subspan(0, WIRES_TO_BE_SHIFTED_START_IDX)) +
184 Commitment::batch_mul(unshifted_comms.subspan(WIRES_TO_BE_SHIFTED_END_IDX),
185 unshifted_challenges.subspan(WIRES_TO_BE_SHIFTED_END_IDX));
186
187 // Batch evaluations: compute inner product with first eval as initial value for unshifted
188 FF batched_unshifted_eval =
189 std::inner_product(unshifted_challenges.begin(), unshifted_challenges.end(), unshifted_evals.begin(), FF(0));
190
191 FF batched_shifted_eval =
192 std::inner_product(shifted_challenges.begin(), shifted_challenges.end(), shifted_evals.begin(), FF(0));
193
194 // Execute Shplemini rounds with batched claims
195 ClaimBatcher batched_claim_batcher{ .unshifted = ClaimBatch{ .commitments = RefVector(batched_unshifted),
196 .evaluations = RefVector(batched_unshifted_eval) },
197 .shifted = ClaimBatch{ .commitments = RefVector(batched_shifted),
198 .evaluations = RefVector(batched_shifted_eval) } };
199 auto opening_claim =
200 Shplemini::compute_batch_opening_claim(batched_claim_batcher, output.challenge, Commitment::one(), transcript)
201 .batch_opening_claim;
202
203 const auto pairing_points = PCS::reduce_verify_batch_opening_claim(std::move(opening_claim), transcript);
204 const auto shplemini_verified = pairing_points.check();
205
206 if (!shplemini_verified) {
207 vinfo("Shplemini verification failed");
208 return false;
209 }
210
211 return true;
212}
213
214} // namespace bb::avm2
IPA (inner product argument) commitment scheme class.
Definition ipa.hpp:87
Fr evaluate_mle(std::span< const Fr > evaluation_points, bool shift=false) const
evaluate multi-linear extension p(X_0,…,X_{n-1}) = \sum_i a_i*L_i(X_0,…,X_{n-1}) at u = (u_0,...
A template class for a reference vector. Behaves as if std::vector<T&> was possible.
Implementation of the sumcheck Verifier for statements of the form for multilinear polynomials .
Definition sumcheck.hpp:802
SumcheckOutput< Flavor > verify(const bb::RelationParameters< FF > &relation_parameters, const std::vector< FF > &gate_challenges)
The Sumcheck verification method. First it extracts round univariate, checks sum (the sumcheck univar...
Definition sumcheck.hpp:859
VerifierCommitments_< Commitment, VerificationKey > VerifierCommitments
Definition flavor.hpp:308
AvmFlavorSettings::PCS PCS
Definition flavor.hpp:41
AvmFlavorSettings::Curve Curve
Definition flavor.hpp:39
std::shared_ptr< Transcript > transcript
Definition verifier.hpp:33
AvmVerifier & operator=(const AvmVerifier &other)=delete
static FF evaluate_public_input_column(const std::vector< FF > &points, const std::vector< FF > &challenges)
Evaluate the given public input column over the multivariate challenge points.
Definition verifier.cpp:42
std::shared_ptr< VerificationKey > key
Definition verifier.hpp:32
bool verify_proof(const HonkProof &proof, const std::vector< std::vector< FF > > &public_inputs)
Verify an AVM proof.
Definition verifier.cpp:53
Flavor::Commitment Commitment
Definition verifier.hpp:17
#define vinfo(...)
Definition log.hpp:94
std::string label
constexpr auto WIRES_TO_BE_SHIFTED_END_IDX
Definition columns.hpp:68
constexpr std::size_t MAX_AVM_TRACE_SIZE
Definition constants.hpp:14
constexpr std::size_t MAX_AVM_TRACE_LOG_SIZE
Definition constants.hpp:13
ColumnAndShifts
Definition columns.hpp:35
constexpr auto WIRES_TO_BE_SHIFTED_START_IDX
Definition columns.hpp:67
constexpr std::array< std::size_t, AVM_NUM_PUBLIC_INPUT_COLUMNS > AVM_PUBLIC_INPUTS_COLUMN_LENGTHS
Definition constants.hpp:19
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)
Logic to support batching opening claims for unshifted and shifted polynomials in Shplemini.
Container for parameters used by the grand product (permutation, lookup) Honk relations.
Contains the evaluations of multilinear polynomials at the challenge point . These are computed by S...
ClaimedEvaluations claimed_evaluations
std::vector< FF > challenge