-
Notifications
You must be signed in to change notification settings - Fork 221
Feat/sig bounds #725
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
base: master
Are you sure you want to change the base?
Feat/sig bounds #725
Conversation
🚨 Bugbot Trial ExpiredYour team's Bugbot trial has expired. Please contact your team administrator to turn on the paid plan to continue using Bugbot. A team admin can activate the plan in the Cursor dashboard. |
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.
Pull Request Overview
This PR implements ECDSA signature malleability protection by enforcing the constraint s < r/2, which prevents signature malleability attacks where an adversary can create a second valid signature for the same message by negating the s component.
- Updated error messages and validation logic to check
s > r_mod/2instead ofs >= r_mod - Modified signing functions to ensure generated signatures satisfy
s < r/2 - Added verification checks to reject signatures with
s > r/2
Reviewed Changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/generator/ecdsa/template/marshal.go.tmpl | Template for signature validation - updated to check s > r_mod/2 |
| internal/generator/ecdsa/template/ecdsa.test.go.tmpl | Template for malleability tests - updated test expectations |
| internal/generator/ecdsa/template/ecdsa.go.tmpl | Template for signing/verification - added s < r/2 enforcement |
| ecc/*/ecdsa/marshal.go | Generated files with updated validation logic |
| ecc/*/ecdsa/ecdsa_test.go | Generated test files with updated expectations |
| ecc/*/ecdsa/ecdsa.go | Generated signing/verification with malleability protection |
Comments suppressed due to low confidence (1)
internal/generator/ecdsa/template/ecdsa.go.tmpl:152
- Using 'order' variable which may not be defined in this context. Should use 'frMod' instead to be consistent with the existing validation logic.
y = y.Sub(fp.Modulus(), y)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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.
LGTM!
Although I need to see how it affects gnark gadgets. I think in some tests we are trying to generate signature with large s. I'll see how to resolve that. Lets wait with merge until it is confirmed.
a45dd40 to
a5d1e2d
Compare
Description
Ensures s < r/2 in ecdsa
Type of change
Please delete options that are not relevant.
How has this been tested?
See test suite ECDSA
Checklist:
golangci-lintdoes not output errors locallyNote
Enforces s <= (order-1)/2 across ECDSA sign/verify/serialization for all supported curves, updates errors/tests, and enhances docs/comments (SEC 1, BIP-62).
Signoutputs canonical signatures by normalizingsto<= (order-1)/2.Verify, reject non-canonical signatures witherrSBiggerThanHalfRMod.SetBytes):sbounds check from< orderto<= (order-1)/2; introduceerrSBiggerThanHalfRMod.s <= (order-1)/2; setvinitialization explicitly.errSBiggerThanHalfRModand adjustS_overflowconstruction.senforcement, verify checks, error names, comments, and tests across generator templates.Written by Cursor Bugbot for commit 5116cf4. This will update automatically on new commits. Configure here.