-
Notifications
You must be signed in to change notification settings - Fork 170
feat(tests): add p256 precompile edge case test #2079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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>
There was a problem hiding this 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!
There was a problem hiding this 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
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! Going to merge your PR just now and add these extra points in a follow up :D |
🗒️ Description
This PR adds an edge case test to the P256VERIFY precompile test suite that probes mathematical boundaries where implementations may fail.
Key addition:
near_field_boundary_p_minus_3
): Tests the maximum valid X coordinate (P-3) withcorresponding 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:
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
✅ Checklist
tox
checks to avoid unnecessary CI fails:uvx --with=tox-uv tox -e lint,typecheck,spellcheck,markdownlint
test(osaka): add critical p256 precompile edge case tests
Additional validation performed: