-
Notifications
You must be signed in to change notification settings - Fork 102
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
fix: Ecdsa Malleability Bug #512
Conversation
cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield_impl.hpp
Outdated
Show resolved
Hide resolved
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've made two changes:
- The function was actually less or equal.
- Once I changed it to be less_than, the logic for constraining s became incorrect. You were checking that s < (Fr::modulus / 2). It is different from 2*s < Fr::modulus, because Fr::modulus is odd. Think mod 3. If you check that something is less than 3/2, then the only option is zero, while 1 should also be a legitimate value.
bool result = composer.check_circuit(); | ||
EXPECT_EQ(result, true); | ||
// Checking edge conditions | ||
fq random_input = fq::random_element(); |
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.
nit, but not a blocker: unit tests should ideally not contain random elements as they then become unreproducable
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.
You are partially right. I'd add something like "random_element_for_test" into the field, so that it would automatically print it. But it is actually better to have random elements than static, because if there is a bug there is a chance that it triggers. And then you can stress the test to find it (that was the case with construct_addition_chains)
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.
Looks good to me
Since this modifies the stdlib by adding extra constraints, I'm marking this a breaking change |
Update: It was decided that changes to the stdlib will not be marked as breaking changes as this would include most commits |
f72d2ca
to
c189a14
Compare
Nice catch, thanks Kesha! |
Co-authored-by: Rumata888 <[email protected]>
Co-authored-by: Rumata888 <[email protected]>
Description
ECDSA has an inherent malleability because of the way$s$ in an ECDSA signature is computed. Read more about this here. This PR adds the constraint $s < |Fr|/2$ in ECDSA verification to fix the malleability. Additionally, in the signature construction, we make sure that $s < |Fr|/2$ .
Acknowledgements: @Rumata888 corrected the constraint on$s$ in verification.
Checklist:
/markdown/specs
have been updated.@brief
describing the intended functionality.