Skip to content

Commit f8a5dbb

Browse files
committed
address Federico's comments
1 parent 1fcb613 commit f8a5dbb

3 files changed

Lines changed: 14 additions & 22 deletions

File tree

barretenberg/cpp/src/barretenberg/bbapi/bbapi_srs.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ SrsInitSrs::Response SrsInitSrs::execute(BB_UNUSED BBApiRequest& request) &&
3434
}
3535
});
3636
} else if (bytes_per_point == COMPRESSED_POINT_SIZE) {
37-
// Verify SHA-256 of every fully-present 4 MB chunk against the in-binary pin
38-
// BN254_G1_CHUNK_HASHES before decompression. This is the same defense as
39-
// verify_bn254_crs_integrity used by get_bn254_g1_data on the C++ download path; without
40-
// it, bb.js (which downloads g1_compressed.dat externally and forwards the bytes here)
41-
// would have no cryptographic gate against a tampered or wrong-trusted-setup payload.
42-
// Partial trailing data is not chunk-hash-verified — instead the post-parse generator and
43-
// tau·G checks below close the small-num_points gap.
37+
// Verify SHA-256 of every 4 MB chunk against the in-binary pin BN254_G1_CHUNK_HASHES.
38+
// Require chunk-aligned input so every byte is covered (no partial trailing chunk).
39+
if (points_buf.size() == 0 || points_buf.size() % bb::srs::SRS_CHUNK_SIZE_BYTES != 0) {
40+
throw_or_abort("SrsInitSrs: compressed points_buf size " + std::to_string(points_buf.size()) +
41+
" must be a positive multiple of " + std::to_string(bb::srs::SRS_CHUNK_SIZE_BYTES));
42+
}
4443
size_t num_full_chunks = points_buf.size() / bb::srs::SRS_CHUNK_SIZE_BYTES;
4544
size_t chunks_to_verify = std::min(num_full_chunks, static_cast<size_t>(bb::srs::SRS_NUM_FULL_CHUNKS));
4645
for (size_t i = 0; i < chunks_to_verify; ++i) {
@@ -72,10 +71,8 @@ SrsInitSrs::Response SrsInitSrs::execute(BB_UNUSED BBApiRequest& request) &&
7271
std::to_string(bytes_per_point));
7372
}
7473

75-
// Parsed-form sanity check that pins the first two G1 points to their canonical trusted-setup
76-
// values. Catches a wrong-SRS swap even when num_points is below one chunk (where the
77-
// compressed-chunk hash loop above has nothing to verify) and runs identically for the
78-
// uncompressed input path.
74+
// Pin the first two G1 points to their canonical trusted-setup values. Defense in depth on the
75+
// compressed path; the only gate on the uncompressed (cached) path.
7976
if (num_points >= 1 && g1_points[0] != bb::srs::BN254_G1_FIRST_ELEMENT) {
8077
throw_or_abort("SrsInitSrs: g1_points[0] is not the canonical BN254 generator");
8178
}

barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.test.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,11 @@ TYPED_TEST(TestAffineElement, AddAffine)
375375
TestFixture::test_add_affine();
376376
}
377377

378-
// Regression test for element +/- affine_element when the affine operand is the infinity sentinel
379-
// on the large-modulus path. The small-modulus path uses a different sentinel (MSB-of-x) and was
380-
// not affected.
378+
// Regression test for `element +/- affine_element` when the affine operand is the infinity sentinel.
379+
// Exercises both the large-modulus and small-modulus branches of `element::operator+=(affine)`.
381380
TYPED_TEST(TestAffineElement, MixedAddInfinityRegression)
382381
{
383-
if constexpr (TypeParam::Fq::modulus.data[3] >= MODULUS_TOP_LIMB_LARGE_THRESHOLD) {
384-
TestFixture::test_mixed_add_infinity_regression();
385-
} else {
386-
GTEST_SKIP();
387-
}
382+
TestFixture::test_mixed_add_infinity_regression();
388383
}
389384

390385
TYPED_TEST(TestAffineElement, ReadWrite)

barretenberg/cpp/src/barretenberg/ecc/groups/element_impl.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,9 @@ element<Fq, Fr, T> element<Fq, Fr, T>::mul_const_time(const Fr& scalar, numeric:
416416
// DPA: per-bit traces of two signings with the same k decorrelate because the bit pattern of k'
417417
// differs across calls.
418418
//
419-
// We force the high bit of r so that r is sampled uniformly from [2^63, 2^64). This guarantees
420-
// r * n has a fixed-width range (MSB at position M+63 or M+64 for n with MSB at M), so the
421-
// iteration count remains exactly NUM_BITS regardless of the sampled r.
419+
// We force the high bit of r to be 1 so that r is sampled uniformly from [2^63, 2^64). This
420+
// guarantees r * n has a fixed-width range (MSB at position M+63 or M+64 for n with MSB at M),
421+
// so the iteration count remains exactly NUM_BITS regardless of the sampled r.
422422
const uint64_t r = engine->get_random_uint64() | (UINT64_C(1) << 63);
423423
const uint512_t r_times_n = uint512_t(uint256_t(Fr::modulus)) * uint512_t(uint256_t(r));
424424
const uint512_t k_blinded = uint512_t(k) + r_times_n;

0 commit comments

Comments
 (0)