tests: add exhaustive extrakeys tweak coverage #1836

pull mangoostaa wants to merge 1 commits into bitcoin-core:master from mangoostaa:add-exhaustive-tweak-tests-extrakeys changing 1 files +70 −1
  1. mangoostaa commented at 8:50 PM on March 12, 2026: none

    Motivation

    • Cover the previously-untested TODO in test_exhaustive_extrakeys to ensure x-only pubkey and keypair tweak APIs are exhaustively validated.
    • Validate success/failure behavior for every non-zero internal key and every tweak scalar in the exhaustive test group.
    • Ensure consistency between xonly_pubkey_tweak_add, xonly_pubkey_tweak_add_check, and keypair_xonly_tweak_add
      and detect edge cases (resulting infinity, parity/x-coordinate mismatches).

    Description

    Replaced the TODO in src/modules/extrakeys/tests_exhaustive_impl.h with nested loops that exercise every internal non-zero key and every tweak scalar and compute the expected resulting group element and parity. For each case the test exercises secp256k1_xonly_pubkey_tweak_add, secp256k1_keypair_xonly_tweak_add, secp256k1_xonly_pubkey_tweak_add_check, and verifies serialized compressed pubkey bytes and x-only serialization against the expected group point. Fixed test-side issues: call secp256k1_fe_get_b32 without wrapping in CHECK (avoids invalid use of EXPECT), normalize field elements before checking parity and exporting to bytes, reset serialized_pklen prior to reuse, and derive the keypair secret bytes via secp256k1_scalar_get_b32 for deterministic keypair creation in the exhaustive loop. All changes are contained in src/modules/extrakeys/tests_exhaustive_impl.h and only affect the exhaustive test code

  2. tests: add exhaustive extrakeys tweak coverage 61796cb68c
  3. real-or-random added the label assurance on Mar 13, 2026
  4. real-or-random added the label tweak/refactor on Mar 13, 2026
  5. real-or-random approved
  6. real-or-random commented at 9:00 AM on March 17, 2026: contributor

    ACK 61796cb68c574ac43a0fe749c9a8c0bae7387e7e

  7. in src/modules/extrakeys/tests_exhaustive_impl.h:65 in 61796cb68c
      61 | @@ -62,7 +62,76 @@ static void test_exhaustive_extrakeys(const secp256k1_context *ctx, const secp25
      62 |          }
      63 |      }
      64 |  
      65 | -    /* TODO: keypair/xonly_pubkey tweak tests */
      66 | +     /* Check keypair/xonly_pubkey tweak behavior over all non-zero tweaks. */
    


    theStack commented at 9:08 PM on April 9, 2026:

    whitespace nit:

        /* Check keypair/xonly_pubkey tweak behavior over all non-zero tweaks. */
    
  8. in src/modules/extrakeys/tests_exhaustive_impl.h:120 in 61796cb68c
     116 | +
     117 | +            CHECK(secp256k1_ec_pubkey_serialize(ctx, serialized_pk, &serialized_pklen, &tweaked_pk, SECP256K1_EC_COMPRESSED));
     118 | +            CHECK(serialized_pklen == sizeof(serialized_pk));
     119 | +            CHECK((serialized_pk[0] == SECP256K1_TAG_PUBKEY_EVEN) || (serialized_pk[0] == SECP256K1_TAG_PUBKEY_ODD));
     120 | +            CHECK(serialized_pk[0] == (expected_pk_parity ? SECP256K1_TAG_PUBKEY_ODD : SECP256K1_TAG_PUBKEY_EVEN));
     121 | +            CHECK(secp256k1_memcmp_var(&serialized_pk[1], expected_x, 32) == 0);
    


    theStack commented at 9:14 PM on April 9, 2026:

    nit (here and below): serializing is not strictly needed I think, one could alternatively do these checks on the internal types, i.e. by loading into a group element instance (via secp256k1_pubkey_load) first and then check its x/y field elements.

  9. theStack approved
  10. theStack commented at 9:14 PM on April 9, 2026: contributor

    ACK 61796cb68c574ac43a0fe749c9a8c0bae7387e7e


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-04-18 17:15 UTC

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