Skip to content

Commit 785ef3d

Browse files
committed
Squashed 'src/secp256k1/' changes from d8311688bd..3d08027789
3d08027789 ci: enable silentpayments module 85946762a5 tests: add BIP-352 test vectors bf349c2a08 silentpayments: add examples/silentpayments.c 9a7106e19c silentpayments: add recipient light client support f113564298 silentpayments: add recipient scanning routine 4fb8716f4f silentpayments: add opaque data type `public_data` 987d829e8f silentpayments: add recipient label support 14ca754578 silentpayments: add sender routine 9b965927da silentpayments: implement output pubkey creation a0fcc2c780 silentpayments: implement shared secret creation 13f203dacd silentpayments: add sortable recipient struct a9326bdd7a doc: add module description for silentpayments 15d3e71cc1 build: add skeleton for new silentpayments (BIP352) module cc7d18a8a8 extrakeys: add secp256k1_pubkey_sort git-subtree-dir: src/secp256k1 git-subtree-split: 3d080277895655e8274ee73aacd154c4ead143e3
1 parent 53eec53 commit 785ef3d

22 files changed

+6269
-12
lines changed

.cirrus.yml

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ env:
2222
RECOVERY: no
2323
SCHNORRSIG: no
2424
ELLSWIFT: no
25+
SILENTPAYMENTS: no
2526
### test options
2627
SECP256K1_TEST_ITERS:
2728
BENCH: yes
@@ -68,6 +69,7 @@ task:
6869
RECOVERY: yes
6970
SCHNORRSIG: yes
7071
ELLSWIFT: yes
72+
SILENTPAYMENTS: yes
7173
matrix:
7274
# Currently only gcc-snapshot, the other compilers are tested on GHA with QEMU
7375
- env: { CC: 'gcc-snapshot' }
@@ -84,6 +86,7 @@ task:
8486
RECOVERY: yes
8587
SCHNORRSIG: yes
8688
ELLSWIFT: yes
89+
SILENTPAYMENTS: yes
8790
WRAPPER_CMD: 'valgrind --error-exitcode=42'
8891
SECP256K1_TEST_ITERS: 2
8992
matrix:

.github/workflows/ci.yml

+21-10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ env:
3333
RECOVERY: 'no'
3434
SCHNORRSIG: 'no'
3535
ELLSWIFT: 'no'
36+
SILENTPAYMENTS: 'no'
3637
### test options
3738
SECP256K1_TEST_ITERS:
3839
BENCH: 'yes'
@@ -71,18 +72,18 @@ jobs:
7172
matrix:
7273
configuration:
7374
- env_vars: { WIDEMUL: 'int64', RECOVERY: 'yes' }
74-
- env_vars: { WIDEMUL: 'int64', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
75+
- env_vars: { WIDEMUL: 'int64', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', SILENTPAYMENTS: 'yes' }
7576
- env_vars: { WIDEMUL: 'int128' }
7677
- env_vars: { WIDEMUL: 'int128_struct', ELLSWIFT: 'yes' }
7778
- env_vars: { WIDEMUL: 'int128', RECOVERY: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
78-
- env_vars: { WIDEMUL: 'int128', ECDH: 'yes', SCHNORRSIG: 'yes' }
79+
- env_vars: { WIDEMUL: 'int128', ECDH: 'yes', SCHNORRSIG: 'yes', SILENTPAYMENTS: 'yes' }
7980
- env_vars: { WIDEMUL: 'int128', ASM: 'x86_64', ELLSWIFT: 'yes' }
8081
- env_vars: { RECOVERY: 'yes', SCHNORRSIG: 'yes' }
81-
- env_vars: { CTIMETESTS: 'no', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', CPPFLAGS: '-DVERIFY' }
82+
- env_vars: { CTIMETESTS: 'no', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', SILENTPAYMENTS: 'yes', CPPFLAGS: '-DVERIFY' }
8283
- env_vars: { BUILD: 'distcheck', WITH_VALGRIND: 'no', CTIMETESTS: 'no', BENCH: 'no' }
8384
- env_vars: { CPPFLAGS: '-DDETERMINISTIC' }
8485
- env_vars: { CFLAGS: '-O0', CTIMETESTS: 'no' }
85-
- env_vars: { CFLAGS: '-O1', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
86+
- env_vars: { CFLAGS: '-O1', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', SILENTPAYMENTS: 'yes' }
8687
- env_vars: { ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
8788
- env_vars: { ECMULTGENPRECISION: 8, ECMULTWINDOW: 4 }
8889
cc:
@@ -141,6 +142,7 @@ jobs:
141142
RECOVERY: 'yes'
142143
SCHNORRSIG: 'yes'
143144
ELLSWIFT: 'yes'
145+
SILENTPAYMENTS: 'yes'
144146
CC: ${{ matrix.cc }}
145147

146148
steps:
@@ -185,6 +187,7 @@ jobs:
185187
RECOVERY: 'yes'
186188
SCHNORRSIG: 'yes'
187189
ELLSWIFT: 'yes'
190+
SILENTPAYMENTS: 'yes'
188191
CTIMETESTS: 'no'
189192

190193
steps:
@@ -236,6 +239,7 @@ jobs:
236239
RECOVERY: 'yes'
237240
SCHNORRSIG: 'yes'
238241
ELLSWIFT: 'yes'
242+
SILENTPAYMENTS: 'yes'
239243
CTIMETESTS: 'no'
240244

241245
steps:
@@ -281,6 +285,7 @@ jobs:
281285
RECOVERY: 'yes'
282286
SCHNORRSIG: 'yes'
283287
ELLSWIFT: 'yes'
288+
SILENTPAYMENTS: 'yes'
284289
CTIMETESTS: 'no'
285290

286291
strategy:
@@ -336,6 +341,7 @@ jobs:
336341
RECOVERY: 'yes'
337342
SCHNORRSIG: 'yes'
338343
ELLSWIFT: 'yes'
344+
SILENTPAYMENTS: 'yes'
339345
CTIMETESTS: 'no'
340346

341347
steps:
@@ -388,6 +394,7 @@ jobs:
388394
RECOVERY: 'yes'
389395
SCHNORRSIG: 'yes'
390396
ELLSWIFT: 'yes'
397+
SILENTPAYMENTS: 'yes'
391398
CTIMETESTS: 'no'
392399
SECP256K1_TEST_ITERS: 2
393400

@@ -439,6 +446,7 @@ jobs:
439446
RECOVERY: 'yes'
440447
SCHNORRSIG: 'yes'
441448
ELLSWIFT: 'yes'
449+
SILENTPAYMENTS: 'yes'
442450
CTIMETESTS: 'no'
443451
CFLAGS: '-fsanitize=undefined,address -g'
444452
UBSAN_OPTIONS: 'print_stacktrace=1:halt_on_error=1'
@@ -496,6 +504,7 @@ jobs:
496504
RECOVERY: 'yes'
497505
SCHNORRSIG: 'yes'
498506
ELLSWIFT: 'yes'
507+
SILENTPAYMENTS: 'yes'
499508
CTIMETESTS: 'yes'
500509
CC: 'clang'
501510
SECP256K1_TEST_ITERS: 32
@@ -543,6 +552,7 @@ jobs:
543552
RECOVERY: 'yes'
544553
SCHNORRSIG: 'yes'
545554
ELLSWIFT: 'yes'
555+
SILENTPAYMENTS: 'yes'
546556
CTIMETESTS: 'no'
547557

548558
strategy:
@@ -599,14 +609,14 @@ jobs:
599609
fail-fast: false
600610
matrix:
601611
env_vars:
602-
- { WIDEMUL: 'int64', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
612+
- { WIDEMUL: 'int64', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', SILENTPAYMENTS: 'yes' }
603613
- { WIDEMUL: 'int128_struct', ECMULTGENPRECISION: 2, ECMULTWINDOW: 4 }
604-
- { WIDEMUL: 'int128', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
614+
- { WIDEMUL: 'int128', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', SILENTPAYMENTS: 'yes' }
605615
- { WIDEMUL: 'int128', RECOVERY: 'yes' }
606-
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
607-
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', CC: 'gcc' }
608-
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', WRAPPER_CMD: 'valgrind --error-exitcode=42', SECP256K1_TEST_ITERS: 2 }
609-
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', CC: 'gcc', WRAPPER_CMD: 'valgrind --error-exitcode=42', SECP256K1_TEST_ITERS: 2 }
616+
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', SILENTPAYMENTS: 'yes' }
617+
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', SILENTPAYMENTS: 'yes', CC: 'gcc' }
618+
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', SILENTPAYMENTS: 'yes', WRAPPER_CMD: 'valgrind --error-exitcode=42', SECP256K1_TEST_ITERS: 2 }
619+
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', SILENTPAYMENTS: 'yes', CC: 'gcc', WRAPPER_CMD: 'valgrind --error-exitcode=42', SECP256K1_TEST_ITERS: 2 }
610620
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', CPPFLAGS: '-DVERIFY', CTIMETESTS: 'no' }
611621
- BUILD: 'distcheck'
612622

@@ -718,6 +728,7 @@ jobs:
718728
RECOVERY: 'yes'
719729
SCHNORRSIG: 'yes'
720730
ELLSWIFT: 'yes'
731+
SILENTPAYMENTS: 'yes'
721732

722733
steps:
723734
- name: Checkout

.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+
silentpayments_example
1314
*.exe
1415
*.so
1516
*.a

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,14 @@ option(SECP256K1_ENABLE_MODULE_RECOVERY "Enable ECDSA pubkey recovery module." O
6060
option(SECP256K1_ENABLE_MODULE_EXTRAKEYS "Enable extrakeys module." ON)
6161
option(SECP256K1_ENABLE_MODULE_SCHNORRSIG "Enable schnorrsig module." ON)
6262
option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON)
63+
option(SECP256K1_ENABLE_MODULE_SILENTPAYMENTS "Enable Silent Payments module." OFF)
6364

6465
# Processing must be done in a topological sorting of the dependency graph
6566
# (dependent module first).
67+
if(SECP256K1_ENABLE_MODULE_SILENTPAYMENTS)
68+
add_compile_definitions(ENABLE_MODULE_SILENTPAYMENTS=1)
69+
endif()
70+
6671
if(SECP256K1_ENABLE_MODULE_ELLSWIFT)
6772
add_compile_definitions(ENABLE_MODULE_ELLSWIFT=1)
6873
endif()
@@ -292,6 +297,7 @@ message(" ECDSA pubkey recovery ............... ${SECP256K1_ENABLE_MODULE_RECOV
292297
message(" extrakeys ........................... ${SECP256K1_ENABLE_MODULE_EXTRAKEYS}")
293298
message(" schnorrsig .......................... ${SECP256K1_ENABLE_MODULE_SCHNORRSIG}")
294299
message(" ElligatorSwift ...................... ${SECP256K1_ENABLE_MODULE_ELLSWIFT}")
300+
message(" Silent Payments ..................... ${SECP256K1_ENABLE_MODULE_SILENTPAYMENTS}")
295301
message("Parameters:")
296302
message(" ecmult window size .................. ${SECP256K1_ECMULT_WINDOW_SIZE}")
297303
message(" ecmult gen precision bits ........... ${SECP256K1_ECMULT_GEN_PREC_BITS}")

Makefile.am

+17
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ noinst_HEADERS += src/field.h
6464
noinst_HEADERS += src/field_impl.h
6565
noinst_HEADERS += src/bench.h
6666
noinst_HEADERS += src/wycheproof/ecdsa_secp256k1_sha256_bitcoin_test.h
67+
noinst_HEADERS += src/hsort.h
68+
noinst_HEADERS += src/hsort_impl.h
6769
noinst_HEADERS += contrib/lax_der_parsing.h
6870
noinst_HEADERS += contrib/lax_der_parsing.c
6971
noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
@@ -182,6 +184,17 @@ schnorr_example_LDFLAGS += -lbcrypt
182184
endif
183185
TESTS += schnorr_example
184186
endif
187+
if ENABLE_MODULE_SILENTPAYMENTS
188+
noinst_PROGRAMS += silentpayments_example
189+
silentpayments_example_SOURCES = examples/silentpayments.c
190+
silentpayments_example_CPPFLAGS = -I$(top_srcdir)/include -DSECP256K1_STATIC
191+
silentpayments_example_LDADD = libsecp256k1.la
192+
silentpayments_example_LDFLAGS = -static
193+
if BUILD_WINDOWS
194+
silentpayments_example_LDFLAGS += -lbcrypt
195+
endif
196+
TESTS += silentpayments_example
197+
endif
185198
endif
186199

187200
### Precomputed tables
@@ -271,3 +284,7 @@ endif
271284
if ENABLE_MODULE_ELLSWIFT
272285
include src/modules/ellswift/Makefile.am.include
273286
endif
287+
288+
if ENABLE_MODULE_SILENTPAYMENTS
289+
include src/modules/silentpayments/Makefile.am.include
290+
endif

ci/ci.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ print_environment() {
1313
# does not rely on bash.
1414
for var in WERROR_CFLAGS MAKEFLAGS BUILD \
1515
ECMULTWINDOW ECMULTGENPRECISION ASM WIDEMUL WITH_VALGRIND EXTRAFLAGS \
16-
EXPERIMENTAL ECDH RECOVERY SCHNORRSIG ELLSWIFT \
16+
EXPERIMENTAL ECDH RECOVERY SCHNORRSIG ELLSWIFT SILENTPAYMENTS \
1717
SECP256K1_TEST_ITERS BENCH SECP256K1_BENCH_ITERS CTIMETESTS\
1818
EXAMPLES \
1919
HOST WRAPPER_CMD \
@@ -77,6 +77,7 @@ esac
7777
--with-ecmult-gen-precision="$ECMULTGENPRECISION" \
7878
--enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \
7979
--enable-module-ellswift="$ELLSWIFT" \
80+
--enable-module-silentpayments="$SILENTPAYMENTS" \
8081
--enable-module-schnorrsig="$SCHNORRSIG" \
8182
--enable-examples="$EXAMPLES" \
8283
--enable-ctime-tests="$CTIMETESTS" \

configure.ac

+10
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_silentpayments,
192+
AS_HELP_STRING([--enable-module-silentpayments],[enable Silent Payments module [default=no]]), [],
193+
[SECP_SET_DEFAULT([enable_module_silentpayments], [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])])
@@ -389,6 +393,10 @@ SECP_CFLAGS="$SECP_CFLAGS $WERROR_CFLAGS"
389393

390394
# Processing must be done in a reverse topological sorting of the dependency graph
391395
# (dependent module first).
396+
if test x"$enable_module_silentpayments" = x"yes"; then
397+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_SILENTPAYMENTS=1"
398+
fi
399+
392400
if test x"$enable_module_ellswift" = x"yes"; then
393401
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ELLSWIFT=1"
394402
fi
@@ -450,6 +458,7 @@ AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"ye
450458
AM_CONDITIONAL([ENABLE_MODULE_EXTRAKEYS], [test x"$enable_module_extrakeys" = x"yes"])
451459
AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" = x"yes"])
452460
AM_CONDITIONAL([ENABLE_MODULE_ELLSWIFT], [test x"$enable_module_ellswift" = x"yes"])
461+
AM_CONDITIONAL([ENABLE_MODULE_SILENTPAYMENTS], [test x"$enable_module_silentpayments" = x"yes"])
453462
AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$enable_external_asm" = x"yes"])
454463
AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm32"])
455464
AM_CONDITIONAL([BUILD_WINDOWS], [test "$build_windows" = "yes"])
@@ -472,6 +481,7 @@ echo " module recovery = $enable_module_recovery"
472481
echo " module extrakeys = $enable_module_extrakeys"
473482
echo " module schnorrsig = $enable_module_schnorrsig"
474483
echo " module ellswift = $enable_module_ellswift"
484+
echo " module silentpayments = $enable_module_silentpayments"
475485
echo
476486
echo " asm = $set_asm"
477487
echo " ecmult window size = $set_ecmult_window"

0 commit comments

Comments
 (0)