Commit Graph

1732 Commits

Author SHA1 Message Date
DarkWindman
b36c4ab717 ecdsa_adaptor: use context hash functions in nonce generation 2026-06-03 13:07:37 +03:00
DarkWindman
baac08d207 modules, tests: Port bitcoin-core/secp256k1#1777 and bitcoin-core/secp256k1#1824 to zkp-specific code 2026-04-20 15:39:54 +03:00
DarkWindman
f7e7e6bb15 Merge branch 'master' into sync-7262adb4 2026-04-01 17:29:57 +03:00
merge-script
95b702de34 Merge bitcoin-core/secp256k1#1839: ecdsa: VERIFY_CHECK result of _fe_set_b32_limit
43fca0ff55 ecdsa: VERIFY_CHECK result of _fe_set_b32_limit (Tim Ruffing)

Pull request description:

  This also avoids a spurious `-Wmaybe-uninitialized` warning emitted by gcc 16 (snapshot) when compiling with `-DDETERMINISTIC`.

  Alternative to #1838 by @mllwchrry who tried very a similar thing as this PR but couldn't convince the compiler. (The GCC snapshot is very annoying: a simple `VERIFY_CHECK(secp256k1_fe_set_b32_limit(&xr, c))` doesn't do the trick. I found this variant here with a local store rather by accident.)

ACKs for top commit:
  mllwchrry:
    ACK 43fca0f
  theStack:
    utACK 43fca0ff55

Tree-SHA512: 2550043e953675db7614f98bbdffb706721834967ef36f7c905f7cbfeee5d88189a9acfcd64865ef822bb0e3272d228440bdfb1124228afe083e025056e53212
2026-03-25 17:01:19 +01:00
Tim Ruffing
43fca0ff55 ecdsa: VERIFY_CHECK result of _fe_set_b32_limit
This also avoids a spurious "-Wmaybe-uninitialized" warning emitted by
gcc 16 (snapshot) when compiling with -DDETERMINISTIC.
2026-03-23 16:54:51 +01:00
mllwchrry
b84635ed3b tests: Fix C89 function pointer initialization in ellswift tests 2026-03-20 16:45:28 +02:00
mllwchrry
be075fe86c bench: Fix bench_whitelist hang 2026-03-18 14:29:02 +02:00
merge-script
ffc25a2731 Merge bitcoin-core/secp256k1#1834: ecmult: Document and test ng=NULL in ecmult
3a403639dc eckey: Call ecmult with NULL instead of zero scalar (Tim Ruffing)
7e68c0c88b ecmult: Document and test ng=NULL in ecmult (Tim Ruffing)

Pull request description:

ACKs for top commit:
  theStack:
    re-ACK 3a403639dc

Tree-SHA512: 954928d4dfa120845c6e899c1a69ad0408072809551d42735eac491b8bc41249eb25d7c57cfa4f44763167620b5cb78639b5c396c0a342c47b0afc48a088c755
2026-03-11 14:45:56 +01:00
Tim Ruffing
3a403639dc eckey: Call ecmult with NULL instead of zero scalar 2026-03-11 11:10:32 +01:00
Tim Ruffing
7e68c0c88b ecmult: Document and test ng=NULL in ecmult 2026-03-11 11:10:32 +01:00
merge-script
daf96bb07c Merge BlockstreamResearch/secp256k1-zkp#343: build: Add missing schnorrsig_halfagg module configuration
92e61ba95f build: Add missing schnorrsig_halfagg module configuration (mllwchrry)

Pull request description:

  The `schnorrsig_halfagg` module was added in 3a9b1d46 but was never configured in the CMake build system. Additionally, the autotools configuration was missing the dependency error check when `schnorrsig` is explicitly disabled.

ACKs for top commit:
  real-or-random:
    ACK 92e61ba95f

Tree-SHA512: f3770f6ae6c91a6ef51b633d147d8156a6ae843b6cb430deef07e7b9e6ea5f0b02cb228dbb41954620ce5560252d5dde7d85ce4114789bd5fcdff195915382dd
2026-03-06 15:18:18 +01:00
mllwchrry
92e61ba95f build: Add missing schnorrsig_halfagg module configuration 2026-03-06 15:07:40 +02:00
merge-script
b0ddc0357e Merge BlockstreamResearch/secp256k1-zkp#338: ci: enable surjectionproof in CI module-enabled configurations
4359f050cc surjection: Remove test that reads out of bounds (Tim Ruffing)
78999f3a9a surjection: Fix leading whitespace (Tim Ruffing)
229e1f127a surjection: Fix read of uninitialized value in tests (Tim Ruffing)
c0a26a9c1b ci: enable surjectionproof module in CI configs (copilot-swe-agent[bot])

Pull request description:

  The CI workflow enabled the ZKP experimental module set but omitted surjectionproof, so that module was never exercised in those jobs. This change wires surjectionproof into the same CI paths as the other enabled ZKP modules.

  - **CI module plumbing (`ci/ci.sh`)**
    - Added `SURJECTIONPROOF` to the exported/printed CI env set.
    - Passed `SURJECTIONPROOF` into configure via `--enable-module-surjectionproof`.

  - **Workflow env defaults and matrices (`.github/workflows/ci.yml`)**
    - Added a global default: `SURJECTIONPROOF: 'no'`.
    - Added `SURJECTIONPROOF: 'yes'` in every job/matrix env block that already enables the ZKP module group (`RANGEPROOF`, `WHITELIST`, `GENERATOR`, etc.).

  - **Representative wiring change**
    ```sh
    --enable-module-rangeproof="$RANGEPROOF" \
    --enable-module-surjectionproof="$SURJECTIONPROOF" \
    --enable-module-whitelist="$WHITELIST"
    ```

  <!-- START COPILOT ORIGINAL PROMPT -->

  <details>

  <summary>Original prompt</summary>

  >
  > ----
  >
  > *This section details on the original issue you should resolve*
  >
  > <issue_title>ci: surjectionproof module is never enabled</issue_title>
  > <issue_description>There's not even a SURJECTIONPROOF env variable in the GitHub Actions workflow... This should be enabled everywhere where the other ZKP modules are enabled.
  >
  > It may be better to enable all modules by default, but that's a change that could potentially benefit even upstream, so maybe let's first just fix this by enabling surjectionproof.</issue_description>
  >
  > <agent_instructions>Only add enabling of the surjectionproof module (no enabling of all modules by default)</agent_instructions>
  >
  > ## Comments on the Issue (you are @copilot in this section)
  >
  > <comments>
  > </comments>
  >

  </details>

  <!-- START COPILOT CODING AGENT SUFFIX -->

  - Fixes BlockstreamResearch/secp256k1-zkp#334

ACKs for top commit:
  mllwchrry:
    ACK 4359f05

Tree-SHA512: 13d776a76f73db6e74ca253099583da3d2600f424ea1f6bcbc9cd12544721477225a4190ffd34f4f1a77ab3b1d1e21d1f6d83409aa969bafe66a7978bef1b2d2
2026-03-06 12:12:06 +01:00
Tim Ruffing
4359f050cc surjection: Remove test that reads out of bounds 2026-03-05 21:27:19 +01:00
Tim Ruffing
78999f3a9a surjection: Fix leading whitespace 2026-03-05 21:12:46 +01:00
Tim Ruffing
229e1f127a surjection: Fix read of uninitialized value in tests 2026-03-05 21:12:40 +01:00
Tim Ruffing
ed985641f4 ecdsa_adaptor: Make arg order in dleq_{prove,verify} consistent 2026-03-05 13:28:23 +01:00
Tim Ruffing
a7d0f246d7 ecdsa_adaptor: Simplify code 2026-03-05 13:25:12 +01:00
Tim Ruffing
41a8a2a65b ecdsa_adaptor: Clarify identifiers 2026-03-05 13:25:12 +01:00
Tim Ruffing
7f1c5390c2 ecdsa_adaptor: Make files more self-contained 2026-03-05 10:09:45 +01:00
Tim Ruffing
dd8db2ea2b ecdsa_adaptor: Run tests with default and overflowing nonce function 2026-03-05 09:38:10 +01:00
Tim Ruffing
a4af91d5b9 ecdsa_adaptor: Add test case for R1==infinity in DLEQ proof 2026-03-05 09:33:53 +01:00
merge-script
5a67b63ecd Merge BlockstreamResearch/secp256k1-zkp#339: ecdsa_adaptor: Fix secp256k1_dleq_verify abort on infinity points (#335)
799a27c813 ecdsa_adaptor: Check for infinity in secp256k1_dleq_verify (mllwchrry)

Pull request description:

  Address #335.

ACKs for top commit:
  real-or-random:
    ACK 799a27c813

Tree-SHA512: 9634ccd864cabbe3188e19a551f18cb21cd634955276e9a12fd92977b71ecde4bec1159e9f7baf6157c5b4c6b956ed938600f85f70379603704ec738035eb4c7
2026-03-05 09:02:31 +01:00
merge-script
1aafe15139 Merge bitcoin-core/secp256k1#1777: Make SHA256 compression runtime pluggable
4d92a083bc sha256: speed up writes using multi-block compression (furszy)
0753f8b909 Add API to override SHA256 compression at runtime (furszy)
fdb6a91a5e Introduce hash context to support pluggable SHA256 compression (furszy)

Pull request description:

  Tackling the long-standing request #702.

  Right now we ship our own SHA256 implementation, a standard baseline version that does not take advantage of any hardware-optimized instruction, and it cannot be accessed by the embedding application - it is for internal usage only.

  This means embedding applications often have to implement or include a different version for their use cases, wasting space on constrained environments, and in performance-sensitive setups it forces them to use a slower path than what the platform provides. Many projects already rely on tuned SHA-NI / ARMv8 / or other hardware-optimized code, so always using the baseline implementation we ship within the library is not ideal.

  These changes allow users to supply their own SHA256 compression function at runtime, while preserving the existing default behavior for everyone else. This is primarily intended for environments where the available SHA256 implementation is detected dynamically and recompiling the library with a different implementation is not feasible (equivalent build-time functionality will come in a follow-up PR).

  It introduces a new API:

  ```C89
  secp256k1_context_set_sha256_transform_callback(ctx, fn_transform)
  ```

  This function installs the optimized SHA256 compression into the `secp256k1_context`, which is then used by all internal computations. Important: The provided function is verified to be output-equivalent to the original one.

  As a quick example, using this functionality in Bitcoin-Core will be very straightforward: f68bef06d9

ACKs for top commit:
  real-or-random:
    ACK 4d92a083bc
  w0xlt:
    ACK 4d92a083bc
  theStack:
    ACK 4d92a083bc

Tree-SHA512: 058e2e82071f1ca77254b684458292c621e60d65bbcc5500574429717e7db75bc9f3221129fafd11eb5d33e666a5efec5e9844460d3b194ef3b6b16f2df28fb9
2026-03-04 08:43:07 +01:00
mllwchrry
799a27c813 ecdsa_adaptor: Check for infinity in secp256k1_dleq_verify 2026-03-03 17:33:57 +02:00
merge-script
b9cb1cbfd7 Merge bitcoin-core/secp256k1#1824: util: introduce and use ARRAY_SIZE macro
921b9711ea util: introduce and use `ARRAY_SIZE` macro (Sebastian Falbesoner)

Pull request description:

  This PR is another tiny improvement found while working on #1765, with the goal to avoid code repetition.

  The `ARRAY_SIZE` macro definition is pretty wide-spread in C projects and e.g. matches the one [used in the Linux Kernel](9702969978/include/linux/array_size.h (L11))  (without the additional check to reject pointers, as we would need GNU C for that, see e.g. https://stackoverflow.com/a/19455169; not sure if a useful counterpart exists that only relies on C89). Replacement instances were identified via `$ git grep sizeof.*/.*sizeof`.

ACKs for top commit:
  w0xlt:
    ACK 921b9711ea
  real-or-random:
    utACK 921b9711ea

Tree-SHA512: 44b6bf0132cf00fade526a3fc04e03dc896d04874123614c032206b61f97c81f94d139b6cc0c108eceaa699251580c19420d230b3150607303ca2cb7ab9a0bcb
2026-03-03 15:31:46 +01:00
mllwchrry
48cbd78dfc modules: Port bitcoin-core/secp256k1#1825 to zkp-specific code 2026-03-03 15:42:49 +02:00
furszy
4d92a083bc sha256: speed up writes using multi-block compression
Multiple 64-byte blocks can now be compressed directly
from the input buffer, without copying them into the
internal buffer.
2026-03-03 10:35:53 -03:00
furszy
0753f8b909 Add API to override SHA256 compression at runtime
This introduces `secp256k1_context_set_sha256_compression()`,
which allows users to provide their own SHA256 block-compression
function at runtime.

This is useful in setups where the fastest implementation can only
be determined dynamically based on the available CPU features, and
rebuilding the library is not possible.

The callback is installed on the `secp256k1_context` and is then used
by all operations that compute SHA256 hashes. As part of the setup,
the library performs sanity checks to ensure that the supplied
function is equivalent to the default transform.

Passing NULL to the callback setter restores the built-in
implementation.
2026-03-03 10:35:53 -03:00
furszy
fdb6a91a5e Introduce hash context to support pluggable SHA256 compression
This is purely a mechanical change with no behavior change.

It introduces a secp256k1_hash_ctx struct inside secp256k1_context
and propagates it to all SHA256-related operations.

This sets up the ability to provide a hardware-optimized SHA256
compression function at runtime in a follow-up commit.
2026-03-03 10:25:50 -03:00
mllwchrry
126501f58b modules: Port bitcoin-core/secp256k1#1815 to zkp-specific code 2026-03-03 15:16:04 +02:00
mllwchrry
3b2ceb3e7a Merge commits '14e56970 1605b02f cd49c57e 453949ab 57315a69 97de5120 c5da3bde 99ab4a10 d071aa56 1d146ac3 322d0a43 c7a7f732 ac561601 dfe042fe 3019186a 95e68158 10f546a2 c0a2aba0 ' into temp-merge-1811 2026-03-03 14:45:28 +02:00
mllwchrry
dc0bda5731 bench: Port bitcoin-core/secp256k1#1796 to zkp-specific code 2026-03-03 13:08:07 +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
d8e87e45f3 unit_test: bump MAX_ARGS from 150 to 200 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
merge-script
c0a2aba088 Merge bitcoin-core/secp256k1#1811: bench: Update help functions in bench and bench_internal
c49c9be504 bench: Update help functions in bench and bench_internal (kevkevinpal)

Pull request description:

  ### Motivation
  This change is motivated by https://github.com/bitcoin-core/secp256k1/pull/1793#pullrequestreview-3644885897

  > While aligning implementation across all benchmarks, argv could be passed to the help() in bench.c and bench_internal.c.

  ### Description

  In the `bench` and `bench_internal` `help` functions `argv` was not being passed. In this change, we pass in argv and use it in the help text.

ACKs for top commit:
  real-or-random:
    ACK c49c9be504

Tree-SHA512: 77184db4bf5c16827f19d888af73939f4139cc2e84ae5256d995cf61f606d5865928480fc009a0185e1a6843f3c38dd1b858d1316e524c9b165459c7367f2318
2026-03-03 09:13:57 +01:00
Tim Ruffing
8d0eda07e9 testrand: Remove testrand_finish
This removes printing of the "random run = " at the end of the tests. I
haven't seen a single case where this proved to be useful. And as of
48789dafc2, this is anyway printed only at
the end of the exhaustive tests and not the normal tests, so the
probability that this will be useful in the future is very low.
2026-03-02 15:06:39 +01: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
merge-script
95e6815843 Merge bitcoin-core/secp256k1#1825: hash: remove redundant secp256k1_sha256_initialize in tagged hash midstate functions
f48b1bfa5d hash: add midstate initializer and use it for tagged hashes (w0xlt)

Pull request description:

  Each tagged hash midstate function (e.g., `secp256k1_schnorrsig_sha256_tagged`) calls `secp256k1_sha256_initialize` before immediately overwriting every field it sets: `s[0]` through `s[7]` and `bytes`. The `buf[64]` member does not need initialization either, because `bytes` is set to 64, which means the buffer position (`bytes & 0x3F`) (`= bytes % 64`) is 0, so buf is always written before being read.

  Remove the 11 redundant `secp256k1_sha256_initialize` calls across the `schnorrsig`, `ellswift`, and `musig` modules.

ACKs for top commit:
  real-or-random:
    utACK f48b1bfa5d
  theStack:
    Code-review ACK f48b1bfa5d

Tree-SHA512: 769beb96f3921cc3c180ed0d17484ffa0dc78041c889a8e56603679d8eaca5fe13e63759ada78f83d8e0ff7aae392e6bcbc1a9fe8b959105ea4a3d8ef51abf15
2026-02-27 21:10:43 +01: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
w0xlt
f48b1bfa5d hash: add midstate initializer and use it for tagged hashes
Introduce secp256k1_sha256_initialize_midstate() in the hash layer and use it at all tagged-hash midstate call sites across schnorrsig, musig, and ellswift.

Document the byte-counter contract at the declaration site in hash.h and add run_sha256_initialize_midstate_tests() to directly verify helper behavior against initialize_tagged.

Also switch the helper to take const uint32_t state[8] to reduce argument-order risk at call sites.
2026-02-25 15:37:43 -08: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