Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
translator_prover.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Planned, auditors: [], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
14
15namespace bb {
16
18 const std::shared_ptr<Transcript>& transcript)
19 : transcript(transcript)
20 , key(key)
21{
22 BB_BENCH();
23 key->proving_key->commitment_key = CommitmentKey(key->proving_key->circuit_size);
24}
25
31{
32 // Fiat-Shamir the vk hash
34 typename Flavor::FF vk_hash = vk.get_hash();
35 transcript->add_to_hash_buffer("vk_hash", vk_hash);
36 vinfo("Translator vk hash in prover: ", vk_hash);
37
38 const size_t RESULT_ROW = Flavor::RESULT_ROW;
39
40 // Set accumulated_result in relation parameters from the witness polynomials
41 // The verifier will receive this value from the ECCVM verifier instead of the transcript
42 relation_parameters.accumulated_result = { key->proving_key->polynomials.accumulators_binary_limbs_0[RESULT_ROW],
43 key->proving_key->polynomials.accumulators_binary_limbs_1[RESULT_ROW],
44 key->proving_key->polynomials.accumulators_binary_limbs_2[RESULT_ROW],
45 key->proving_key->polynomials.accumulators_binary_limbs_3[RESULT_ROW] };
46}
47
54void TranslatorProver::commit_to_witness_polynomial(Polynomial& polynomial, const std::string& label)
55{
56 transcript->send_to_verifier(label, key->proving_key->commitment_key.commit(polynomial));
57}
58
64{
65 BB_BENCH_NAME("TranslatorProver::execute_wire_and_sorted_constraints_commitments_round");
66
67 // Create and commit to Gemini masking polynomial (for ZK-PCS)
68 const size_t circuit_size = key->proving_key->circuit_size;
69 key->proving_key->polynomials.gemini_masking_poly = Polynomial::random(circuit_size);
70 auto masking_commitment =
71 key->proving_key->commitment_key.commit(key->proving_key->polynomials.gemini_masking_poly);
72 transcript->send_to_verifier("Gemini:masking_poly_comm", masking_commitment);
73
74 // Commit to non-op-queue wires and ordered range constraints
75 // Note: Op queue wires (op, x_lo_y_hi, x_hi_z_1, y_lo_z_2) are NOT committed to here
76 // They are provided by the merge protocol and passed to the verifier
77 auto batch = key->proving_key->commitment_key.start_batch();
78 for (const auto& [wire, label] :
79 zip_view(key->proving_key->polynomials.get_non_opqueue_wires_and_ordered_range_constraints(),
80 commitment_labels.get_non_opqueue_wires_and_ordered_range_constraints())) {
81 batch.add_to_batch(wire, label, /*mask for zk?*/ false);
82 }
83 batch.commit_and_send_to_verifier(transcript);
84}
85
91{
92 // Compute and store parameters required by relations in Sumcheck
93 FF beta = transcript->template get_challenge<FF>("beta");
94 FF gamma = transcript->template get_challenge<FF>("gamma");
95 const size_t NUM_LIMB_BITS = Flavor::NUM_LIMB_BITS;
98 auto uint_evaluation_input = uint256_t(key->evaluation_input_x);
99 relation_parameters.evaluation_input_x = { uint_evaluation_input.slice(0, NUM_LIMB_BITS),
100 uint_evaluation_input.slice(NUM_LIMB_BITS, NUM_LIMB_BITS * 2),
101 uint_evaluation_input.slice(NUM_LIMB_BITS * 2, NUM_LIMB_BITS * 3),
102 uint_evaluation_input.slice(NUM_LIMB_BITS * 3, NUM_LIMB_BITS * 4),
103 uint_evaluation_input };
104
105 std::vector<uint256_t> uint_batching_challenge_powers;
106 auto batching_challenge_v = key->batching_challenge_v;
107 uint_batching_challenge_powers.emplace_back(batching_challenge_v);
108 auto running_power = batching_challenge_v * batching_challenge_v;
109 uint_batching_challenge_powers.emplace_back(running_power);
110 running_power *= batching_challenge_v;
111 uint_batching_challenge_powers.emplace_back(running_power);
112 running_power *= batching_challenge_v;
113 uint_batching_challenge_powers.emplace_back(running_power);
114
115 for (size_t i = 0; i < 4; i++) {
117 uint_batching_challenge_powers[i].slice(0, NUM_LIMB_BITS),
118 uint_batching_challenge_powers[i].slice(NUM_LIMB_BITS, NUM_LIMB_BITS * 2),
119 uint_batching_challenge_powers[i].slice(NUM_LIMB_BITS * 2, NUM_LIMB_BITS * 3),
120 uint_batching_challenge_powers[i].slice(NUM_LIMB_BITS * 3, NUM_LIMB_BITS * 4),
121 uint_batching_challenge_powers[i]
122 };
123 }
124 // Compute constraint permutation grand product
125 compute_grand_products<Flavor>(key->proving_key->polynomials, relation_parameters);
126
127 commit_to_witness_polynomial(key->proving_key->polynomials.z_perm, commitment_labels.z_perm);
128}
129
135{
136 using Sumcheck = SumcheckProver<Flavor>;
137
138 // Each linearly independent subrelation contribution is multiplied by `alpha^i`, where
139 // i = 0, ..., NUM_SUBRELATIONS- 1.
140 const FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");
141
142 std::vector<FF> gate_challenges(Flavor::CONST_TRANSLATOR_LOG_N);
143 for (size_t idx = 0; idx < gate_challenges.size(); idx++) {
144 gate_challenges[idx] = transcript->template get_challenge<FF>("Sumcheck:gate_challenge_" + std::to_string(idx));
145 }
146
147 const size_t circuit_size = key->proving_key->circuit_size;
148
149 Sumcheck sumcheck(circuit_size,
150 key->proving_key->polynomials,
152 alpha,
153 gate_challenges,
156
157 const size_t log_subgroup_size = static_cast<size_t>(numeric::get_msb(Flavor::Curve::SUBGROUP_SIZE));
158 // Create a temporary commitment key that is only used to initialize the ZKSumcheckData
159 // If proving in WASM, the commitment key that is part of the Translator proving key remains deallocated
160 // until we enter the PCS round
161 CommitmentKey ck(1 << (log_subgroup_size + 1));
162
163 zk_sumcheck_data = ZKData(key->proving_key->log_circuit_size, transcript, ck);
164
165 sumcheck_output = sumcheck.prove(zk_sumcheck_data);
166}
167
175{
176 using Curve = typename Flavor::Curve;
178 using SmallSubgroupIPA = SmallSubgroupIPAProver<Flavor>;
179 using PolynomialBatcher = GeminiProver_<Curve>::PolynomialBatcher;
180
181 auto& ck = key->proving_key->commitment_key;
182
183 SmallSubgroupIPA small_subgroup_ipa_prover(
184 zk_sumcheck_data, sumcheck_output.challenge, sumcheck_output.claimed_libra_evaluation, transcript, ck);
185 small_subgroup_ipa_prover.prove();
186
187 PolynomialBatcher polynomial_batcher(key->proving_key->circuit_size);
188
189 // Unshifted for PCS (excludes computable precomputed — verifier computes them locally)
190 polynomial_batcher.set_unshifted(key->proving_key->polynomials.get_pcs_unshifted());
191 // Shifted for PCS (base to-be-shifted + concatenated)
192 polynomial_batcher.set_to_be_shifted_by_one(key->proving_key->polynomials.get_pcs_to_be_shifted());
193
194 const OpeningClaim prover_opening_claim =
195 ShpleminiProver_<Curve>::prove(key->proving_key->circuit_size,
196 polynomial_batcher,
197 sumcheck_output.challenge,
198 ck,
200 small_subgroup_ipa_prover.get_witness_polynomials());
201
202 PCS::compute_opening_proof(ck, prover_opening_claim, transcript);
203}
204
206{
207 return transcript->export_proof();
208}
209
211{
212 BB_BENCH_NAME("TranslatorProver::construct_proof");
213
214 // Add circuit size public input size and public inputs to transcript.
216
217 // Compute first three wire commitments
219
220 // Fiat-Shamir: gamma
221 // Compute grand product(s) and commitments.
223
224 // Fiat-Shamir: alpha
225 // Run sumcheck subprotocol.
227
228 // Fiat-Shamir: rho, y, x, z
229 // Execute Shplemini PCS
231 vinfo("computed opening proof");
232 return export_proof();
233}
234
241{
242 const size_t RESULT_ROW = Flavor::RESULT_ROW;
243 return uint256_t(key->proving_key->polynomials.accumulators_binary_limbs_0[RESULT_ROW]) +
244 (uint256_t(key->proving_key->polynomials.accumulators_binary_limbs_1[RESULT_ROW]) << 68) +
245 (uint256_t(key->proving_key->polynomials.accumulators_binary_limbs_2[RESULT_ROW]) << 136) +
246 (uint256_t(key->proving_key->polynomials.accumulators_binary_limbs_3[RESULT_ROW]) << 204);
247}
248
249} // namespace bb
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:225
#define BB_BENCH()
Definition bb_bench.hpp:229
Simple verification key class for fixed-size circuits (ECCVM, Translator, AVM).
Definition flavor.hpp:101
Class responsible for computation of the batched multilinear polynomials required by the Gemini proto...
Definition gemini.hpp:125
Unverified claim (C,r,v) for some witness polynomial p(X) such that.
Definition claim.hpp:55
static Polynomial random(size_t size, size_t start_index=0)
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:36
A Curve-agnostic ZK protocol to prove inner products of small vectors.
The implementation of the sumcheck Prover for statements of the form for multilinear polynomials .
Definition sumcheck.hpp:298
static constexpr size_t CONST_TRANSLATOR_LOG_N
static constexpr size_t NUM_LIMB_BITS
static constexpr size_t RESULT_ROW
CommitmentLabels commitment_labels
typename Flavor::CommitmentKey CommitmentKey
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_preamble_round()
Add circuit size and values used in the relations to the transcript.
void commit_to_witness_polynomial(Polynomial &polynomial, const std::string &label)
Utility to commit to witness polynomial and send the commitment to verifier.
uint256_t get_accumulated_result() const
Extract the accumulated result from the circuit.
TranslatorProver(const std::shared_ptr< TranslatorProvingKey > &key, const std::shared_ptr< Transcript > &transcript)
BB_PROFILE void execute_grand_product_computation_round()
Compute permutation product polynomial and commitments.
std::shared_ptr< TranslatorProvingKey > key
bb::RelationParameters< FF > relation_parameters
std::shared_ptr< Transcript > transcript
ZKSumcheckData< Flavor > ZKData
BB_PROFILE void execute_wire_and_sorted_constraints_commitments_round()
Compute commitments to wires and ordered range constraints.
SumcheckOutput< Flavor > sumcheck_output
typename Flavor::Polynomial Polynomial
BB_PROFILE void execute_pcs_rounds()
Produce a univariate opening claim for the sumcheck multivariate evalutions and a batched univariate ...
typename Flavor::FF FF
#define vinfo(...)
Definition log.hpp:94
constexpr T get_msb(const T in)
Definition get_msb.hpp:49
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
std::vector< fr > HonkProof
Definition proof.hpp:15
CommitmentKey< Curve > ck
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)
std::array< std::array< T, NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR+NUM_NATIVE_LIMBS_IN_GOBLIN_TRANSLATOR >, NUM_CHALLENGE_POWERS_IN_GOBLIN_TRANSLATOR > batching_challenge_v
std::array< T, NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR > accumulated_result
std::array< T, NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR+NUM_NATIVE_LIMBS_IN_GOBLIN_TRANSLATOR > evaluation_input_x