Commit Graph

430 Commits

Author SHA1 Message Date
mllwchrry
799a27c813 ecdsa_adaptor: Check for infinity in secp256k1_dleq_verify 2026-03-03 17:33:57 +02:00
mllwchrry
fe48cc9fa5 generator: Port bitcoin-core/secp256k1#1764 to zkp-specific code 2026-03-03 13:08:07 +02:00
mllwchrry
d111d31293 generator: Port bitcoin-core/secp256k1#1779 to zkp-specific code 2026-03-03 13:08:07 +02:00
mllwchrry
2542b43451 modules: Port bitcoin-core/secp256k1#1774 to zkp-specific code 2026-03-03 13:07:59 +02:00
mllwchrry
07d4de6433 Merge commits '115b135f c8206b1c b6c2a3cd e7f7083b be5e4f02 5c751833 540fec8a aa2a39c1 8d445730 f9a944ff 2d9137ce 4721e077 471e3a13 ebb35882 1a53f496 c7a52400 ' into temp-merge-1809 2026-03-02 15:56:43 +02:00
mllwchrry
3f7a9429ad ecdsa_adaptor: batch affine conversion in dleq_pair and dleq_prove 2026-03-02 12:41:51 +02:00
mllwchrry
d380549e38 ecdsa_adaptor: optimize encrypt with batch affine conversion 2026-03-02 12:33:12 +02:00
DarkWindman
7111d365fb modules, tests: Port bitcoin-core/secp256k1#1734 to zkp-specific code 2026-02-27 14:47:59 +02:00
DarkWindman
7699fe9aa6 modules: Port bitcoin-core/secp256k1#1735 to zkp-specific code 2026-02-27 14:47:59 +02:00
DarkWindman
f1e52fac20 Merge commits '88be4e8d b4756543 10dab907 58178851 de6af6ae baa26542 2b7337f6 a44a3393 f44c1ebd d543c0d9 43e7b115 7a2fff85 ' into temp-merge-1758 2026-02-27 14:47:34 +02:00
DarkWindman
01b1b916eb modules: Port bitcoin-core/secp256k1#1725 to zkp-specific code 2026-02-25 13:16:24 +02:00
DarkWindman
38284aa008 Merge commits '2c076d90 20e3b447 74b8068c e523e4f9 d5997141 d2dcf520 f36afb8b 8113671f d93380fb 03fb60ad 4985ac0f 36e76952 ' into temp-merge-1738 2026-02-25 10:44:34 +02:00
mllwchrry
9dcd857d54 Merge commits '29e73f4b 89096c23 c4987790 ad60ef7e 943479a7 cbbbf3bd 73a69595 7c338042 5e74086d 6037833c 020ee604 a660a497 b9313c6e ' into temp-merge-1708 2026-02-24 13:31:44 +02:00
DarkWindman
cc4a92b510 Merge commits '70f149b9 13906b71 4187a466 bb597b3d 9fab4252 92394476 201b2b8f f24b838b 95db29b1 2a9d3747 a28c2ffa 746e36b1 ' into temp-merge-1678 2026-02-23 18:07:05 +02:00
mllwchrry
17ad196018 schnorrsig_halfagg: Fix symbol visibility for internal function 2026-02-20 18:50:53 +02:00
mllwchrry
ec343f0b2f Port bitcoin-core/secp256k1#1642 to zkp-specific code 2026-02-20 18:41:10 +02:00
mllwchrry
79953d074b Merge commits '1b1fc093 6c2a39da 31860823 abd25054 4ba1ba2a 03bbe8c6 13ed6f65 a7a51171 2abb35b0 e56716a3 3f54ed8c d84bb83e ' into temp-merge-1661 2026-02-20 18:29:53 +02:00
DarkWindman
e3bddfa750 modules: Port bitcoin-core/secp256k1#1579 to zkp-specific code 2026-02-19 10:24:07 +02:00
DarkWindman
913be29ea2 Merge commits 'b161bffb 0cdc758a ec329c25 8deef00b f79f46c7 00774d07 2e3bf136 c0d9480f ' into temp-merge-1654 2026-02-18 15:57:18 +02:00
mllwchrry
347d6adfd2 Merge commits 'a88aa935 01b58933 18f9b967 e59158b6 1fae76f5 f0868a9b 68b55209 9b7c59cb 1464f15c 9a8db52f 7d48f5ed a38d879a ' into temp-merge-1628 2026-02-16 16:04:51 +02:00
mllwchrry
8d443b8030 musig: Re-add adaptor signatures support 2026-02-13 15:07:52 +02:00
mllwchrry
248358f2bc Merge commit '3660fe5e' into temp-merge-1479 2026-02-13 13:08:00 +02:00
mllwchrry
21c24fdc7a musig: Remove module in preparation for upstream merge 2026-02-13 11:36:52 +02:00
mllwchrry
513e550e8a Merge commits '4392f0f7 ' into temp-merge-1533 2026-02-09 13:10:17 +02:00
DarkWindman
2cb2e312e9 extrakeys: Migrate to bitcoin-core/secp256k1#1518 secp256k1_ec_pubkey_sort 2026-02-05 19:02:49 +02:00
mllwchrry
8c72644a0e Merge commits '5ad3aa3 2483627 0653a25 d926510 cdc9a62 427e86b 05bfab6 4b77fec d831168 ' into temp-merge-1515 2026-01-23 19:51:09 +02:00
merge-script
8d445730ec Merge bitcoin-core/secp256k1#1783: Add VERIFY_CHECKs and documentation that flags must be 0 or 1
ae00c552df Add VERIFY_CHECKs that flags are 0 or 1 (John Moffett)

Pull request description:

  Flags for constant-time masking rely on the values being exactly `0` or `1` rather than `0` or true (any nonzero). One function, `secp256k1_fe_cmov` [documents](e7f7083b53/src/field.h (L315)) and [`VERIFY_CHECK`s](e7f7083b53/src/field_impl.h (L365)) this, but most don't.

  This updates the documentation and adds `VERIFY_CHECK`s enforcing `flag == 0 || flag == 1` for:

  `secp256k1_fe_storage_cmov`
  `secp256k1_gej_cmov`
  `secp256k1_ge_storage_cmov`
  `secp256k1_scalar_cadd_bit`
  `secp256k1_scalar_cond_negate`
  `secp256k1_scalar_cmov`
  `secp256k1_int_cmov`

ACKs for top commit:
  furszy:
    ACK ae00c55
  hebasto:
    re-ACK ae00c552df.

Tree-SHA512: c9d358929d39d93b0aea602d318429f7e82af96bf601f048a1cdeb0621b8adc6d1204648d352aa2060cb0f63db6dcf0da863854375ed313cea44dfad61c19a18
2025-12-15 20:43:58 +01:00
furszy
d822b29021 test: split monolithic ellswift test into independent cases
No behavior changes.

Refactors the previously monolithic ElligatorSwift test into isolated,
independent test cases. Doing so allows the test suite to execute
these cases in parallel rather than sequentially.

Overall, seen 35-40% tests time reduction locally.

This is quite useful for the Debug build with no optimizations,
which is noticeably slow.

#### Local Debug-build Results (7 jobs):

- master: 138.0 seconds.
- this PR: 89.3 seconds.
   (~1.55× speedup, ~35% reduction)

#### Local Release-build Results (7 jobs):

- master: 9.5 seconds.
- this PR: 5.9 seconds.
   (~1.61× speedup, ~38% reduction)
2025-12-15 09:28:28 -05:00
John Moffett
ae00c552df Add VERIFY_CHECKs that flags are 0 or 1
Flags for constant-time masking rely
on the values being exactly 0 or 1 rather
than 0 or true. Add VERIFY_CHECKs to enforce
in VERIFY builds as a preventative
measure and add documentation where relevant.
2025-12-15 09:07:42 -05:00
Sebastian Falbesoner
8bcda186d2 test: Add non-NULL checks for "pointer of array" API functions 2025-12-09 01:38:48 +01:00
Sebastian Falbesoner
5a08c1bcdc Add ARG_CHECKs to ensure "array of pointers" elements are non-NULL 2025-12-06 01:13:58 +01:00
Sebastian Falbesoner
0d3659c547 use new _eckey_pubkey_serialize{33,65} functions in modules (ellswift,musig) 2025-11-17 18:13:56 +01:00
merge-script
d543c0d917 Merge bitcoin-core/secp256k1#1734: Introduce (mini) unit test framework
2f4546ce56 test: add --log option to display tests execution (furszy)
95b9953ea4 test: Add option to display all available tests (furszy)
953f7b0088 test: support running specific tests/modules targets (furszy)
0302c1a3d7 test: add --help for command-line options (furszy)
9ec3bfe22d test: adapt modules to the new test infrastructure (furszy)
48789dafc2 test: introduce (mini) unit test framework (furszy)
9cce703863 refactor: move 'gettime_i64()' to tests_common.h (furszy)

Pull request description:

  Early Note:
  Don’t be scared by the PR’s line changes count — most of it’s just doc or part of the test framework API.

  Context:
  Currently, all tests run single-threaded sequentially and the library lacks the ability to specify which test (or group of tests) you would like to run. This is not only inconvenient as more tests are added but also time consuming during development and affects downstream projects that may want to parallelize the workload (such as Bitcoin-Core CI).

  PR Goal:
  Introduce a lightweight, extensible C89 unit test framework with no dynamic memory allocations, providing a structured way to register, execute, and report tests. The framework supports named command-line arguments in `-key=value` form, parallel test execution across multiple worker processes, granular test selection (selecting tests either by name or by module name), and time accumulation reports.

  The introduced framework supports:
  * `-help` or `-h`: display list of available commands along with their descriptions.
  * `-jobs=<num>`: distribute tests across multiple worker processes (default: sequential if 0).
  * `-target=<name>` or `-t=<name>`: run only specific tests by name; can be repeated to select multiple tests.
  *  `-target=<module name>`, `-t=<module>`  Run all tests within a specific module (can be provided multiple times)
  * `-seed=<hex>`: set a specific RNG seed (defaults to random if unspecified).
  * `-iterations=<n>`: specify the number of iterations.
  * `-list_tests`:   display list of available tests and modules you can run.
  * `-log=<0|1>`: enable or disable test execution logging (default: 0 = disabled).

  Beyond these features, the idea is to also make future developments smoother, as adding new tests require only a single entry in the central test registry, and new command-line options can be introduced easily by extending the framework’s `parse_arg()` function.

  Compatibility Note:
  The framework continues accepting the two positional arguments previously supported (iterations and seed), ensuring existing workflows remain intact.

  Testing Notes:
  Have fun. You can quickly try it through `./tests -j=<workers_num>` for parallel execution  or `./tests -t=<test_name>` to run a specific test (call `./tests -print_tests` to display all available tests and modules).

  Extra Note:
  I haven't checked the exhaustive tests file so far, but I will soon. For now, this only runs all tests declared in the `tests` binary.

  Testing Results: (Current master branch vs PR in seconds)

  * Raspberry Pi 5: master \~100 s → PR \~38 s (5 jobs)
  * MacBook Pro M1: master \~30 s → PR \~10 s (6 jobs)

ACKs for top commit:
  theStack:
    re-ACK 2f4546ce56
  real-or-random:
    ACK 2f4546ce56
  hebasto:
    ACK 2f4546ce56.

Tree-SHA512: 85ca2cbb620b84b35b353d5d4cf093c388fc3851ca405eeb0e458f8fa72b60534bccd357c7edabf8fc9aa93d9ad0a6fbac3dd5c4d5f9dfdf4d8701a9834755b9
2025-10-15 08:37:23 +02:00
furszy
9ec3bfe22d test: adapt modules to the new test infrastructure
This not only provides a structural improvement but also
allows us to (1) specify individual tests to run and (2)
execute each of them concurrently.
2025-10-01 10:17:57 -04:00
Sebastian Falbesoner
dfe284ed2d bench: improve context creation in ECDH benchmark
Calling `secp256k1_context_create` with `SECP256K1_FLAGS_TYPE_CONTEXT`
seems to be not strictly API-compliant, as the only allowed
(non-deprecated) value is `SECP256K1_CONTEXT_NONE`, even if the
former happens to map to the latter currently.

Fix this by not dynamically creating a context in the first place and
switch to using the static context, as it is sufficient for this
benchmark and presumably matches what the "no capabilities" comment
intended back then.
2025-09-16 23:17:08 +02:00
Sebastian Falbesoner
0c91c56041 test: introduce group order byte-array constant for deduplication 2025-09-12 15:52:43 +02:00
Jonas Nick
53fd89b635 musig/tests: initialize keypair
The keypair is unused in musig_partial_sign, but clang-snapshot gives a compiler
warning anyway.
2025-09-09 21:56:00 +05:30
Tim Ruffing
40bd8549dd musig/test: Remove dead code
This avoids a compiler warning on clang-snapshot about &keypair being uninitialized.

(cherry picked from commit 8d967a602b)
2025-09-09 21:55:51 +05:30
BEULAHEVANJALIN
c4570307ec test/fix: refactor unterminated string initializers to brace arrays
- Mirror upstream fix (bitcoin-core/secp256k1 fa67b675)
- Convert tags, test vectors, and constants in -zkp-only modules (ecdsa_adaptor, ecdsa_s2c, musig, bppp, rangeproof, schnorrsig_halfagg)
- Avoid -Wunterminated-string-initialization without changing behavior
2025-09-09 21:55:17 +05:30
MarcoFalke
654a8c327c refactor: Use array initialization for unterminated strings
The previous code is correct and harmless to initialize an array with a
non-terminated character sequence using a string literal.

However, it requires exactly specifying the array size, which can be
cumbersome.

Also, GCC-15 may issue the -Wunterminated-string-initialization warning.
[1]

Fix both issues by using array initialization. This refactoring commit
does not change behavior.

[1] Example warning:

src/modules/schnorrsig/main_impl.h:48:46: error: initializer-string for array of 'unsigned char' is too long [-Werror=unterminated-string-initialization]
   48 | static const unsigned char bip340_algo[13] = "BIP0340/nonce";
      |                                              ^~~~~~~~~~~~~~~

(cherry picked from commit fa67b6752d)

Conflicts:
	src/testrand_impl.h (kept local name `secp256k1_testrand_seed`)
2025-09-09 21:47:12 +05:30
Jonas Nick
83d0fa25a8 extrakeys: fix pubkey_sort_cmp test
Instead of providing CTX directly, pass a cmp_data object containing CTX.
Otherwise, memory sanitizer fails with "use-of-uninitialized-value".
2025-09-08 19:18:39 +00:00
John Moffett
399b582a5f Split memclear into two versions
secp256k1_memclear has the side effect of undefining bytes for
valgrind checks. In some cases, we may want to zero bytes
but allow subsequent reads. So we split memclear into
memclear_explicit, which makes no guarantees about the content
of the buffer on return, and memzero_explicit, which guarantees
zero value on return.

Change the memset in partial_sign to use memzero_explicit.
2025-09-08 12:26:04 -04:00
John Moffett
325d65a8cf Rename and clear var containing k or -k
buf currently holds k or -k and isn't cleared, so clear it and rename to
nonce32 to clarify its sensitivity and match how it is named in the
corresponding ECDSA sign_inner.
2025-09-02 12:40:35 -04:00
josibake
5153cf1c91 tests: refactor tagged hash tests
Move the sha256_tag_test_internal function out of the musig module
into tests.c. This makes it available to other modules wishing to verify tagged
hashes without needing to duplicate the function.

Change the function signature to expect a const unsigned char and update
the tagged hash tests to use static const unsigned char character
arrays (where necessary).

Add a comment for each tag. This is done as a convenience for checking
the strings against the protocol specifications, where the tags are
normally specified as strings.

Update tests in the ellswift and schnorrsig modules to use the
sha256_tag_test_internal helper function.
2025-08-20 10:37:06 +01:00
Jonas Nick
cde4130898 musig/tests: initialize keypair
The keypair is unused in musig_partial_sign, but clang-snapshot gives a compiler
warning anyway.
2025-07-21 14:08:23 +00:00
Tim Ruffing
8d967a602b musig/test: Remove dead code
This avoids a compiler warning on clang-snapshot about &keypair being uninitialized.
2025-07-21 14:47:57 +02:00
Tim Ruffing
983711cd6d musig/tests: Refactor vectors_signverify
for improved readability
2025-07-21 14:44:57 +02:00
Jonas Nick
4187a46649 Merge bitcoin-core/secp256k1#1492: tests: Add Wycheproof ECDH vectors
e266ba11ae tests: Add Wycheproof ECDH vectors (RandomLattice)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK e266ba11ae

Tree-SHA512: a5cc59886595b134dadcc50e6cd6f03ce036c2857cdd848f138f0c49d4bd742ae5eb5ebca7840ec8666b5d43fa9c4f67cde4d0fb2245b1cf56b079ca3f7c7f8e
2025-05-12 19:50:56 +00:00
RandomLattice
e266ba11ae tests: Add Wycheproof ECDH vectors
Adds a test for the ECDH module using the Wycheproof vectors.
We use a python script to convert the JSON-formatted vectors
into C code, in the same spirit as https://github.com/bitcoin-core/secp256k1/pull/1245

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
2025-05-12 11:27:45 -04:00
Tim Ruffing
961ec25a83 musig: Fix clearing of pubnonces
Fixes a silent merge conflict between #1614 and #1579.
2025-03-10 15:10:29 +01:00