test: deduplicate scalar and field constants for n-1 and p-1 #1820

pull therohityadav wants to merge 1 commits into bitcoin-core:master from therohityadav:refactor-dedup-scalars changing 1 files +21 −21
  1. therohityadav commented at 4:37 am on February 5, 2026: contributor

    Following up on feedback from #1819, this PR deduplicates the hardcoded constants for the group order minus one (n-1) and the field prime minus one (p-1) within src/tests.c.

    Changes:

    • Defined scalar_n_m1 and fe_p_m1 as global static constants at the top of the file.
    • Replaced all hardcoded hex occurrences of these values in:
      • test_scalar_check_overflow
      • run_scalar_tests (HALF_TESTS)
      • scalar_cmov_test
      • scalar_cases and fe_cases arrays
      • Local scalar_minus_one and fe_minus_one definitions.
    • Verified that make check passes all tests.
  2. therohityadav force-pushed on Feb 5, 2026
  3. test: deduplicate scalar and field constants for n-1 and p-1 8c35adfd88
  4. therohityadav force-pushed on Feb 5, 2026
  5. real-or-random added the label assurance on Feb 5, 2026
  6. real-or-random added the label tweak/refactor on Feb 5, 2026
  7. real-or-random commented at 7:49 pm on February 6, 2026: contributor

    Concept ~0

    I’m not convinced this really improves readability or maintainability

  8. therohityadav commented at 5:11 am on February 7, 2026: contributor

    Concept ~0

    I’m not convinced this really improves readability or maintainability

    Thanks for the review @real-or-random.

    I understand the concern about readability . having explicit values in tests is often preferred.

    However, my idea here was to treat n-1 and p-1 as constants rather than arbitrary test vectors. By defining them in one place , we eliminate the risk of typos that could occur when these hex strings are repeated across the file. It ensures that every test checking these boundaries is mathematically guaranteed to be checking the same boundary.


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-02-16 20:15 UTC

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