Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
eccvm_prover.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#include "eccvm_prover.hpp"
19
20namespace bb {
21
23 const std::shared_ptr<Transcript>& transcript,
24 const std::shared_ptr<Transcript>& ipa_transcript)
25 : transcript(transcript)
26 , ipa_transcript(ipa_transcript)
27{
28 BB_BENCH_NAME("ECCVMProver(CircuitBuilder&)");
29
30 // TODO(https://github.com/AztecProtocol/barretenberg/issues/939): Remove redundancy between
31 // ProvingKey/ProverPolynomials and update the model to reflect what's done in all other proving systems.
32
33 // Construct the proving key; populates all polynomials except for witness polys
35
36 key->commitment_key = CommitmentKey(key->circuit_size);
37}
38
44{
46
47 // Fiat-Shamir the vk hash
49 typename Flavor::BF vk_hash = vk.hash();
50 transcript->add_to_hash_buffer("vk_hash", vk_hash);
51 vinfo("ECCVM vk hash in prover: ", vk_hash);
52}
53
59{
60 BB_BENCH_NAME("ECCVMProver::execute_wire_commitments_round");
61 // To commit to the masked wires when `real_size` < `circuit_size`, we use
62 // `commit_structured` that ignores 0 coefficients between the real size and the last NUM_DISABLED_ROWS_IN_SUMCHECK
63 // wire entries.
64 const size_t circuit_size = key->circuit_size;
65 unmasked_witness_size = circuit_size - NUM_DISABLED_ROWS_IN_SUMCHECK;
66
67 auto batch = key->commitment_key.start_batch();
68 for (const auto& [wire, label] : zip_view(key->polynomials.get_wires(), commitment_labels.get_wires())) {
69 batch.add_to_batch(wire, label, /* mask for zk? */ true);
70 }
71 batch.commit_and_send_to_verifier(transcript);
72}
73
79{
80 BB_BENCH_NAME("ECCVMProver::execute_log_derivative_commitments_round");
81
82 // Compute and add beta to relation parameters
83 auto [beta, gamma] = transcript->template get_challenges<FF>("beta", "gamma");
84
85 // TODO(#583)(@zac-williamson): fix Transcript to be able to generate more than 2 challenges per round! oof.
86 auto beta_sqr = beta * beta;
90 relation_parameters.beta_cube = beta_sqr * beta;
92 gamma * (gamma + beta_sqr) * (gamma + beta_sqr + beta_sqr) * (gamma + beta_sqr + beta_sqr + beta_sqr);
94 // Compute inverse polynomial for our logarithmic-derivative lookup method
98 true>(key->polynomials, relation_parameters, unmasked_witness_size);
99 commit_to_witness_polynomial(key->polynomials.lookup_inverses, commitment_labels.lookup_inverses);
100}
101
107{
108 BB_BENCH_NAME("ECCVMProver::execute_grand_product_computation_round");
109 // Compute permutation grand product and their commitments
110 compute_grand_products<Flavor>(key->polynomials, relation_parameters, unmasked_witness_size);
111 commit_to_witness_polynomial(key->polynomials.z_perm, commitment_labels.z_perm);
112}
113
119{
120 BB_BENCH_NAME("ECCVMProver::execute_relation_check_rounds");
121 using Sumcheck = SumcheckProver<Flavor>;
122
123 // Each linearly independent subrelation contribution is multiplied by `alpha^i`, where
124 // i = 0, ..., NUM_SUBRELATIONS- 1.
125 FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");
126
127 std::vector<FF> gate_challenges(CONST_ECCVM_LOG_N);
128 for (size_t idx = 0; idx < gate_challenges.size(); idx++) {
129 gate_challenges[idx] = transcript->template get_challenge<FF>("Sumcheck:gate_challenge_" + std::to_string(idx));
130 }
131
132 Sumcheck sumcheck(key->circuit_size,
133 key->polynomials,
135 alpha,
136 gate_challenges,
138 CONST_ECCVM_LOG_N);
139
140 zk_sumcheck_data = ZKData(key->log_circuit_size, transcript, key->commitment_key);
141
142 sumcheck_output = sumcheck.prove(zk_sumcheck_data);
143}
144
152{
153 BB_BENCH_NAME("ECCVMProver::execute_pcs_rounds");
154 using Curve = typename Flavor::Curve;
155 using Shplemini = ShpleminiProver_<Curve>;
156 using Shplonk = ShplonkProver_<Curve>;
158 using PolynomialBatcher = GeminiProver_<Curve>::PolynomialBatcher;
159
160 SmallSubgroupIPA small_subgroup_ipa_prover(zk_sumcheck_data,
161 sumcheck_output.challenge,
162 sumcheck_output.claimed_libra_evaluation,
164 key->commitment_key);
165 small_subgroup_ipa_prover.prove();
166
167 // Execute the Shplemini (Gemini + Shplonk) protocol to produce a univariate opening claim for the multilinear
168 // evaluations produced by Sumcheck
169 PolynomialBatcher polynomial_batcher(key->circuit_size);
170 polynomial_batcher.set_unshifted(key->polynomials.get_unshifted());
171 polynomial_batcher.set_to_be_shifted_by_one(key->polynomials.get_to_be_shifted());
172
173 OpeningClaim multivariate_to_univariate_opening_claim =
174 Shplemini::prove(key->circuit_size,
175 polynomial_batcher,
176 sumcheck_output.challenge,
177 key->commitment_key,
179 small_subgroup_ipa_prover.get_witness_polynomials(),
180 sumcheck_output.round_univariates,
181 sumcheck_output.round_univariate_evaluations);
182
184
185 opening_claims.back() = std::move(multivariate_to_univariate_opening_claim);
186
187 // Reduce the opening claims to a single opening claim via Shplonk
188 const OpeningClaim batch_opening_claim = Shplonk::prove(key->commitment_key, opening_claims, transcript);
189
190 // Compute the opening proof for the batched opening claim with the univariate PCS
191 PCS::compute_opening_proof(key->commitment_key, batch_opening_claim, ipa_transcript);
192}
193
195{
196 return { transcript->export_proof(), ipa_transcript->export_proof() };
197}
198
212
258{
259 // Used to capture the batched evaluation of unmasked `translation_polynomials` while preserving ZK
261
262 // Initialize SmallSubgroupIPA structures
265
266 // Collect the polynomials to be batched
267 RefArray translation_polynomials{ key->polynomials.transcript_op,
268 key->polynomials.transcript_Px,
269 key->polynomials.transcript_Py,
270 key->polynomials.transcript_z1,
271 key->polynomials.transcript_z2 };
272
273 // Extract the masking terms of `translation_polynomials`, concatenate them in the Lagrange basis over SmallSubgroup
274 // H, mask the resulting polynomial, and commit to it
275 TranslationData<Transcript> translation_data(translation_polynomials, transcript, key->commitment_key);
276
277 // Get a challenge to evaluate the `translation_polynomials` as univariates
278 evaluation_challenge_x = transcript->template get_challenge<FF>("Translation:evaluation_challenge_x");
279
280 // Evaluate `translation_polynomial` as univariates and add their evaluations at x to the transcript
281 for (auto [eval, poly, label] :
283 eval = poly.evaluate(evaluation_challenge_x);
284 transcript->send_to_verifier(label, eval);
285 }
286
287 // Get another challenge to batch the evaluations of the transcript polynomials
288 batching_challenge_v = transcript->template get_challenge<FF>("Translation:batching_challenge_v");
289
290 SmallIPA translation_masking_term_prover(
291 translation_data, evaluation_challenge_x, batching_challenge_v, transcript, key->commitment_key);
292 translation_masking_term_prover.prove();
293
294 // Get the challenge to check evaluations of the SmallSubgroupIPA witness polynomials
295 FF small_ipa_evaluation_challenge =
296 transcript->template get_challenge<FF>("Translation:small_ipa_evaluation_challenge");
297
298 // Populate SmallSubgroupIPA opening claims:
299 // 1. Get the evaluation points and labels
300 evaluation_points = translation_masking_term_prover.evaluation_points(small_ipa_evaluation_challenge);
301 evaluation_labels = translation_masking_term_prover.evaluation_labels();
302 // 2. Compute the evaluations of witness polynomials at corresponding points, send them to the verifier, and create
303 // the opening claims
304 for (size_t idx = 0; idx < NUM_SMALL_IPA_EVALUATIONS; idx++) {
305 auto witness_poly = translation_masking_term_prover.get_witness_polynomials()[idx];
306 const FF evaluation = witness_poly.evaluate(evaluation_points[idx]);
307 transcript->send_to_verifier(evaluation_labels[idx], evaluation);
308 opening_claims[idx] = { .polynomial = witness_poly, .opening_pair = { evaluation_points[idx], evaluation } };
309 }
310
311 // Compute the opening claim for the masked evaluations of `op`, `Px`, `Py`, `z1`, and `z2` at
312 // `evaluation_challenge_x` batched by the powers of `batching_challenge_v`.
313 Polynomial batched_translation_univariate{ key->circuit_size };
314 FF batched_translation_evaluation{ 0 };
315 FF batching_scalar = FF(1);
316 for (auto [polynomial, eval] : zip_view(translation_polynomials, translation_evaluations.get_all())) {
317 batched_translation_univariate.add_scaled(polynomial, batching_scalar);
318 batched_translation_evaluation += eval * batching_scalar;
319 batching_scalar *= batching_challenge_v;
320 }
321
322 // Add the batched claim to the array of SmallSubgroupIPA opening claims.
323 opening_claims[NUM_SMALL_IPA_EVALUATIONS] = { batched_translation_univariate,
324 { evaluation_challenge_x, batched_translation_evaluation } };
325}
326
334 const std::string& label,
335 CommitmentKey::CommitType commit_type,
336 const std::vector<std::pair<size_t, size_t>>& active_ranges)
337{
338 // We add NUM_DISABLED_ROWS_IN_SUMCHECK-1 random values to the coefficients of each wire polynomial to not leak
339 // information via the commitment and evaluations. -1 is caused by shifts.
340 polynomial.mask();
341 transcript->send_to_verifier(label, key->commitment_key.commit_with_type(polynomial, commit_type, active_ranges));
342}
343} // namespace bb
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:218
A container for the prover polynomials.
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
typename Curve::ScalarField FF
typename Curve::BaseField BF
curve::Grumpkin Curve
ECCVMLookupRelation< FF > LookupRelation
ECCVMProof construct_proof()
ECCVMProver(CircuitBuilder &builder, const std::shared_ptr< Transcript > &transcript, const std::shared_ptr< Transcript > &ipa_transcript=std::make_shared< Transcript >())
SumcheckOutput< Flavor > sumcheck_output
BB_PROFILE void execute_log_derivative_commitments_round()
Compute sorted witness-table accumulator.
size_t unmasked_witness_size
std::shared_ptr< Transcript > ipa_transcript
ZKSumcheckData< Flavor > ZKData
std::shared_ptr< Transcript > transcript
ECCVMProof export_proof()
CommitmentLabels commitment_labels
TranslationEvaluations translation_evaluations
std::shared_ptr< ProvingKey > key
void commit_to_witness_polynomial(Polynomial &polynomial, const std::string &label, CommitmentKey::CommitType commit_type=CommitmentKey::CommitType::Default, const std::vector< std::pair< size_t, size_t > > &active_ranges={})
Utility to mask and commit to a witness polynomial and send the commitment to verifier.
BB_PROFILE void execute_preamble_round()
Fiat-Shamir the VK.
BB_PROFILE void execute_wire_commitments_round()
Compute commitments to the first three wires.
Flavor::CommitmentKey CommitmentKey
std::array< OpeningClaim, NUM_OPENING_CLAIMS > opening_claims
BB_PROFILE void execute_grand_product_computation_round()
Compute permutation and lookup grand product polynomials and commitments.
BB_PROFILE void execute_relation_check_rounds()
Run Sumcheck resulting in u = (u_1,...,u_d) challenges and all evaluations at u being calculated.
BB_PROFILE void execute_pcs_rounds()
Produce a univariate opening claim for the sumcheck multivariate evalutions and a batched univariate ...
void compute_translation_opening_claims()
To link the ECCVM Transcript wires op, Px, Py, z1, and z2 to the accumulator computed by the translat...
bb::RelationParameters< FF > relation_parameters
Class responsible for computation of the batched multilinear polynomials required by the Gemini proto...
Definition gemini.hpp:129
void mask()
Add random values to the coefficients of a polynomial. In practice, this is used for ensuring the com...
Polynomial p and an opening pair (r,v) such that p(r) = v.
Definition claim.hpp:34
A template class for a reference array. Behaves as if std::array<T&, N> was possible.
Definition ref_array.hpp:22
Shplonk Prover.
Definition shplonk.hpp:36
A Curve-agnostic ZK protocol to prove inner products of small vectors.
std::array< bb::Polynomial< FF >, NUM_SMALL_IPA_EVALUATIONS > get_witness_polynomials() const
void prove()
Compute the derived witnesses and and commit to them.
The implementation of the sumcheck Prover for statements of the form for multilinear polynomials .
Definition sumcheck.hpp:126
A class designed to accept the ECCVM Transcript Polynomials, concatenate their masking terms in Lagra...
#define vinfo(...)
Definition log.hpp:79
AluTraceBuilder builder
Definition alu.test.cpp:123
UltraKeccakFlavor::VerificationKey VerificationKey
Entry point for Barretenberg command-line interface.
void compute_logderivative_inverse(Polynomials &polynomials, auto &relation_parameters, const size_t circuit_size)
Compute the inverse polynomial I(X) required for logderivative lookupsdetails Inverse may be defined ...
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)
RefArray< BF, NUM_TRANSLATION_EVALUATIONS > get_all()
std::array< std::string, NUM_TRANSLATION_EVALUATIONS > labels