Skip to content

Commit f90c454

Browse files
committed
Squashed 'src/secp256k1/' changes from 0cdc758a56..e440c4fe45
e440c4fe45 build: Add build option for batch module 7c6b9df9ec SQUASH ME: Fix silent merge conflicts 4a0ea6104d batch: Generate graphs for batch verification speed up a804f05738 batch, extrakeys: Add benchmark for batch verify and `tweak_add_check` 2fa3654b1e batch: Add tests for `batch_add_*` APIs 2167f490c5 batch,ecmult: Add tests for core batch APIs and `strauss_batch` refactor 453a42c22f batch: Add API usage example 564b573451 batch: Add `batch_add_*` APIs c6577399a0 batch, ecmult: Add `batch_verify` API and refactor `strauss_batch` bb04d14af5 batch: Add `create` and `destroy` APIs e28dd3a120 batch: Initialize an experimental batch module 8deef00b33 Merge bitcoin-core/secp256k1#1634: Fix some misspellings 39705450eb Fix some misspellings ec329c2501 Merge bitcoin-core/secp256k1#1633: release cleanup: bump version after 0.6.0 c97059f594 release cleanup: bump version after 0.6.0 git-subtree-dir: src/secp256k1 git-subtree-split: e440c4fe45b82dba2fb39889c1b5244574ae4bd5
1 parent 2d46a89 commit f90c454

40 files changed

+2623
-80
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ecdsa_example
1212
schnorr_example
1313
ellswift_example
1414
musig_example
15+
batch_example
1516
*.exe
1617
*.so
1718
*.a

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
810
## [0.6.0] - 2024-11-04
911

1012
#### Added
@@ -162,6 +164,7 @@ This version was in fact never released.
162164
The number was given by the build system since the introduction of autotools in Jan 2014 (ea0fe5a5bf0c04f9cc955b2966b614f5f378c6f6).
163165
Therefore, this version number does not uniquely identify a set of source files.
164166

167+
[unreleased]: https://github.com/bitcoin-core/secp256k1/compare/v0.6.0...HEAD
165168
[0.6.0]: https://github.com/bitcoin-core/secp256k1/compare/v0.5.1...v0.6.0
166169
[0.5.1]: https://github.com/bitcoin-core/secp256k1/compare/v0.5.0...v0.5.1
167170
[0.5.0]: https://github.com/bitcoin-core/secp256k1/compare/v0.4.1...v0.5.0

CMakeLists.txt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ project(libsecp256k1
77
# The package (a.k.a. release) version is based on semantic versioning 2.0.0 of
88
# the API. All changes in experimental modules are treated as
99
# backwards-compatible and therefore at most increase the minor version.
10-
VERSION 0.6.0
10+
VERSION 0.6.1
1111
DESCRIPTION "Optimized C library for ECDSA signatures and secret/public key operations on curve secp256k1."
1212
HOMEPAGE_URL "https://github.com/bitcoin-core/secp256k1"
1313
LANGUAGES C
@@ -32,7 +32,7 @@ endif()
3232
# All changes in experimental modules are treated as if they don't affect the
3333
# interface and therefore only increase the revision.
3434
set(${PROJECT_NAME}_LIB_VERSION_CURRENT 5)
35-
set(${PROJECT_NAME}_LIB_VERSION_REVISION 0)
35+
set(${PROJECT_NAME}_LIB_VERSION_REVISION 1)
3636
set(${PROJECT_NAME}_LIB_VERSION_AGE 0)
3737

3838
#=============================
@@ -55,11 +55,12 @@ option(SECP256K1_INSTALL "Enable installation." ${PROJECT_IS_TOP_LEVEL})
5555
## Modules
5656

5757
# We declare all options before processing them, to make sure we can express
58-
# dependendencies while processing.
58+
# dependencies while processing.
5959
option(SECP256K1_ENABLE_MODULE_ECDH "Enable ECDH module." ON)
6060
option(SECP256K1_ENABLE_MODULE_RECOVERY "Enable ECDSA pubkey recovery module." OFF)
6161
option(SECP256K1_ENABLE_MODULE_EXTRAKEYS "Enable extrakeys module." ON)
6262
option(SECP256K1_ENABLE_MODULE_SCHNORRSIG "Enable schnorrsig module." ON)
63+
option(SECP256K1_ENABLE_MODULE_BATCH "Enable batch module." OFF)
6364
option(SECP256K1_ENABLE_MODULE_MUSIG "Enable musig module." ON)
6465
option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON)
6566

@@ -69,6 +70,18 @@ if(SECP256K1_ENABLE_MODULE_ELLSWIFT)
6970
add_compile_definitions(ENABLE_MODULE_ELLSWIFT=1)
7071
endif()
7172

73+
option(SECP256K1_EXPERIMENTAL "Allow experimental configuration options." OFF)
74+
if(SECP256K1_ENABLE_MODULE_BATCH)
75+
if(NOT SECP256K1_EXPERIMENTAL)
76+
message(FATAL_ERROR "Schnorrsig batch validation is experimental. Use -DSECP256K1_EXPERIMENTAL=ON to allow.")
77+
endif()
78+
if(DEFINED SECP256K1_ENABLE_MODULE_SCHNORRSIG AND NOT SECP256K1_ENABLE_MODULE_SCHNORRSIG)
79+
message(FATAL_ERROR "Module dependency error: You have disabled the schnorrsig module explicitly, but it is required by the Schnorrsig batch validation module.")
80+
endif()
81+
set(SECP256K1_ENABLE_MODULE_SCHNORRSIG ON)
82+
add_compile_definitions(ENABLE_MODULE_BATCH=1)
83+
endif()
84+
7285
if(SECP256K1_ENABLE_MODULE_MUSIG)
7386
if(DEFINED SECP256K1_ENABLE_MODULE_SCHNORRSIG AND NOT SECP256K1_ENABLE_MODULE_SCHNORRSIG)
7487
message(FATAL_ERROR "Module dependency error: You have disabled the schnorrsig module explicitly, but it is required by the musig module.")
@@ -156,7 +169,6 @@ elseif(SECP256K1_ASM)
156169
endif()
157170
endif()
158171

159-
option(SECP256K1_EXPERIMENTAL "Allow experimental configuration options." OFF)
160172
if(NOT SECP256K1_EXPERIMENTAL)
161173
if(SECP256K1_ASM STREQUAL "arm32")
162174
message(FATAL_ERROR "ARM32 assembly is experimental. Use -DSECP256K1_EXPERIMENTAL=ON to allow.")
@@ -325,6 +337,7 @@ message(" ECDH ................................ ${SECP256K1_ENABLE_MODULE_ECDH}
325337
message(" ECDSA pubkey recovery ............... ${SECP256K1_ENABLE_MODULE_RECOVERY}")
326338
message(" extrakeys ........................... ${SECP256K1_ENABLE_MODULE_EXTRAKEYS}")
327339
message(" schnorrsig .......................... ${SECP256K1_ENABLE_MODULE_SCHNORRSIG}")
340+
message(" batch ............................... ${SECP256K1_ENABLE_MODULE_BATCH}")
328341
message(" musig ............................... ${SECP256K1_ENABLE_MODULE_MUSIG}")
329342
message(" ElligatorSwift ...................... ${SECP256K1_ENABLE_MODULE_ELLSWIFT}")
330343
message("Parameters:")

Makefile.am

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ if BUILD_WINDOWS
183183
schnorr_example_LDFLAGS += -lbcrypt
184184
endif
185185
TESTS += schnorr_example
186+
if ENABLE_MODULE_BATCH
187+
noinst_PROGRAMS += batch_example
188+
batch_example_SOURCES = examples/batch.c
189+
batch_example_CPPFLAGS = -I$(top_srcdir)/include
190+
batch_example_LDADD = libsecp256k1.la
191+
batch_example_LDFLAGS = -static
192+
if BUILD_WINDOWS
193+
batch_example_LDFLAGS += -lbcrypt
194+
endif
195+
TESTS += batch_example
196+
endif
186197
endif
187198
if ENABLE_MODULE_ELLSWIFT
188199
noinst_PROGRAMS += ellswift_example
@@ -300,3 +311,7 @@ endif
300311
if ENABLE_MODULE_ELLSWIFT
301312
include src/modules/ellswift/Makefile.am.include
302313
endif
314+
315+
if ENABLE_MODULE_BATCH
316+
include src/modules/batch/Makefile.am.include
317+
endif

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Features:
2222
* Optional module for Schnorr signatures according to [BIP-340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki).
2323
* Optional module for ElligatorSwift key exchange according to [BIP-324](https://github.com/bitcoin/bips/blob/master/bip-0324.mediawiki).
2424
* Optional module for MuSig2 Schnorr multi-signatures according to [BIP-327](https://github.com/bitcoin/bips/blob/master/bip-0327.mediawiki).
25+
* Optional module for Batch Verification (experimental).
2526

2627
Implementation details
2728
----------------------

ci/cirrus.sh

Lines changed: 82 additions & 0 deletions
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

configure.ac

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ AC_PREREQ([2.60])
55
# backwards-compatible and therefore at most increase the minor version.
66
define(_PKG_VERSION_MAJOR, 0)
77
define(_PKG_VERSION_MINOR, 6)
8-
define(_PKG_VERSION_PATCH, 0)
9-
define(_PKG_VERSION_IS_RELEASE, true)
8+
define(_PKG_VERSION_PATCH, 1)
9+
define(_PKG_VERSION_IS_RELEASE, false)
1010

1111
# The library version is based on libtool versioning of the ABI. The set of
1212
# rules for updating the version can be found here:
1313
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
1414
# All changes in experimental modules are treated as if they don't affect the
1515
# interface and therefore only increase the revision.
1616
define(_LIB_VERSION_CURRENT, 5)
17-
define(_LIB_VERSION_REVISION, 0)
17+
define(_LIB_VERSION_REVISION, 1)
1818
define(_LIB_VERSION_AGE, 0)
1919

2020
AC_INIT([libsecp256k1],m4_join([.], _PKG_VERSION_MAJOR, _PKG_VERSION_MINOR, _PKG_VERSION_PATCH)m4_if(_PKG_VERSION_IS_RELEASE, [true], [], [-dev]),[https://github.com/bitcoin-core/secp256k1/issues],[libsecp256k1],[https://github.com/bitcoin-core/secp256k1])
@@ -192,6 +192,10 @@ AC_ARG_ENABLE(module_ellswift,
192192
AS_HELP_STRING([--enable-module-ellswift],[enable ElligatorSwift module [default=yes]]), [],
193193
[SECP_SET_DEFAULT([enable_module_ellswift], [yes], [yes])])
194194

195+
AC_ARG_ENABLE(module_batch,
196+
AS_HELP_STRING([--enable-module-batch],[enable batch verification module (experimental) [default=no]]), [],
197+
[SECP_SET_DEFAULT([enable_module_batch], [no], [yes])])
198+
195199
AC_ARG_ENABLE(external_default_callbacks,
196200
AS_HELP_STRING([--enable-external-default-callbacks],[enable external default callback functions [default=no]]), [],
197201
[SECP_SET_DEFAULT([enable_external_default_callbacks], [no], [no])])
@@ -254,8 +258,8 @@ fi
254258
print_msan_notice=no
255259
if test x"$enable_ctime_tests" = x"yes"; then
256260
SECP_MSAN_CHECK
257-
# MSan on Clang >=16 reports unitialized memory in function parameters and return values, even if
258-
# the uninitalized variable is never actually "used". This is called "eager" checking, and it's
261+
# MSan on Clang >=16 reports uninitialized memory in function parameters and return values, even if
262+
# the uninitialized variable is never actually "used". This is called "eager" checking, and it's
259263
# sounds like good idea for normal use of MSan. However, it yields many false positives in the
260264
# ctime_tests because many return values depend on secret (i.e., "uninitialized") values, and
261265
# we're only interested in detecting branches (which count as "uses") on secret data.
@@ -430,6 +434,10 @@ if test x"$enable_module_ecdh" = x"yes"; then
430434
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDH=1"
431435
fi
432436

437+
if test x"$enable_module_batch" = x"yes"; then
438+
AC_DEFINE(ENABLE_MODULE_BATCH, 1, [Define this symbol to enable the batch verification module])
439+
fi
440+
433441
if test x"$enable_external_default_callbacks" = x"yes"; then
434442
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_EXTERNAL_DEFAULT_CALLBACKS=1"
435443
fi
@@ -442,6 +450,9 @@ if test x"$enable_experimental" = x"no"; then
442450
if test x"$set_asm" = x"arm32"; then
443451
AC_MSG_ERROR([ARM32 assembly is experimental. Use --enable-experimental to allow.])
444452
fi
453+
if test x"$enable_module_batch" = x"yes"; then
454+
AC_MSG_ERROR([batch verification module is experimental. Use --enable-experimental to allow.])
455+
fi
445456
fi
446457

447458
###
@@ -463,6 +474,7 @@ AM_CONDITIONAL([ENABLE_MODULE_EXTRAKEYS], [test x"$enable_module_extrakeys" = x"
463474
AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" = x"yes"])
464475
AM_CONDITIONAL([ENABLE_MODULE_MUSIG], [test x"$enable_module_musig" = x"yes"])
465476
AM_CONDITIONAL([ENABLE_MODULE_ELLSWIFT], [test x"$enable_module_ellswift" = x"yes"])
477+
AM_CONDITIONAL([ENABLE_MODULE_BATCH], [test x"$enable_module_batch" = x"yes"])
466478
AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$enable_external_asm" = x"yes"])
467479
AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm32"])
468480
AM_CONDITIONAL([BUILD_WINDOWS], [test "$build_windows" = "yes"])
@@ -486,6 +498,7 @@ echo " module extrakeys = $enable_module_extrakeys"
486498
echo " module schnorrsig = $enable_module_schnorrsig"
487499
echo " module musig = $enable_module_musig"
488500
echo " module ellswift = $enable_module_ellswift"
501+
echo " module batch = $enable_module_batch"
489502
echo
490503
echo " asm = $set_asm"
491504
echo " ecmult window size = $set_ecmult_window"

doc/speedup-batch.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Schnorrsig Batch Verification Speedup
2+
3+
![Speedup over single verification](speedup-batch/schnorrsig-speedup-batch.png)
4+
5+
# Tweak Pubkey Check Batch Verification Speedup
6+
7+
![Speedup over single verification](speedup-batch/tweakcheck-speedup-batch.png)
8+
9+
Build steps
10+
-----------
11+
To generate the above graphs on your local machine:
12+
13+
$ cd doc/speedup-batch
14+
$ make
15+
$ make speedup-batch.png

doc/speedup-batch/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.dat

doc/speedup-batch/Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
schnorrsig_data = schnorrsig_batch.dat schnorrsig_single.dat
2+
tweak_data = tweak_batch.dat tweak_single.dat
3+
4+
bench_output.txt: bench.sh
5+
SECP256K1_BENCH_ITERS=500000 ./bench.sh bench_output.txt
6+
7+
schnorrsig_batch.dat: bench_output.txt
8+
cat bench_output.txt | grep -v "schnorrsig_batch_verify_1 " | awk '{ gsub(/ /,""); print }' | awk -F, 'match($$0, /schnorrsig_batch_verify_([0-9]+)/, arr) {print arr[1] " " $$3}' > schnorrsig_batch.dat
9+
10+
schnorrsig_single.dat: bench_output.txt
11+
cat bench_output.txt | awk '{ gsub(/ /,""); print }' | awk -F, 'match($$0, /schnorrsig_verify/) {print $$3}' > schnorrsig_single.dat
12+
13+
tweak_batch.dat: bench_output.txt
14+
cat bench_output.txt | grep -v "tweak_check_batch_verify_1 " | awk '{ gsub(/ /,""); print }' | awk -F, 'match($$0, /tweak_check_batch_verify_([0-9]+)/, arr) {print arr[1] " " $$3}' > tweak_batch.dat
15+
16+
tweak_single.dat: bench_output.txt
17+
cat bench_output.txt | awk '{ gsub(/ /,""); print }' | awk -F, 'match($$0, /tweak_add_check/) {print $$3}' > tweak_single.dat
18+
19+
speedup-batch.png: $(schnorrsig_data) $(tweak_data) plot.gp
20+
gnuplot plot.gp
21+
22+
clean:
23+
rm *.log *.txt *.dat *.png

doc/speedup-batch/bench.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
output_file=$1
4+
cur_dir=$(pwd)
5+
6+
cd ../../
7+
echo "HEAD: $(git rev-parse --short HEAD)" > "$cur_dir/$output_file.log"
8+
make clean
9+
./autogen.sh
10+
./configure --enable-experimental --enable-module-batch --enable-module-schnorrsig >> "$cur_dir/$output_file.log"
11+
make -j
12+
./bench schnorrsig > "$cur_dir/$output_file"
13+
./bench extrakeys >> "$cur_dir/$output_file"

0 commit comments

Comments
 (0)