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.
28 op_queue->merge(settings);
30 commitment_key.initialized() ? commitment_key : CommitmentKey(op_queue->get_ultra_ops_table_num_rows());
31};
32
63{
64
67 std::array<Polynomial, NUM_WIRES> merged_table = op_queue->construct_ultra_ops_table_columns(); // T
68 std::array<Polynomial, NUM_WIRES> left_table_reversed;
69
71 left_table = op_queue->construct_current_ultra_ops_subtable_columns(); // t
72 right_table = op_queue->construct_previous_ultra_ops_table_columns(); // T_prev
73 } else {
74 left_table = op_queue->construct_previous_ultra_ops_table_columns(); // T_prev
75 right_table = op_queue->construct_current_ultra_ops_subtable_columns(); // t
76 }
77 // Compute g_j(X)
78 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
79 left_table_reversed[idx] = left_table[idx].reverse();
80 }
81
82 const size_t merged_table_size = merged_table[0].size();
83
84 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1341): Once the op queue is fixed, we won't have to
85 // send the shift size in the append mode. This is desirable to ensure we don't reveal the number of ecc ops in a
86 // subtable when sending a merge proof to the rollup.
87 const size_t shift_size = left_table[0].size();
88 transcript->send_to_verifier("shift_size", static_cast<uint32_t>(shift_size));
89
90 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1473): remove generation of commitment to T_prev
91 // Compute commitments [T_prev], [m_j], [g_j], and send to the verifier
92 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
93 transcript->send_to_verifier("MERGED_TABLE_" + std::to_string(idx),
94 pcs_commitment_key.commit(merged_table[idx]));
95 transcript->send_to_verifier("LEFT_TABLE_REVERSED_" + std::to_string(idx),
96 pcs_commitment_key.commit(left_table_reversed[idx]));
97 }
98
99 // Compute evaluation challenge
100 const FF kappa = transcript->template get_challenge<FF>("kappa");
101 const FF pow_kappa = kappa.pow(shift_size);
102 const FF kappa_inv = kappa.invert();
103
104 // Opening claims for each polynomial p_j, l_j, g_j
105 //
106 // The opening claims are sent in the following order:
107 // {kappa, 0}, {kappa, 0}, {kappa, 0}, {kappa, 0},
108 // {1/kappa, l_1(1/kappa)}, {kappa, g_1(kappa)},
109 // {1/kappa, l_2(1/kappa)}, {kappa, g_2(kappa)},
110 // {1/kappa, l_3(1/kappa)}, {kappa, g_3(kappa)},
111 // {1/kappa, l_4(1/kappa)}, {kappa, g_4(kappa)}
112 std::vector<OpeningClaim> opening_claims;
113
114 // Set opening claims p_j(\kappa) = l_j(X) + kappa^l r_j(X) - m_j(X)
115 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
116 Polynomial partially_evaluated_difference(merged_table_size);
117 partially_evaluated_difference += left_table[idx];
118 partially_evaluated_difference.add_scaled(right_table[idx], pow_kappa);
119 partially_evaluated_difference -= merged_table[idx];
120
121 opening_claims.emplace_back(OpeningClaim{ partially_evaluated_difference, { kappa, FF(0) } });
122 }
123 // Compute evaluation l_j(1/kappa), g_j(\kappa), send to verifier, and set opening claims
124 for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
125 FF evaluation;
126
127 // Evaluate l_j(1/kappa)
128 evaluation = left_table[idx].evaluate(kappa_inv);
129 transcript->send_to_verifier("left_table_eval_kappa_inv_" + std::to_string(idx), evaluation);
130 opening_claims.emplace_back(OpeningClaim{ left_table[idx], { kappa_inv, evaluation } });
131
132 // Evaluate g_j(\kappa)
133 evaluation = left_table_reversed[idx].evaluate(kappa);
134 transcript->send_to_verifier("left_table_reversed_eval" + std::to_string(idx), evaluation);
135 opening_claims.emplace_back(OpeningClaim{ left_table_reversed[idx], { kappa, evaluation } });
136 }
137
138 // Shplonk prover
139 OpeningClaim shplonk_opening_claim = ShplonkProver_<Curve>::prove(pcs_commitment_key, opening_claims, transcript);
140
141 // KZG prover
143
144 return transcript->export_proof();
145}
146} // 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 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