Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
recursive_verifier.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4#include <cstddef>
5#include <memory>
6
17
18namespace bb::avm2 {
19
20// TODO(#15892): Remove vk argument from all functions once its fixed.
21AvmRecursiveVerifier::AvmRecursiveVerifier(Builder& builder, const std::shared_ptr<VerificationKey>& vkey)
23 , key(vkey)
24{
25 // TODO(#15892): Uncomment this when we make the AVM vk and vk
26 // hash fixed.
27 // key->fix_witness();
28 // compute the vk hash from the native vk fields
29 // this->vk_hash.fix_witness();
30}
31
32// Evaluate the given public input column over the multivariate challenge points
34 const std::vector<FF>& challenges)
35{
36 auto coefficients = SharedShiftedVirtualZeroesArray<FF>{
37 .start_ = 0,
38 .end_ = points.size(),
39 .virtual_size_ = MAX_AVM_TRACE_SIZE,
40 .backing_memory_ = BackingMemory<FF>::allocate(points.size()),
41 };
42
43 memcpy(
44 static_cast<void*>(coefficients.data()), static_cast<const void*>(points.data()), sizeof(FF) * points.size());
45
46 return generic_evaluate_mle<FF>(challenges, coefficients);
47}
48
50 const HonkProof& proof, const std::vector<std::vector<fr>>& public_inputs_vec_nt)
51{
52 StdlibProof stdlib_proof(builder, proof);
53
54 std::vector<std::vector<FF>> public_inputs_ct;
55 public_inputs_ct.reserve(public_inputs_vec_nt.size());
56
57 for (const auto& vec : public_inputs_vec_nt) {
58 std::vector<FF> vec_ct;
59 vec_ct.reserve(vec.size());
60 for (const auto& el : vec) {
61 vec_ct.push_back(stdlib::witness_t<Builder>(&builder, el));
62 }
63 public_inputs_ct.push_back(vec_ct);
64 }
65
66 return verify_proof(stdlib_proof, public_inputs_ct);
67}
68
69// TODO(#991): (see https://github.com/AztecProtocol/barretenberg/issues/991)
70// TODO(#14234)[Unconditional PIs validation]: rename stdlib_proof_with_pi_flag to stdlib_proof
72 const stdlib::Proof<Builder>& stdlib_proof_with_pi_flag, const std::vector<std::vector<FF>>& public_inputs)
73{
74 using Curve = typename Flavor::Curve;
75 using PCS = typename Flavor::PCS;
77 using RelationParams = RelationParameters<typename Flavor::FF>;
78 using Shplemini = ShpleminiVerifier_<Curve>;
79 using ClaimBatcher = ClaimBatcher_<Curve>;
80 using ClaimBatch = ClaimBatcher::Batch;
81 using stdlib::bool_t;
82
83 // TODO(#14234)[Unconditional PIs validation]: Remove the next 3 lines
84 StdlibProof stdlib_proof = stdlib_proof_with_pi_flag;
85 bool_t<Builder> pi_validation = !bool_t<Builder>(stdlib_proof.at(0));
86 stdlib_proof.erase(stdlib_proof.begin());
87
88 if (public_inputs.size() != AVM_NUM_PUBLIC_INPUT_COLUMNS) {
89 throw_or_abort("AvmRecursiveVerifier::verify_proof: public inputs size mismatch");
90 }
91
92 transcript->load_proof(stdlib_proof);
93
94 // TODO(#15892): Fiat-Shamir the vk hash by uncommenting the add_to_hash_buffer.
95 // transcript->add_to_hash_buffer("avm_vk_hash", vk_hash);
96 info("AVM vk hash in recursive verifier: ", vk_hash);
97
98 RelationParams relation_parameters;
99 VerifierCommitments commitments{ key };
100
101 // Get commitments to VM wires
102 for (auto [comm, label] : zip_view(commitments.get_wires(), commitments.get_wires_labels())) {
103 comm = transcript->template receive_from_prover<Commitment>(label);
104 }
105
106 auto [beta, gamma] = transcript->template get_challenges<FF>("beta", "gamma");
107 relation_parameters.beta = beta;
108 relation_parameters.gamma = gamma;
109
110 // Get commitments to inverses
111 for (auto [label, commitment] : zip_view(commitments.get_derived_labels(), commitments.get_derived())) {
112 commitment = transcript->template receive_from_prover<Commitment>(label);
113 }
114
115 FF one{ 1 };
116 one.convert_constant_to_fixed_witness(&builder);
117
118 std::vector<FF> padding_indicator_array(key->log_fixed_circuit_size);
119 std::ranges::fill(padding_indicator_array, one);
120
121 // Multiply each linearly independent subrelation contribution by `alpha^i` for i = 0, ..., NUM_SUBRELATIONS - 1.
122 const FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");
123
124 SumcheckVerifier<Flavor> sumcheck(transcript, alpha, key->log_fixed_circuit_size);
125
126 std::vector<FF> gate_challenges =
127 transcript->template get_powers_of_challenge<FF>("Sumcheck:gate_challenge", key->log_fixed_circuit_size);
128
129 // No need to constrain that sumcheck_verified is true as this is guaranteed by the implementation of
130 // when called over a "circuit field" types.
131 SumcheckOutput<Flavor> output = sumcheck.verify(relation_parameters, gate_challenges, padding_indicator_array);
132 vinfo("verified sumcheck: ", (output.verified));
133
135 output.claimed_evaluations.public_inputs_cols_0_,
136 output.claimed_evaluations.public_inputs_cols_1_,
137 output.claimed_evaluations.public_inputs_cols_2_,
138 output.claimed_evaluations.public_inputs_cols_3_,
139 };
140
141 // TODO(#14234)[Unconditional PIs validation]: Inside of loop, replace pi_validation.must_imply() by
142 // public_input_evaluation.assert_equal(claimed_evaluations[i]
143 for (size_t i = 0; i < AVM_NUM_PUBLIC_INPUT_COLUMNS; i++) {
144 FF public_input_evaluation = evaluate_public_input_column(public_inputs[i], output.challenge);
145 vinfo("public_input_evaluation failed, public inputs col ", i);
146 pi_validation.must_imply(public_input_evaluation == claimed_evaluations[i], "public_input_evaluation failed");
147 }
148
149 // Execute Shplemini rounds.
150 ClaimBatcher claim_batcher{
151 .unshifted = ClaimBatch{ commitments.get_unshifted(), output.claimed_evaluations.get_unshifted() },
152 .shifted = ClaimBatch{ commitments.get_to_be_shifted(), output.claimed_evaluations.get_shifted() }
153 };
154 const BatchOpeningClaim<Curve> opening_claim = Shplemini::compute_batch_opening_claim(
155 padding_indicator_array, claim_batcher, output.challenge, Commitment::one(&builder), transcript);
156
157 auto pairing_points = PCS::reduce_verify_batch_opening_claim(opening_claim, transcript);
158 return pairing_points;
159}
160
161} // namespace bb::avm2
#define AVM_NUM_PUBLIC_INPUT_COLUMNS
static std::shared_ptr< BackingMemory< Fr > > allocate(size_t size)
An efficient verifier for the evaluation proofs of multilinear polynomials and their shifts.
NativeFlavor::VerifierCommitments_< Commitment, VerificationKey > VerifierCommitments
AvmRecursiveFlavorSettings::Curve Curve
AvmRecursiveFlavorSettings::PCS PCS
std::shared_ptr< Transcript > transcript
typename Flavor::VerifierCommitments VerifierCommitments
stdlib::Proof< Builder > StdlibProof
std::shared_ptr< VerificationKey > key
FF evaluate_public_input_column(const std::vector< FF > &points, const std::vector< FF > &challenges)
PairingPoints verify_proof(const HonkProof &proof, const std::vector< std::vector< fr > > &public_inputs_vec_nt)
typename Flavor::CircuitBuilder Builder
AvmRecursiveVerifier(Builder &builder, const std::shared_ptr< VerificationKey > &vkey)
A simple wrapper around a vector of stdlib field elements representing a proof.
Definition proof.hpp:19
Implements boolean logic in-circuit.
Definition bool.hpp:59
void vinfo(Args... args)
Definition log.hpp:76
void info(Args... args)
Definition log.hpp:70
AluTraceBuilder builder
Definition alu.test.cpp:123
constexpr size_t MAX_AVM_TRACE_SIZE
Definition constants.hpp:10
std::vector< fr > HonkProof
Definition proof.hpp:15
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
For a small integer N = virtual_log_n and a given witness x = log_n, compute in-circuit an indicator_...
A shared pointer array template that represents a virtual array filled with zeros up to virtual_size_...
size_t start_
The starting index of the memory-backed range.
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.
void throw_or_abort(std::string const &err)