Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
prover.cpp
Go to the documentation of this file.
2
3#include <cstdlib>
4
17
18namespace bb::avm2 {
19
20// Maximum number of polynomials to batch commit at once.
22 getenv("AVM_MAX_MSM_BATCH_SIZE") != nullptr ? std::stoul(getenv("AVM_MAX_MSM_BATCH_SIZE")) : 32;
23
25using FF = Flavor::FF;
26
37 const PCSCommitmentKey& commitment_key)
38 : key(std::move(input_key))
39 , vk(std::move(vk))
40 , prover_polynomials(*key)
41 , commitment_key(commitment_key)
42{}
43
49{
50 // TODO(#15892): Fiat-shamir the vk hash by uncommenting the line below.
51 FF vk_hash = vk->hash();
52 // transcript->add_to_hash_buffer("avm_vk_hash", vk_hash);
53 info("AVM vk hash in prover: ", vk_hash);
54}
55
61{
62 BB_BENCH_NAME("AvmProver::execute_public_inputs_round");
63
64 using C = ColumnAndShifts;
65 // We take the starting values of the public inputs polynomials to add to the transcript
66 const auto public_inputs_cols = std::vector({ &prover_polynomials.get(C::public_inputs_cols_0_),
67 &prover_polynomials.get(C::public_inputs_cols_1_),
68 &prover_polynomials.get(C::public_inputs_cols_2_),
69 &prover_polynomials.get(C::public_inputs_cols_3_) });
70 for (size_t i = 0; i < public_inputs_cols.size(); ++i) {
71 for (size_t j = 0; j < AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH; ++j) {
72 // The public inputs are added to the hash buffer, but do not increase the size of the proof
73 transcript->add_to_hash_buffer("public_input_" + std::to_string(i) + "_" + std::to_string(j),
74 j < public_inputs_cols[i]->size() ? public_inputs_cols[i]->at(j) : FF(0));
75 }
76 }
77}
83{
84 BB_BENCH_NAME("AvmProver::execute_wire_commitments_round");
85 // Commit to all polynomials (apart from logderivative inverse polynomials, which are committed to in the later
86 // logderivative phase)
87 auto wire_polys = prover_polynomials.get_wires();
88 const auto& labels = prover_polynomials.get_wires_labels();
89 auto batch = commitment_key.start_batch();
90 for (size_t idx = 0; idx < wire_polys.size(); ++idx) {
91 batch.add_to_batch(wire_polys[idx], labels[idx], /*mask for zk?*/ false);
92 }
93 batch.commit_and_send_to_verifier(transcript, AVM_MAX_MSM_BATCH_SIZE);
94}
95
97{
98 BB_BENCH_NAME("AvmProver::execute_log_derivative_inverse_round");
99
100 auto [beta, gamma] = transcript->template get_challenges<FF>("beta", "gamma");
103 std::vector<std::function<void()>> tasks;
104
105 bb::constexpr_for<0, std::tuple_size_v<Flavor::LookupRelations>, 1>([&]<size_t relation_idx>() {
107 tasks.push_back([&]() {
108 // We need to resize the inverse polynomials for the relation, now that the selectors have been computed.
110 Relation::Settings::INVERSES,
111 Relation::Settings::SRC_SELECTOR,
112 Relation::Settings::DST_SELECTOR);
113
114 AVM_TRACK_TIME(std::string("prove/log_derivative_inverse_round/") + std::string(Relation::NAME),
115 (compute_logderivative_inverse<FF, Relation>(
116 prover_polynomials, relation_parameters, key->circuit_size)));
117 });
118 });
119
120 bb::parallel_for(tasks.size(), [&](size_t i) { tasks[i](); });
121}
122
124{
125 BB_BENCH_NAME("AvmProver::execute_log_derivative_inverse_commitments_round");
126 auto batch = commitment_key.start_batch();
127 // Commit to all logderivative inverse polynomials and send to verifier
128 for (auto [derived_poly, commitment, label] : zip_view(prover_polynomials.get_derived(),
129 witness_commitments.get_derived(),
130 prover_polynomials.get_derived_labels())) {
131
132 batch.add_to_batch(derived_poly, label, /*mask for zk?*/ false);
133 }
134 batch.commit_and_send_to_verifier(transcript, AVM_MAX_MSM_BATCH_SIZE);
135}
136
142{
143 BB_BENCH_NAME("AvmProver::execute_relation_check_rounds");
144 using Sumcheck = SumcheckProver<Flavor>;
145
146 // Multiply each linearly independent subrelation contribution by `alpha^i` for i = 0, ..., NUM_SUBRELATIONS - 1.
147 const FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");
148
149 // Generate gate challenges
150 std::vector<FF> gate_challenges =
151 transcript->template get_powers_of_challenge<FF>("Sumcheck:gate_challenge", key->log_circuit_size);
152
153 Sumcheck sumcheck(key->circuit_size,
156 alpha,
157 gate_challenges,
159 key->log_circuit_size);
160
161 sumcheck_output = sumcheck.prove();
162}
163
165{
166 BB_BENCH_NAME("AvmProver::execute_pcs_rounds");
167
169 using PolynomialBatcher = GeminiProver_<Curve>::PolynomialBatcher;
170
171 PolynomialBatcher polynomial_batcher(key->circuit_size);
172 polynomial_batcher.set_unshifted(RefVector<Polynomial>::from_span(prover_polynomials.get_unshifted()));
173 polynomial_batcher.set_to_be_shifted_by_one(
175
176 const OpeningClaim prover_opening_claim = ShpleminiProver_<Curve>::prove(
177 key->circuit_size, polynomial_batcher, sumcheck_output.challenge, commitment_key, transcript);
178
180}
181
183{
184 return transcript->export_proof();
185}
186
188{
189 // Add circuit size public input size and public inputs to transcript.
191
192 // TODO(https://github.com/AztecProtocol/aztec-packages/pull/17045): make the protocols secure at some point
193 // // Add public inputs to transcript.
194 // AVM_TRACK_TIME("prove/public_inputs_round", execute_public_inputs_round());
195
196 // Compute wire commitments.
197 AVM_TRACK_TIME("prove/wire_commitments_round", execute_wire_commitments_round());
198
199 // Compute log derivative inverses.
200 AVM_TRACK_TIME("prove/log_derivative_inverse_round", execute_log_derivative_inverse_round());
201
202 // Compute commitments to logderivative inverse polynomials.
203 AVM_TRACK_TIME("prove/log_derivative_inverse_commitments_round",
205
206 // Run sumcheck subprotocol.
208
209 // Execute PCS.
210 AVM_TRACK_TIME("prove/pcs_rounds", execute_pcs_rounds());
211
212 return export_proof();
213}
214
215} // namespace bb::avm2
#define AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:218
CommitmentKey object over a pairing group 𝔾₁.
CommitBatch start_batch()
Class responsible for computation of the batched multilinear polynomials required by the Gemini proto...
Definition gemini.hpp:129
static void compute_opening_proof(const CK &ck, const ProverOpeningClaim< Curve > &opening_claim, const std::shared_ptr< Transcript > &prover_trancript)
Computes the KZG commitment to an opening proof polynomial at a single evaluation point.
Definition kzg.hpp:40
Unverified claim (C,r,v) for some witness polynomial p(X) such that.
Definition claim.hpp:53
Polynomial p and an opening pair (r,v) such that p(r) = v.
Definition claim.hpp:34
A template class for a reference vector. Behaves as if std::vector<T&> was possible.
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
static OpeningClaim prove(const FF circuit_size, PolynomialBatcher &polynomial_batcher, std::span< FF > multilinear_challenge, const CommitmentKey< Curve > &commitment_key, const std::shared_ptr< Transcript > &transcript, const std::array< Polynomial, NUM_SMALL_IPA_EVALUATIONS > &libra_polynomials={}, const std::vector< Polynomial > &sumcheck_round_univariates={}, const std::vector< std::array< FF, 3 > > &sumcheck_round_evaluations={})
Definition shplemini.hpp:35
The implementation of the sumcheck Prover for statements of the form for multilinear polynomials .
Definition sumcheck.hpp:126
DataType & get(ColumnAndShifts c)
Definition flavor.hpp:150
AvmFlavorSettings::FF FF
Definition flavor.hpp:36
virtual void execute_pcs_rounds()
Definition prover.cpp:164
std::shared_ptr< Transcript > transcript
Definition prover.hpp:44
SumcheckOutput< Flavor > sumcheck_output
Definition prover.hpp:60
PCSCommitmentKey commitment_key
Definition prover.hpp:62
std::shared_ptr< VerificationKey > vk
Definition prover.hpp:51
virtual void execute_relation_check_rounds()
Run Sumcheck resulting in u = (u_1,...,u_d) challenges and all evaluations at u being calculated.
Definition prover.cpp:141
AvmProver(std::shared_ptr< ProvingKey > input_key, std::shared_ptr< VerificationKey > vk, const PCSCommitmentKey &commitment_key)
Definition prover.cpp:35
virtual void execute_preamble_round()
Add circuit size, public input size, and public inputs to transcript.
Definition prover.cpp:48
ProverPolynomials prover_polynomials
Definition prover.hpp:54
virtual void execute_log_derivative_inverse_commitments_round()
Definition prover.cpp:123
Flavor::WitnessCommitments witness_commitments
Definition prover.hpp:56
virtual void execute_log_derivative_inverse_round()
Definition prover.cpp:96
bb::RelationParameters< FF > relation_parameters
Definition prover.hpp:48
Flavor::FF FF
Definition prover.hpp:14
virtual HonkProof construct_proof()
Definition prover.cpp:187
std::shared_ptr< ProvingKey > key
Definition prover.hpp:50
virtual void execute_public_inputs_round()
Add public inputs to transcript.
Definition prover.cpp:60
virtual void execute_wire_commitments_round()
Compute commitments to all of the witness wires (apart from the logderivative inverse wires)
Definition prover.cpp:82
virtual HonkProof export_proof()
Definition prover.cpp:182
void info(Args... args)
Definition log.hpp:74
void resize_inverses(AvmFlavor::ProverPolynomials &prover_polynomials, Column inverses_col, Column src_selector_col, Column dst_selector_col)
const size_t AVM_MAX_MSM_BATCH_SIZE
Definition prover.cpp:21
ColumnAndShifts
Definition columns.hpp:34
AvmFlavorSettings::FF FF
Definition field.hpp:10
std::vector< fr > HonkProof
Definition proof.hpp:15
void parallel_for(size_t num_iterations, const std::function< void(size_t)> &func)
Definition thread.cpp:111
VerifierCommitmentKey< Curve > vk
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)
#define AVM_TRACK_TIME(key, body)
Definition stats.hpp:16
void add_to_batch(Polynomial< Fr > &poly, const std::string &label, bool mask)