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: 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
11
12namespace bb {
13
14TranslatorVerifier::TranslatorVerifier(const std::shared_ptr<Transcript>& transcript)
15 : transcript(transcript)
16{}
17
18TranslatorVerifier::TranslatorVerifier(const std::shared_ptr<VerificationKey>& verifier_key,
19 const std::shared_ptr<Transcript>& transcript)
20 : key(verifier_key)
21 , transcript(transcript)
22{}
23
25 const BF& batching_challenge_v,
26 const uint256_t& accumulated_result)
27{
28
29 const auto compute_four_limbs = [](const auto& in) {
30 constexpr size_t NUM_LIMB_BITS = Flavor::NUM_LIMB_BITS;
31 return std::array<FF, 4>{ in.slice(0, NUM_LIMB_BITS),
32 in.slice(NUM_LIMB_BITS, NUM_LIMB_BITS * 2),
33 in.slice(NUM_LIMB_BITS * 2, NUM_LIMB_BITS * 3),
34 in.slice(NUM_LIMB_BITS * 3, NUM_LIMB_BITS * 4) };
35 };
36
37 const auto compute_five_limbs = [](const auto& in) {
38 constexpr size_t NUM_LIMB_BITS = Flavor::NUM_LIMB_BITS;
39 return std::array<FF, 5>{ in.slice(0, NUM_LIMB_BITS),
40 in.slice(NUM_LIMB_BITS, NUM_LIMB_BITS * 2),
41 in.slice(NUM_LIMB_BITS * 2, NUM_LIMB_BITS * 3),
42 in.slice(NUM_LIMB_BITS * 3, NUM_LIMB_BITS * 4),
43 in };
44 };
45
47
48 uint256_t batching_challenge_v_power{ batching_challenge_v };
49 for (size_t i = 0; i < 4; i++) {
50 relation_parameters.batching_challenge_v[i] = compute_five_limbs(batching_challenge_v_power);
51 batching_challenge_v_power = BF(batching_challenge_v_power) * batching_challenge_v;
52 }
53
54 relation_parameters.accumulated_result = compute_four_limbs(accumulated_result);
55};
56
61 const uint256_t& evaluation_input_x,
62 const BF& batching_challenge_v)
63{
64 using Curve = Flavor::Curve;
65 using PCS = Flavor::PCS;
66 using Shplemini = ShpleminiVerifier_<Curve>;
67 using ClaimBatcher = ClaimBatcher_<Curve>;
68 using ClaimBatch = ClaimBatcher::Batch;
69 using InterleavedBatch = ClaimBatcher::InterleavedBatch;
70 using Sumcheck = SumcheckVerifier<Flavor>;
72
73 // Load the proof produced by the translator prover
74 transcript->load_proof(proof);
75
76 // Fiat-Shamir the vk hash
77 typename Flavor::FF vk_hash = key->hash();
78 transcript->add_to_hash_buffer("vk_hash", vk_hash);
79 vinfo("Translator vk hash in verifier: ", vk_hash);
80
81 Flavor::VerifierCommitments commitments{ key };
82 Flavor::CommitmentLabels commitment_labels;
83
84 const BF accumulated_result = transcript->template receive_from_prover<BF>("accumulated_result");
85
87
88 // Get commitments to wires and the ordered range constraints that do not require additional challenges
89 for (auto [comm, label] : zip_view(commitments.get_wires_and_ordered_range_constraints(),
90 commitment_labels.get_wires_and_ordered_range_constraints())) {
91 comm = transcript->template receive_from_prover<Commitment>(label);
92 }
93 op_queue_commitments = { commitments.op, commitments.x_lo_y_hi, commitments.x_hi_z_1, commitments.y_lo_z_2 };
94
95 // Get permutation challenges
96 FF beta = transcript->template get_challenge<FF>("beta");
97 FF gamma = transcript->template get_challenge<FF>("gamma");
98
101
102 // Get commitment to permutation and lookup grand products
103 commitments.z_perm = transcript->template receive_from_prover<Commitment>(commitment_labels.z_perm);
104
105 // Each linearly independent subrelation contribution is multiplied by `alpha^i`, where
106 // i = 0, ..., NUM_SUBRELATIONS- 1.
107 const FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");
108
109 // Execute Sumcheck Verifier
110 Sumcheck sumcheck(transcript, alpha, Flavor::CONST_TRANSLATOR_LOG_N);
111
112 std::vector<FF> gate_challenges(Flavor::CONST_TRANSLATOR_LOG_N);
113 for (size_t idx = 0; idx < gate_challenges.size(); idx++) {
114 gate_challenges[idx] = transcript->template get_challenge<FF>("Sumcheck:gate_challenge_" + std::to_string(idx));
115 }
116
117 // Receive commitments to Libra masking polynomials
119 libra_commitments[0] = transcript->template receive_from_prover<Commitment>("Libra:concatenation_commitment");
120
121 std::vector<FF> padding_indicator_array(Flavor::CONST_TRANSLATOR_LOG_N);
122 std::ranges::fill(padding_indicator_array, FF{ 1 });
123
124 auto sumcheck_output = sumcheck.verify(relation_parameters, gate_challenges, padding_indicator_array);
125
126 // If Sumcheck did not verify, return false
127 if (!sumcheck_output.verified) {
128 return false;
129 }
130
131 libra_commitments[1] = transcript->template receive_from_prover<Commitment>("Libra:grand_sum_commitment");
132 libra_commitments[2] = transcript->template receive_from_prover<Commitment>("Libra:quotient_commitment");
133
134 // Execute Shplemini
135 bool consistency_checked = false;
136 ClaimBatcher claim_batcher{
137 .unshifted = ClaimBatch{ commitments.get_unshifted_without_interleaved(),
138 sumcheck_output.claimed_evaluations.get_unshifted_without_interleaved() },
139 .shifted = ClaimBatch{ commitments.get_to_be_shifted(), sumcheck_output.claimed_evaluations.get_shifted() },
140 .interleaved = InterleavedBatch{ .commitments_groups = commitments.get_groups_to_be_interleaved(),
141 .evaluations = sumcheck_output.claimed_evaluations.get_interleaved() }
142 };
143 const BatchOpeningClaim<Curve> opening_claim =
144 Shplemini::compute_batch_opening_claim(padding_indicator_array,
145 claim_batcher,
146 sumcheck_output.challenge,
147 Commitment::one(),
151 &consistency_checked,
152 libra_commitments,
153 sumcheck_output.claimed_libra_evaluation);
154 const auto pairing_points = PCS::reduce_verify_batch_opening_claim(opening_claim, transcript);
155
156 VerifierCommitmentKey pcs_vkey{};
157 auto verified = pcs_vkey.pairing_check(pairing_points[0], pairing_points[1]);
158 return verified && consistency_checked;
159}
160
162 const BF& translation_masking_term_eval)
163{
164 const auto reconstruct_from_array = [&](const auto& arr) {
165 const BF elt_0 = (static_cast<uint256_t>(arr[0]));
166 const BF elt_1 = (static_cast<uint256_t>(arr[1]) << 68);
167 const BF elt_2 = (static_cast<uint256_t>(arr[2]) << 136);
168 const BF elt_3 = (static_cast<uint256_t>(arr[3]) << 204);
169 const BF reconstructed = elt_0 + elt_1 + elt_2 + elt_3;
170 return reconstructed;
171 };
172
173 const auto& reconstruct_value_from_eccvm_evaluations = [&](const TranslationEvaluations& translation_evaluations,
174 auto& relation_parameters) {
175 const BF accumulated_result = reconstruct_from_array(relation_parameters.accumulated_result);
176 const BF x = reconstruct_from_array(relation_parameters.evaluation_input_x);
177 const BF v1 = reconstruct_from_array(relation_parameters.batching_challenge_v[0]);
178 const BF v2 = reconstruct_from_array(relation_parameters.batching_challenge_v[1]);
179 const BF v3 = reconstruct_from_array(relation_parameters.batching_challenge_v[2]);
180 const BF v4 = reconstruct_from_array(relation_parameters.batching_challenge_v[3]);
181 const BF& op = translation_evaluations.op;
182 const BF& Px = translation_evaluations.Px;
183 const BF& Py = translation_evaluations.Py;
184 const BF& z1 = translation_evaluations.z1;
185 const BF& z2 = translation_evaluations.z2;
186
187 const BF eccvm_opening = (op + (v1 * Px) + (v2 * Py) + (v3 * z1) + (v4 * z2)) - translation_masking_term_eval;
188 // multiply by x here to deal with shift
189 return x * accumulated_result == eccvm_opening;
190 };
191
192 bool is_value_reconstructed =
193 reconstruct_value_from_eccvm_evaluations(translation_evaluations, relation_parameters);
194 return is_value_reconstructed;
195}
196
206{
207 if (op_queue_commitments[0] != merge_commitments[0]) {
208 info("Consistency check failed: op commitment mismatch");
209 return false;
210 }
211
212 if (op_queue_commitments[1] != merge_commitments[1]) {
213 info("Consistency check failed: x_lo_y_hi commitment mismatch");
214 return false;
215 }
216
217 if (op_queue_commitments[2] != merge_commitments[2]) {
218 info("Consistency check failed: x_hi_z_1 commitment mismatch");
219 return false;
220 }
221
222 if (op_queue_commitments[3] != merge_commitments[3]) {
223 info("Consistency check failed: y_lo_z_2 commitment mismatch");
224 return false;
225 }
226
227 return true;
228}
229} // namespace bb
An efficient verifier for the evaluation proofs of multilinear polynomials and their shifts.
Implementation of the sumcheck Verifier for statements of the form for multilinear polynomials .
Definition sumcheck.hpp:645
A container for commitment labels.
auto get_wires_and_ordered_range_constraints()
Witness Entities to which the prover commits and do not require challenges (i.e. not derived).
static constexpr RepeatedCommitmentsData REPEATED_COMMITMENTS
static constexpr size_t CONST_TRANSLATOR_LOG_N
static constexpr bool HasZK
static constexpr size_t NUM_LIMB_BITS
bb::VerifierCommitmentKey< Curve > VerifierCommitmentKey
bool verify_proof(const HonkProof &proof, const uint256_t &evaluation_input_x, const BF &batching_challenge_v)
This function verifies a TranslatorFlavor Honk proof for given program settings.
void put_translation_data_in_relation_parameters(const uint256_t &evaluation_input_x, const BF &batching_challenge_v, const uint256_t &accumulated_result)
std::array< Commitment, TranslatorFlavor::NUM_OP_QUEUE_WIRES > op_queue_commitments
bool verify_translation(const TranslationEvaluations &translation_evaluations, const BF &translation_masking_term_eval)
std::shared_ptr< VerificationKey > key
RelationParameters< FF > relation_parameters
bool verify_consistency_with_final_merge(const std::array< Commitment, TranslatorFlavor::NUM_OP_QUEUE_WIRES > &merge_commitments)
Checks that translator and merge protocol operate on the same EccOpQueue data.
TranslatorVerifier(const std::shared_ptr< Transcript > &transcript)
std::shared_ptr< Transcript > transcript
void vinfo(Args... args)
Definition log.hpp:76
void info(Args... args)
Definition log.hpp:70
Entry point for Barretenberg command-line interface.
std::vector< fr > HonkProof
Definition proof.hpp:15
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)
An accumulator consisting of the Shplonk evaluation challenge and vectors of commitments and scalars.
Definition claim.hpp:169
Logic to support batching opening claims for unshifted and shifted polynomials in Shplemini.
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
Stores the evaluations of op, Px, Py, z1, and z2 computed by the ECCVM Prover. These evaluations are ...