Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
merge_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
7#include "merge_prover.hpp"
10
11namespace bb {
12
19 const MergeSettings settings,
20 const CommitmentKey& commitment_key,
21 const std::shared_ptr<Transcript>& transcript)
22 : op_queue(op_queue)
23 , transcript(transcript)
24 , settings(settings)
25{
26 // Merge the current subtable (for which a merge proof is being constructed) prior to
27 // procedeing with proving.
29 size_t last_subtable_size = op_queue->get_current_subtable_size();
30 op_queue->merge(settings, ECCOpQueue::OP_QUEUE_SIZE - last_subtable_size);
31
32 } else {
33 op_queue->merge(settings);
34 }
35
37 commitment_key.initialized() ? commitment_key : CommitmentKey(op_queue->get_ultra_ops_table_num_rows());
38};
39
70{
71
74 std::array<Polynomial, NUM_WIRES> merged_table = op_queue->construct_ultra_ops_table_columns(); // T
75 std::array<Polynomial, NUM_WIRES> left_table_reversed;
76
78 left_table = op_queue->construct_current_ultra_ops_subtable_columns(); // t
79 right_table = op_queue->construct_previous_ultra_ops_table_columns(); // T_prev
80 } else {
81 left_table = op_queue->construct_previous_ultra_ops_table_columns(); // T_prev
82 right_table = op_queue->construct_current_ultra_ops_subtable_columns(); // t
83 }
84 // Compute g_j(X)
85 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
86 left_table_reversed[idx] = left_table[idx].reverse();
87 }
88
89 const size_t merged_table_size = merged_table[0].size();
90
91 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1341): Once the op queue is fixed, we won't have to
92 // send the shift size in the append mode. This is desirable to ensure we don't reveal the number of ecc ops in a
93 // subtable when sending a merge proof to the rollup.
94 const size_t shift_size = left_table[0].size();
95 transcript->send_to_verifier("shift_size", static_cast<uint32_t>(shift_size));
96
97 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1473): remove generation of commitment to T_prev
98 // Compute commitments [T_prev], [m_j], [g_j], and send to the verifier
99 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
100 transcript->send_to_verifier("MERGED_TABLE_" + std::to_string(idx),
101 pcs_commitment_key.commit(merged_table[idx]));
102 transcript->send_to_verifier("LEFT_TABLE_REVERSED_" + std::to_string(idx),
103 pcs_commitment_key.commit(left_table_reversed[idx]));
104 }
105
106 // Compute evaluation challenge
107 const FF kappa = transcript->template get_challenge<FF>("kappa");
108 const FF pow_kappa = kappa.pow(shift_size);
109 const FF kappa_inv = kappa.invert();
110
111 // Opening claims for each polynomial p_j, l_j, g_j
112 //
113 // The opening claims are sent in the following order:
114 // {kappa, 0}, {kappa, 0}, {kappa, 0}, {kappa, 0},
115 // {1/kappa, l_1(1/kappa)}, {kappa, g_1(kappa)},
116 // {1/kappa, l_2(1/kappa)}, {kappa, g_2(kappa)},
117 // {1/kappa, l_3(1/kappa)}, {kappa, g_3(kappa)},
118 // {1/kappa, l_4(1/kappa)}, {kappa, g_4(kappa)}
119 std::vector<OpeningClaim> opening_claims;
120
121 // Set opening claims p_j(\kappa) = l_j(X) + kappa^l r_j(X) - m_j(X)
122 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
123 Polynomial partially_evaluated_difference(merged_table_size);
124 partially_evaluated_difference += left_table[idx];
125 partially_evaluated_difference.add_scaled(right_table[idx], pow_kappa);
126 partially_evaluated_difference -= merged_table[idx];
127
128 opening_claims.emplace_back(OpeningClaim{ partially_evaluated_difference, { kappa, FF(0) } });
129 }
130 // Compute evaluation l_j(1/kappa), g_j(\kappa), send to verifier, and set opening claims
131 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
132 FF evaluation;
133
134 // Evaluate l_j(1/kappa)
135 evaluation = left_table[idx].evaluate(kappa_inv);
136 transcript->send_to_verifier("left_table_eval_kappa_inv_" + std::to_string(idx), evaluation);
137 opening_claims.emplace_back(OpeningClaim{ left_table[idx], { kappa_inv, evaluation } });
138
139 // Evaluate g_j(\kappa)
140 evaluation = left_table_reversed[idx].evaluate(kappa);
141 transcript->send_to_verifier("left_table_reversed_eval" + std::to_string(idx), evaluation);
142 opening_claims.emplace_back(OpeningClaim{ left_table_reversed[idx], { kappa, evaluation } });
143 }
144
145 // Shplonk prover
146 OpeningClaim shplonk_opening_claim = ShplonkProver_<Curve>::prove(pcs_commitment_key, opening_claims, transcript);
147
148 // KZG prover
150
151 return transcript->export_proof();
152}
153} // namespace bb
CommitmentKey object over a pairing group 𝔾₁.
Commitment commit(PolynomialSpan< const Fr > polynomial) const
Uses the ProverSRS to create a commitment to p(X)
bool initialized() const
Checks the commitment key is properly initialized.
static const size_t OP_QUEUE_SIZE
static void compute_opening_proof(const CK &ck, const ProverOpeningClaim< Curve > &opening_claim, const std::shared_ptr< Transcript > &prover_trancript)
Computes the KZG commitment to an opening proof polynomial at a single evaluation point.
Definition kzg.hpp:40
static constexpr size_t NUM_WIRES
Curve::ScalarField FF
std::shared_ptr< ECCOpQueue > op_queue
BB_PROFILE MergeProof construct_proof()
std::vector< FF > MergeProof
MergeSettings settings
ProverOpeningClaim< Curve > OpeningClaim
MergeProver(const std::shared_ptr< ECCOpQueue > &op_queue, const MergeSettings settings=MergeSettings::PREPEND, const CommitmentKey &commitment_key=CommitmentKey(), const std::shared_ptr< Transcript > &transcript=std::make_shared< Transcript >())
Create MergeProver.
std::shared_ptr< Transcript > transcript
CommitmentKey pcs_commitment_key
bb::CommitmentKey< Curve > CommitmentKey
static ProverOpeningClaim< Curve > prove(const CommitmentKey< Curve > &commitment_key, std::span< ProverOpeningClaim< Curve > > opening_claims, const std::shared_ptr< Transcript > &transcript, std::span< ProverOpeningClaim< Curve > > libra_opening_claims={}, std::span< ProverOpeningClaim< Curve > > sumcheck_round_claims={}, const size_t virtual_log_n=0)
Returns a batched opening claim equivalent to a set of opening claims consisting of polynomials,...
Definition shplonk.hpp:267
typename Flavor::Polynomial Polynomial
Entry point for Barretenberg command-line interface.
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)
BB_INLINE constexpr field pow(const uint256_t &exponent) const noexcept
constexpr field invert() const noexcept