Conversation
Rumata888
left a comment
There was a problem hiding this comment.
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.
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.
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)
|
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 <isennovskiy@gmail.com>
Co-authored-by: Rumata888 <isennovskiy@gmail.com>
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/specshave been updated.@briefdescribing the intended functionality.