Skip to content
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

fe_sqr tests could be improved #1472

Closed
Coding-Enthusiast opened this issue Dec 24, 2023 · 5 comments
Closed

fe_sqr tests could be improved #1472

Coding-Enthusiast opened this issue Dec 24, 2023 · 5 comments

Comments

@Coding-Enthusiast
Copy link
Contributor

secp256k1/src/tests.c

Lines 3289 to 3303 in efe85c7

static void run_sqr(void) {
secp256k1_fe x, s;
{
int i;
secp256k1_fe_set_int(&x, 1);
secp256k1_fe_negate(&x, &x, 1);
for (i = 1; i <= 512; ++i) {
secp256k1_fe_mul_int(&x, 2);
secp256k1_fe_normalize(&x);
secp256k1_fe_sqr(&s, &x);
}
}
}

This method doesn't test anything and after looking through commits it was added in 59447da and got removed in the next commit 21f81a8. I'm not sure what the "problem" mentioned in the first commit is but if it is checking it using the SECP256K1_FE_VERIFY method, it is pointless to call run_sqr without this build configuration.

@real-or-random
Copy link
Contributor

it is pointless to call run_sqr without this build configuration.

Well, there's nothing wrong with it, except that it adds a few milliseconds to the noverify_tests. I claim that adding #ifdefs isn't worth the complexity and the development time. So this is not an issue.

The test itself could perhaps be improved. We could compare with the result of another method, e.g., fe_mul. We can't use fe_mul to compute x*x directly (see docs) but we could, e.g., check that (x+y)*(x-y) = x^2 - y^2 for some random values y != 0.

@real-or-random
Copy link
Contributor

@Coding-Enthusiast

we could, e.g., check that (x+y)*(x-y) = x^2 - y^2 for some random values y != 0.

Do you want to give it a try and work on a PR?

@real-or-random real-or-random changed the title run_sqr(void) in tests needs #ifdef VERIFY fe_sqr tests could be improved Jan 9, 2024
@Coding-Enthusiast
Copy link
Contributor Author

Sadly my C skills are readonly 😊

@real-or-random
Copy link
Contributor

We all started small... ;)

jonasnick added a commit that referenced this issue Feb 27, 2024
2028069 doc: clarify input requirements for secp256k1_fe_mul (Sebastian Falbesoner)
11420a7 tests: improve fe_sqr test (Sebastian Falbesoner)

Pull request description:

ACKs for top commit:
  real-or-random:
    utACK 2028069
  jonasnick:
    ACK 2028069

Tree-SHA512: bb01bf6ceb34f0475a60b8dcb0cec000859a0c20f1009426bd8cab609f1941f44f84802f1565a719f7d2a55466076fb1591a353b1b75e6c0ceac44806d908176
@real-or-random
Copy link
Contributor

This has been resolved by #1490.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants