Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
translator_verifier.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Sergei], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
18
19namespace bb {
20
21namespace {
22// Native helper: slice uint256_t values into limbs
23template <typename Flavor>
24void put_translation_data_in_relation_parameters_impl(RelationParameters<typename Flavor::FF>& relation_parameters,
25 const uint256_t& evaluation_input_x,
26 const typename Flavor::BF& batching_challenge_v,
27 const uint256_t& accumulated_result)
28 requires(!Flavor::Curve::is_stdlib_type)
29{
30 using FF = typename Flavor::FF;
31 using BF = typename Flavor::BF;
32
33 const auto compute_four_limbs = [](const auto& in) {
34 constexpr size_t NUM_LIMB_BITS = Flavor::NUM_LIMB_BITS;
35 return std::array<FF, 4>{ in.slice(0, NUM_LIMB_BITS),
36 in.slice(NUM_LIMB_BITS, NUM_LIMB_BITS * 2),
37 in.slice(NUM_LIMB_BITS * 2, NUM_LIMB_BITS * 3),
38 in.slice(NUM_LIMB_BITS * 3, NUM_LIMB_BITS * 4) };
39 };
40
41 const auto compute_five_limbs = [](const auto& in) {
42 constexpr size_t NUM_LIMB_BITS = Flavor::NUM_LIMB_BITS;
43 return std::array<FF, 5>{ in.slice(0, NUM_LIMB_BITS),
44 in.slice(NUM_LIMB_BITS, NUM_LIMB_BITS * 2),
45 in.slice(NUM_LIMB_BITS * 2, NUM_LIMB_BITS * 3),
46 in.slice(NUM_LIMB_BITS * 3, NUM_LIMB_BITS * 4),
47 in };
48 };
49
50 relation_parameters.evaluation_input_x = compute_five_limbs(evaluation_input_x);
51
52 uint256_t batching_challenge_v_power{ batching_challenge_v };
53 for (size_t i = 0; i < 4; i++) {
54 relation_parameters.batching_challenge_v[i] = compute_five_limbs(batching_challenge_v_power);
55 batching_challenge_v_power = BF(batching_challenge_v_power) * batching_challenge_v;
56 }
57
58 relation_parameters.accumulated_result = compute_four_limbs(accumulated_result);
59}
60
61// Recursive helper: extract limbs from bigfield elements
62template <typename Flavor>
63void put_translation_data_in_relation_parameters_impl(RelationParameters<typename Flavor::FF>& relation_parameters,
64 const typename Flavor::BF& evaluation_input_x,
65 const typename Flavor::BF& batching_challenge_v,
66 const typename Flavor::BF& accumulated_result)
67 requires(Flavor::Curve::is_stdlib_type)
68{
69 using FF = typename Flavor::FF;
70 using BF = typename Flavor::BF;
71
72 const auto compute_four_limbs = [](const BF& in) {
73 auto result = std::array<FF, 4>{ FF(in.binary_basis_limbs[0].element),
74 FF(in.binary_basis_limbs[1].element),
75 FF(in.binary_basis_limbs[2].element),
76 FF(in.binary_basis_limbs[3].element) };
77 // Ensure extracted limbs are witnesses, not constants
78 for (const auto& limb : result) {
79 BB_ASSERT(!limb.is_constant());
80 }
81 return result;
82 };
83
84 const auto compute_five_limbs = [](const BF& in) {
85 auto result = std::array<FF, 5>{ FF(in.binary_basis_limbs[0].element),
86 FF(in.binary_basis_limbs[1].element),
87 FF(in.binary_basis_limbs[2].element),
88 FF(in.binary_basis_limbs[3].element),
89 FF(in.prime_basis_limb) };
90 // Ensure extracted limbs are witnesses, not constants
91 for (const auto& limb : result) {
92 BB_ASSERT(!limb.is_constant());
93 }
94 return result;
95 };
96
97 relation_parameters.evaluation_input_x = compute_five_limbs(evaluation_input_x);
98
99 BF batching_challenge_v_power = batching_challenge_v;
100 for (size_t i = 0; i < 4; i++) {
101 relation_parameters.batching_challenge_v[i] = compute_five_limbs(batching_challenge_v_power);
102 batching_challenge_v_power = batching_challenge_v_power * batching_challenge_v;
103 }
104
105 relation_parameters.accumulated_result = compute_four_limbs(accumulated_result);
106
107 // OriginTag false positive: The accumulated_result limbs originate from ECCVM verifier (different protocol phase)
108 // and are used directly in Translator relations. The fact that these values do not interact
109 // with any other value from the Translator circuit would trigger the round provenance mechanism if we didn't clear
110 // the round provenance. This cross-protocol usage is sound because:
111 // 1. ECCVM proves correctness of translation evaluations via its own sumcheck + IPA
112 // 2. ECCVM computes accumulated_result = (op + v·Px + v²·Py + v³·z1 + v⁴·z2 - masking) / x
113 // 3. Translator re-computes the same accumulator non-natively in its circuit
114 // 4. TranslatorAccumulatorTransferRelationImpl enforces exact equality at the final row:
115 // accumulators_binary_limbs_i == accumulated_result[i] for i ∈ {0,1,2,3}
116 // This binds the two protocols - Translator output must match ECCVM claim.
117 for (auto& limb : relation_parameters.accumulated_result) {
118 limb.clear_round_provenance();
119 }
120}
121} // namespace
122
124{
125 put_translation_data_in_relation_parameters_impl<Flavor>(
126 relation_parameters, evaluation_input_x, batching_challenge_v, accumulated_result);
127}
128
141template <typename Flavor>
143{
144 transcript->load_proof(proof);
145
146 // Fiat-Shamir the vk hash
147 transcript->add_to_hash_buffer("vk_hash", vk_hash);
148 vinfo("Translator vk hash in verifier: ", vk_hash);
149
150 VerifierCommitments commitments{ key };
151 CommitmentLabels commitment_labels;
152
153 // For recursive verification, mark the accumulated result's prime basis limb as used
154 // (it can be recovered from binary basis limbs, so no need to constrain it further)
155 if constexpr (IsRecursive) {
156 mark_witness_as_used(accumulated_result.prime_basis_limb);
157 }
158
159 // Use accumulated_result from ECCVM verifier
160 put_translation_data_in_relation_parameters();
161
162 // Receive Gemini masking polynomial commitment (for ZK-PCS)
163 commitments.gemini_masking_poly = transcript->template receive_from_prover<Commitment>("Gemini:masking_poly_comm");
164
165 // Set op queue wire commitments (provided by merge protocol, not from translator proof)
166 commitments.op = op_queue_wire_commitments[0];
167 commitments.x_lo_y_hi = op_queue_wire_commitments[1];
168 commitments.x_hi_z_1 = op_queue_wire_commitments[2];
169 commitments.y_lo_z_2 = op_queue_wire_commitments[3];
170
171 // Receive commitments to non-op-queue wires and ordered range constraints
172 for (auto [comm, label] : zip_view(commitments.get_non_opqueue_wires_and_ordered_range_constraints(),
173 commitment_labels.get_non_opqueue_wires_and_ordered_range_constraints())) {
174 comm = transcript->template receive_from_prover<Commitment>(label);
175 }
176
177 // Get permutation challenges
178 FF beta = transcript->template get_challenge<FF>("beta");
179 FF gamma = transcript->template get_challenge<FF>("gamma");
180
181 relation_parameters.beta = beta;
182 relation_parameters.gamma = gamma;
183
184 // Get commitment to permutation and lookup grand products
185 commitments.z_perm = transcript->template receive_from_prover<Commitment>(commitment_labels.z_perm);
186
187 return commitments;
188}
189
190template <typename Flavor>
192{
193 BB_BENCH_NAME("TranslatorVerifier::reduce");
194 using PCS = typename Flavor::PCS;
196 using ClaimBatcher = ClaimBatcher_<Curve>;
197 using ClaimBatch = typename ClaimBatcher::Batch;
198 using Sumcheck = SumcheckVerifier<Flavor>;
199
200 auto commitments = receive_pre_sumcheck();
201
202 // Each linearly independent subrelation contribution is multiplied by `alpha^i`, where
203 // i = 0, ..., NUM_SUBRELATIONS- 1.
204 const FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");
205
206 // Execute Sumcheck Verifier
207 Sumcheck sumcheck(transcript, alpha, TranslatorFlavor::CONST_TRANSLATOR_LOG_N);
208
209 std::vector<FF> gate_challenges(TranslatorFlavor::CONST_TRANSLATOR_LOG_N);
210 for (size_t idx = 0; idx < gate_challenges.size(); idx++) {
211 gate_challenges[idx] = transcript->template get_challenge<FF>("Sumcheck:gate_challenge_" + std::to_string(idx));
212 }
213
214 // Receive commitments to Libra masking polynomials
215 std::array<Commitment, NUM_LIBRA_COMMITMENTS> libra_commitments = {};
216 libra_commitments[0] = transcript->template receive_from_prover<Commitment>("Libra:concatenation_commitment");
217
218 // Create padding indicator array
219 std::vector<FF> padding_indicator_array(TranslatorFlavor::CONST_TRANSLATOR_LOG_N, FF(1));
220
221 auto sumcheck_output = sumcheck.verify(relation_parameters, gate_challenges, padding_indicator_array);
222
223 libra_commitments[1] = transcript->template receive_from_prover<Commitment>("Libra:grand_sum_commitment");
224 libra_commitments[2] = transcript->template receive_from_prover<Commitment>("Libra:quotient_commitment");
225
226 // Unshifted concat evals are reconstructed inside sumcheck (via complete_full_circuit_evaluations).
227 // Here we only need the shifted concat evals for PCS, which are not stored in AllEntities.
228 auto& claimed = sumcheck_output.claimed_evaluations;
230 claimed.get_groups_to_be_concatenated_shifted(), std::span<const FF>(sumcheck_output.challenge));
231
232 // --- PCS: build opening claims and verify ---
233 auto combined_unshifted_comms = commitments.get_pcs_unshifted();
234 auto combined_unshifted_evals = claimed.get_pcs_unshifted();
235
236 // For shifted: commitments use the getter, but evals must be assembled manually since
237 // the reconstructed shifted concat evals live in a local array, not in AllEntities.
238 auto combined_shifted_comms = commitments.get_pcs_to_be_shifted();
239 RefVector<FF> combined_shifted_evals(claimed.get_pcs_shifted());
240 for (auto& eval : concat_shift_evals) {
241 combined_shifted_evals.push_back(eval);
242 }
243
244 BB_ASSERT_EQ(combined_unshifted_comms.size(), TranslatorFlavor::NUM_PCS_UNSHIFTED);
245 BB_ASSERT_EQ(combined_unshifted_evals.size(), TranslatorFlavor::NUM_PCS_UNSHIFTED);
246 BB_ASSERT_EQ(combined_shifted_comms.size(), TranslatorFlavor::NUM_PCS_TO_BE_SHIFTED);
248
249 ClaimBatcher claim_batcher{ .unshifted = ClaimBatch{ combined_unshifted_comms, combined_unshifted_evals },
250 .shifted = ClaimBatch{ combined_shifted_comms, combined_shifted_evals } };
251
252 Commitment commitment_one;
253 if constexpr (IsRecursive) {
254 commitment_one = Commitment::one(builder);
255 } else {
256 commitment_one = Commitment::one();
257 }
258
259 auto [opening_claim, consistency_checked] =
260 Shplemini::compute_batch_opening_claim(padding_indicator_array,
261 claim_batcher,
262 sumcheck_output.challenge,
263 commitment_one,
264 transcript,
266 libra_commitments,
267 sumcheck_output.claimed_libra_evaluation);
268
269 auto pairing_points = PCS::reduce_verify_batch_opening_claim(std::move(opening_claim), transcript);
270
271 vinfo("Translator Verifier: sumcheck verified: ", sumcheck_output.verified);
272 vinfo("Translator Verifier: consistency checked: ", consistency_checked);
273
274 return { pairing_points, sumcheck_output.verified && consistency_checked };
275}
276
277// Explicit instantiations
280
281} // namespace bb
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:83
bb::field< bb::Bn254FrParams > FF
Definition field.cpp:24
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:225
typename Curve::ScalarField FF
typename Curve::BaseField BF
static constexpr RepeatedCommitmentsData REPEATED_COMMITMENTS
IPA (inner product argument) commitment scheme class.
Definition ipa.hpp:86
A template class for a reference vector. Behaves as if std::vector<T&> was possible.
std::size_t size() const
void push_back(T &element)
Implementation of the sumcheck Verifier for statements of the form for multilinear polynomials .
Definition sumcheck.hpp:747
static constexpr size_t NUM_PCS_UNSHIFTED
static constexpr size_t CONST_TRANSLATOR_LOG_N
static std::array< FFType, NUM_CONCATENATED_POLYS > reconstruct_concatenated_evaluations(const std::vector< RefVector< FFType > > &groups, std::span< const FFType > challenge)
Reconstruct concatenated polynomial evaluations from individual wire evaluations using the Lagrange b...
static constexpr size_t NUM_PCS_TO_BE_SHIFTED
Translator verifier class that verifies the proof of the Translator circuit.
ReductionResult reduce_to_pairing_check()
Reduce the translator proof to a pairing check.
void put_translation_data_in_relation_parameters()
Populate relation parameters with translation data from ECCVM verifier.
typename Flavor::VerifierCommitments VerifierCommitments
VerifierCommitments receive_pre_sumcheck()
Load translator proof and run the pre-sumcheck (Oink-like) phase on the shared transcript.
typename Flavor::CommitmentLabels CommitmentLabels
typename Flavor::Commitment Commitment
#define vinfo(...)
Definition log.hpp:94
AluTraceBuilder builder
Definition alu.test.cpp:124
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)
This file contains part of the logic for the Origin Tag mechanism that tracks the use of in-circuit p...
Logic to support batching opening claims for unshifted and shifted polynomials in Shplemini.
Result of reducing translator proof to pairing check.