Skip to content

Conversation

bshastry
Copy link
Contributor

@bshastry bshastry commented Aug 25, 2025

🗒️ Description

This PR adds an edge case test to the P256VERIFY precompile test suite that probes mathematical boundaries where implementations may fail.

Key addition:

  1. Near-field boundary test (near_field_boundary_p_minus_3): Tests the maximum valid X coordinate (P-3) with
    corresponding edge values for signature components R=(N-2) and S=(N-1)/2. This ensures proper handling of field arithmetic at mathematical boundaries.

Why these tests matter:

  • X = P-3: The largest X coordinate with a valid point on the P256 curve (P-2 has no valid Y due to quadratic non-residue)
  • R = N-2: Tests near-maximum signature component handling
  • S = (N-1)/2: Tests the malleability boundary where S equals its complement
  • H = P-1: Tests maximum hash value and proper modular reduction

These synthetic test vectors are designed to fail signature verification while passing all input validation, ensuring
implementations correctly handle extreme but mathematically valid inputs without overflow or consensus divergence.

🔗 Related Issues or PRs

  • Related to EIP-7951 P256VERIFY precompile test coverage enhancement
  • Builds upon existing P256 test suite

✅ Checklist

  • All: Ran fast tox checks to avoid unnecessary CI fails:
    uvx --with=tox-uv tox -e lint,typecheck,spellcheck,markdownlint
  • All: PR title adheres to the repo standard
    • Suggested title: test(osaka): add critical p256 precompile edge case tests
  • All: Considered adding an entry to CHANGELOG.md
  • Tests: Verified test integration with existing suite

Additional validation performed:

  • Test fixtures generated successfully: All 975 tests pass

bshastry and others added 4 commits August 25, 2025 14:14
Add two critical test cases for EIP-7951 p256verify precompile that commonly
surface through fuzzing:

1. Near-field boundary modular reduction test
   - Tests values at P-1, P-2, N-1, N-2 boundaries
   - Exercises modular reduction edge cases
   - Catches off-by-one errors in field arithmetic
   - Tests carry propagation in multi-precision arithmetic

2. Scalar multiplication special bit pattern test
   - Tests edge cases with single high bit set (0x8000...)
   - Tests alternating bit patterns (0x5555...)
   - Exercises rarely-tested code paths in scalar multiplication
   - Can expose timing variations in implementations

These tests complement existing Wycheproof vectors by focusing on
implementation-specific arithmetic edge cases rather than purely
cryptographic validity, making them valuable for catching subtle
bugs in client implementations.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@spencer-tb spencer-tb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently running a sage script to get the largest valid Y. Using the same approach for X I get the same result as you here.

Approved from my side. Thanks for the find!

Copy link
Contributor

@kevaundray kevaundray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to have this test too

@bshastry
Copy link
Contributor Author

bshastry commented Aug 25, 2025

Currently running a sage script to get the largest valid Y. Using the same approach for X I get the same result as you here.

Approved from my side. Thanks for the find!

Thank you. Do you mind sharing the sage script you used if it's not sensitive?

@spencer-tb
Copy link
Contributor

spencer-tb commented Aug 26, 2025

Currently running a sage script to get the largest valid Y. Using the same approach for X I get the same result as you here.
Approved from my side. Thanks for the find!

Thank you. Do you mind sharing the sage script you used if it's not sensitive?

Still working on it but this is what I have so far!
https://gist.github.com/spencer-tb/0fb46447fa456c3075cd1bf87a8ce3d0

Going to merge your PR just now and add these extra points in a follow up :D

@spencer-tb spencer-tb added scope:tests Scope: Changes EL client test cases in `./tests` fork:osaka Osaka hardfork feature:eof labels Aug 26, 2025
@spencer-tb spencer-tb changed the title test(osaka): add p256 precompile edge case test feat(tests): add p256 precompile edge case test Aug 26, 2025
@spencer-tb spencer-tb merged commit 71ec8cb into ethereum:main Aug 26, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:eof fork:osaka Osaka hardfork scope:tests Scope: Changes EL client test cases in `./tests`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants