Skip to content

Commit d5f970e

Browse files
committed
Squashed 'src/secp256k1/' changes from efe85c70a2..282757398c
282757398c WIP: Silent merge conflicts 42dc5a9494 batch: Generate graphs for batch verification speed up fd9f58842f batch, extrakeys: Add benchmark for batch verify and `tweak_add_check` 94df19cd26 batch: Add tests for `batch_add_*` APIs 32d3f93683 batch,ecmult: Add tests for core batch APIs and `strauss_batch` refactor 30d5b37526 batch: Add API usage example 014c1501e2 batch: Add `batch_add_*` APIs 57f1c10a48 batch, ecmult: Add `batch_verify` API and refactor `strauss_batch` 871ade3aac batch: Add `create` and `destroy` APIs 960b6dafa4 batch: Initialize an experimental batch module 0653a25d50 Merge bitcoin-core/secp256k1#1486: ci: Update cache action 94a14d5290 ci: Update cache action 2483627299 Merge bitcoin-core/secp256k1#1483: cmake: Recommend native CMake commands in README 5ad3aa3dcd Merge bitcoin-core/secp256k1#1484: tests: Drop redundant _scalar_check_overflow calls 51df2d9ab3 tests: Drop redundant _scalar_check_overflow calls 3777e3f36a cmake: Recommend native CMake commands in README e4af41c61b Merge bitcoin-core/secp256k1#1249: cmake: Add `SECP256K1_LATE_CFLAGS` configure option 3bf4d68fc0 Merge bitcoin-core/secp256k1#1482: build: Clean up handling of module dependencies e6822678ea build: Error if required module explicitly off 89ec583ccf build: Clean up handling of module dependencies 44378867a0 Merge bitcoin-core/secp256k1#1468: v0.4.1 release aftermath a9db9f2d75 Merge bitcoin-core/secp256k1#1480: Get rid of untested sizeof(secp256k1_ge_storage) == 64 code path 74b7c3b53e Merge bitcoin-core/secp256k1#1476: include: make docs more consistent b37fdb28ce check-abi: Minor UI improvements ad5f589a94 check-abi: Default to HEAD for new version 9fb7e2f156 release process: Style and formatting nits ba5d72d626 assumptions: Use new STATIC_ASSERT macro e53c2d9ffc Require that sizeof(secp256k1_ge_storage) == 64 d0ba2abbff util: Add STATIC_ASSERT macro da7bc1b803 include: in doc, remove article in front of "pointer" aa3dd5280b include: make doc about ctx more consistent e3f690015a include: remove obvious "cannot be NULL" doc d373bf6d08 Merge bitcoin-core/secp256k1#1474: tests: restore scalar_mul test 79e094517c Merge bitcoin-core/secp256k1#1473: Fix typos 3dbfb48946 tests: restore scalar_mul test d77170a88d Fix typos e7053d065b release process: Add email step 429d21dc79 release process: Run sanity checks on release PR 42f8c51402 cmake: Add `SECP256K1_LATE_CFLAGS` configure option git-subtree-dir: src/secp256k1 git-subtree-split: 282757398c85c747addee74c5e410ab0b050f4ac
1 parent 29fde02 commit d5f970e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2847
-287
lines changed

.github/actions/install-homebrew-valgrind/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ runs:
1616
cat valgrind_fingerprint
1717
shell: bash
1818
19-
- uses: actions/cache@v3
19+
- uses: actions/cache@v4
2020
id: cache
2121
with:
2222
path: ${{ env.CI_HOMEBREW_CELLAR_VALGRIND }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ctime_tests
1010
ecdh_example
1111
ecdsa_example
1212
schnorr_example
13+
batch_example
1314
*.exe
1415
*.so
1516
*.a

CMakeLists.txt

+30-11
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,40 @@ endif()
5151

5252
option(SECP256K1_INSTALL "Enable installation." ${PROJECT_IS_TOP_LEVEL})
5353

54-
option(SECP256K1_ENABLE_MODULE_ECDH "Enable ECDH module." ON)
55-
if(SECP256K1_ENABLE_MODULE_ECDH)
56-
add_compile_definitions(ENABLE_MODULE_ECDH=1)
57-
endif()
54+
## Modules
5855

56+
# We declare all options before processing them, to make sure we can express
57+
# dependendencies while processing.
58+
option(SECP256K1_ENABLE_MODULE_ECDH "Enable ECDH module." ON)
5959
option(SECP256K1_ENABLE_MODULE_RECOVERY "Enable ECDSA pubkey recovery module." OFF)
60-
if(SECP256K1_ENABLE_MODULE_RECOVERY)
61-
add_compile_definitions(ENABLE_MODULE_RECOVERY=1)
62-
endif()
63-
6460
option(SECP256K1_ENABLE_MODULE_EXTRAKEYS "Enable extrakeys module." ON)
6561
option(SECP256K1_ENABLE_MODULE_SCHNORRSIG "Enable schnorrsig module." ON)
62+
option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON)
63+
64+
# Processing must be done in a topological sorting of the dependency graph
65+
# (dependent module first).
66+
if(SECP256K1_ENABLE_MODULE_ELLSWIFT)
67+
add_compile_definitions(ENABLE_MODULE_ELLSWIFT=1)
68+
endif()
69+
6670
if(SECP256K1_ENABLE_MODULE_SCHNORRSIG)
71+
if(DEFINED SECP256K1_ENABLE_MODULE_EXTRAKEYS AND NOT SECP256K1_ENABLE_MODULE_EXTRAKEYS)
72+
message(FATAL_ERROR "Module dependency error: You have disabled the extrakeys module explicitly, but it is required by the schnorrsig module.")
73+
endif()
6774
set(SECP256K1_ENABLE_MODULE_EXTRAKEYS ON)
6875
add_compile_definitions(ENABLE_MODULE_SCHNORRSIG=1)
6976
endif()
77+
7078
if(SECP256K1_ENABLE_MODULE_EXTRAKEYS)
7179
add_compile_definitions(ENABLE_MODULE_EXTRAKEYS=1)
7280
endif()
7381

74-
option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON)
75-
if(SECP256K1_ENABLE_MODULE_ELLSWIFT)
76-
add_compile_definitions(ENABLE_MODULE_ELLSWIFT=1)
82+
if(SECP256K1_ENABLE_MODULE_RECOVERY)
83+
add_compile_definitions(ENABLE_MODULE_RECOVERY=1)
84+
endif()
85+
86+
if(SECP256K1_ENABLE_MODULE_ECDH)
87+
add_compile_definitions(ENABLE_MODULE_ECDH=1)
7788
endif()
7889

7990
option(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS "Enable external default callback functions." OFF)
@@ -254,9 +265,14 @@ if(SECP256K1_BUILD_BENCHMARK OR SECP256K1_BUILD_TESTS OR SECP256K1_BUILD_EXHAUST
254265
enable_testing()
255266
endif()
256267

268+
set(SECP256K1_LATE_CFLAGS "" CACHE STRING "Compiler flags that are added to the command line after all other flags added by the build system.")
269+
include(AllTargetsCompileOptions)
270+
257271
add_subdirectory(src)
272+
all_targets_compile_options(src "${SECP256K1_LATE_CFLAGS}")
258273
if(SECP256K1_BUILD_EXAMPLES)
259274
add_subdirectory(examples)
275+
all_targets_compile_options(examples "${SECP256K1_LATE_CFLAGS}")
260276
endif()
261277

262278
message("\n")
@@ -330,6 +346,9 @@ else()
330346
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
331347
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
332348
endif()
349+
if(SECP256K1_LATE_CFLAGS)
350+
message("SECP256K1_LATE_CFLAGS ................. ${SECP256K1_LATE_CFLAGS}")
351+
endif()
333352
message("\n")
334353
if(SECP256K1_EXPERIMENTAL)
335354
message(

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The Contributor Workflow & Peer Review in libsecp256k1 are similar to Bitcoin Co
4444

4545
In addition, libsecp256k1 tries to maintain the following coding conventions:
4646

47-
* No runtime heap allocation (e.g., no `malloc`) unless explicitly requested by the caller (via `secp256k1_context_create` or `secp256k1_scratch_space_create`, for example). Morever, it should be possible to use the library without any heap allocations.
47+
* No runtime heap allocation (e.g., no `malloc`) unless explicitly requested by the caller (via `secp256k1_context_create` or `secp256k1_scratch_space_create`, for example). Moreover, it should be possible to use the library without any heap allocations.
4848
* The tests should cover all lines and branches of the library (see [Test coverage](#coverage)).
4949
* Operations involving secret data should be tested for being constant time with respect to the secrets (see [src/ctime_tests.c](src/ctime_tests.c)).
5050
* Local variables containing secret data should be cleared explicitly to try to delete secrets from memory.

Makefile.am

+15
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,17 @@ if BUILD_WINDOWS
181181
schnorr_example_LDFLAGS += -lbcrypt
182182
endif
183183
TESTS += schnorr_example
184+
if ENABLE_MODULE_BATCH
185+
noinst_PROGRAMS += batch_example
186+
batch_example_SOURCES = examples/batch.c
187+
batch_example_CPPFLAGS = -I$(top_srcdir)/include
188+
batch_example_LDADD = libsecp256k1.la
189+
batch_example_LDFLAGS = -static
190+
if BUILD_WINDOWS
191+
batch_example_LDFLAGS += -lbcrypt
192+
endif
193+
TESTS += batch_example
194+
endif
184195
endif
185196
endif
186197

@@ -271,3 +282,7 @@ endif
271282
if ENABLE_MODULE_ELLSWIFT
272283
include src/modules/ellswift/Makefile.am.include
273284
endif
285+
286+
if ENABLE_MODULE_BATCH
287+
include src/modules/batch/Makefile.am.include
288+
endif

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Features:
2020
* Optional module for public key recovery.
2121
* Optional module for ECDH key exchange.
2222
* Optional module for Schnorr signatures according to [BIP-340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki).
23+
* Optional module for Batch Verification (experimental).
2324

2425
Implementation details
2526
----------------------
@@ -79,9 +80,9 @@ To maintain a pristine source tree, CMake encourages to perform an out-of-source
7980

8081
$ mkdir build && cd build
8182
$ cmake ..
82-
$ make
83-
$ make check # run the test suite
84-
$ sudo make install # optional
83+
$ cmake --build .
84+
$ ctest # run the test suite
85+
$ sudo cmake --build . --target install # optional
8586

8687
To compile optional modules (such as Schnorr signatures), you need to run `cmake` with additional flags (such as `-DSECP256K1_ENABLE_MODULE_SCHNORRSIG=ON`). Run `cmake .. -LH` to see the full list of available flags.
8788

ci/cirrus.sh

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/sh
2+
3+
set -e
4+
set -x
5+
6+
export LC_ALL=C
7+
8+
# Start persistent wineserver if necessary.
9+
# This speeds up jobs with many invocations of wine (e.g., ./configure with MSVC) tremendously.
10+
case "$WRAPPER_CMD" in
11+
*wine*)
12+
# This is apparently only reliable when we run a dummy command such as "hh.exe" afterwards.
13+
wineserver -p && wine hh.exe
14+
;;
15+
esac
16+
17+
env >> test_env.log
18+
19+
$CC -v || true
20+
valgrind --version || true
21+
$WRAPPER_CMD --version || true
22+
23+
./autogen.sh
24+
25+
./configure \
26+
--enable-experimental="$EXPERIMENTAL" \
27+
--with-test-override-wide-multiply="$WIDEMUL" --with-asm="$ASM" \
28+
--with-ecmult-window="$ECMULTWINDOW" \
29+
--with-ecmult-gen-precision="$ECMULTGENPRECISION" \
30+
--enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \
31+
--enable-module-schnorrsig="$SCHNORRSIG" \
32+
--enable-module-batch="$BATCH" \
33+
--enable-examples="$EXAMPLES" \
34+
--with-valgrind="$WITH_VALGRIND" \
35+
--host="$HOST" $EXTRAFLAGS
36+
37+
# We have set "-j<n>" in MAKEFLAGS.
38+
make
39+
40+
# Print information about binaries so that we can see that the architecture is correct
41+
file *tests* || true
42+
file bench* || true
43+
file .libs/* || true
44+
45+
# This tells `make check` to wrap test invocations.
46+
export LOG_COMPILER="$WRAPPER_CMD"
47+
48+
make "$BUILD"
49+
50+
if [ "$BENCH" = "yes" ]
51+
then
52+
# Using the local `libtool` because on macOS the system's libtool has nothing to do with GNU libtool
53+
EXEC='./libtool --mode=execute'
54+
if [ -n "$WRAPPER_CMD" ]
55+
then
56+
EXEC="$EXEC $WRAPPER_CMD"
57+
fi
58+
{
59+
$EXEC ./bench_ecmult
60+
$EXEC ./bench_internal
61+
$EXEC ./bench
62+
} >> bench.log 2>&1
63+
fi
64+
65+
if [ "$CTIMETEST" = "yes" ]
66+
then
67+
./libtool --mode=execute valgrind --error-exitcode=42 ./valgrind_ctime_test > valgrind_ctime_test.log 2>&1
68+
fi
69+
70+
# Rebuild precomputed files (if not cross-compiling).
71+
if [ -z "$HOST" ]
72+
then
73+
make clean-precomp
74+
make precomp
75+
fi
76+
77+
# Shutdown wineserver again
78+
wineserver -k || true
79+
80+
# Check that no repo files have been modified by the build.
81+
# (This fails for example if the precomp files need to be updated in the repo.)
82+
git diff --exit-code

cmake/AllTargetsCompileOptions.cmake

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Add compile options to all targets added in the subdirectory.
2+
function(all_targets_compile_options dir options)
3+
get_directory_property(targets DIRECTORY ${dir} BUILDSYSTEM_TARGETS)
4+
separate_arguments(options)
5+
set(compiled_target_types STATIC_LIBRARY SHARED_LIBRARY OBJECT_LIBRARY EXECUTABLE)
6+
foreach(target ${targets})
7+
get_target_property(type ${target} TYPE)
8+
if(type IN_LIST compiled_target_types)
9+
target_compile_options(${target} PRIVATE ${options})
10+
endif()
11+
endforeach()
12+
endfunction()

configure.ac

+30-13
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ AC_ARG_ENABLE(module_ellswift,
188188
AS_HELP_STRING([--enable-module-ellswift],[enable ElligatorSwift module [default=yes]]), [],
189189
[SECP_SET_DEFAULT([enable_module_ellswift], [yes], [yes])])
190190

191+
AC_ARG_ENABLE(module_batch,
192+
AS_HELP_STRING([--enable-module-batch],[enable batch verification module (experimental) [default=no]]), [],
193+
[SECP_SET_DEFAULT([enable_module_batch], [no], [yes])])
194+
191195
AC_ARG_ENABLE(external_default_callbacks,
192196
AS_HELP_STRING([--enable-external-default-callbacks],[enable external default callback functions [default=no]]), [],
193197
[SECP_SET_DEFAULT([enable_external_default_callbacks], [no], [no])])
@@ -387,29 +391,36 @@ SECP_CFLAGS="$SECP_CFLAGS $WERROR_CFLAGS"
387391
### Handle module options
388392
###
389393

390-
if test x"$enable_module_ecdh" = x"yes"; then
391-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDH=1"
392-
fi
393-
394-
if test x"$enable_module_recovery" = x"yes"; then
395-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_RECOVERY=1"
394+
# Processing must be done in a reverse topological sorting of the dependency graph
395+
# (dependent module first).
396+
if test x"$enable_module_ellswift" = x"yes"; then
397+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ELLSWIFT=1"
396398
fi
397399

398400
if test x"$enable_module_schnorrsig" = x"yes"; then
399-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_SCHNORRSIG=1"
401+
if test x"$enable_module_extrakeys" = x"no"; then
402+
AC_MSG_ERROR([Module dependency error: You have disabled the extrakeys module explicitly, but it is required by the schnorrsig module.])
403+
fi
400404
enable_module_extrakeys=yes
405+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_SCHNORRSIG=1"
401406
fi
402407

403-
if test x"$enable_module_ellswift" = x"yes"; then
404-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ELLSWIFT=1"
405-
fi
406-
407-
# Test if extrakeys is set after the schnorrsig module to allow the schnorrsig
408-
# module to set enable_module_extrakeys=yes
409408
if test x"$enable_module_extrakeys" = x"yes"; then
410409
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_EXTRAKEYS=1"
411410
fi
412411

412+
if test x"$enable_module_recovery" = x"yes"; then
413+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_RECOVERY=1"
414+
fi
415+
416+
if test x"$enable_module_ecdh" = x"yes"; then
417+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDH=1"
418+
fi
419+
420+
if test x"$enable_module_batch" = x"yes"; then
421+
AC_DEFINE(ENABLE_MODULE_BATCH, 1, [Define this symbol to enable the batch verification module])
422+
fi
423+
413424
if test x"$enable_external_default_callbacks" = x"yes"; then
414425
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_EXTERNAL_DEFAULT_CALLBACKS=1"
415426
fi
@@ -422,11 +433,15 @@ if test x"$enable_experimental" = x"yes"; then
422433
AC_MSG_NOTICE([******])
423434
AC_MSG_NOTICE([WARNING: experimental build])
424435
AC_MSG_NOTICE([Experimental features do not have stable APIs or properties, and may not be safe for production use.])
436+
AC_MSG_NOTICE([Building batch verification module: $enable_module_batch])
425437
AC_MSG_NOTICE([******])
426438
else
427439
if test x"$set_asm" = x"arm32"; then
428440
AC_MSG_ERROR([ARM32 assembly is experimental. Use --enable-experimental to allow.])
429441
fi
442+
if test x"$enable_module_batch" = x"yes"; then
443+
AC_MSG_ERROR([batch verification module is experimental. Use --enable-experimental to allow.])
444+
fi
430445
fi
431446

432447
###
@@ -447,6 +462,7 @@ AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"ye
447462
AM_CONDITIONAL([ENABLE_MODULE_EXTRAKEYS], [test x"$enable_module_extrakeys" = x"yes"])
448463
AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" = x"yes"])
449464
AM_CONDITIONAL([ENABLE_MODULE_ELLSWIFT], [test x"$enable_module_ellswift" = x"yes"])
465+
AM_CONDITIONAL([ENABLE_MODULE_BATCH], [test x"$enable_module_batch" = x"yes"])
450466
AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$enable_external_asm" = x"yes"])
451467
AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm32"])
452468
AM_CONDITIONAL([BUILD_WINDOWS], [test "$build_windows" = "yes"])
@@ -469,6 +485,7 @@ echo " module recovery = $enable_module_recovery"
469485
echo " module extrakeys = $enable_module_extrakeys"
470486
echo " module schnorrsig = $enable_module_schnorrsig"
471487
echo " module ellswift = $enable_module_ellswift"
488+
echo " module batch = $enable_module_batch"
472489
echo
473490
echo " asm = $set_asm"
474491
echo " ecmult window size = $set_ecmult_window"

contrib/lax_der_parsing.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ extern "C" {
6767
*
6868
* Returns: 1 when the signature could be parsed, 0 otherwise.
6969
* Args: ctx: a secp256k1 context object
70-
* Out: sig: a pointer to a signature object
71-
* In: input: a pointer to the signature to be parsed
70+
* Out: sig: pointer to a signature object
71+
* In: input: pointer to the signature to be parsed
7272
* inputlen: the length of the array pointed to be input
7373
*
7474
* This function will accept any valid DER encoded signature, even if the

0 commit comments

Comments
 (0)