Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
merge_recursive_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
9
11
12template <typename CircuitBuilder>
14 const MergeSettings settings,
15 const std::shared_ptr<Transcript>& transcript)
17 , transcript(transcript)
18 , settings(settings)
19{}
20
67template <typename CircuitBuilder>
71 const InputCommitments& input_commitments)
72{
74
75 transcript->load_proof(proof);
76
77 FF shift_size = transcript->template receive_from_prover<FF>("shift_size");
78 BB_ASSERT_GT(shift_size.get_value(), 0U, "Shift size should always be bigger than 0");
79
80 // Vector of commitments to be passed to the Shplonk verifier
81 // The vector is composed of: [l_1], [r_1], [m_1], [g_1], ..., [l_4], [r_4], [m_4], [g_4]
82 std::vector<Commitment> table_commitments;
83 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
84 auto left_table = settings == MergeSettings::PREPEND ? input_commitments.t_commitments[idx]
85 : input_commitments.T_prev_commitments[idx];
86 auto right_table = settings == MergeSettings::PREPEND ? input_commitments.T_prev_commitments[idx]
87 : input_commitments.t_commitments[idx];
88
89 table_commitments.emplace_back(left_table);
90 table_commitments.emplace_back(right_table);
91 table_commitments.emplace_back(
92 transcript->template receive_from_prover<Commitment>("MERGED_TABLE_" + std::to_string(idx)));
93 table_commitments.emplace_back(
94 transcript->template receive_from_prover<Commitment>("LEFT_TABLE_REVERSED_" + std::to_string(idx)));
95 }
96
97 // Store T_commitments of the verifier
98 TableCommitments merged_table_commitments;
99 size_t commitment_idx = 2; // Index of [m_j = T_j] in the vector of commitments
100 for (auto& commitment : merged_table_commitments) {
101 commitment = table_commitments[commitment_idx];
102 commitment_idx += NUM_WIRES;
103 }
104
105 // Evaluation challenge
106 const FF kappa = transcript->template get_challenge<FF>("kappa");
107 const FF kappa_inv = kappa.invert();
108 const FF pow_kappa = kappa.pow(shift_size);
109 const FF pow_kappa_minus_one = pow_kappa * kappa_inv;
110
111 // Opening claims to be passed to the Shplonk verifier
112 std::vector<Claims> opening_claims;
113
114 // Add opening claim for p_j(X) = l_j(X) + X^k r_j(X) - m_j(X)
115 commitment_idx = 0;
116 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
117 opening_claims.emplace_back(Claims{ { /*index of [l_j]*/ commitment_idx,
118 /*index of [r_j]*/ commitment_idx + 1,
119 /*index of [m_j]*/ commitment_idx + 2 },
120 { FF(1), pow_kappa, FF(-1) },
121 { kappa, FF(0) } });
122
123 // Move commitment_idx to the index of [l_{j+1}]
124 commitment_idx += NUM_WIRES;
125 }
126
127 // Add opening claim for l_j(1/kappa), g_j(kappa) and check g_j(kappa) = l_j(1/kappa) * kappa^{k-1}
128 commitment_idx = 0;
129 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
130 // Opening claim for l_j(1/kappa)
131 FF left_table_eval_kappa_inv =
132 transcript->template receive_from_prover<FF>("left_table_eval_kappa_inv_" + std::to_string(idx));
133 opening_claims.emplace_back(
134 Claims{ { /*index of [l_j]*/ commitment_idx }, { FF(1) }, { kappa_inv, left_table_eval_kappa_inv } });
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 opening_claims.emplace_back(
140 Claims{ { /*index of [g_j]*/ commitment_idx + 3 }, { FF(1) }, { kappa, left_table_reversed_eval } });
141
142 // Move commitment_idx to index of left_table_{j+1}
143 commitment_idx += NUM_WIRES;
144
145 // Degree identity
146 left_table_reversed_eval.assert_equal(left_table_eval_kappa_inv * pow_kappa_minus_one);
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(kappa.get_context()));
155
156 // KZG verifier
157 auto pairing_points = KZG::reduce_verify_batch_opening_claim(batch_opening_claim, transcript);
158
159 return { pairing_points, merged_table_commitments };
160}
161
164
165} // namespace bb::stdlib::recursion::goblin
#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
Shplonk Verifier.
Definition shplonk.hpp:343
A simple wrapper around a vector of stdlib field elements representing a proof.
Definition proof.hpp:19
std::pair< PairingPoints, TableCommitments > verify_proof(const stdlib::Proof< CircuitBuilder > &proof, const InputCommitments &input_commitments)
Computes inputs to a pairing check that, if verified, establishes proper construction of the aggregat...
MergeRecursiveVerifier_(CircuitBuilder *builder, const MergeSettings settings=MergeSettings::PREPEND, const std::shared_ptr< Transcript > &transcript=std::make_shared< Transcript >())
AluTraceBuilder builder
Definition alu.test.cpp:123
typename Flavor::FF FF
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)