Commit Graph

2797 Commits

Author SHA1 Message Date
mllwchrry
f9cf003d9b scalar: Port bitcoin-core/secp256k1#1512 to zkp-specific code 2026-01-29 12:51:33 +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
Jonas Nick
797e2ed61a Merge elementsproject/secp256k1-zkp#306: sync-upstream: improve help text
db8750de46 sync-upstream: improve help text (Jonas Nick)

Pull request description:

ACKs for top commit:
  real-or-random:
    utACK db8750de46

Tree-SHA512: 06f28c5ebd74437c3c2ef5ae460bec66ff9f15c4bae3b76c74b1323e2ef24d8ec456b72d58df9d68a3d41fcd44d6dfbefe8115900ccb10b8f028a7b0952b6df1
2026-01-22 11:07:36 +00:00
Jonas Nick
db8750de46 sync-upstream: improve help text 2026-01-22 09:09:27 +00:00
merge-script
42e75b613b Merge BlockstreamResearch/secp256k1-zkp#304: ci: Backport MSan fixes for ctime_tests
b9a82b481f ci: Update macOS image (Hennadii Stepanov)
a1be8ed1b1 ci: Silent Homebrew's noisy reinstall warnings (Hennadii Stepanov)
fd259fe9ad ci: Add job with -fsanitize-memory-param-retval (Tim Ruffing)
76b3396516 configure: Move "experimental" warning to bottom (Tim Ruffing)
e639e6caa9 autotools: Disable eager MSan in ctime_tests (Tim Ruffing)

Pull request description:

  Cherry-picked the upstream fixes from bitcoin-core/secp256k1#1517 to align behaviour here and silence the false 'use-of-uninitialized-value' reports in ctime_tests under Clang ≥16.

  #### Result:
  - `ctime_tests` is clean under MSan.
  - Other tests are unchanged.
  - No API or behaviour changes.

  #### Commits cherry-picked:
  - [55e5d975db](55e5d975db),
  - [e1bef0961c](e1bef0961c),
  - [ebfb82ee2f](ebfb82ee2f)

  #### References:
  Upstream: https://github.com/bitcoin-core/secp256k1/pull/1517

ACKs for top commit:
  apoelstra:
    ACK b9a82b481fc35c5db3a127185ffada77fe107d46; successfully ran local tests
  jonasnick:
    ACK b9a82b481f

Tree-SHA512: b6c9ae38b142c7fadf1157a1b25cdc8e85e6cd271222b950b1246f14daf85b072979d4f2ee8791c8b81b2f6a94ad1094fc8110bbd4ff19153de6a6efad2e3cc0
2025-09-19 17:58:29 +02:00
Hennadii Stepanov
b9a82b481f ci: Update macOS image
The macOS 12 GHA image has been deprecated since 2024-10-07.
See: https://github.com/actions/runner-images/issues/10721
2025-09-18 13:12:29 +05:30
Hennadii Stepanov
a1be8ed1b1 ci: Silent Homebrew's noisy reinstall warnings 2025-09-18 13:12:18 +05:30
Tim Ruffing
fd259fe9ad ci: Add job with -fsanitize-memory-param-retval 2025-09-16 15:27:23 +05:30
Tim Ruffing
76b3396516 configure: Move "experimental" warning to bottom
to make it more promiment
2025-09-16 15:24:23 +05:30
Tim Ruffing
e639e6caa9 autotools: Disable eager MSan in ctime_tests
Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2025-09-16 15:17:35 +05:30
Jonas Nick
f92fd5cc91 Merge elementsproject/secp256k1-zkp#303: ci: backport upstream string-initializer fixes and clean up related tests
7d779c6d9d examples/musig: use brace-enclosed initializer for 32-byte msg (BEULAHEVANJALIN)
53fd89b635 musig/tests: initialize keypair (Jonas Nick)
40bd8549dd musig/test: Remove dead code (Tim Ruffing)
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 (BEULAHEVANJALIN)
654a8c327c refactor: Use array initialization for unterminated strings (MarcoFalke)

Pull request description:

ACKs for top commit:
  real-or-random:
    utACK 7d779c6d9d thanks!
  jonasnick:
    ACK 7d779c6d9d

Tree-SHA512: edb9885a36eab499dee05e0c87a184f139ba6f68c01128ae692ab1195546ba8ff77d0c0b06faa22164fd89fd27935fd68b1e9c04a1fc9bcd0b7d6472515095dd
2025-09-16 06:00:35 +00:00
BEULAHEVANJALIN
7d779c6d9d examples/musig: use brace-enclosed initializer for 32-byte msg
Switch msg initialization from a string literal to a brace-enclosed
array to avoid -Wunterminated-string-initialization. Upstream removed
the trailing '!' from the message; this change retains it.
2025-09-09 21:56:53 +05:30
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
Andrew Poelstra
f9a04ae405 Merge BlockstreamResearch/secp256k1-zkp#302: extrakeys: fix pubkey_sort_cmp test
83d0fa25a8 extrakeys: fix pubkey_sort_cmp test (Jonas Nick)

Pull request description:

  Instead of providing CTX directly, pass a cmp_data object containing CTX. Otherwise, memory sanitizer fails with "use-of-uninitialized-value".


ACKs for top commit:
  real-or-random:
    utACK 83d0fa25a8
  apoelstra:
    ACK 83d0fa25a826d716f809e00ef0a67385b776aec9; successfully ran local tests


Tree-SHA512: eb36c9f90632a3fb472653686ffb5c7a9c29849e05ab1084106a49c23e60ca1c90022ee1accd99ab5bfaa4fd5b3f4670cea8d5a2c415f00c05d645c793b6bedd
2025-09-09 15:27:50 +00:00
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
Andrew Poelstra
6152622613 Merge ElementsProject/secp256k1-zkp#295: rangeproof: add unit test for malleating single-value proofs
3a1c39625e rangeproof: add unit test for malleating single-value proofs (Andrew Poelstra)

Pull request description:

  I was a bit confused reading `secp256k1_rangeproof_getheader_impl` because in the case of single-value proofs (`has_nz_range == 0`) some bits of the header are unconstrained. At first I thought this was a malleability vector. And I think I've had this same confusion in the past.

  But in fact it is not a malleability vector because the whole header gets hashed into the proof.

  Add a unit test to confirm this to reduce future confusion.

ACKs for top commit:
  real-or-random:
    utACK 3a1c39625e

Tree-SHA512: 9670cd04fcc0bb322d89c2c86ef863e13c29e4477dc6fecdda16b9a745e42a84f237a7ec387b3291f334e2a5c5806a8cc7cc00e40246ad5b36366be841195b4b
2024-06-20 13:18:07 +00:00
Andrew Poelstra
3a1c39625e rangeproof: add unit test for malleating single-value proofs
I was a bit confused reading `secp256k1_rangeproof_getheader_impl`
because in the case of single-value proofs (`has_nz_range == 0`) some
bits of the header are unconstrained. At first I thought this was a
malleability vector. And I think I've had this same confusion in the
past.

But in fact it is not a malleability vector because the whole header
gets hashed into the proof.

Add a unit test to confirm this to reduce future confusion.
2024-06-19 15:27:06 +00:00
Jonas Nick
168377204d Merge elementsproject/secp256k1-zkp#294: generator: massively speed up serialization
6361266013 generator: speed up parsing (Andrew Poelstra)
5e7c2c178d generator: massively speed up serialization (Andrew Poelstra)

Pull request description:

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

Tree-SHA512: 9f35467ac9d39d23b68a3f830c920f61ae39d99974d6a864df4a3c19860dc8fc447609d0480e45234c66250878d34da03bfcf0056eaa83d3c78babb254962bf4
2024-05-22 11:55:07 +00:00
Andrew Poelstra
6361266013 generator: speed up parsing
Similar to speeding up serialization; in our parsing logic we did a
bunch of expensive stuff then expensively inverted it. Drop everything
except the essential checks and then memcpy.
2024-05-21 13:32:12 +00:00
Andrew Poelstra
5e7c2c178d generator: massively speed up serialization
`secp256k1_pedersen_commit_serialize` would call `_load` (which does a
sqrt to fully decompress the key, then a conditional negation based on
the flag), then check the Jacobian symbol of the resulting y-coordinate,
then re-serialize based on this.

Instead, don't do any of this stuff. Copy the flag directly out of the
internal representation and copy the x-coordinate directly out of the
internal representation.

Checked that none of the other _serialize methods in the modules do
this.

Fixes #293
2024-05-20 12:40:02 +00:00
Tim Ruffing
d661a93cc9 Merge BlockstreamResearch/secp256k1-zkp#292: doc: fix sage code for deriving alternative generator H
7040a20247 doc: fix sage code for deriving alternative generator H (Sebastian Falbesoner)

Pull request description:

  The line calculating H (in particular, the expression `G.decode('hex')`) fails with the following error message on Sage 9.5:

  ```
  AttributeError: 'str' object has no attribute 'decode'
  ```

  Fix that by converting the hex-string to bytes using `bytes.fromhex`.

  (Noticed while reviewing https://github.com/bitcoin/bitcoin/pull/30048 which picks this code snippet comment up.)

ACKs for top commit:
  josibake:
    ACK 7040a20247
  real-or-random:
    utACK 7040a20247

Tree-SHA512: 0a44f399b103c2f5840056d163c1483a1d4f032bc0f8d3822507ac6da9d567f46e36caa79c7f5016aebcc8827b79e9aec7ebdb4f21c3c0242dc6875be140f289
2024-05-08 12:20:56 +02:00
Sebastian Falbesoner
7040a20247 doc: fix sage code for deriving alternative generator H
The expression `G.decode('hex')` fails with the following error message
on Sage 9.5:

AttributeError: 'str' object has no attribute 'decode'

Fix that by converting the hex-string to bytes using `bytes.fromhex`.
2024-05-07 19:38:51 +02:00
Tim Ruffing
d8311688bd Merge bitcoin-core/secp256k1#1515: ci: Note affected clangs in comment on ASLR quirk
a85e2233e7 ci: Note affected clangs in comment on ASLR quirk (Tim Ruffing)

Pull request description:

  Resolves #1506.

ACKs for top commit:
  fanquake:
    ACK a85e2233e7

Tree-SHA512: a82d6f5e57175434c1f66c7b01c90eb2877db794d7f5213b3652ecb51ebb7c03ff13ab13424b3e6d41b9eaa504af330f16855e32e63d1805c1a475f462c6da66
2024-04-04 11:52:27 +02:00
Tim Ruffing
a85e2233e7 ci: Note affected clangs in comment on ASLR quirk
Resolves #1506.
2024-04-04 11:49:00 +02:00
Tim Ruffing
4b77fec67a Merge bitcoin-core/secp256k1#1512: msan: notate more variable assignments from assembly code
f7f0184ba1 msan: notate more variable assignments from assembly code (Cory Fields)
a61339149f change inconsistent array param to pointer (Cory Fields)

Pull request description:

  This was missed in 31ba404944 because older versions of clang did not complain about it. But clang-17, at least, does.

  The array-as-a-param makes this annoying because `sizeof(l)` is not helpful. I'd be happy to change the size calculation if there are any better suggestions or strong preferences.

ACKs for top commit:
  sipa:
    utACK f7f0184ba1
  real-or-random:
    ACK f7f0184ba1 tests work fine with clang 17 and `./configure CFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" CC=clang`

Tree-SHA512: 8ab22209ef322a10f500b123c82ae5e7141ae1da0e7a890cbf90bd7d2eb11f397db4ccfe15a1666f2f49228585cccbf5bec741effebd1e2c6012cb7ea1689675
2024-04-03 19:06:22 +02:00
Cory Fields
f7f0184ba1 msan: notate more variable assignments from assembly code
This was missed in 31ba404944 because older
versions of clang did not complain about it. But clang-17, at least, does.
2024-04-03 16:03:19 +00:00
Cory Fields
a61339149f change inconsistent array param to pointer
The behavior is identical, but the former syntax suggests guarantees that
don't actually exist.
2024-04-03 16:03:19 +00:00
Tim Ruffing
05bfab69ae Merge bitcoin-core/secp256k1#1507: ci: Add workaround for ASLR bug in sanitizers
a5e8ab2484 ci: Add sanitizer env variables to debug output (Tim Ruffing)
84a93de4d2 ci: Add workaround for ASLR bug in sanitizers (Tim Ruffing)

Pull request description:

  Fixes #1506.

  This also adds the sanitizer env variables to our debug output as suggested in the same issue.

ACKs for top commit:
  sipa:
    utACK a5e8ab2484
  jonasnick:
    ACK a5e8ab2484

Tree-SHA512: 5162d14eeec01e088c600ed77e21c5ffd4dec23327b7e81b5ecac59b7c535cac97cd7b7b744c767766036dfc6d9152a9933eb326cf4065d56c46e2ee858da662
2024-03-20 13:25:32 +01:00
Tim Ruffing
a5e8ab2484 ci: Add sanitizer env variables to debug output 2024-03-19 23:52:15 +01:00
Tim Ruffing
84a93de4d2 ci: Add workaround for ASLR bug in sanitizers
Fixes #1506.
2024-03-19 23:52:15 +01:00
Tim Ruffing
a7907b1af2 Merge BlockstreamResearch/secp256k1-zkp#261: Schnorr (Incremental) Half Aggregation
3a9b1d46a3 New Experimental Module: Incremental Half-Aggregation for Schnorr Signatures (Benedikt)

Pull request description:

  Revisited PR #130 by jonasnick.
  I am happy to hear your thoughts.

  **Summary of changes compared to #130:**

  - Address comments from rustyrussell
  - Use tagged hash
  - Compute hashes with common prefix by copying midstate
  - Allow Incremental Aggregation and make code consistent with the [draft spec](https://github.com/BlockstreamResearch/cross-input-aggregation/blob/master/half-aggregation.mediawiki)

ACKs for top commit:
  real-or-random:
    ACK 3a9b1d46a3

Tree-SHA512: 27239033f8b28ecf87ea310b3dd5a19dbbe6fd07495db71ef7017f8f444ec25a12897087d1bea0a2e9c3df77d7f17c38b183d7fe768858da2180f26624add4aa
2024-03-05 12:17:22 +01:00
Jonas Nick
427e86b9ed Merge bitcoin-core/secp256k1#1490: tests: improve fe_sqr test (issue #1472)
2028069df2 doc: clarify input requirements for secp256k1_fe_mul (Sebastian Falbesoner)
11420a7a28 tests: improve fe_sqr test (Sebastian Falbesoner)

Pull request description:

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

Tree-SHA512: bb01bf6ceb34f0475a60b8dcb0cec000859a0c20f1009426bd8cab609f1941f44f84802f1565a719f7d2a55466076fb1591a353b1b75e6c0ceac44806d908176
2024-02-27 17:17:00 +00:00
Sebastian Falbesoner
2028069df2 doc: clarify input requirements for secp256k1_fe_mul
"... neither can be equal to b." could suggest that the values are not
allowed to be identical, but what is meant here is that the mentioned
inputs shouldn't point to the same object.
2024-02-27 16:32:49 +01:00
Sebastian Falbesoner
11420a7a28 tests: improve fe_sqr test
Currently the `run_sqr` test doesn't do anything with the
result of the `fe_sqr` call. Improve that by checking that
the equation `(x+y)*(x-y) = x^2 - y^2` holds for some random
values y, as suggested in issue #1471 by real-or-random.
The existing loop for generating the x values is kept as-is.
2024-02-27 16:32:45 +01:00
Jonas Nick
cdc9a6258e Merge bitcoin-core/secp256k1#1489: tests: add missing fe comparison checks for inverse field test cases
e7bdddd9c9 refactor: rename `check_fe_equal` -> `fe_equal` (Sebastian Falbesoner)
00111c9c56 tests: add missing fe comparison checks for inverse field test cases (Sebastian Falbesoner)

Pull request description:

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

Tree-SHA512: 1d14cb87bf3d190be6e11ae205ed25090758aae589f50793d9bcbdb3c04378ca08f6a3d41567fdf472786ea3234cf1f3b9c95ece8b605b4a7667a81a27b249e2
2024-02-27 15:18:20 +00:00
Tim Ruffing
d926510cf7 Merge bitcoin-core/secp256k1#1496: msan: notate variable assignments from assembly code
31ba404944 msan: notate variable assignments from assembly code (Cory Fields)
e7ea32e30a msan: Add SECP256K1_CHECKMEM_MSAN_DEFINE which applies to memory sanitizer and not valgrind (Cory Fields)

Pull request description:

  msan isn't smart enough to see that these are set without some help.

  This was pointed out here: https://github.com/bitcoin-core/secp256k1/pull/1169#issuecomment-1370003449

  With this commit, msan output is clean even with x86 asm turned on.

ACKs for top commit:
  real-or-random:
    utACK 31ba404944
  hebasto:
    re-ACK 31ba404944.

Tree-SHA512: c9c51fe542247e1e0a93f6d0063d119cf777ca8c1b7e9c8e45e168a2020dc503872eb2a78004725de81267a3ce78c923be1f8546fb92a3e95fc7ef034e5ba932
2024-02-27 14:47:18 +01:00
Benedikt
3a9b1d46a3 New Experimental Module: Incremental Half-Aggregation for Schnorr Signatures 2024-02-27 14:04:40 +01:00
Cory Fields
31ba404944 msan: notate variable assignments from assembly code
msan isn't smart enough to see that these are set without some help.
2024-02-23 17:30:39 +00:00
Cory Fields
e7ea32e30a msan: Add SECP256K1_CHECKMEM_MSAN_DEFINE which applies to memory sanitizer and not valgrind 2024-02-23 17:30:39 +00:00
Jonas Nick
900a4371d3 Merge elementsproject/secp256k1-zkp#290: configure: Clean ups
860e3bb294 configure: Fix reduced surjection proof size (Tim Ruffing)
0873358f77 configure: Reorder modules also for AC_ARG_ENABLE (Tim Ruffing)
9de973f613 configure: Document canonical order of modules (Tim Ruffing)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK 860e3bb294

Tree-SHA512: cfbaf9cb8a686aeab43ef6727b38d94467b862746062c1c06876bd98614ada7a00bc617481b0e0059dc294250a94a53581f3ffd685aa05c47a665950b280da51
2024-02-16 14:04:16 +00:00
Tim Ruffing
860e3bb294 configure: Fix reduced surjection proof size
The variable set automatically by AC_ARG_ENABLE is called enable_...
2024-02-16 10:59:25 +01:00
Tim Ruffing
0873358f77 configure: Reorder modules also for AC_ARG_ENABLE 2024-02-16 10:59:25 +01:00
Tim Ruffing
9de973f613 configure: Document canonical order of modules 2024-02-16 10:59:25 +01:00
Jonas Nick
1e04d32447 Merge elementsproject/secp256k1-zkp#288: cmake: Add support for -zkp modules
4228fd1124 cmake: Add support for -zkp modules (Tim Ruffing)

Pull request description:

ACKs for top commit:
  jonasnick:
    utACK 4228fd1124

Tree-SHA512: 72606bb3421a4d6479c5cbc94e2468d6a9a53581f571fd5340edc41595eac18fbb04dcaacce8f39020e32a69b733ba6743aac4b901e1600f5245a4a04cb0e27a
2024-02-02 19:47:59 +00:00
Sebastian Falbesoner
e7bdddd9c9 refactor: rename check_fe_equal -> fe_equal
As this function doesn't do any checking, it's better to rename it,
so that it's less likely to miss the needed `CHECK`.
2024-02-01 15:34:40 +01:00
Sebastian Falbesoner
00111c9c56 tests: add missing fe comparison checks for inverse field test cases
`check_fe_equal` is a wrapper around `secp256k1_fe_equal` that takes
care of normalization. Since it doesn't check anything itself, the
CHECK macro is needed at the call-sites to actually ensure equality.
2024-02-01 00:49:25 +01:00
Tim Ruffing
4228fd1124 cmake: Add support for -zkp modules
Co-authored-by: lightyear15 <g.minist8@gmail.com>
2024-01-25 15:58:52 +01:00