-
Notifications
You must be signed in to change notification settings - Fork 130
fix: Ecdsa Malleability Bug #512
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -708,6 +708,53 @@ template <typename Composer> class stdlib_bigfield : public testing::Test { | |
| EXPECT_EQ(result, true); | ||
| } | ||
|
|
||
| static void test_assert_less_than_success() | ||
| { | ||
| auto composer = Composer(); | ||
| size_t num_repetitions = 10; | ||
| constexpr size_t num_bits = 200; | ||
| constexpr uint256_t bit_mask = (uint256_t(1) << num_bits) - 1; | ||
| for (size_t i = 0; i < num_repetitions; ++i) { | ||
|
|
||
| fq inputs[4]{ uint256_t(fq::random_element()) && bit_mask, | ||
| uint256_t(fq::random_element()) && bit_mask, | ||
| uint256_t(fq::random_element()) && bit_mask, | ||
| uint256_t(fq::random_element()) && bit_mask }; | ||
|
|
||
| fq_ct a(witness_ct(&composer, fr(uint256_t(inputs[0]).slice(0, fq_ct::NUM_LIMB_BITS * 2))), | ||
| witness_ct(&composer, | ||
| fr(uint256_t(inputs[0]).slice(fq_ct::NUM_LIMB_BITS * 2, fq_ct::NUM_LIMB_BITS * 4)))); | ||
| fq_ct b(witness_ct(&composer, fr(uint256_t(inputs[1]).slice(0, fq_ct::NUM_LIMB_BITS * 2))), | ||
| witness_ct(&composer, | ||
| fr(uint256_t(inputs[1]).slice(fq_ct::NUM_LIMB_BITS * 2, fq_ct::NUM_LIMB_BITS * 4)))); | ||
|
|
||
| fq_ct c = a; | ||
| fq expected = inputs[0]; | ||
| for (size_t i = 0; i < 16; ++i) { | ||
| c = b * b + c; | ||
| expected = inputs[1] * inputs[1] + expected; | ||
| } | ||
| // fq_ct c = a + a + a + a - b - b - b - b; | ||
| c.assert_less_than(bit_mask + 1); | ||
| uint256_t result = (c.get_value().lo); | ||
| EXPECT_EQ(result, uint256_t(expected)); | ||
| EXPECT_EQ(c.get_value().get_msb() < num_bits, true); | ||
| } | ||
| 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 commentThe 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 commentThe 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) |
||
| fq_ct a(witness_ct(&composer, fr(uint256_t(random_input).slice(0, fq_ct::NUM_LIMB_BITS * 2))), | ||
| witness_ct(&composer, | ||
| fr(uint256_t(random_input).slice(fq_ct::NUM_LIMB_BITS * 2, fq_ct::NUM_LIMB_BITS * 4)))); | ||
|
|
||
| a.assert_less_than(random_input + 1); | ||
| EXPECT_EQ(composer.check_circuit(), true); | ||
|
|
||
| a.assert_less_than(random_input); | ||
| EXPECT_EQ(composer.check_circuit(), false); | ||
| } | ||
|
|
||
| static void test_byte_array_constructors() | ||
| { | ||
| auto composer = Composer(); | ||
|
|
@@ -866,6 +913,10 @@ TYPED_TEST(stdlib_bigfield, assert_is_in_field_succes) | |
| { | ||
| TestFixture::test_assert_is_in_field_success(); | ||
| } | ||
| TYPED_TEST(stdlib_bigfield, assert_less_than_success) | ||
| { | ||
| TestFixture::test_assert_less_than_success(); | ||
| } | ||
| TYPED_TEST(stdlib_bigfield, byte_array_constructors) | ||
| { | ||
| TestFixture::test_byte_array_constructors(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.