Skip to content

Commit 235da29

Browse files
fanquake5tefan
authored andcommitted
Partial merge bitcoin#22448: Update libsecp256k1 subtree to latest upstream
c020cba Squashed 'src/secp256k1/' changes from efad350..be8d9c2 (Pieter Wuille) Pull request description: This updates our src/secp256k1 subtree to the lastest upstream master. Notable changes: * New schnorrsig API (bitcoin-core/secp256k1#844), which adds support for variable-length messages (not used in BIP341/342 transaction signing, so not relevant for us, but it changes the API, and makes some other simplifications). Some of our call sites had to be adapted. * Don't use asm optimizations for `gen_context` (bitcoin-core/secp256k1#965). This fixes bitcoin#22441. * Various testing/CI improvements ACKs for top commit: hebasto: ACK e4ffb44 jonatack: Light ACK e4ffb44 debug built (debian clang 13.0), ran bitcoind node/tests/git-subtree-check.sh, lightly reviewed the diff and API changes fanquake: ACK e4ffb44 Tree-SHA512: 89a5c3019ec010d578e84bcef756d2c679420c5c768bcdece673405c4e10955179c5a1339aafc68b8b74b1e3912e147bf2f392f44f15af73791d93f6537960b3
1 parent dd45c61 commit 235da29

Some content is hidden

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

42 files changed

+1222
-365
lines changed

src/secp256k1/.cirrus.yml

Lines changed: 173 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
env:
2-
WIDEMUL: auto
2+
### compiler options
3+
HOST:
4+
# Specific warnings can be disabled with -Wno-error=foo.
5+
# -pedantic-errors is not equivalent to -Werror=pedantic and thus not implied by -Werror according to the GCC manual.
6+
WERROR_CFLAGS: -Werror -pedantic-errors
7+
MAKEFLAGS: -j2
8+
BUILD: check
9+
### secp256k1 config
310
STATICPRECOMPUTATION: yes
411
ECMULTGENPRECISION: auto
512
ASM: no
6-
BUILD: check
13+
WIDEMUL: auto
714
WITH_VALGRIND: yes
8-
RUN_VALGRIND: no
915
EXTRAFLAGS:
10-
HOST:
16+
### secp256k1 modules
17+
EXPERIMENTAL: no
1118
ECDH: no
1219
RECOVERY: no
1320
SCHNORRSIG: no
14-
EXPERIMENTAL: no
15-
CTIMETEST: yes
21+
### test options
22+
TEST_ITERS:
1623
BENCH: yes
17-
ITERS: 2
18-
MAKEFLAGS: -j2
24+
BENCH_ITERS: 2
25+
CTIMETEST: yes
1926

2027
cat_logs_snippet: &CAT_LOGS
2128
always:
@@ -63,27 +70,8 @@ task:
6370
- env: {BUILD: distcheck, WITH_VALGRIND: no, CTIMETEST: no, BENCH: no}
6471
- env: {CPPFLAGS: -DDETERMINISTIC}
6572
- env: {CFLAGS: -O0, CTIMETEST: no}
66-
- env:
67-
CFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
68-
LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
69-
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
70-
ASM: x86_64
71-
ECDH: yes
72-
RECOVERY: yes
73-
EXPERIMENTAL: yes
74-
SCHNORRSIG: yes
75-
CTIMETEST: no
7673
- env: { ECMULTGENPRECISION: 2 }
7774
- env: { ECMULTGENPRECISION: 8 }
78-
- env:
79-
RUN_VALGRIND: yes
80-
ASM: x86_64
81-
ECDH: yes
82-
RECOVERY: yes
83-
EXPERIMENTAL: yes
84-
SCHNORRSIG: yes
85-
EXTRAFLAGS: "--disable-openssl-tests"
86-
BUILD:
8775
matrix:
8876
- env:
8977
CC: gcc
@@ -111,6 +99,7 @@ task:
11199
CC: i686-linux-gnu-gcc
112100
- env:
113101
CC: clang --target=i686-pc-linux-gnu -isystem /usr/i686-linux-gnu/include
102+
<< : *MERGE_BASE
114103
test_script:
115104
- ./ci/cirrus.sh
116105
<< : *CAT_LOGS
@@ -181,9 +170,9 @@ task:
181170
cpu: 1
182171
memory: 1G
183172
env:
184-
QEMU_CMD: qemu-s390x
173+
WRAPPER_CMD: qemu-s390x
174+
TEST_ITERS: 16
185175
HOST: s390x-linux-gnu
186-
BUILD:
187176
WITH_VALGRIND: no
188177
ECDH: yes
189178
RECOVERY: yes
@@ -196,3 +185,158 @@ task:
196185
- rm /etc/ld.so.cache
197186
- ./ci/cirrus.sh
198187
<< : *CAT_LOGS
188+
189+
task:
190+
name: "ARM32: Linux (Debian stable, QEMU)"
191+
container:
192+
dockerfile: ci/linux-debian.Dockerfile
193+
cpu: 1
194+
memory: 1G
195+
env:
196+
WRAPPER_CMD: qemu-arm
197+
TEST_ITERS: 16
198+
HOST: arm-linux-gnueabihf
199+
WITH_VALGRIND: no
200+
ECDH: yes
201+
RECOVERY: yes
202+
EXPERIMENTAL: yes
203+
SCHNORRSIG: yes
204+
CTIMETEST: no
205+
matrix:
206+
- env: {}
207+
- env: {ASM: arm}
208+
<< : *MERGE_BASE
209+
test_script:
210+
- ./ci/cirrus.sh
211+
<< : *CAT_LOGS
212+
213+
task:
214+
name: "ARM64: Linux (Debian stable, QEMU)"
215+
container:
216+
dockerfile: ci/linux-debian.Dockerfile
217+
cpu: 1
218+
memory: 1G
219+
env:
220+
WRAPPER_CMD: qemu-aarch64
221+
TEST_ITERS: 16
222+
HOST: aarch64-linux-gnu
223+
WITH_VALGRIND: no
224+
ECDH: yes
225+
RECOVERY: yes
226+
EXPERIMENTAL: yes
227+
SCHNORRSIG: yes
228+
CTIMETEST: no
229+
<< : *MERGE_BASE
230+
test_script:
231+
- ./ci/cirrus.sh
232+
<< : *CAT_LOGS
233+
234+
task:
235+
name: "ppc64le: Linux (Debian stable, QEMU)"
236+
container:
237+
dockerfile: ci/linux-debian.Dockerfile
238+
cpu: 1
239+
memory: 1G
240+
env:
241+
WRAPPER_CMD: qemu-ppc64le
242+
TEST_ITERS: 16
243+
HOST: powerpc64le-linux-gnu
244+
WITH_VALGRIND: no
245+
ECDH: yes
246+
RECOVERY: yes
247+
EXPERIMENTAL: yes
248+
SCHNORRSIG: yes
249+
CTIMETEST: no
250+
<< : *MERGE_BASE
251+
test_script:
252+
- ./ci/cirrus.sh
253+
<< : *CAT_LOGS
254+
255+
task:
256+
name: "x86_64 (mingw32-w64): Windows (Debian stable, Wine)"
257+
container:
258+
dockerfile: ci/linux-debian.Dockerfile
259+
cpu: 1
260+
memory: 1G
261+
env:
262+
WRAPPER_CMD: wine64-stable
263+
TEST_ITERS: 16
264+
HOST: x86_64-w64-mingw32
265+
WITH_VALGRIND: no
266+
ECDH: yes
267+
RECOVERY: yes
268+
EXPERIMENTAL: yes
269+
SCHNORRSIG: yes
270+
CTIMETEST: no
271+
<< : *MERGE_BASE
272+
test_script:
273+
- ./ci/cirrus.sh
274+
<< : *CAT_LOGS
275+
276+
# Sanitizers
277+
task:
278+
container:
279+
dockerfile: ci/linux-debian.Dockerfile
280+
cpu: 1
281+
memory: 1G
282+
env:
283+
ECDH: yes
284+
RECOVERY: yes
285+
EXPERIMENTAL: yes
286+
SCHNORRSIG: yes
287+
CTIMETEST: no
288+
EXTRAFLAGS: "--disable-openssl-tests"
289+
matrix:
290+
- name: "Valgrind (memcheck)"
291+
env:
292+
# The `--error-exitcode` is required to make the test fail if valgrind found errors, otherwise it'll return 0 (https://www.valgrind.org/docs/manual/manual-core.html)
293+
WRAPPER_CMD: "valgrind --error-exitcode=42"
294+
TEST_ITERS: 16
295+
- name: "UBSan, ASan, LSan"
296+
env:
297+
CFLAGS: "-fsanitize=undefined,address"
298+
CFLAGS_FOR_BUILD: "-fsanitize=undefined,address"
299+
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
300+
ASAN_OPTIONS: "strict_string_checks=1:detect_stack_use_after_return=1:detect_leaks=1"
301+
LSAN_OPTIONS: "use_unaligned=1"
302+
TEST_ITERS: 32
303+
# Try to cover many configurations with just a tiny matrix.
304+
matrix:
305+
- env:
306+
ASM: auto
307+
STATICPRECOMPUTATION: yes
308+
- env:
309+
ASM: no
310+
STATICPRECOMPUTATION: no
311+
ECMULTGENPRECISION: 2
312+
matrix:
313+
- env:
314+
CC: clang
315+
- env:
316+
HOST: i686-linux-gnu
317+
CC: i686-linux-gnu-gcc
318+
<< : *MERGE_BASE
319+
test_script:
320+
- ./ci/cirrus.sh
321+
<< : *CAT_LOGS
322+
323+
task:
324+
name: "C++ -fpermissive"
325+
container:
326+
dockerfile: ci/linux-debian.Dockerfile
327+
cpu: 1
328+
memory: 1G
329+
env:
330+
# ./configure correctly errors out when given CC=g++.
331+
# We hack around this by passing CC=g++ only to make.
332+
CC: gcc
333+
MAKEFLAGS: -j2 CC=g++ CFLAGS=-fpermissive
334+
WERROR_CFLAGS:
335+
EXPERIMENTAL: yes
336+
ECDH: yes
337+
RECOVERY: yes
338+
SCHNORRSIG: yes
339+
<< : *MERGE_BASE
340+
test_script:
341+
- ./ci/cirrus.sh
342+
<< : *CAT_LOGS

src/secp256k1/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ aclocal.m4
2323
autom4te.cache/
2424
config.log
2525
config.status
26+
conftest*
2627
*.tar.gz
2728
*.la
2829
libtool
@@ -33,6 +34,14 @@ libtool
3334
*~
3435
*.log
3536
*.trs
37+
38+
coverage/
39+
coverage.html
40+
coverage.*.html
41+
*.gcda
42+
*.gcno
43+
*.gcov
44+
3645
src/libsecp256k1-config.h
3746
src/libsecp256k1-config.h.in
3847
src/ecmult_static_context.h

src/secp256k1/Makefile.am

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
ACLOCAL_AMFLAGS = -I build-aux/m4
22

3+
# AM_CFLAGS will be automatically prepended to CFLAGS by Automake when compiling some foo
4+
# which does not have an explicit foo_CFLAGS variable set.
5+
AM_CFLAGS = $(SECP_CFLAGS)
6+
37
lib_LTLIBRARIES = libsecp256k1.la
48
include_HEADERS = include/secp256k1.h
59
include_HEADERS += include/secp256k1_preallocated.h
@@ -68,7 +72,7 @@ endif
6872
endif
6973

7074
libsecp256k1_la_SOURCES = src/secp256k1.c
71-
libsecp256k1_la_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
75+
libsecp256k1_la_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
7276
libsecp256k1_la_LIBADD = $(SECP_LIBS) $(COMMON_LIB)
7377

7478
if VALGRIND_ENABLED
@@ -81,27 +85,27 @@ noinst_PROGRAMS += bench_verify bench_sign bench_internal bench_ecmult
8185
bench_verify_SOURCES = src/bench_verify.c
8286
bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
8387
# SECP_TEST_INCLUDES are only used here for CRYPTO_CPPFLAGS
84-
bench_verify_CPPFLAGS = -DSECP256K1_BUILD $(SECP_TEST_INCLUDES)
88+
bench_verify_CPPFLAGS = $(SECP_TEST_INCLUDES)
8589
bench_sign_SOURCES = src/bench_sign.c
8690
bench_sign_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
8791
bench_internal_SOURCES = src/bench_internal.c
8892
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB)
89-
bench_internal_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
93+
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
9094
bench_ecmult_SOURCES = src/bench_ecmult.c
9195
bench_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB)
92-
bench_ecmult_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
96+
bench_ecmult_CPPFLAGS = $(SECP_INCLUDES)
9397
endif
9498

9599
TESTS =
96100
if USE_TESTS
97101
noinst_PROGRAMS += tests
98102
tests_SOURCES = src/tests.c
99-
tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
103+
tests_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
100104
if VALGRIND_ENABLED
101105
tests_CPPFLAGS += -DVALGRIND
102106
noinst_PROGRAMS += valgrind_ctime_test
103107
valgrind_ctime_test_SOURCES = src/valgrind_ctime_test.c
104-
valgrind_ctime_test_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_LIBS) $(COMMON_LIB)
108+
valgrind_ctime_test_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB)
105109
endif
106110
if !ENABLE_COVERAGE
107111
tests_CPPFLAGS += -DVERIFY
@@ -114,7 +118,7 @@ endif
114118
if USE_EXHAUSTIVE_TESTS
115119
noinst_PROGRAMS += exhaustive_tests
116120
exhaustive_tests_SOURCES = src/tests_exhaustive.c
117-
exhaustive_tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src $(SECP_INCLUDES)
121+
exhaustive_tests_CPPFLAGS = -I$(top_srcdir)/src $(SECP_INCLUDES)
118122
if !ENABLE_COVERAGE
119123
exhaustive_tests_CPPFLAGS += -DVERIFY
120124
endif
@@ -129,10 +133,10 @@ CPPFLAGS_FOR_BUILD +=-I$(top_srcdir) -I$(builddir)/src
129133
gen_context_OBJECTS = gen_context.o
130134
gen_context_BIN = gen_context$(BUILD_EXEEXT)
131135
gen_%.o: src/gen_%.c src/libsecp256k1-config.h
132-
$(CC_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
136+
$(CC_FOR_BUILD) $(DEFS) $(CPPFLAGS_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
133137

134138
$(gen_context_BIN): $(gen_context_OBJECTS)
135-
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
139+
$(CC_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
136140

137141
$(libsecp256k1_la_OBJECTS): src/ecmult_static_context.h
138142
$(tests_OBJECTS): src/ecmult_static_context.h

src/secp256k1/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Features:
1717
* Suitable for embedded systems.
1818
* Optional module for public key recovery.
1919
* Optional module for ECDH key exchange.
20+
* Optional module for Schnorr signatures according to [BIP-340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki) (experimental).
2021

2122
Experimental features have not received enough scrutiny to satisfy the standard of quality of this library but are made available for testing and review by the community. The APIs of these features should not be considered stable.
2223

@@ -96,7 +97,8 @@ To create a report, `gcovr` is recommended, as it includes branch coverage repor
9697

9798
To create a HTML report with coloured and annotated source code:
9899

99-
$ gcovr --exclude 'src/bench*' --html --html-details -o coverage.html
100+
$ mkdir -p coverage
101+
$ gcovr --exclude 'src/bench*' --html --html-details -o coverage/coverage.html
100102

101103
Reporting a vulnerability
102104
------------

src/secp256k1/build-aux/m4/bitcoin_secp.m4

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,19 @@ if test x"$has_valgrind" != x"yes"; then
8282
AC_CHECK_HEADER([valgrind/memcheck.h], [has_valgrind=yes; AC_DEFINE(HAVE_VALGRIND,1,[Define this symbol if valgrind is installed])])
8383
fi
8484
])
85+
86+
dnl SECP_TRY_APPEND_CFLAGS(flags, VAR)
87+
dnl Append flags to VAR if CC accepts them.
88+
AC_DEFUN([SECP_TRY_APPEND_CFLAGS], [
89+
AC_MSG_CHECKING([if ${CC} supports $1])
90+
SECP_TRY_APPEND_CFLAGS_saved_CFLAGS="$CFLAGS"
91+
CFLAGS="$1 $CFLAGS"
92+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])], [flag_works=yes], [flag_works=no])
93+
AC_MSG_RESULT($flag_works)
94+
CFLAGS="$SECP_TRY_APPEND_CFLAGS_saved_CFLAGS"
95+
if test x"$flag_works" = x"yes"; then
96+
$2="$$2 $1"
97+
fi
98+
unset flag_works
99+
AC_SUBST($2)
100+
])

0 commit comments

Comments
 (0)