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: 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
14
15namespace bb {
16
18 const std::shared_ptr<Transcript>& transcript)
19 : transcript(transcript)
20 , key(key)
21{
22 BB_BENCH();
23 if (!key->proving_key->commitment_key.initialized()) {
24 key->proving_key->commitment_key = CommitmentKey(key->proving_key->circuit_size);
25 }
26}
27
33{
34 // Fiat-Shamir the vk hash
36 typename Flavor::FF vk_hash = vk.hash();
37 transcript->add_to_hash_buffer("vk_hash", vk_hash);
38 vinfo("Translator vk hash in prover: ", vk_hash);
39
40 const auto SHIFT = uint256_t(1) << Flavor::NUM_LIMB_BITS;
41 const auto SHIFTx2 = uint256_t(1) << (Flavor::NUM_LIMB_BITS * 2);
42 const auto SHIFTx3 = uint256_t(1) << (Flavor::NUM_LIMB_BITS * 3);
43 const size_t RESULT_ROW = Flavor::RESULT_ROW;
44 const auto accumulated_result =
45 BF(uint256_t(key->proving_key->polynomials.accumulators_binary_limbs_0[RESULT_ROW]) +
46 uint256_t(key->proving_key->polynomials.accumulators_binary_limbs_1[RESULT_ROW]) * SHIFT +
47 uint256_t(key->proving_key->polynomials.accumulators_binary_limbs_2[RESULT_ROW]) * SHIFTx2 +
48 uint256_t(key->proving_key->polynomials.accumulators_binary_limbs_3[RESULT_ROW]) * SHIFTx3);
49
50 relation_parameters.accumulated_result = { key->proving_key->polynomials.accumulators_binary_limbs_0[RESULT_ROW],
51 key->proving_key->polynomials.accumulators_binary_limbs_1[RESULT_ROW],
52 key->proving_key->polynomials.accumulators_binary_limbs_2[RESULT_ROW],
53 key->proving_key->polynomials.accumulators_binary_limbs_3[RESULT_ROW] };
54
55 // Send the accumulation result to the verifier, this value cannot be linked to the actual content of the op queue
56 // in practice (CIVC scenario) as we add a random, but genuine scalar mul operation to the op queue
57 transcript->send_to_verifier("accumulated_result", accumulated_result);
58}
59
66void TranslatorProver::commit_to_witness_polynomial(Polynomial& polynomial, const std::string& label)
67{
68 transcript->send_to_verifier(label, key->proving_key->commitment_key.commit(polynomial));
69}
70
76{
77 BB_BENCH_NAME("TranslatorProver::execute_wire_and_sorted_constraints_commitments_round");
78 auto batch = key->proving_key->commitment_key.start_batch();
79 for (const auto& [wire, label] :
80 zip_view(key->proving_key->polynomials.get_wires(), commitment_labels.get_wires())) {
81
82 batch.add_to_batch(wire, label, /*mask for zk?*/ false);
83 }
84
85 // The ordered range constraints are of full circuit size.
86 for (const auto& [ordered_range_constraint, label] :
87 zip_view(key->proving_key->polynomials.get_ordered_range_constraints(),
88 commitment_labels.get_ordered_range_constraints())) {
89 batch.add_to_batch(ordered_range_constraint, label, /*mask for zk?*/ false);
90 }
91 batch.commit_and_send_to_verifier(transcript);
92}
93
99{
100 // Compute and store parameters required by relations in Sumcheck
101 FF beta = transcript->template get_challenge<FF>("beta");
102 FF gamma = transcript->template get_challenge<FF>("gamma");
103 const size_t NUM_LIMB_BITS = Flavor::NUM_LIMB_BITS;
106 auto uint_evaluation_input = uint256_t(key->evaluation_input_x);
107 relation_parameters.evaluation_input_x = { uint_evaluation_input.slice(0, NUM_LIMB_BITS),
108 uint_evaluation_input.slice(NUM_LIMB_BITS, NUM_LIMB_BITS * 2),
109 uint_evaluation_input.slice(NUM_LIMB_BITS * 2, NUM_LIMB_BITS * 3),
110 uint_evaluation_input.slice(NUM_LIMB_BITS * 3, NUM_LIMB_BITS * 4),
111 uint_evaluation_input };
112
113 std::vector<uint256_t> uint_batching_challenge_powers;
114 auto batching_challenge_v = key->batching_challenge_v;
115 uint_batching_challenge_powers.emplace_back(batching_challenge_v);
116 auto running_power = batching_challenge_v * batching_challenge_v;
117 uint_batching_challenge_powers.emplace_back(running_power);
118 running_power *= batching_challenge_v;
119 uint_batching_challenge_powers.emplace_back(running_power);
120 running_power *= batching_challenge_v;
121 uint_batching_challenge_powers.emplace_back(running_power);
122
123 for (size_t i = 0; i < 4; i++) {
125 uint_batching_challenge_powers[i].slice(0, NUM_LIMB_BITS),
126 uint_batching_challenge_powers[i].slice(NUM_LIMB_BITS, NUM_LIMB_BITS * 2),
127 uint_batching_challenge_powers[i].slice(NUM_LIMB_BITS * 2, NUM_LIMB_BITS * 3),
128 uint_batching_challenge_powers[i].slice(NUM_LIMB_BITS * 3, NUM_LIMB_BITS * 4),
129 uint_batching_challenge_powers[i]
130 };
131 }
132 // Compute constraint permutation grand product
133 compute_grand_products<Flavor>(key->proving_key->polynomials, relation_parameters);
134
135 commit_to_witness_polynomial(key->proving_key->polynomials.z_perm, commitment_labels.z_perm);
136}
137
143{
144 using Sumcheck = SumcheckProver<Flavor>;
145
146 // Each linearly independent subrelation contribution is multiplied by `alpha^i`, where
147 // i = 0, ..., NUM_SUBRELATIONS- 1.
148 const FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");
149
150 std::vector<FF> gate_challenges(Flavor::CONST_TRANSLATOR_LOG_N);
151 for (size_t idx = 0; idx < gate_challenges.size(); idx++) {
152 gate_challenges[idx] = transcript->template get_challenge<FF>("Sumcheck:gate_challenge_" + std::to_string(idx));
153 }
154
155 const size_t circuit_size = key->proving_key->circuit_size;
156
157 Sumcheck sumcheck(circuit_size,
158 key->proving_key->polynomials,
160 alpha,
161 gate_challenges,
164
165 const size_t log_subgroup_size = static_cast<size_t>(numeric::get_msb(Flavor::Curve::SUBGROUP_SIZE));
166 // Create a temporary commitment key that is only used to initialize the ZKSumcheckData
167 // If proving in WASM, the commitment key that is part of the Translator proving key remains deallocated
168 // until we enter the PCS round
169 CommitmentKey ck(1 << (log_subgroup_size + 1));
170
171 zk_sumcheck_data = ZKData(key->proving_key->log_circuit_size, transcript, ck);
172
173 sumcheck_output = sumcheck.prove(zk_sumcheck_data);
174}
175
183{
184 using Curve = typename Flavor::Curve;
186 using SmallSubgroupIPA = SmallSubgroupIPAProver<Flavor>;
187 using PolynomialBatcher = GeminiProver_<Curve>::PolynomialBatcher;
188
189 // Check whether the commitment key has been deallocated and reinitialize it if necessary
190 auto& ck = key->proving_key->commitment_key;
191 if (!ck.initialized()) {
192 ck = CommitmentKey(key->proving_key->circuit_size);
193 }
194
195 SmallSubgroupIPA small_subgroup_ipa_prover(
196 zk_sumcheck_data, sumcheck_output.challenge, sumcheck_output.claimed_libra_evaluation, transcript, ck);
197 small_subgroup_ipa_prover.prove();
198
199 PolynomialBatcher polynomial_batcher(key->proving_key->circuit_size);
200 polynomial_batcher.set_unshifted(key->proving_key->polynomials.get_unshifted_without_interleaved());
201 polynomial_batcher.set_to_be_shifted_by_one(key->proving_key->polynomials.get_to_be_shifted());
202 polynomial_batcher.set_interleaved(key->proving_key->polynomials.get_interleaved(),
203 key->proving_key->polynomials.get_groups_to_be_interleaved());
204
205 const OpeningClaim prover_opening_claim =
206 ShpleminiProver_<Curve>::prove(key->proving_key->circuit_size,
207 polynomial_batcher,
208 sumcheck_output.challenge,
209 ck,
211 small_subgroup_ipa_prover.get_witness_polynomials());
212
213 PCS::compute_opening_proof(ck, prover_opening_claim, transcript);
214}
215
217{
218 return transcript->export_proof();
219}
220
222{
223 BB_BENCH_NAME("TranslatorProver::construct_proof");
224
225 // Add circuit size public input size and public inputs to transcript.
227
228 // Compute first three wire commitments
230
231 // Fiat-Shamir: gamma
232 // Compute grand product(s) and commitments.
234
235 // #ifndef __wasm__
236 // Free the commitment key
237 key->proving_key->commitment_key = CommitmentKey();
238 // #endif
239
240 // Fiat-Shamir: alpha
241 // Run sumcheck subprotocol.
243
244 // Fiat-Shamir: rho, y, x, z
245 // Execute Shplemini PCS
247 vinfo("computed opening proof");
248 return export_proof();
249}
250
251} // namespace bb
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:218
#define BB_BENCH()
Definition bb_bench.hpp:222
Class responsible for computation of the batched multilinear polynomials required by the Gemini proto...
Definition gemini.hpp:129
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
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
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:126
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
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.
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.
typename Flavor::BF BF
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:79
constexpr T get_msb(const T in)
Definition get_msb.hpp:47
Entry point for Barretenberg command-line interface.
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