Skip to content

Commit 0559fc6

Browse files
Merge #988: Make signing table fully static
7dfcece build: Remove #undef hack for ASM in the precomputation programs (Tim Ruffing) bb36fe9 ci: Test `make precomp` (Tim Ruffing) d94a37a build: Remove CC_FOR_BUILD stuff (Tim Ruffing) ad63bb4 build: Prebuild and distribute ecmult_gen table (Tim Ruffing) ac49361 prealloc: Get rid of manual memory management for prealloc contexts (Tim Ruffing) 6573c08 ecmult_gen: Tidy precomputed file and save space (Tim Ruffing) 5eba83f ecmult_gen: Precompute tables for all values of ECMULT_GEN_PREC_BITS (Tim Ruffing) fdb33dd refactor: Make PREC_BITS a parameter of ecmult_gen_build_prec_table (Tim Ruffing) a4875e3 refactor: Move default callbacks to util.h (Tim Ruffing) 4c94c55 doc: Remove obsolete hint for valgrind stack size (Tim Ruffing) 5106226 exhaustive_tests: Fix with ecmult_gen table with custom generator (Tim Ruffing) e1a7653 refactor: Make generator a parameter of ecmult_gen_create_prec_table (Tim Ruffing) 9ad09f6 refactor: Rename program that generates static ecmult_gen table (Tim Ruffing) 8ae18f1 refactor: Rename file that contains static ecmult_gen table (Tim Ruffing) 00d2fa1 ecmult_gen: Make code consistent with comment (Tim Ruffing) 3b0c218 ecmult_gen: Simplify ecmult_gen context after making table static (Tim Ruffing) e43ba02 refactor: Decouple table generation and ecmult_gen context (Tim Ruffing) 22dc2c0 ecmult_gen: Move table creation to new file and force static prec (Tim Ruffing) Pull request description: This resolves #893, resolves #692 (and also resolves bitcoin/bitcoin#22854). - [x] Extract table generation to separate function in separate file (to be used by generation script and exhaustive tests) - [x] Tidy up - [x] Remove code that deals with non-static tables - [x] Make functions that need ecmult_gen not depend on signing context - [x] Rename stuff to make it fit the new structure and consistent with how we hande verification tables (#956) - [x] Fix exhaustive tests - [x] Make table generation function take generator as input - [x] Overwrite the static tables with a table with custom generator in exhaustive tests - [x] Overhaul script that generates table files - [x] Make table generation function take PREC_BITS as input (I have some code already, just not yet in this branch) - [x] Change generation script to generate three tables (for all three values of ECMULT_GEN_PREC_BITS) - [x] Ship pre-built tables - [x] Add pregenerated table file to repo - [x] Remove generation of table file from build process (like in #956) - [x] Remove left-over stuff (e.g., detecting a compiler running on the build machine) from build system - [x] Final cleanups (copyright headers, commit, messages, etc.) - [ ] (separate PR:) Make sure link-time optimization remove corresponding static tables (and code) when no signing/verifcation function is called - [ ] (separate PR:) Compile precomputation as a separate object file and link it (#988 (comment)) - [ ] (separate PR:) Document the backwards-compatible API changes made in this PR and in #956. - [ ] Maybe deprecate the static context ACKs for top commit: sipa: ACK 7dfcece robot-dreams: ACK 7dfcece (based on range-diff between 56284c7 and 7dfcece) Tree-SHA512: 6efb3f36f05efe3b79bbd877881fe1409f71fd6488d24c811b2e77d9f053bed78670dd1dcbb42ad780458a51c4ffa36de9cd6567271b22041dc7a122ceb677c5
2 parents 5d0dbef + 7dfcece commit 0559fc6

23 files changed

+10134
-616
lines changed

.cirrus.yml

-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ task:
294294
- name: "UBSan, ASan, LSan"
295295
env:
296296
CFLAGS: "-fsanitize=undefined,address -g"
297-
CFLAGS_FOR_BUILD: "-fsanitize=undefined,address -g"
298297
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
299298
ASAN_OPTIONS: "strict_string_checks=1:detect_stack_use_after_return=1:detect_leaks=1"
300299
LSAN_OPTIONS: "use_unaligned=1"

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
src/ecmult_static_pre_g.h linguist-generated
2+
src/ecmult_gen_static_prec_table.h linguist-generated

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ bench_ecmult
33
bench_internal
44
tests
55
exhaustive_tests
6-
gen_context
6+
gen_ecmult_gen_static_prec_table
77
gen_ecmult_static_pre_g
88
valgrind_ctime_test
99
*.exe
@@ -41,7 +41,6 @@ coverage.*.html
4141

4242
src/libsecp256k1-config.h
4343
src/libsecp256k1-config.h.in
44-
src/ecmult_static_context.h
4544
build-aux/config.guess
4645
build-aux/config.sub
4746
build-aux/depcomp

Makefile.am

+36-22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.PHONY: clean-precomp precomp
2+
13
ACLOCAL_AMFLAGS = -I build-aux/m4
24

35
# AM_CFLAGS will be automatically prepended to CFLAGS by Automake when compiling some foo
@@ -28,6 +30,8 @@ noinst_HEADERS += src/ecmult_const.h
2830
noinst_HEADERS += src/ecmult_const_impl.h
2931
noinst_HEADERS += src/ecmult_gen.h
3032
noinst_HEADERS += src/ecmult_gen_impl.h
33+
noinst_HEADERS += src/ecmult_gen_prec.h
34+
noinst_HEADERS += src/ecmult_gen_prec_impl.h
3135
noinst_HEADERS += src/field_10x26.h
3236
noinst_HEADERS += src/field_10x26_impl.h
3337
noinst_HEADERS += src/field_5x52.h
@@ -50,6 +54,7 @@ noinst_HEADERS += src/hash_impl.h
5054
noinst_HEADERS += src/field.h
5155
noinst_HEADERS += src/field_impl.h
5256
noinst_HEADERS += src/bench.h
57+
noinst_HEADERS += src/basic-config.h
5358
noinst_HEADERS += contrib/lax_der_parsing.h
5459
noinst_HEADERS += contrib/lax_der_parsing.c
5560
noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
@@ -115,7 +120,7 @@ endif
115120
if USE_EXHAUSTIVE_TESTS
116121
noinst_PROGRAMS += exhaustive_tests
117122
exhaustive_tests_SOURCES = src/tests_exhaustive.c
118-
exhaustive_tests_CPPFLAGS = -I$(top_srcdir)/src $(SECP_INCLUDES)
123+
exhaustive_tests_CPPFLAGS = $(SECP_INCLUDES)
119124
if !ENABLE_COVERAGE
120125
exhaustive_tests_CPPFLAGS += -DVERIFY
121126
endif
@@ -124,36 +129,45 @@ exhaustive_tests_LDFLAGS = -static
124129
TESTS += exhaustive_tests
125130
endif
126131

127-
EXTRA_PROGRAMS = gen_ecmult_static_pre_g
132+
### Precomputed tables
133+
EXTRA_PROGRAMS = gen_ecmult_static_pre_g gen_ecmult_gen_static_prec_table
134+
CLEANFILES = $(EXTRA_PROGRAMS)
135+
128136
gen_ecmult_static_pre_g_SOURCES = src/gen_ecmult_static_pre_g.c
129-
# See Automake manual, Section "Errors with distclean"
137+
gen_ecmult_static_pre_g_CPPFLAGS = $(SECP_INCLUDES)
138+
gen_ecmult_static_pre_g_LDADD = $(SECP_LIBS) $(COMMON_LIB)
139+
140+
gen_ecmult_gen_static_prec_table_SOURCES = src/gen_ecmult_gen_static_prec_table.c
141+
gen_ecmult_gen_static_prec_table_CPPFLAGS = $(SECP_INCLUDES)
142+
gen_ecmult_gen_static_prec_table_LDADD = $(SECP_LIBS) $(COMMON_LIB)
143+
144+
# See Automake manual, Section "Errors with distclean".
145+
# We don't list any dependencies for the prebuilt files here because
146+
# otherwise make's decision whether to rebuild them (even in the first
147+
# build by a normal user) depends on mtimes, and thus is very fragile.
148+
# This means that rebuilds of the prebuilt files always need to be
149+
# forced by deleting them, e.g., by invoking `make clean-precomp`.
130150
src/ecmult_static_pre_g.h:
131151
$(MAKE) $(AM_MAKEFLAGS) gen_ecmult_static_pre_g$(EXEEXT)
132152
./gen_ecmult_static_pre_g$(EXEEXT)
153+
src/ecmult_gen_static_prec_table.h:
154+
$(MAKE) $(AM_MAKEFLAGS) gen_ecmult_gen_static_prec_table$(EXEEXT)
155+
./gen_ecmult_gen_static_prec_table$(EXEEXT)
133156

134-
if USE_ECMULT_STATIC_PRECOMPUTATION
135-
CPPFLAGS_FOR_BUILD +=-I$(top_srcdir) -I$(builddir)/src
136-
137-
gen_context_OBJECTS = gen_context.o
138-
gen_context_BIN = gen_context$(BUILD_EXEEXT)
139-
$(gen_context_OBJECTS): src/gen_context.c src/libsecp256k1-config.h
140-
$(CC_FOR_BUILD) $(DEFS) $(CPPFLAGS_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
157+
PRECOMP = src/ecmult_gen_static_prec_table.h src/ecmult_static_pre_g.h
158+
noinst_HEADERS += $(PRECOMP)
159+
precomp: $(PRECOMP)
141160

142-
$(gen_context_BIN): $(gen_context_OBJECTS)
143-
$(CC_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
161+
# Ensure the prebuilt files will be build first (only if they don't exist,
162+
# e.g., after `make maintainer-clean`).
163+
BUILT_SOURCES = $(PRECOMP)
144164

145-
$(libsecp256k1_la_OBJECTS): src/ecmult_static_context.h
146-
$(tests_OBJECTS): src/ecmult_static_context.h
147-
$(bench_internal_OBJECTS): src/ecmult_static_context.h
148-
$(bench_ecmult_OBJECTS): src/ecmult_static_context.h
165+
maintainer-clean-local: clean-precomp
149166

150-
src/ecmult_static_context.h: $(gen_context_BIN)
151-
./$(gen_context_BIN)
152-
153-
CLEANFILES = $(gen_context_BIN) src/ecmult_static_context.h
154-
endif
167+
clean-precomp:
168+
rm -f $(PRECOMP)
155169

156-
EXTRA_DIST = autogen.sh src/gen_context.c src/ecmult_static_pre_g.h src/basic-config.h
170+
EXTRA_DIST = autogen.sh SECURITY.md
157171

158172
if ENABLE_MODULE_ECDH
159173
include src/modules/ecdh/Makefile.am.include

README.md

+1-10
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,9 @@ libsecp256k1 is built using autotools:
6666
$ ./autogen.sh
6767
$ ./configure
6868
$ make
69-
$ make check
69+
$ make check # run the test suite
7070
$ sudo make install # optional
7171

72-
Exhaustive tests
73-
-----------
74-
75-
$ ./exhaustive_tests
76-
77-
With valgrind, you might need to increase the max stack size:
78-
79-
$ valgrind --max-stackframe=2500000 ./exhaustive_tests
80-
8172
Test coverage
8273
-----------
8374

build-aux/m4/ax_prog_cc_for_build.m4

-125
This file was deleted.

ci/cirrus.sh

+12
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,19 @@ then
4848
$EXEC ./bench
4949
} >> bench.log 2>&1
5050
fi
51+
5152
if [ "$CTIMETEST" = "yes" ]
5253
then
5354
./libtool --mode=execute valgrind --error-exitcode=42 ./valgrind_ctime_test > valgrind_ctime_test.log 2>&1
5455
fi
56+
57+
# Rebuild precomputed files (if not cross-compiling).
58+
if [ -z "$HOST" ]
59+
then
60+
make clean-precomp
61+
make precomp
62+
fi
63+
64+
# Check that no repo files have been modified by the build.
65+
# (This fails for example if the precomp files need to be updated in the repo.)
66+
git diff --exit-code

0 commit comments

Comments
 (0)