Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
prover.cpp
Go to the documentation of this file.
2
14
15namespace bb::avm2 {
16
18using FF = Flavor::FF;
19
30 const PCSCommitmentKey& commitment_key)
31 : key(std::move(input_key))
32 , vk(std::move(vk))
33 , prover_polynomials(*key)
34 , commitment_key(commitment_key)
35{}
36
42{
43 // TODO(#15892): Fiat-shamir the vk hash by uncommenting the line below.
44 FF vk_hash = vk->hash();
45 // transcript->add_to_hash_buffer("avm_vk_hash", vk_hash);
46 info("AVM vk hash in prover: ", vk_hash);
47}
48
54{
55 // Commit to all polynomials (apart from logderivative inverse polynomials, which are committed to in the later
56 // logderivative phase)
57 auto wire_polys = prover_polynomials.get_wires();
58 const auto& labels = prover_polynomials.get_wires_labels();
59 for (size_t idx = 0; idx < wire_polys.size(); ++idx) {
60 auto comm = commitment_key.commit(wire_polys[idx]);
61 transcript->send_to_verifier(labels[idx], comm);
62 }
63}
64
66{
67 auto [beta, gamma] = transcript->template get_challenges<FF>("beta", "gamma");
70 std::vector<std::function<void()>> tasks;
71
72 bb::constexpr_for<0, std::tuple_size_v<Flavor::LookupRelations>, 1>([&]<size_t relation_idx>() {
74 tasks.push_back([&]() {
75 AVM_TRACK_TIME(std::string("prove/log_derivative_inverse_round/") + std::string(Relation::NAME),
76 (compute_logderivative_inverse<FF, Relation>(
78 });
79 });
80
81 bb::parallel_for(tasks.size(), [&](size_t i) { tasks[i](); });
82}
83
85{
86 // Commit to all logderivative inverse polynomials
87 for (auto [commitment, key_poly] : zip_view(witness_commitments.get_derived(), key->get_derived())) {
88 commitment = commitment_key.commit(key_poly);
89 }
90
91 // Send all commitments to the verifier
92 for (auto [label, commitment] :
94 transcript->send_to_verifier(label, commitment);
95 }
96}
97
103{
104 using Sumcheck = SumcheckProver<Flavor>;
105
106 // Multiply each linearly independent subrelation contribution by `alpha^i` for i = 0, ..., NUM_SUBRELATIONS - 1.
107 const FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");
108
109 // Generate gate challenges
110 std::vector<FF> gate_challenges =
111 transcript->template get_powers_of_challenge<FF>("Sumcheck:gate_challenge", key->log_circuit_size);
112
113 Sumcheck sumcheck(key->circuit_size,
116 alpha,
117 gate_challenges,
119 key->log_circuit_size);
120
121 sumcheck_output = sumcheck.prove();
122}
123
125{
127 using PolynomialBatcher = GeminiProver_<Curve>::PolynomialBatcher;
128
129 PolynomialBatcher polynomial_batcher(key->circuit_size);
130 polynomial_batcher.set_unshifted(prover_polynomials.get_unshifted());
131 polynomial_batcher.set_to_be_shifted_by_one(prover_polynomials.get_to_be_shifted());
132
133 const OpeningClaim prover_opening_claim = ShpleminiProver_<Curve>::prove(
134 key->circuit_size, polynomial_batcher, sumcheck_output.challenge, commitment_key, transcript);
135
137}
138
140{
141 return transcript->export_proof();
142}
143
145{
146 // Add circuit size public input size and public inputs to transcript.
148
149 // Compute wire commitments.
150 AVM_TRACK_TIME("prove/wire_commitments_round", execute_wire_commitments_round());
151
152 // Compute log derivative inverses.
153 AVM_TRACK_TIME("prove/log_derivative_inverse_round", execute_log_derivative_inverse_round());
154
155 // Compute commitments to logderivative inverse polynomials.
156 AVM_TRACK_TIME("prove/log_derivative_inverse_commitments_round",
158
159 // Run sumcheck subprotocol.
161
162 // Execute PCS.
163 AVM_TRACK_TIME("prove/pcs_rounds", execute_pcs_rounds());
164
165 return export_proof();
166}
167
168} // namespace bb::avm2
CommitmentKey object over a pairing group 𝔾₁.
Commitment commit(PolynomialSpan< const Fr > polynomial) const
Uses the ProverSRS to create a commitment to p(X)
Class responsible for computation of the batched multilinear polynomials required by the Gemini proto...
Definition gemini.hpp:123
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 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:123
static const auto & get_derived_labels()
Definition flavor.hpp:167
static const auto & get_wires_labels()
Definition flavor.hpp:165
AvmFlavorSettings::FF FF
Definition flavor.hpp:34
virtual void execute_pcs_rounds()
Definition prover.cpp:124
std::shared_ptr< Transcript > transcript
Definition prover.hpp:43
SumcheckOutput< Flavor > sumcheck_output
Definition prover.hpp:59
PCSCommitmentKey commitment_key
Definition prover.hpp:61
std::shared_ptr< VerificationKey > vk
Definition prover.hpp:50
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:102
AvmProver(std::shared_ptr< ProvingKey > input_key, std::shared_ptr< VerificationKey > vk, const PCSCommitmentKey &commitment_key)
Definition prover.cpp:28
virtual void execute_preamble_round()
Add circuit size, public input size, and public inputs to transcript.
Definition prover.cpp:41
ProverPolynomials prover_polynomials
Definition prover.hpp:53
virtual void execute_log_derivative_inverse_commitments_round()
Definition prover.cpp:84
Flavor::WitnessCommitments witness_commitments
Definition prover.hpp:55
virtual void execute_log_derivative_inverse_round()
Definition prover.cpp:65
bb::RelationParameters< FF > relation_parameters
Definition prover.hpp:47
Flavor::FF FF
Definition prover.hpp:14
virtual HonkProof construct_proof()
Definition prover.cpp:144
std::shared_ptr< ProvingKey > key
Definition prover.hpp:49
virtual void execute_wire_commitments_round()
Compute commitments to all of the witness wires (apart from the logderivative inverse wires)
Definition prover.cpp:53
virtual HonkProof export_proof()
Definition prover.cpp:139
void info(Args... args)
Definition log.hpp:70
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:72
VerifierCommitmentKey< Curve > vk
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
#define AVM_TRACK_TIME(key, body)
Definition stats.hpp:17