1493 Commits

Author SHA1 Message Date
Jesse Posner
5368c81a3c
frost trusted dealer: key tweaking
This commits add BIP-341 ("Taproot") and BIP-32 ("ordinary") public key
tweaking.
2024-05-14 15:28:00 -07:00
Jesse Posner
9b852191de
frost trusted dealer: nonce generation
This commits adds nonce generation, as well as serialization and
parsing.
2024-05-14 15:26:35 -07:00
Jesse Posner
8969cee21c
frost trusted dealer: share generation
This commit adds trusted share generation, as well as share
serialization and parsing.
2024-05-14 14:32:10 -07:00
Jesse Posner
6f47d2eb22
frost trusted dealer: initialize project
This commit adds the foundational configuration and building scripts
and an initial structure for the project.
2024-05-14 14:32:05 -07: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
Benedikt
3a9b1d46a3 New Experimental Module: Incremental Half-Aggregation for Schnorr Signatures 2024-02-27 14:04:40 +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
Jonas Nick
03aecafe4c
Merge elementsproject/secp256k1-zkp#286: shallue_van_de_woestijne rewrite
6b9d335ef641b77884fdb0e65f95c5ac4dd2209f generator: add shallue_van_de_woestijne test for t = 0 (Jonas Nick)
26522241b407a04825442dea839af82d97372daf generators: shallue_van_de_woestijne improve comments (Jonas Nick)
5d87e80c6928694bc9d2fe3bf8fd89343ba16f83 shallue_van_de_woestijne rewrite (Russell O'Connor)

Pull request description:

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

Tree-SHA512: 4a5ca291ec760ea54a43ff0b811ca1fac024002172d4639919fb97f63cfa0e75a580674c86a5a0ac9866e00520be4dd8d1d37b6d2fd8d2057e42a804dbf9127c
2024-01-25 09:07:16 +00:00
Jonas Nick
6b9d335ef6 generator: add shallue_van_de_woestijne test for t = 0 2024-01-24 17:55:38 -05:00
Jonas Nick
26522241b4 generators: shallue_van_de_woestijne improve comments 2024-01-24 17:55:36 -05:00
Russell O'Connor
5d87e80c69 shallue_van_de_woestijne rewrite
The previous implementation returns an off-curve point for the input t=0.

This rewrite addresses that issue by implicity returning the on-curve point
(d, sqrt(1 + b)), which is the point that the paper Indifferentiable Hashing
to Barreto–Naehrig Curves suggests returning in this case.

Note: At the moment it is cryptographically impossible for the input t to be 0.
2024-01-24 17:50:48 -05:00
Jonas Nick
b673a43090 musig: new upstream def of VERIFY_CHECK (empty in non-VERIFY)
Remove explicity VERIFY_CHECKs in keyaggcoef_internal since normalization should
be checked in the fe_* functions.
2024-01-23 16:04:45 +01:00
Jonas Nick
cd173688fb musig: replace point_{save,load} with ge_{to,from}_bytes 2024-01-23 16:04:45 +01:00
Jonas Nick
33db8edb27 group: add ge_to_bytes and ge_from_bytes 2024-01-23 16:04:45 +01:00
Tim Ruffing
4f65698865 extrakeys: Remove redundant secp256k1_pubkey_cmp
It was a verbatim copy of secp256k1_ec_pubkey_cmp.
2024-01-23 16:04:45 +01:00
Tim Ruffing
e626f00d1e Merge commits 'b314cf28 1f1bb78b 40f50d0f c891c5c2 ea47c82e e7210393 c1b49664 5814d848 07687e81 10e6d29b d3e29db8 e2c9888e 4197d667 5e9a4d7a 77af1da9 1a81df82 1ad5185c efe85c70 79e09451 d373bf6d 74b7c3b5 a9db9f2d 44378867 3bf4d68f e4af41c6 ' into temp-merge-1249 2024-01-23 16:04:45 +01:00
Tim Ruffing
ba5d72d626 assumptions: Use new STATIC_ASSERT macro
This also splits the big "&&" expression into separate expressions. If
we ever see an assertion fail, the error message will tell it precisely
which one failed.
2024-01-08 16:10:55 +01:00
Tim Ruffing
e53c2d9ffc Require that sizeof(secp256k1_ge_storage) == 64
This gets rid of an untested code path. Resolves #1352.

secp256k1_ge_storage is a struct with two secp256k1_fe_storage fields.
The C standard allows the compiler to add padding between the fields and
at the end of the struct, but no sane compiler in the end would do this:
The only reason to add padding is to ensure alignment, but such padding
is never necessary between two fields of the same type.

Similarly, secp256k1_fe_storage is a struct with a single array of
uintXX_t. No padding is allowed between array elements. Again, C allows
the compiler to insert padding at the end of the struct, but there's no
absolute reason to do so in this case.

For the uintXX_t itself, this guaranteed to have no padding bits, i.e.,
it's guaranteed to have exactly XX bits.

So I claim that for any existing compiler in the real world,
sizeof(secp256k1_ge_storage) == 64.
2024-01-08 16:08:42 +01:00
Tim Ruffing
d0ba2abbff util: Add STATIC_ASSERT macro 2024-01-08 16:08:42 +01:00
Sanket Kanjalkar
e2eb3fae40 Make *key_cache const in musig_pubkey_get 2024-01-07 07:44:11 -08:00
Tim Ruffing
d373bf6d08
Merge bitcoin-core/secp256k1#1474: tests: restore scalar_mul test
3dbfb48946b9d2a98acef23674617510cf1b3386 tests: restore scalar_mul test (Jonas Nick)

Pull request description:

  Without this commit, the res[i][1] test vectors are unused. They were introduced to test the correctness of scalar_sqr(x) and scalar_mul(x, x). These tests were deleted as part of removing scalar_sqr in commit
  [5437e7bdfbffddf69fdf7b4af7e997c78f5dafbf](5437e7bdfb (diff-c2d5f1f7616875ab71cd41b053cfb428696988ff89642b931a0963d50f34f7e8L2195)).

  Discovered in https://github.com/bitcoin-core/secp256k1/discussions/1463 by Coding-Enthusiast (thanks!).

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

Tree-SHA512: 914e08db3efaa1cef546a9730096e740478c422d41fedb2b71ec3a7ea962f81740a05dc7e7c1fb191088f6d38b5690479c7d0864ca8abf2b2e9c4334f03ca605
2024-01-04 17:48:36 +01:00
Jonas Nick
3dbfb48946
tests: restore scalar_mul test
Without this commit, the res[i][1] test vectors are unused. They were introduced
to test the correctness of scalar_sqr(x) and scalar_mul(x, x). These tests were
deleted as part of removing scalar_sqr in commit
5437e7bdfbffddf69fdf7b4af7e997c78f5dafbf.
2024-01-04 15:45:11 +00:00
shuoer86
d77170a88d
Fix typos 2024-01-03 20:03:07 +08:00
Coding Enthusiast
3928b7c383 doc: improve secp256k1_fe_set_b32_mod doc 2023-12-08 14:58:38 +03:30
Tim Ruffing
5e9a4d7aec
Merge bitcoin-core/secp256k1#990: Add comment on length checks when parsing ECDSA sigs
e02f313b1f251ccb363ae1ac24016d87c1be9009 Add comment on length checks when parsing ECDSA sigs (Tim Ruffing)

Pull request description:

  I claim the check can be removed but I don't want to touch this
  stable and well-tested code.

  On the way, we fix grammar in another comment.

ACKs for top commit:
  sipa:
    ACK e02f313b1f251ccb363ae1ac24016d87c1be9009
  RandyMcMillan:
    ACK e02f313

Tree-SHA512: f82691a8f5db82a1e9683e52ce8e952ebd56b476a2817c5a876ce4638254b7b4ac93175318fb59598ed5532f33433951d75afea03724ef4419c3e1bd12ca8c20
2023-12-07 09:26:38 +01:00
Pieter Wuille
04af0ba162 Replace ge_equals_ge[,j] calls with group.h equality calls 2023-12-01 16:10:20 -05:00
Pieter Wuille
60525f6c14 Add unit tests for group.h equality functions 2023-12-01 16:10:15 -05:00
Pieter Wuille
a47cd97d51 Add group.h ge/gej equality functions 2023-12-01 16:06:29 -05:00
Jonas Nick
10e6d29b60
Merge bitcoin-core/secp256k1#1446: field: Remove x86_64 asm
f07cead0ca96e26356466b635ce6e7fe3834c949 build: Don't call assembly an optimization (Tim Ruffing)
2f0762fa8fd30b457bc5dcf53403123212091df5 field: Remove x86_64 asm (Tim Ruffing)

Pull request description:

ACKs for top commit:
  sipa:
    utACK f07cead0ca96e26356466b635ce6e7fe3834c949
  theStack:
    ACK f07cead0ca96e26356466b635ce6e7fe3834c949
  jonasnick:
    ACK f07cead0ca96e26356466b635ce6e7fe3834c949

Tree-SHA512: df7f895ab8ab924c5f8f01c35d0cd2f65d5c947c5ab5325787d169c5b202834ab8aa5d85dedb25839fff3f518097fe8cf8e837d3c1918e5f039ddd6ddf4187da
2023-12-01 18:49:48 +00:00
Sebastian Falbesoner
bb4672342e remove VERIFY_SETUP define
This define was seemingly introduced for VERIFY mode code with side
effects (for setup purposes), that should just be executed without any
checks. The same can be achieved by putting it in an `#if VERIFY` block,
so we can remove it.
2023-12-01 01:36:32 +01:00
Sebastian Falbesoner
a3a3e11acd remove unneeded VERIFY_SETUP uses in ECMULT_CONST_TABLE_GET_GE macro
As the fields r->x and r->y are set immediately after (three lines
below), there is no need to clear them.
2023-12-01 01:36:32 +01:00
Sebastian Falbesoner
a0fb68a2e7 introduce and use SECP256K1_SCALAR_VERIFY macro
By providing an uppercase variant of these verification functions,
it is better visible that it is test code.
2023-12-01 01:36:29 +01:00
Sebastian Falbesoner
cf25c86d05 introduce and use SECP256K1_{FE,GE,GEJ}_VERIFY macros
By providing an uppercase variant of these verification functions, it is
better visible that it is test code and surrounding `#ifdef VERIFY`
blocks can be removed (if there is no other code around that could
remain in production mode), as they don't serve their purpose any more.

At some places intentional blank lines are inserted for grouping and
better readadbility.
2023-12-01 00:54:58 +01:00
Sebastian Falbesoner
5d89bc031b remove superfluous #ifdef VERIFY/#endif preprocessor conditions
Now that the `VERIFY_CHECK` compiles to empty in non-VERIFY mode, blocks
that only consist of these macros don't need surrounding `#ifdef VERIFY`
conditions anymore.

At some places intentional blank lines are inserted for grouping and
better readadbility.
2023-12-01 00:54:41 +01:00
Sebastian Falbesoner
c2688f8de9 redefine VERIFY_CHECK to empty in production (non-VERIFY) mode
As suggested in issue #1381, this will make things simpler and
improve code readability, as we don't need to force omitting of
evaluations on a case-by-case basis anymore and hence can remove
lots of `#ifdef VERIFY`/`#endif` lines (see next commit). Plus,
VERIFY_CHECK behaves now identical in both non-VERIFY and coverage mode,
making the latter not special anymore and hopefully decreasing
maintenance burden. The idea of "side-effect safety" is given up.

Note that at two places in the ellswift module void-casts of return
values have to be inserted for non-VERIFY builds, in order to avoid
   "variable ... set but not used [-Wunused-but-set-variable]"
warnings.
2023-12-01 00:22:40 +01:00
Tim Ruffing
5814d8485c
Merge bitcoin-core/secp256k1#1438: correct assertion for secp256k1_fe_mul_inner
dcdda31f2cda13839a4285d8601118c041b18c13 Tighten secp256k1_fe_mul_inner's VERIFY_BITS checks (Russell O'Connor)
8e2a5fe908faa2ad0b847b3e5c42662614c8fa88 correct assertion for secp256k1_fe_mul_inner (roconnor-blockstream)

Pull request description:

  Based on the surrounding asserts, 112 bits before this line, and 61 bits after this line, this assertion should be 113 bits.  Notably the commensurate line in secp256k1_fe_sqr_inner is correctly assert to be 113 bits.

ACKs for top commit:
  real-or-random:
    ACK dcdda31f2cda13839a4285d8601118c041b18c13 tested with asm disabled

Tree-SHA512: c35170e37d9a6d1413dd625032028129ab2eccee7da86697ab9641b68ad78efd7251953d51e7acaefd14888d3fd61877f9f05349c44f6fc0133ce9b3921b0e1a
2023-11-27 09:45:09 +01:00
Tim Ruffing
2f0762fa8f field: Remove x86_64 asm
Widely available versions of GCC and Clang beat our field asm on -O2.
In particular, GCC 10.5.0, which is Bitcoin Core's current compiler
for official x86_64 builds, produces code that is > 20% faster for
fe_mul and > 10% faster for signature verification (see #726).

These are the alternatives to this PR:

We could replace our current asm with the fastest compiler output
that we can find. This is potentially faster, but it has multiple
drawbacks:
 - It's more coding work because it needs detailed benchmarks (e.g.,
   with many compiler/options).
 - It's more review work because we need to deal with inline asm
   (including clobbers etc.) and there's a lack of experts reviewers
   in this area.
 - It's not unlikely that we'll fall behind again in a few compiler
   versions, and then we have to deal with this again, i.e., redo the
   benchmarks. Given our history here, I doubt that we'll revolve
   this timely.

We could change the default of the asm build option to off. But this
will also disable the scalar asm, which is still faster.

We could split the build option into two separate options for field
and scalar asm and only disable the field asm by default. But this
adds complexity to the build and to the test matrix.

My conclusion is that this PR gets the low-hanging fruit in terms of
performance. It simplifies our code significantly. It's clearly an
improvement, and it's very easy to review. Whether re-introducing
better asm (whether from a compiler or from CryptOpt) is worth the
hassle can be evaluated separately, and should not hold up this
improvement.

Solves #726.
2023-11-24 08:11:08 +01:00
Sebastian Falbesoner
1ddd76af0a bench: add --help option to bench_internal 2023-11-24 02:33:40 +01:00
roconnor-blockstream
c33d2241cb Typo in shallue_van_de_woestijne description 2023-11-17 14:58:35 -05:00
Tim Ruffing
e72103932d
Merge bitcoin-core/secp256k1#1441: asm: add .note.GNU-stack section for non-exec stack
33dc7e4d3e1947af4c84c09ecc75ea2eeed3f7e0 asm: add .note.GNU-stack section for non-exec stack (fanquake)

Pull request description:

  With this in place, we no-longer see warnings like the following:
  ```bash
  /usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/bin/ld: warning: field_10x26_arm.o: missing .note.GNU-stack section implies executable stack
  /usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
  ```

  Should close #1434.

ACKs for top commit:
  sipa:
    utACK 33dc7e4d3e1947af4c84c09ecc75ea2eeed3f7e0
  real-or-random:
    utACK 33dc7e4d3e1947af4c84c09ecc75ea2eeed3f7e0

Tree-SHA512: f75ded8d971f54d1e871bcc4d815ba367b3e154eea2f18309ecaf9053e22f986bfffcf28418367f8055b65a5a0b245fee045adfcb63a2196df5e2f3aa6c97b89
2023-11-16 09:46:16 +01:00
Russell O'Connor
dcdda31f2c Tighten secp256k1_fe_mul_inner's VERIFY_BITS checks
These changes bring the checks to the same values used at the corresponding positions in secp256k1_fe_sqr_inner.
2023-11-14 12:07:00 -05:00
roconnor-blockstream
10271356c8
Return temporaries to being unsigned in secp256k1_fe_sqr_inner
These temporaries seem to been inadvertently changed to signed during a refactoring.  Generally, bit shifting is frowned upon for signed values.
2023-11-14 09:29:21 -05:00
fanquake
33dc7e4d3e
asm: add .note.GNU-stack section for non-exec stack
With this in place, we no-longer see warnings like the following:
```bash
/usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/bin/ld: warning: field_10x26_arm.o: missing .note.GNU-stack section implies executable stack
/usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
```

Should close #1434.
2023-11-13 14:49:35 +00:00
roconnor-blockstream
8e2a5fe908
correct assertion for secp256k1_fe_mul_inner
Based on the surrounding asserts, 112 bits before this line, and 61 bits after this line, this assertion should be 113 bits.  Notably the commensurate line in secp256k1_fe_sqr_inner is correctly assert to be 113 bits.
2023-11-06 17:40:17 -05:00
Pieter Wuille
21f49d9bec Remove unused secp256k1_scalar_shr_int 2023-11-04 15:55:12 -04:00
Pieter Wuille
115fdc7232 Remove unused secp256k1_wnaf_const 2023-11-04 15:55:12 -04:00
Jonas Nick
aa9f3a3c00 ecmult_const: add/improve tests
* add test case for a=infinity

  The corresponding ecmult_const branch was not tested before this commit.

* add test for edge cases
2023-11-04 15:55:12 -04:00
Pieter Wuille
4d16e90111 Signed-digit based ecmult_const algorithm 2023-11-04 15:55:12 -04:00
Pieter Wuille
ba523be067 make SECP256K1_SCALAR_CONST reduce modulo exhaustive group order 2023-11-04 15:54:08 -04:00
Pieter Wuille
2140da9cd5 Add secp256k1_scalar_half for halving scalars (+ tests/benchmarks).
Co-authored-by: Jonas Nick <jonasd.nick@gmail.com>
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
2023-11-04 15:54:08 -04:00