Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
batched_honk_translator_prover.cpp
Go to the documentation of this file.
2
10
11namespace bb {
12
14 std::shared_ptr<MegaZKVK> mega_zk_vk,
15 std::shared_ptr<Transcript> transcript)
16 : mega_zk_inst(std::move(mega_zk_instance))
17 , mega_zk_vk(std::move(mega_zk_vk))
18 , transcript(std::move(transcript))
19{}
20
28{
29 BB_BENCH_NAME("BatchedHonkTranslatorProver::execute_mega_zk_oink");
31 oink_prover.prove(/*emit_alpha=*/false);
32}
33
50
69{
70 BB_BENCH_NAME("BatchedHonkTranslatorProver::execute_joint_sumcheck_rounds");
71 // Draw joint alpha after all pre-sumcheck commitments from both circuits.
72 const FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");
73
74 // Draw joint gate challenges (17 total).
75 std::vector<FF> gate_challenges =
76 transcript->template get_dyadic_powers_of_challenge<FF>("Sumcheck:gate_challenge", JOINT_LOG_N);
77
78 // Compute α^{K_H}: offset for translator subrelation separators.
79 FF alpha_power_KH = FF(1);
80 for (size_t i = 0; i < MegaZKFlavor::NUM_SUBRELATIONS; i++) {
81 alpha_power_KH *= alpha;
82 }
83
84 // Subrelation separator arrays (powers of alpha starting at alpha^1).
85 const MegaZKSubrelationSeparators mega_zk_alphas =
87 const TransSubrelationSeparators translator_alphas =
89
90 // Derive MegaZK circuit log_circuit_size from the proving instance.
91 const size_t mega_zk_log_n = mega_zk_inst->log_dyadic_size();
92 BB_ASSERT(mega_zk_log_n <= JOINT_LOG_N);
93
94 // Joint ZK data: single Libra masking for all 17 rounds.
95 constexpr size_t log_subgroup_size = static_cast<size_t>(numeric::get_msb(Curve::SUBGROUP_SIZE));
96 MegaZKCommitmentKey small_ck(1 << (log_subgroup_size + 1));
98
99 // Single gate separator for both circuits: beta_products has size 2^JOINT_LOG_N which covers
100 // both the MegaZK real rounds (2^mega_zk_log_n) and translator rounds (2^JOINT_LOG_N).
101 GateSeparatorPolynomial<FF> gate_sep(gate_challenges, JOINT_LOG_N);
102
103 // Round helper objects.
104 MegaZKProverRound mega_zk_round(static_cast<size_t>(1) << mega_zk_log_n);
105 TransProverRound translator_round(static_cast<size_t>(1) << JOINT_LOG_N);
106
107 // Row disabling polynomial for the MegaZK circuit.
108 // (TranslatorFlavor does not use UseRowDisablingPolynomial.)
110
111 auto& mega_zk_polys = mega_zk_inst->polynomials;
112 auto& mega_zk_params = mega_zk_inst->relation_parameters;
113 auto& translator_polys = translator_key->proving_key->polynomials;
114
115 // Allocate partially evaluated polynomial tables (populated by the first partially_evaluate call).
116 MegaZKPartialEvals mega_zk_partial(mega_zk_polys, static_cast<size_t>(1) << mega_zk_log_n);
117 TransPartialEvals translator_partial(translator_polys, static_cast<size_t>(1) << JOINT_LOG_N);
118
119 // Type aliases for static partial-evaluation helpers from SumcheckProver.
120 using MegaZKSumcheck = SumcheckProver<MegaZKFlavor>;
121 using TransSumcheck = SumcheckProver<TranslatorFlavor>;
122
124
126
127 // Use committed sumcheck infrastructure: commits to round univariates and stores them for Shplemini.
128 static constexpr bool UseCommittedSumcheck = true;
130
131 auto send_round = [&](size_t round_idx) -> FF {
133 handler.process_round_univariate(round_idx, U_joint);
134 FF u = transcript->template get_challenge<FF>("Sumcheck:u_" + std::to_string(round_idx));
135 joint_challenge.emplace_back(u);
136 return u;
137 };
138
139 // Per-round helper: update ZK data, gate separators, translator round size, and optionally send
140 // translator minicircuit evaluations.
141 auto update_round_state = [&](size_t round_idx, const FF& u) {
142 if (round_idx == TranslatorFlavor::LOG_MINI_CIRCUIT_SIZE - 1) {
143 transcript->send_to_verifier("Sumcheck:minicircuit_evaluations",
145 }
147 gate_sep.partially_evaluate(u);
148 translator_round.round_size >>= 1;
149 };
150
151 // Per-round helper: compute U_joint = U_MZK + α^{K_H}·U_translator from given polynomial
152 // sources, add Libra masking, send to verifier, and return the round challenge.
153 // hpolys/tpolys are the full tables on round 0, the partial-eval tables on subsequent rounds.
154 auto do_round = [&](auto& hpolys, auto& tpolys, size_t round_idx) -> FF {
156
157 auto U_H = mega_zk_round.compute_univariate(hpolys, mega_zk_params, gate_sep, mega_zk_alphas);
158 U_H += mega_zk_round.compute_disabled_contribution(hpolys, mega_zk_params, gate_sep, mega_zk_alphas, rdp);
159 U_joint += U_H;
160
161 auto U_T =
162 translator_round.compute_univariate(tpolys, translator_relation_parameters, gate_sep, translator_alphas);
163 for (auto& eval : U_T.evaluations) {
164 eval *= alpha_power_KH;
165 }
166 U_joint += U_T;
167
168 return send_round(round_idx);
169 };
170
171 // ==================== Round 0: bootstraps mega_zk_partial and translator_partial ====================
172 // PartiallyEvaluatedMultivariates only allocates output buffers; values are populated here.
173 {
174 const FF u = do_round(mega_zk_polys, translator_polys, 0);
175 MegaZKSumcheck::partially_evaluate(mega_zk_polys, mega_zk_partial, u);
176 TransSumcheck::partially_evaluate(translator_polys, translator_partial, u);
177 rdp.update_evaluations(u, 0);
178 mega_zk_round.round_size >>= 1;
179 mega_zk_round.excluded_head_size = 2; // After round 0, disabled zone collapses to 1 edge pair
180 update_round_state(0, u);
181 }
182
183 // ==================== Real rounds 1..mega_zk_log_n-1 ====================
184 for (size_t round_idx = 1; round_idx < mega_zk_log_n; round_idx++) {
185 const FF u = do_round(mega_zk_partial, translator_partial, round_idx);
186 MegaZKSumcheck::partially_evaluate_in_place(mega_zk_partial, u);
187 TransSumcheck::partially_evaluate_in_place(translator_partial, u);
188 rdp.update_evaluations(u, round_idx);
189 mega_zk_round.round_size >>= 1;
190 update_round_state(round_idx, u);
191 }
192
193 // ==================== Virtual rounds mega_zk_log_n..JOINT_LOG_N-1 ====================
194 // MegaZK contributes a virtual (zero-extended) univariate with RDP factor; translator contributes a real round.
195 for (size_t round_idx = mega_zk_log_n; round_idx < JOINT_LOG_N; round_idx++) {
197
198 U_joint += MegaZKSumcheck::compute_virtual_round_univariate(
199 mega_zk_round, mega_zk_partial, mega_zk_params, gate_sep, mega_zk_alphas, rdp);
200
201 auto U_T = translator_round.compute_univariate(
202 translator_partial, translator_relation_parameters, gate_sep, translator_alphas);
203 for (auto& eval : U_T.evaluations) {
204 eval *= alpha_power_KH;
205 }
206 U_joint += U_T;
207
208 // send_round adds libra masking, sends univariate, and returns the challenge
209 const FF u = send_round(round_idx);
210
211 MegaZKSumcheck::fold_for_zero_extension(mega_zk_partial, u);
212 TransSumcheck::partially_evaluate_in_place(translator_partial, u);
213 rdp.update_evaluations(u, round_idx);
214 update_round_state(round_idx, u);
215 }
216
217 handler.finalize_last_round(JOINT_LOG_N, U_joint, joint_challenge.back());
218 round_univariates_list = std::move(handler.round_univariates);
219 round_evaluations_list = std::move(handler.round_evaluations);
220
221 // Extract and send MegaZK evaluations after all rounds — full N-variable evaluations.
222 for (auto [eval, poly] : zip_view(mega_zk_claimed_evals.get_all(), mega_zk_partial.get_all())) {
223 eval = poly[0];
224 }
225 transcript->send_to_verifier("Sumcheck:evaluations", mega_zk_claimed_evals.get_all());
226
227 // Extract and send translator evaluations after all rounds.
228 for (auto [eval, poly] : zip_view(trans_claimed_evals.get_all(), translator_partial.get_all())) {
229 eval = poly[0];
230 }
231 transcript->send_to_verifier("Sumcheck:evaluations_translator",
233
234 // Compute and send the claimed Libra evaluation (covers all JOINT_LOG_N rounds).
236 for (const auto& libra_eval : zk_sumcheck_data.libra_evaluations) {
237 claimed_libra_evaluation += libra_eval;
238 }
239 transcript->send_to_verifier("Libra:claimed_evaluation", claimed_libra_evaluation);
240}
241
251{
252 BB_BENCH_NAME("BatchedHonkTranslatorProver::execute_joint_pcs");
254 using PolynomialBatcher = GeminiProver_<Curve>::PolynomialBatcher;
255 using SmallSubgroupIPA = SmallSubgroupIPAProver<MegaZKFlavor>;
256
257 // Use the translator's commitment key (sized to 2^17 = joint_circuit_size) for all PCS work.
258 // The translator key is initialised by TranslatorProver in execute_translator_oink().
259 auto& ck = translator_key->proving_key->commitment_key;
260
261 // Prove the small-subgroup IPA opening for the joint Libra polynomial.
262 SmallSubgroupIPA small_subgroup_ipa(zk_sumcheck_data, joint_challenge, claimed_libra_evaluation, transcript, ck);
263 small_subgroup_ipa.prove();
264
265 // Build joint PolynomialBatcher at joint_circuit_size = 2^17.
266 // max_end_index covers hiding (2^16) and translator (2^17) polynomials; use the larger.
267 const size_t joint_circuit_size = static_cast<size_t>(1) << JOINT_LOG_N;
268 const size_t mega_zk_max_end = mega_zk_inst->polynomials.max_end_index();
269 const size_t trans_max_end = translator_key->proving_key->circuit_size; // translator polys fill 2^17
270 const size_t max_end_index = std::max(mega_zk_max_end, trans_max_end);
271
272 PolynomialBatcher polynomial_batcher(joint_circuit_size, max_end_index);
273
274 // Combine unshifted polynomials: translator first (its masking poly at position 0 for Shplemini offset=2),
275 // then MegaZK (no masking poly — translator provides the joint masking poly).
276 auto trans_unshifted = translator_key->proving_key->polynomials.get_pcs_unshifted();
277 auto mega_zk_unshifted = mega_zk_inst->polynomials.get_unshifted();
278 auto joint_unshifted = concatenate(trans_unshifted, mega_zk_unshifted);
279 polynomial_batcher.set_unshifted(joint_unshifted);
280
281 // Combine shifted polynomials: MegaZK first, then translator.
282 auto mega_zk_shifted = mega_zk_inst->polynomials.get_to_be_shifted();
283 auto trans_shifted = translator_key->proving_key->polynomials.get_pcs_to_be_shifted();
284 auto joint_shifted = concatenate(mega_zk_shifted, trans_shifted);
285 polynomial_batcher.set_to_be_shifted_by_one(joint_shifted);
286
287 const OpeningClaim prover_opening_claim =
288 ShpleminiProver_<Curve>::prove(joint_circuit_size,
289 polynomial_batcher,
291 ck,
293 small_subgroup_ipa.get_witness_polynomials(),
296
298}
299
301{
302 BB_BENCH_NAME("BatchedHonkTranslatorProver::prove_mega_zk_oink");
304 return transcript->export_proof();
305}
306
308{
309 BB_BENCH_NAME("BatchedHonkTranslatorProver::prove");
310 translator_key = std::move(translator_proving_key);
314 return transcript->export_proof();
315}
316
317} // namespace bb
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:264
std::shared_ptr< MegaZKProverInstance > mega_zk_inst
BatchedHonkTranslatorProver(std::shared_ptr< MegaZKProverInstance > mega_zk_instance, std::shared_ptr< MegaZKVK > mega_zk_vk, std::shared_ptr< Transcript > transcript)
std::vector< Polynomial< FF > > round_univariates_list
std::shared_ptr< TranslatorProvingKey > translator_key
void execute_joint_sumcheck_rounds()
Execute the joint 17-round sumcheck.
bb::RelationParameters< FF > translator_relation_parameters
void execute_joint_pcs()
Execute the joint Shplemini / KZG PCS over both circuits' polynomials.
std::array< FF, MegaZKFlavor::NUM_SUBRELATIONS - 1 > MegaZKSubrelationSeparators
HonkProof prove(std::shared_ptr< TranslatorProvingKey > translator_proving_key)
std::vector< std::array< FF, 3 > > round_evaluations_list
std::array< FF, TranslatorFlavor::NUM_SUBRELATIONS - 1 > TransSubrelationSeparators
void execute_mega_zk_oink()
Run the MegaZK circuit's Oink phase.
void execute_translator_oink()
Run the translator's Oink phase on the shared transcript.
CommitmentKey object over a pairing group 𝔾₁.
Class responsible for computation of the batched multilinear polynomials required by the Gemini proto...
Definition gemini.hpp:128
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:43
static constexpr size_t NUM_SUBRELATIONS
Executes the "Oink" phase of the Honk proving protocol: the initial rounds that commit to witness dat...
void prove(bool emit_alpha=true)
Commit to witnesses, compute relation parameters, and prepare for Sumcheck.
Unverified claim (C,r,v) for some witness polynomial p(X) such that.
Definition claim.hpp:55
A container for storing the partially evaluated multivariates produced by sumcheck.
Polynomial p and an opening pair (r,v) such that p(r) = v.
Definition claim.hpp:36
static OpeningClaim prove(size_t 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:37
A Curve-agnostic ZK protocol to prove inner products of small vectors.
Flavor::CommitmentKey commitment_key
The implementation of the sumcheck Prover for statements of the form for multilinear polynomials .
Definition sumcheck.hpp:294
Imlementation of the Sumcheck prover round.
SumcheckRoundUnivariate compute_univariate(ProverPolynomialsOrPartiallyEvaluatedMultivariates &polynomials, const bb::RelationParameters< FF > &relation_parameters, const bb::GateSeparatorPolynomial< FF > &gate_separators, const SubrelationSeparators &alphas)
Return the evaluations of the univariate round polynomials. Toggles between chunked computation (desi...
static SumcheckRoundUnivariate compute_libra_univariate(const ZKData &zk_sumcheck_data, size_t round_idx)
Compute Libra round univariate expressed given by the formula.
SumcheckRoundUnivariate compute_disabled_contribution(ProverPolynomialsOrPartiallyEvaluatedMultivariates &polynomials, const bb::RelationParameters< FF > &relation_parameters, const bb::GateSeparatorPolynomial< FF > &gate_separators, const SubrelationSeparators &alphas, const RowDisablingPolynomial< FF > row_disabling_polynomial)
Compute the disabled rows' contribution to the round univariate.
size_t round_size
In Round , equals .
static std::array< FFType, NUM_FULL_CIRCUIT_EVALUATIONS > get_full_circuit_evaluations(AllEntities< FFType > &evals)
Prover: extract the full-circuit evaluations via get_full_circuit_entities().
static constexpr size_t LOG_MINI_CIRCUIT_SIZE
static constexpr size_t NUM_SUBRELATIONS
static std::array< FF, NUM_MINICIRCUIT_EVALUATIONS > get_minicircuit_evaluations(PolyContainer &polys)
Prover: read the 154 minicircuit wire evaluations from partially-evaluated polynomials.
BB_PROFILE void execute_preamble_round()
Add circuit size and values used in the relations to the transcript.
BB_PROFILE void execute_grand_product_computation_round()
Compute permutation product polynomial and commitments.
bb::RelationParameters< FF > relation_parameters
BB_PROFILE void execute_wire_and_sorted_constraints_commitments_round()
Compute commitments to wires and ordered range constraints.
A univariate polynomial represented by its values on {0, 1,..., domain_end - 1}.
static Univariate zero()
static constexpr size_t SUBGROUP_SIZE
Definition bn254.hpp:34
constexpr T get_msb(const T in)
Definition get_msb.hpp:50
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
std::vector< fr > HonkProof
Definition proof.hpp:15
RefArray< T,(Ns+...)> constexpr concatenate(const RefArray< T, Ns > &... ref_arrays)
Concatenates multiple RefArray objects into a single RefArray.
CommitmentKey< Curve > ck
std::array< FF, N > initialize_relation_separator(const FF &alpha)
Definition sumcheck.hpp:949
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)
Implementation of the methods for the -polynomials used in in Sumcheck.
void partially_evaluate(FF challenge)
Partially evaluate the -polynomial at the new challenge and update .
Handler for processing round univariates in sumcheck. Default implementation: send evaluations direct...
Definition sumcheck.hpp:27
void finalize_last_round(size_t, const bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > &, const FF &)
Definition sumcheck.hpp:45
void process_round_univariate(size_t round_idx, bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > &round_univariate)
Definition sumcheck.hpp:39
Polynomial for Sumcheck with disabled Rows.
void update_evaluations(FF round_challenge, size_t round_idx)
Compute the evaluations of L^{(i)} at 0 and 1.
ClaimedLibraEvaluations libra_evaluations
void update_zk_sumcheck_data(const FF &round_challenge, const size_t round_idx)
Upon receiving the challenge , the prover updates Libra data. If .