Skip to content

Commit f9431cd

Browse files
authored
feat: merge-train/barretenberg (#20511)
BEGIN_COMMIT_OVERRIDE chore!: pairing points audit (#20456) fix: default pp handling (#20516) chore: Address DSL audit comments (#20074) fix: skip default pp in sol aggregation (#20521) chore: address informational findings in biggroup (#20549) END_COMMIT_OVERRIDE
2 parents 4844401 + 4750714 commit f9431cd

36 files changed

+1686
-1331
lines changed

barretenberg/cpp/scripts/test_chonk_standalone_vks_havent_changed.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cd ..
1313
# - Generate a hash for versioning: sha256sum bb-chonk-inputs.tar.gz
1414
# - Upload the compressed results: aws s3 cp bb-chonk-inputs.tar.gz s3://aztec-ci-artifacts/protocol/bb-chonk-inputs-[hash(0:8)].tar.gz
1515
# Note: In case of the "Test suite failed to run ... Unexpected token 'with' " error, need to run: docker pull aztecprotocol/build:3.0
16-
pinned_short_hash="be87b42c"
16+
pinned_short_hash="600b85bd"
1717
pinned_chonk_inputs_url="https://aztec-ci-artifacts.s3.us-east-2.amazonaws.com/protocol/bb-chonk-inputs-${pinned_short_hash}.tar.gz"
1818

1919
script_path="$(cd "$(dirname "${BASH_SOURCE[0]}")/scripts" && pwd)/$(basename "${BASH_SOURCE[0]}")"

barretenberg/cpp/src/barretenberg/chonk/chonk.test.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,9 @@ class ChonkTests : public ::testing::Test {
160160
// Tamper with the specified field
161161
switch (field_to_tamper) {
162162
case KernelIOField::PAIRING_INPUTS: {
163-
// Replace with valid default pairing points (different from actual accumulated values)
164-
using namespace bb::stdlib::recursion;
165-
kernel_io.pairing_inputs.P0() = Commitment(DEFAULT_PAIRING_POINT_P0_X, DEFAULT_PAIRING_POINT_P0_Y);
166-
kernel_io.pairing_inputs.P1() = Commitment(DEFAULT_PAIRING_POINT_P1_X, DEFAULT_PAIRING_POINT_P1_Y);
163+
// Replace with valid pairing points at infinity (different from actual accumulated values)
164+
kernel_io.pairing_inputs.P0() = Commitment::infinity();
165+
kernel_io.pairing_inputs.P1() = Commitment::infinity();
167166
EXPECT_TRUE(kernel_io.pairing_inputs.check());
168167
break;
169168
}

barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class KZGTest : public CommitmentTest<Curve> {
4848
auto verifier_transcript = NativeTranscript::test_verifier_init_empty(prover_transcript);
4949
const auto pairing_points = PCS::reduce_verify(opening_claim, verifier_transcript);
5050

51-
EXPECT_EQ(vk.pairing_check(pairing_points[0], pairing_points[1]), true);
51+
EXPECT_EQ(pairing_points.check(), true);
5252
}
5353
};
5454

@@ -91,7 +91,7 @@ TEST_F(KZGTest, WrongEvaluationFails)
9191
auto verifier_transcript = NativeTranscript::test_verifier_init_empty(prover_transcript);
9292
auto pairing_point = PCS::reduce_verify(opening_claim, verifier_transcript);
9393
// Make sure that the pairing check fails
94-
EXPECT_EQ(vk.pairing_check(pairing_point[0], pairing_point[1]), false);
94+
EXPECT_EQ(pairing_point.check(), false);
9595
}
9696

9797
TEST_F(KZGTest, ZeroPolynomial)
@@ -169,7 +169,7 @@ TEST_F(KZGTest, SingleInLagrangeBasis)
169169
auto verifier_transcript = NativeTranscript::test_verifier_init_empty(prover_transcript);
170170
auto pairing_points = PCS::reduce_verify(opening_claim, verifier_transcript);
171171

172-
EXPECT_EQ(vk.pairing_check(pairing_points[0], pairing_points[1]), true);
172+
EXPECT_EQ(pairing_points.check(), true);
173173
}
174174
TEST_F(KZGTest, ShpleminiKzgWithShift)
175175
{
@@ -222,7 +222,7 @@ TEST_F(KZGTest, ShpleminiKzgWithShift)
222222
PCS::reduce_verify_batch_opening_claim(std::move(batch_opening_claim), verifier_transcript);
223223
// Final pairing check: e([Q] - [Q_z] + z[W], [1]_2) = e([W], [x]_2)
224224

225-
EXPECT_EQ(vk.pairing_check(pairing_points[0], pairing_points[1]), true);
225+
EXPECT_EQ(pairing_points.check(), true);
226226
}
227227

228228
TEST_F(KZGTest, ShpleminiKzgWithShiftAndInterleaving)
@@ -281,7 +281,7 @@ TEST_F(KZGTest, ShpleminiKzgWithShiftAndInterleaving)
281281
PCS::reduce_verify_batch_opening_claim(std::move(batch_opening_claim), verifier_transcript);
282282
// Final pairing check: e([Q] - [Q_z] + z[W], [1]_2) = e([W], [x]_2)
283283

284-
EXPECT_EQ(vk.pairing_check(pairing_points[0], pairing_points[1]), true);
284+
EXPECT_EQ(pairing_points.check(), true);
285285
}
286286
TEST_F(KZGTest, ShpleminiKzgShiftsRemoval)
287287
{
@@ -347,7 +347,7 @@ TEST_F(KZGTest, ShpleminiKzgShiftsRemoval)
347347
PCS::reduce_verify_batch_opening_claim(std::move(batch_opening_claim), verifier_transcript);
348348

349349
// Final pairing check: e([Q] - [Q_z] + z[W], [1]_2) = e([W], [x]_2)
350-
EXPECT_EQ(vk.pairing_check(pairing_points[0], pairing_points[1]), true);
350+
EXPECT_EQ(pairing_points.check(), true);
351351
}
352352

353353
} // namespace bb

barretenberg/cpp/src/barretenberg/commitment_schemes/pairing_points.hpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// === AUDIT STATUS ===
2-
// internal: { status: Planned, auditors: [Khashayar], commit: }
2+
// internal: { status: complete, auditors: [Luke], commit: }
33
// external_1: { status: not started, auditors: [], commit: }
44
// external_2: { status: not started, auditors: [], commit: }
55
// =====================
66

77
#pragma once
88

9-
#include "barretenberg/commitment_schemes/commitment_key.hpp"
109
#include "barretenberg/commitment_schemes/verification_key.hpp"
1110
#include "barretenberg/common/assert.hpp"
1211

@@ -22,7 +21,6 @@ namespace bb {
2221
template <typename Curve_> class PairingPoints {
2322
public:
2423
using Curve = Curve_;
25-
using CK = CommitmentKey<Curve>;
2624
using Point = typename Curve::AffineElement;
2725
using Fr = typename Curve::ScalarField;
2826
using Fq = typename Curve::BaseField;
@@ -34,8 +32,6 @@ template <typename Curve_> class PairingPoints {
3432
using value_type = Point;
3533
static constexpr size_t SIZE = 2;
3634

37-
std::array<Point, 2> _points = { Point::infinity(), Point::infinity() };
38-
3935
// Named accessors
4036
Point& P0() { return _points[0]; }
4137
Point& P1() { return _points[1]; }
@@ -47,9 +43,6 @@ template <typename Curve_> class PairingPoints {
4743
: _points{ p0, p1 }
4844
{}
4945

50-
auto& operator[](size_t idx) { return _points[idx]; }
51-
const auto& operator[](size_t idx) const { return _points[idx]; }
52-
5346
// Iterator support for range-based for (required by Codec)
5447
auto begin() { return _points.begin(); }
5548
auto end() { return _points.end(); }
@@ -58,32 +51,38 @@ template <typename Curve_> class PairingPoints {
5851
static constexpr size_t size() { return SIZE; }
5952

6053
/**
61-
* @brief Aggregate the current pairing points with another set of pairing points using a random scalar
54+
* @brief Aggregate the current pairing points with another set of pairing points using a random scalar.
55+
* @details If this is at infinity (default-constructed), simply copies other. The incoming points must not be at
56+
* infinity since they should always represent the output of actual PCS verification.
6257
*/
6358
void aggregate(const PairingPoints<Curve>& other)
6459
{
65-
if (P0() == Point::infinity() || P1() == Point::infinity() || other.P0() == Point::infinity() ||
66-
other.P1() == Point::infinity()) {
67-
throw_or_abort("WARNING: Shouldn't be aggregating with Point at infinity! The pairing points are probably "
68-
"uninitialized.");
60+
if (other.P0() == Point::infinity() || other.P1() == Point::infinity()) {
61+
throw_or_abort("Cannot aggregate: incoming pairing points are at infinity (probably uninitialized).");
62+
}
63+
// If this is at infinity (default/uninitialized), just adopt the incoming points
64+
if (P0() == Point::infinity() || P1() == Point::infinity()) {
65+
*this = other;
66+
return;
6967
}
7068
Fr aggregation_separator = Fr::random_element();
7169
P0() = P0() + other.P0() * aggregation_separator;
7270
P1() = P1() + other.P1() * aggregation_separator;
7371
}
7472

7573
/**
76-
* @brief Perform the pairing check
74+
* @brief Verify the pairing equation e(P0, [1]₂) · e(P1, [x]₂) = 1.
7775
*/
7876
bool check() const
7977
{
80-
VerifierCK pcs_vkey{};
78+
VerifierCK vck{};
8179
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1423): Rename to verifier_pcs_key or vckey or
8280
// something. Issue exists in many places besides just here.
83-
return pcs_vkey.pairing_check(P0(), P1());
81+
return vck.pairing_check(P0(), P1());
8482
}
8583

86-
bool operator==(const PairingPoints<Curve>& other) const = default;
84+
private:
85+
std::array<Point, 2> _points = { Point::infinity(), Point::infinity() };
8786
};
8887

8988
} // namespace bb
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include "barretenberg/commitment_schemes/pairing_points.hpp"
2+
#include "barretenberg/commitment_schemes/commitment_key.hpp"
3+
#include "barretenberg/srs/global_crs.hpp"
4+
5+
#include <gtest/gtest.h>
6+
7+
namespace bb {
8+
9+
class NativePairingPointsTests : public ::testing::Test {
10+
public:
11+
using Curve = curve::BN254;
12+
using PP = PairingPoints<Curve>;
13+
using Point = Curve::AffineElement;
14+
15+
static void SetUpTestSuite() { srs::init_file_crs_factory(srs::bb_crs_path()); }
16+
17+
// P0 = [s]₁, P1 = -[1]₁ satisfies e(P0,[1]₂)·e(P1,[s]₂) = 1
18+
static PP make_valid_pairing_points()
19+
{
20+
CommitmentKey<Curve> ck(2);
21+
auto srs = ck.get_monomial_points();
22+
return PP(srs[1], -srs[0]);
23+
}
24+
};
25+
26+
// Default construction produces infinity points
27+
TEST_F(NativePairingPointsTests, DefaultConstructionIsInfinity)
28+
{
29+
PP pp;
30+
EXPECT_EQ(pp.P0(), Point::infinity());
31+
EXPECT_EQ(pp.P1(), Point::infinity());
32+
}
33+
34+
// Infinity points pass the pairing check: e(∞, Q) = 1
35+
TEST_F(NativePairingPointsTests, InfinityPassesPairingCheck)
36+
{
37+
PP pp;
38+
EXPECT_TRUE(pp.check());
39+
}
40+
41+
// Valid SRS-derived points pass the pairing check
42+
TEST_F(NativePairingPointsTests, ValidPointsPassPairingCheck)
43+
{
44+
PP pp = make_valid_pairing_points();
45+
EXPECT_TRUE(pp.check());
46+
}
47+
48+
// Arbitrary non-trivial points fail the pairing check
49+
TEST_F(NativePairingPointsTests, InvalidPointsFailPairingCheck)
50+
{
51+
Point G = Point::one();
52+
PP pp(G, G);
53+
EXPECT_FALSE(pp.check());
54+
}
55+
56+
// Aggregating into default (infinity) adopts the incoming points
57+
TEST_F(NativePairingPointsTests, AggregateIntoDefaultAdoptsOther)
58+
{
59+
PP acc;
60+
PP other = make_valid_pairing_points();
61+
acc.aggregate(other);
62+
EXPECT_EQ(acc.P0(), other.P0());
63+
EXPECT_EQ(acc.P1(), other.P1());
64+
}
65+
66+
// Aggregating two populated sets produces a valid result
67+
TEST_F(NativePairingPointsTests, AggregatePopulatedPoints)
68+
{
69+
PP acc = make_valid_pairing_points();
70+
PP other = make_valid_pairing_points();
71+
acc.aggregate(other);
72+
EXPECT_TRUE(acc.check());
73+
}
74+
75+
// Aggregating infinity into a populated accumulator throws
76+
TEST_F(NativePairingPointsTests, AggregateInfinityIntoPopulatedThrows)
77+
{
78+
PP acc = make_valid_pairing_points();
79+
PP empty;
80+
EXPECT_THROW(acc.aggregate(empty), std::runtime_error);
81+
}
82+
83+
} // namespace bb

barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplemini.test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ TYPED_TEST(ShpleminiTest, ShpleminiZKNoSumcheckOpenings)
364364
const auto pairing_points =
365365
KZG<Curve>::reduce_verify_batch_opening_claim(std::move(batch_opening_claim), verifier_transcript);
366366
// Final pairing check: e([Q] - [Q_z] + z[W], [1]_2) = e([W], [x]_2)
367-
EXPECT_EQ(this->vk().pairing_check(pairing_points[0], pairing_points[1]), true);
367+
EXPECT_EQ(pairing_points.check(), true);
368368
}
369369
EXPECT_EQ(consistency_checked, true);
370370
}
@@ -473,7 +473,7 @@ TYPED_TEST(ShpleminiTest, ShpleminiZKWithSumcheckOpenings)
473473
const auto pairing_points =
474474
KZG<Curve>::reduce_verify_batch_opening_claim(std::move(batch_opening_claim), verifier_transcript);
475475
// Final pairing check: e([Q] - [Q_z] + z[W], [1]_2) = e([W], [x]_2)
476-
EXPECT_EQ(this->vk().pairing_check(pairing_points[0], pairing_points[1]), true);
476+
EXPECT_EQ(pairing_points.check(), true);
477477
}
478478
}
479479

@@ -548,7 +548,7 @@ TYPED_TEST(ShpleminiTest, HighDegreeAttackAccept)
548548
} else {
549549
const auto pairing_points =
550550
KZG<Curve>::reduce_verify_batch_opening_claim(std::move(batch_opening_claim), verifier_transcript);
551-
EXPECT_EQ(this->vk().pairing_check(pairing_points[0], pairing_points[1]), true);
551+
EXPECT_EQ(pairing_points.check(), true);
552552
}
553553
}
554554

@@ -615,7 +615,7 @@ TYPED_TEST(ShpleminiTest, HighDegreeAttackReject)
615615
} else {
616616
const auto pairing_points =
617617
KZG<Curve>::reduce_verify_batch_opening_claim(std::move(batch_opening_claim), verifier_transcript);
618-
EXPECT_EQ(this->vk().pairing_check(pairing_points[0], pairing_points[1]), false);
618+
EXPECT_EQ(pairing_points.check(), false);
619619
}
620620
}
621621

@@ -817,7 +817,7 @@ void run_libra_tampering_test(ShpleminiTest<TypeParam>* test,
817817
} else {
818818
const auto pairing_points =
819819
KZG<Curve>::reduce_verify_batch_opening_claim(std::move(batch_opening_claim), verifier_transcript);
820-
EXPECT_FALSE(test->vk().pairing_check(pairing_points[0], pairing_points[1]));
820+
EXPECT_FALSE(pairing_points.check());
821821
}
822822
}
823823

barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ TYPED_TEST(ShplonkTest, ExportBatchClaimAndVerify)
8585
// KZG verifier
8686
auto final_proof_points = KZG<curve::BN254>::reduce_verify_batch_opening_claim(
8787
std::move(batched_verifier_claim), verifier_transcript);
88-
ASSERT_TRUE(this->vk().pairing_check(final_proof_points[0], final_proof_points[1]));
88+
ASSERT_TRUE(final_proof_points.check());
8989
} else {
9090
// Verify IPA proof
9191
auto vk = create_verifier_commitment_key<VerifierCommitmentKey<curve::Grumpkin>>();

barretenberg/cpp/src/barretenberg/commitment_schemes/verification_key.hpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// === AUDIT STATUS ===
2-
// internal: { status: Planned, auditors: [Khashayar], commit: }
2+
// internal: { status: Complete, auditors: [Luke], commit: }
33
// external_1: { status: not started, auditors: [], commit: }
44
// external_2: { status: not started, auditors: [], commit: }
55
// =====================
@@ -11,18 +11,12 @@
1111
*
1212
*/
1313

14-
#include "barretenberg/commitment_schemes/commitment_key.hpp"
1514
#include "barretenberg/ecc/curves/bn254/bn254.hpp"
1615
#include "barretenberg/ecc/curves/bn254/pairing.hpp"
1716
#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"
18-
#include "barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp"
19-
#include "barretenberg/numeric/bitop/pow.hpp"
20-
#include "barretenberg/polynomials/polynomial_arithmetic.hpp"
2117
#include "barretenberg/srs/global_crs.hpp"
2218

23-
#include <cstddef>
2419
#include <memory>
25-
#include <string_view>
2620

2721
namespace bb {
2822

@@ -47,7 +41,6 @@ template <> class VerifierCommitmentKey<curve::BN254> {
4741
srs = srs::get_crs_factory<Curve>()->get_verifier_crs();
4842
}
4943
};
50-
bool operator==(const VerifierCommitmentKey&) const = default;
5144

5245
bool initialized() const { return srs != nullptr; }
5346

@@ -58,19 +51,14 @@ template <> class VerifierCommitmentKey<curve::BN254> {
5851
}
5952

6053
/**
61-
* @brief verifies a pairing equation over 2 points using the verifier SRS
62-
*
63-
* @param p0 = P₀
64-
* @param p1 = P₁
65-
* @return e(P₀,[1]₁)e(P₁,[x]₂) ≡ [1]ₜ
54+
* @brief Verify the pairing equation e(P₀,[1]₂) · e(P₁,[x]₂) = [1]ₜ
6655
*/
6756
bool pairing_check(const GroupElement& p0, const GroupElement& p1)
6857
{
6958
initialize();
70-
Commitment pairing_points[2]{ p0, p1 };
71-
// The final pairing check of step 12.
72-
Curve::TargetField result =
73-
bb::pairing::reduced_ate_pairing_batch_precomputed(pairing_points, srs->get_precomputed_g2_lines(), 2);
59+
std::array<Commitment, 2> pairing_points{ p0, p1 };
60+
Curve::TargetField result = bb::pairing::reduced_ate_pairing_batch_precomputed(
61+
pairing_points.data(), srs->get_precomputed_g2_lines(), 2);
7462

7563
return (result == Curve::TargetField::one());
7664
}
@@ -93,9 +81,8 @@ template <> class VerifierCommitmentKey<curve::Grumpkin> {
9381
/**
9482
* @brief Construct a new IPA Verification Key object from existing SRS
9583
*
96-
*
9784
* @param num_points specifies the length of the SRS
98-
* @param path is the location to the SRS file
85+
* @param crs_factory the CRS factory to use
9986
*/
10087
VerifierCommitmentKey(size_t num_points, const std::shared_ptr<bb::srs::factories::CrsFactory<Curve>>& crs_factory)
10188
: srs(crs_factory->get_crs(num_points))
@@ -105,8 +92,6 @@ template <> class VerifierCommitmentKey<curve::Grumpkin> {
10592

10693
VerifierCommitmentKey() = default;
10794

108-
bool operator==(const VerifierCommitmentKey&) const = default;
109-
11095
bool initialized() const { return srs != nullptr; }
11196

11297
Commitment get_g1_identity() const { return srs->get_g1_identity(); }

0 commit comments

Comments
 (0)