Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
verifier.cpp
Go to the documentation of this file.
2
8
9namespace bb::avm2 {
10
12 : key(std::move(verifier_key))
13{}
14
16 : key(std::move(other.key))
17 , transcript(std::move(other.transcript))
18{}
19
21{
22 key = other.key;
23 transcript = other.transcript;
24 commitments.clear();
25 return *this;
26}
27
28using FF = AvmFlavor::FF;
29
30// Evaluate the given public input column over the multivariate challenge points
31inline FF AvmVerifier::evaluate_public_input_column(const std::vector<FF>& points, std::vector<FF> challenges)
32{
33 Polynomial<FF> polynomial(points, (1 << key->log_circuit_size));
34 return polynomial.evaluate_mle(challenges);
35}
36
41bool AvmVerifier::verify_proof(const HonkProof& proof, const std::vector<std::vector<FF>>& public_inputs)
42{
43 using Flavor = AvmFlavor;
44 using FF = Flavor::FF;
46 using PCS = Flavor::PCS;
47 using Curve = Flavor::Curve;
48 using VerifierCommitments = Flavor::VerifierCommitments;
49 using Shplemini = ShpleminiVerifier_<Curve>;
50 using ClaimBatcher = ClaimBatcher_<Curve>;
51 using ClaimBatch = ClaimBatcher::Batch;
53
54 RelationParameters<FF> relation_parameters;
55
56 transcript->load_proof(proof);
57
58 // TODO(#15892): Fiat-Shamir the vk hash by uncommenting the line below.
59 FF vk_hash = key->hash();
60 // transcript->add_to_hash_buffer("avm_vk_hash", vk_hash);
61 info("AVM vk hash in verifier: ", vk_hash);
62
63 VerifierCommitments commitments{ key };
64 // Get commitments to VM wires
65 for (auto [comm, label] : zip_view(commitments.get_wires(), commitments.get_wires_labels())) {
66 comm = transcript->template receive_from_prover<Commitment>(label);
67 }
68
69 auto [beta, gamm] = transcript->template get_challenges<FF>("beta", "gamma");
70 relation_parameters.beta = beta;
71 relation_parameters.gamma = gamm;
72
73 // Get commitments to inverses
74 for (auto [label, commitment] : zip_view(commitments.get_derived_labels(), commitments.get_derived())) {
75 commitment = transcript->template receive_from_prover<Commitment>(label);
76 }
77
78 // Execute Sumcheck Verifier
79 std::vector<FF> padding_indicator_array(key->log_circuit_size, 1);
80
81 // Multiply each linearly independent subrelation contribution by `alpha^i` for i = 0, ..., NUM_SUBRELATIONS - 1.
82 const FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");
83
84 SumcheckVerifier<Flavor> sumcheck(transcript, alpha, key->log_circuit_size);
85
86 // Get the gate challenges for sumcheck computation
87 std::vector<FF> gate_challenges =
88 transcript->template get_powers_of_challenge<FF>("Sumcheck:gate_challenge", key->log_circuit_size);
89
90 SumcheckOutput<Flavor> output = sumcheck.verify(relation_parameters, gate_challenges, padding_indicator_array);
91
92 // If Sumcheck did not verify, return false
93 if (!output.verified) {
94 vinfo("Sumcheck verification failed");
95 return false;
96 }
97
98 if (public_inputs.size() != AVM_NUM_PUBLIC_INPUT_COLUMNS) {
99 vinfo("Public inputs size mismatch");
100 return false;
101 }
102
104 output.claimed_evaluations.public_inputs_cols_0_,
105 output.claimed_evaluations.public_inputs_cols_1_,
106 output.claimed_evaluations.public_inputs_cols_2_,
107 output.claimed_evaluations.public_inputs_cols_3_,
108 };
109 for (size_t i = 0; i < AVM_NUM_PUBLIC_INPUT_COLUMNS; i++) {
110 FF public_input_evaluation = evaluate_public_input_column(public_inputs[i], output.challenge);
111 if (public_input_evaluation != claimed_evaluations[i]) {
112 vinfo("public_input_evaluation failed, public inputs col ", i);
113 return false;
114 }
115 }
116
117 ClaimBatcher claim_batcher{
118 .unshifted = ClaimBatch{ commitments.get_unshifted(), output.claimed_evaluations.get_unshifted() },
119 .shifted = ClaimBatch{ commitments.get_to_be_shifted(), output.claimed_evaluations.get_shifted() }
120 };
121 const BatchOpeningClaim<Curve> opening_claim = Shplemini::compute_batch_opening_claim(
122 padding_indicator_array, claim_batcher, output.challenge, Commitment::one(), transcript);
123
124 const auto pairing_points = PCS::reduce_verify_batch_opening_claim(opening_claim, transcript);
125 VerifierCommitmentKey pcs_vkey{};
126 const auto shplemini_verified = pcs_vkey.pairing_check(pairing_points[0], pairing_points[1]);
127
128 if (!shplemini_verified) {
129 vinfo("Shplemini verification failed");
130 return false;
131 }
132
133 return true;
134}
135
136} // namespace bb::avm2
#define AVM_NUM_PUBLIC_INPUT_COLUMNS
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
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,...
An efficient verifier for the evaluation proofs of multilinear polynomials and their shifts.
Implementation of the sumcheck Verifier for statements of the form for multilinear polynomials .
Definition sumcheck.hpp:645
SumcheckOutput< Flavor > verify(const bb::RelationParameters< FF > &relation_parameters, std::vector< FF > &gate_challenges, const std::vector< FF > &padding_indicator_array)
Extract round univariate, check sum, generate challenge, compute next target sum.....
Definition sumcheck.hpp:718
AvmFlavorSettings::FF FF
Definition flavor.hpp:34
AvmFlavorSettings::VerifierCommitmentKey VerifierCommitmentKey
Definition flavor.hpp:41
VerifierCommitments_< Commitment, VerificationKey > VerifierCommitments
Definition flavor.hpp:361
AvmFlavorSettings::PCS PCS
Definition flavor.hpp:32
AvmFlavorSettings::Commitment Commitment
Definition flavor.hpp:38
AvmFlavorSettings::Curve Curve
Definition flavor.hpp:30
AvmVerifier(std::shared_ptr< VerificationKey > verifier_key)
Definition verifier.cpp:11
std::shared_ptr< Transcript > transcript
Definition verifier.hpp:31
AvmVerifier & operator=(const AvmVerifier &other)=delete
FF evaluate_public_input_column(const std::vector< FF > &points, std::vector< FF > challenges)
Definition verifier.cpp:31
std::shared_ptr< VerificationKey > key
Definition verifier.hpp:29
virtual bool verify_proof(const HonkProof &proof, const std::vector< std::vector< FF > > &public_inputs)
This function verifies an Avm Honk proof for given program settings.
Definition verifier.cpp:41
std::map< std::string, Commitment > commitments
Definition verifier.hpp:30
Flavor::Commitment Commitment
Definition verifier.hpp:12
void vinfo(Args... args)
Definition log.hpp:76
void info(Args... args)
Definition log.hpp:70
AvmFlavorSettings::FF FF
Definition field.hpp:10
std::vector< fr > HonkProof
Definition proof.hpp:15
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
An accumulator consisting of the Shplonk evaluation challenge and vectors of commitments and scalars.
Definition claim.hpp:169
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