Skip to content

test: refactor: simplify tests by using _ecmult_gen_ge helper, add test#1864

Merged
real-or-random merged 2 commits into
bitcoin-core:masterfrom
theStack:test-dedup-using-ecmult_gen_ge-helper
Jun 12, 2026
Merged

test: refactor: simplify tests by using _ecmult_gen_ge helper, add test#1864
real-or-random merged 2 commits into
bitcoin-core:masterfrom
theStack:test-dedup-using-ecmult_gen_ge-helper

Conversation

@theStack

@theStack theStack commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

This PR is a small follow-up to #1861. If the generator point multiplication result in Jacobian coordinates is immediately converted to affine coordinates after and is not needed for anything else, we can deduplicate by using the new secp256k1_ecmult_gen_ge helper. The second commit adds a simple unit tests, verifying for random scalars that the result of secp256k1_ecmult_gen_ge matches the two expected steps (secp256k1_ecmult_gen_gej plus Jacobian->affine conersion via secp256k1_ge_set_gej).

Note that in a very strict sense the first commit is not a refactor, as the Jacobian object is now cleared out which was not done on master, but for the logic in the tests this shouldn't matter at all.

If the generator point multiplication result in Jacobian coordinates is
immediately converted to affine coordinates after and is not needed for
anything else, we can deduplicate by using the helper introduced in bitcoin-core#1861.

Note that in a very strict sense this is not a refactor, as the Jacobian
object is now cleared out which was not done on master, but for the logic
in the tests this shouldn't matter at all.

@real-or-random real-or-random left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Maybe secp256k1_ecmult_gen_ge should itself get a dedicated test

@theStack

theStack commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Maybe secp256k1_ecmult_gen_ge should itself get a dedicated test

Makes sense, added one. I decided to run the loop COUNT times... that's maybe a bit exaggerated, but it isn't noticeable in the runtime (tested two $ time SECP256K1_TEST_ITERS=1000 ./build/bin/tests -t=ecmult runs with and without the new test, and they both took about ~90 seconds on my machine).

@theStack theStack changed the title test: refactor: simplify tests by using _ecmult_gen_ge helper test: refactor: simplify tests by using _ecmult_gen_ge helper, add test Jun 9, 2026

@real-or-random real-or-random left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK bb51480

Copilot AI left a comment

Copy link
Copy Markdown

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 updates the test suite to use the new secp256k1_ecmult_gen_ge helper where generator scalar multiplication results are immediately needed in affine coordinates, and adds a unit test to confirm secp256k1_ecmult_gen_ge matches the gej-plus-conversion path.

Changes:

  • Replace secp256k1_ecmult_gen_gej + secp256k1_ge_set_gej sequences in tests with secp256k1_ecmult_gen_ge.
  • Add a new run_ecmult_gen_ge test that compares secp256k1_ecmult_gen_ge output to the manual gej -> ge conversion over random scalars.
  • Update exhaustive tests to use the affine helper directly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/tests.c Refactors generator-multiply test callsites to secp256k1_ecmult_gen_ge and adds a new unit test for the helper.
src/tests_exhaustive.c Simplifies the exhaustive ecmult_gen verification by using secp256k1_ecmult_gen_ge directly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/tests.c Outdated
Comment thread src/tests.c
@theStack theStack force-pushed the test-dedup-using-ecmult_gen_ge-helper branch from bb51480 to 2ee79e7 Compare June 11, 2026 15:57

@real-or-random real-or-random left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 2ee79e7

@real-or-random real-or-random merged commit aea86bc into bitcoin-core:master Jun 12, 2026
122 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants