Commit Graph

1546 Commits

Author SHA1 Message Date
mllwchrry
21c24fdc7a musig: Remove module in preparation for upstream merge 2026-02-13 11:36:52 +02:00
DarkWindman
551b5dd415 Merge commits 'fded437c cdf08c1a 642c885b f8c1b0e0 3fdf146b b3076144 19888550 2f2ccc46 472faaa8 4c57c7a5 ' into temp-merge-1554 2026-02-11 13:56:17 +02:00
DarkWindman
d0dde4aa2a Merge commits '35c0fdc 5dd637f 69b2192 d7ae25c d403eea f473c95 4af241b a526937 fcc5d73 ca06e58 ea2d5f0 0055b86 ' into temp-merge-1551 2026-02-10 13:06:38 +02:00
mllwchrry
513e550e8a Merge commits '4392f0f7 ' into temp-merge-1533 2026-02-09 13:10:17 +02:00
mllwchrry
c946b0978a Merge commits 'e3a885d4 d7f6613d 7d0bc087 7712a530 4155e62f 06bff6de 1791f6fc 4b8d5eea bedffd53 ' into temp-merge-1488 2026-02-06 10:42:44 +02:00
merge-script
d176205dd7 Merge BlockstreamResearch/secp256k1-zkp#313: Upstream PR 1518
2cb2e312e9 extrakeys: Migrate to bitcoin-core/secp256k1#1518 secp256k1_ec_pubkey_sort (DarkWindman)
7d2591ce12 Add secp256k1_pubkey_sort (Jonas Nick)

Pull request description:

  Merge bitcoin-core/secp256k1#1518: Add secp256k1_pubkey_sort

  This PR can be recreated with `./contrib/sync-upstream.sh -b master range bb528cf`.
  Tip: Use `git show --remerge-diff` to show the changes manually added to the merge commit.

ACKs for top commit:
  real-or-random:
    ACK 2cb2e312e9

Tree-SHA512: dbdb6c5df2195d2ece9574367e0f684a651ea199806a80232c85b0ffd0ba6b930b108bd97385d9fab656754a85fa6de223a93b945046b043aab20ad7bb3d1bff
2026-02-05 22:59:07 +01:00
DarkWindman
2cb2e312e9 extrakeys: Migrate to bitcoin-core/secp256k1#1518 secp256k1_ec_pubkey_sort 2026-02-05 19:02:49 +02:00
DarkWindman
3291b021bf Merge commits 'bb528cf ' into temp-merge-1518 2026-02-05 18:50:53 +02:00
mllwchrry
96a415b1c0 scalar: Port bitcoin-core/secp256k1#1393 to zkp-specific code 2026-02-05 17:29:53 +02:00
Jonas Nick
9a57e3c650 Merge commits 'da515074 ' into temp-merge-1058 2026-01-30 21:18:06 +00:00
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
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
MarcoFalke
fa67b6752d 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";
      |                                              ^~~~~~~~~~~~~~~
2024-08-15 17:58:14 +02:00
Jonas Nick
af551ab9db tests: do not use functions from extrakeys module
This fixes a bug introduced in 7d2591ce12 that
prevented compiling the library without enabling the extrakeys module.
2024-07-24 06:57:38 +00:00
Elliot Lee
0e2fadb20c fix: typos in secp256k1.c 2024-06-24 14:24:48 -07: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
Sebastian Falbesoner
e73f6f8fd9 tests: refactor: drop secp256k1_ prefix from testrand.h functions
The rename was done with the following command:

$ sed -i 's/secp256k1_testrand/testrand/g' $(git grep -l secp256k1_testrand)
2024-05-27 03:29:36 +02:00
Sebastian Falbesoner
0ee7453a99 tests: refactor: add testutil_ prefix to testutil.h functions 2024-05-27 03:29:32 +02:00
Sebastian Falbesoner
0c6bc76dcd tests: refactor: move random_ helpers from tests.c to testutil.h
Can be reviewed via `--color-moved=dimmed-zebra`.
2024-05-27 03:09:11 +02:00
Sebastian Falbesoner
0fef8479be tests: refactor: rename random_field_element_magnitude -> random_fe_magnitude
Note that the already existing function `random_fe_magnitude` is removed
and the call-sites are adapted to pass the magnitude range of 8
(the maximum for secp256k1_fe_mul and secp256k1_fe_sqr) explicitly.
2024-05-27 03:09:11 +02:00
Sebastian Falbesoner
59db007f0f tests: refactor: rename random_group_element_... -> random_ge_...
The rename was done with the following command:

$ sed -i 's/random_group_element_/random_ge_/g' $(git grep -l random_group_element_)
2024-05-27 03:09:04 +02: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
Nicolas Iooss
9554362b15 tests: call secp256k1_ecmult_multi_var with a non-NULL error callback
Function secp256k1_ecmult_multi_var expects to be called with a non-NULL
error_callback parameter. Fix the invocation in test_ecmult_accumulate
to do this.

While at it, wrap the call in a CHECK macro to ensure it succeeds.

Fixes: https://github.com/bitcoin-core/secp256k1/issues/1527
2024-05-08 19:13:35 +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
Jonas Nick
7d2591ce12 Add secp256k1_pubkey_sort
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
Co-authored-by: Russell O'Connor <roconnor@blockstream.io>
2024-04-25 20:23:31 +00:00
Pieter Wuille
a043940253 Permit COMB_BITS < 256 for exhaustive tests 2024-04-19 11:43:46 -04:00
Pieter Wuille
39b2f2a321 Add test case for ecmult_gen recoded = {-1,0,1} 2024-04-19 11:43:46 -04:00
Pieter Wuille
644e86de9a Reintroduce projective blinding 2024-04-19 11:43:46 -04:00
Peter Dettman
07810d9abb Reduce side channels from single-bit reads
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
2024-04-19 11:43:46 -04:00
Peter Dettman
a0d32b597d Optimization: use Nx32 representation for recoded bits
The existing code needs to deal with the edge case that bit_pos >= 256,
which would lead to an out-of-bounds read from secp256k1_scalar.

Instead, recode the scalar into an array of uint32_t with enough zero
padding at the end to alleviate the issue. This also simplifies the
code, and is necessary for a security improvement in a follow-up
commit.

Original code by Peter Dettman, with modifications by Pieter Wuille.
2024-04-19 11:43:46 -04:00
Pieter Wuille
e03dcc44b5 Make secp256k1_scalar_get_bits support 32-bit reads
The old code would trigger UB when count=32.
2024-04-19 11:43:46 -04:00
Pieter Wuille
5005abee60 Rename scalar_get_bits -> scalar_get_bits_limb32; return uint32_t 2024-04-19 11:43:46 -04:00
Peter Dettman
6247f485b6 Optimization: avoid unnecessary doublings in precomputation 2024-04-19 11:43:46 -04:00
Pieter Wuille
15d0cca2a6 Optimization: first table lookup needs no point addition 2024-04-19 11:43:46 -04:00
Pieter Wuille
7a33db35cd Optimization: move (2^COMB_BITS-1)/2 term into ctx->scalar_offset
It is unnecessary to recompute this term needed by the SDMC algorithm
for every multiplication; move it into the context scalar_offset value
instead.
2024-04-19 11:43:45 -04:00
Pieter Wuille
ed2a056f3d Provide 3 configurations accessible through ./configure 2024-04-19 11:43:26 -04:00
Pieter Wuille
5f7be9f6a5 Always generate tables for current (blocks,teeth) config 2024-04-19 11:43:26 -04:00
Peter Dettman
fde1dfcd8d Signed-digit multi-comb ecmult_gen algorithm
This introduces the signed-digit multi-comb multiplication algorithm
for constant-time G multiplications (ecmult_gen). It is based on
section 3.3 of "Fast and compact elliptic-curve cryptography" by
Mike Hamburg (see https://eprint.iacr.org/2012/309).

Original implementation by Peter Dettman, with changes by Pieter Wuille
to use scalars for recoding, and additional comments.
2024-04-19 11:43:22 -04:00
Pieter Wuille
486518b350 Make exhaustive tests's scalar_inverse(&x,&x) work
The old code overwrote the input at the start of the function,
making a call like secp256k1_scalar_inverse(&x,&x) always fail.
2024-04-19 10:27:15 -04:00
Pieter Wuille
ab45c3e089 Initial gej blinding -> final ge blinding
Instead of having the starting point of the ecmult_gen computation be
offset, do it with the final point. This enables reasoning over the
set of points reachable in intermediary computations, which can be
leveraged by potential future optimization.

Because the final point is in affine coordinates, its projective
blinding is no longer possible. It will be reintroduced again in
a different way, in a later commit.

Also introduce some more comments and more descriptive names.
2024-04-19 10:27:12 -04:00
Tim Ruffing
aa00a6b892 Introduce CEIL_DIV macro and use it 2024-04-15 13:18:27 -04: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