@@ -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 }
0 commit comments