Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
merge_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
7#include "merge_verifier.hpp"
11
12namespace bb {
13
14MergeVerifier::MergeVerifier(const MergeSettings settings, const std::shared_ptr<Transcript>& transcript)
15 : transcript(transcript)
16 , settings(settings) {};
17
63 const HonkProof& proof, const InputCommitments& input_commitments)
64{
66
67 transcript->load_proof(proof);
68
69 const uint32_t shift_size = transcript->template receive_from_prover<uint32_t>("shift_size");
70 BB_ASSERT_GT(shift_size, 0U, "Shift size should always be bigger than 0");
71
72 // Vector of commitments to be passed to the Shplonk verifier
73 // The vector is composed of: [l_1], [r_1], [m_1], [g_1], ..., [l_4], [r_4], [m_4], [g_4]
74 std::vector<Commitment> table_commitments;
75 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
76 auto left_table = settings == MergeSettings::PREPEND ? input_commitments.t_commitments[idx]
77 : input_commitments.T_prev_commitments[idx];
78 auto right_table = settings == MergeSettings::PREPEND ? input_commitments.T_prev_commitments[idx]
79 : input_commitments.t_commitments[idx];
80
81 table_commitments.emplace_back(left_table);
82 table_commitments.emplace_back(right_table);
83 table_commitments.emplace_back(
84 transcript->template receive_from_prover<Commitment>("MERGED_TABLE_" + std::to_string(idx)));
85 table_commitments.emplace_back(
86 transcript->template receive_from_prover<Commitment>("LEFT_TABLE_REVERSED_" + std::to_string(idx)));
87 }
88
89 // Store T_commitments of the verifier
90 TableCommitments merged_table_commitments;
91 size_t commitment_idx = 2; // Index of [m_j = T_j] in the vector of commitments
92 for (auto& commitment : merged_table_commitments) {
93 commitment = table_commitments[commitment_idx];
94 commitment_idx += NUM_WIRES;
95 }
96
97 // Evaluation challenge
98 const FF kappa = transcript->template get_challenge<FF>("kappa");
99 const FF kappa_inv = kappa.invert();
100 const FF pow_kappa = kappa.pow(shift_size);
101
102 // Opening claims to be passed to the Shplonk verifier
103 std::vector<Claims> opening_claims;
104
105 // Add opening claim for p_j(X) = l_j(X) + X^k r_j(X) - m_j(X)
106 commitment_idx = 0;
107 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
108 Claims claim{ { /*index of [l_j]*/ commitment_idx,
109 /*index of [r_j]*/ commitment_idx + 1,
110 /*index of [m_j]*/ commitment_idx + 2 },
111 { FF::one(), pow_kappa, FF::neg_one() },
112 { kappa, FF::zero() } };
113 opening_claims.emplace_back(claim);
114
115 // Move commitment_idx to the index of [l_{j+1}]
116 commitment_idx += NUM_WIRES;
117 }
118
119 // Boolean keeping track of the degree identities
120 bool degree_check_verified = true;
121
122 // Add opening claim for l_j(1/kappa), g_j(kappa) and check g_j(kappa) = l_j(1/kappa) * kappa^{k-1}
123 commitment_idx = 0;
124 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
125 Claims claim;
126
127 // Opening claim for l_j(1/kappa)
128 FF left_table_eval_kappa_inv =
129 transcript->template receive_from_prover<FF>("left_table_eval_kappa_inv_" + std::to_string(idx));
130 claim = { { commitment_idx }, { FF::one() }, { kappa_inv, left_table_eval_kappa_inv } };
131 opening_claims.emplace_back(claim);
132
133 // Move commitment_idx to index of g_j
134 commitment_idx += 3;
135
136 // Opening claim for g_j(kappa)
137 FF left_table_reversed_eval =
138 transcript->template receive_from_prover<FF>("left_table_reversed_eval_" + std::to_string(idx));
139 claim = { { commitment_idx }, { FF::one() }, { kappa, left_table_reversed_eval } };
140 opening_claims.emplace_back(claim);
141
142 // Move commitment_idx to index of left_table_{j+1}
143 commitment_idx += 1;
144
145 // Degree identity
146 degree_check_verified &= (left_table_eval_kappa_inv * kappa.pow(shift_size - 1) == left_table_reversed_eval);
147 }
148
149 // Initialize Shplonk verifier
150 ShplonkVerifier_<Curve> verifier(table_commitments, transcript, opening_claims.size());
151 verifier.reduce_verification_vector_claims_no_finalize(opening_claims);
152
153 // Export batched claim
154 auto batch_opening_claim = verifier.export_batch_opening_claim(Commitment::one());
155
156 // KZG verifier
157 auto pairing_points = PCS::reduce_verify_batch_opening_claim(batch_opening_claim, transcript);
158 VerifierCommitmentKey pcs_vkey{};
159 bool claims_verified = pcs_vkey.pairing_check(pairing_points[0], pairing_points[1]);
160
161 return { degree_check_verified && claims_verified, merged_table_commitments };
162}
163} // namespace bb
#define BB_ASSERT_GT(left, right,...)
Definition assert.hpp:87
static VerifierAccumulator reduce_verify_batch_opening_claim(BatchOpeningClaim< Curve > batch_opening_claim, const std::shared_ptr< Transcript > &transcript)
Computes the input points for the pairing check needed to verify a KZG opening claim obtained from a ...
Definition kzg.hpp:122
std::pair< bool, TableCommitments > verify_proof(const HonkProof &proof, const InputCommitments &input_commitments)
Verify proper construction of the aggregate Goblin ECC op queue polynomials T_j, j = 1,...
MergeVerifier(const MergeSettings settings=MergeSettings::PREPEND, const std::shared_ptr< Transcript > &transcript=std::make_shared< Transcript >())
MergeSettings settings
static constexpr size_t NUM_WIRES
typename Curve::ScalarField FF
std::array< Commitment, NUM_WIRES > TableCommitments
std::shared_ptr< Transcript > transcript
Shplonk Verifier.
Definition shplonk.hpp:343
Entry point for Barretenberg command-line interface.
std::vector< fr > HonkProof
Definition proof.hpp:15
MergeSettings
The MergeSettings define whether an current subtable will be added at the beginning (PREPEND) or at t...
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)
static constexpr field neg_one()
static constexpr field one()
static constexpr field zero()