tests: check that R or S overflow alone fails compact signature parsing #1997

pull nniiovoo wants to merge 1 commits into bitcoin-core:master from nniiovoo:tests-compact-sig-overflow changing 2 files +14 −0
  1. nniiovoo commented at 6:09 AM on November 14, 2026: none

    secp256k1_ecdsa_signature_parse_compact has to reject the signature if R or S is not below the group order. The only test for this sets all 64 bytes to 0xFF, so both overflow at once, and the test suite still passes if either of the two ret &= !overflow; lines is removed. secp256k1_ecdsa_recoverable_signature_parse_compact has the same gap for S, since its test only overflows R.

    This adds a case where only R is out of range and one where only S is, and the S case for the recoverable version.

  2. tests: check that R or S overflow alone fails compact signature parsing
    The only failing case for secp256k1_ecdsa_signature_parse_compact sets
    all 64 bytes to 0xFF, so both R and S overflow, and the tests still pass
    if either overflow check is removed. Add cases where only R or only S is
    not below the group order.
    
    The test for secp256k1_ecdsa_recoverable_signature_parse_compact only
    overflows R, so add the S case there too.
    b8902ff072
  3. fametrano commented at 6:16 PM on November 14, 2026: contributor

    ACK b8902ff07200a283430942cb3021082377ac604a

    Deleting any one of the four ret &= !overflow; lines in the two compact parsers now makes tests and noverify_tests abort (runs).

  4. theStack added the label assurance on Nov 15, 2026
  5. in src/modules/recovery/tests_impl.h:98 in b8902ff072
      91 | @@ -92,6 +92,10 @@ static void test_ecdsa_recovery_api_internal(void) {
      92 |      /* overflow in signature will not result in calling illegal_callback */
      93 |      memcpy(sig, over_privkey, 32);
      94 |      CHECK(secp256k1_ecdsa_recoverable_signature_parse_compact(CTX, &recsig, sig, recid) == 0);
      95 | +    /* Same if only S overflows */
      96 | +    memcpy(sig, privkey, 32);
      97 | +    memcpy(sig + 32, over_privkey, 32);
      98 | +    CHECK(secp256k1_ecdsa_recoverable_signature_parse_compact(CTX, &recsig, sig, recid) == 0);
    


    theStack commented at 12:42 AM on November 16, 2026:

    nit: could test with the exact boundary as well, e.g. by turning over_privkey into a pointer to _group_order_bytes, or simply replacing all existing and new instances

  6. theStack approved
  7. theStack commented at 12:42 AM on November 16, 2026: contributor

    ACK b8902ff07200a283430942cb3021082377ac604a

  8. real-or-random added the label tweak/refactor on Nov 16, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-24 04:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me