Skip to content

Commit 94bed32

Browse files
committed
frost trusted dealer: add tests
Add api tests, nonce tests, tweak tests, sha256 tag tests, and constant time tests.
1 parent 1000eae commit 94bed32

File tree

6 files changed

+850
-12
lines changed

6 files changed

+850
-12
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ env:
4040
MUSIG: 'no'
4141
ECDSAADAPTOR: 'no'
4242
BPPP: 'no'
43+
FROST: 'no'
4344
### test options
4445
SECP256K1_TEST_ITERS:
4546
BENCH: 'yes'
@@ -78,14 +79,14 @@ jobs:
7879
matrix:
7980
configuration:
8081
- env_vars: { WIDEMUL: 'int64', RECOVERY: 'yes' }
81-
- env_vars: { WIDEMUL: 'int64', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes' }
82+
- env_vars: { WIDEMUL: 'int64', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', FROST: 'yes' }
8283
- env_vars: { WIDEMUL: 'int128' }
8384
- env_vars: { WIDEMUL: 'int128_struct', ELLSWIFT: 'yes' }
8485
- env_vars: { WIDEMUL: 'int128', RECOVERY: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
85-
- env_vars: { WIDEMUL: 'int128', ECDH: 'yes', SCHNORRSIG: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes'}
86+
- env_vars: { WIDEMUL: 'int128', ECDH: 'yes', SCHNORRSIG: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', FROST: 'yes' }
8687
- env_vars: { WIDEMUL: 'int128', ASM: 'x86_64', ELLSWIFT: 'yes' }
87-
- env_vars: { RECOVERY: 'yes', SCHNORRSIG: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes'}
88-
- env_vars: { CTIMETESTS: 'no', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', CPPFLAGS: '-DVERIFY' }
88+
- env_vars: { RECOVERY: 'yes', SCHNORRSIG: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', FROST: 'yes' }
89+
- env_vars: { CTIMETESTS: 'no', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', FROST: 'yes', CPPFLAGS: '-DVERIFY' }
8990
- env_vars: { BUILD: 'distcheck', WITH_VALGRIND: 'no', CTIMETESTS: 'no', BENCH: 'no' }
9091
- env_vars: { CPPFLAGS: '-DDETERMINISTIC' }
9192
- env_vars: { CFLAGS: '-O0', CTIMETESTS: 'no' }
@@ -156,6 +157,7 @@ jobs:
156157
MUSIG: 'yes'
157158
ECDSAADAPTOR: 'yes'
158159
BPPP: 'yes'
160+
FROST: 'yes'
159161
CC: ${{ matrix.cc }}
160162

161163
steps:
@@ -208,6 +210,7 @@ jobs:
208210
MUSIG: 'yes'
209211
ECDSAADAPTOR: 'yes'
210212
BPPP: 'yes'
213+
FROST: 'yes'
211214
CTIMETESTS: 'no'
212215

213216
steps:
@@ -267,6 +270,7 @@ jobs:
267270
MUSIG: 'yes'
268271
ECDSAADAPTOR: 'yes'
269272
BPPP: 'yes'
273+
FROST: 'yes'
270274
CTIMETESTS: 'no'
271275

272276
steps:
@@ -320,6 +324,7 @@ jobs:
320324
MUSIG: 'yes'
321325
ECDSAADAPTOR: 'yes'
322326
BPPP: 'yes'
327+
FROST: 'yes'
323328
CTIMETESTS: 'no'
324329

325330
strategy:
@@ -383,6 +388,7 @@ jobs:
383388
MUSIG: 'yes'
384389
ECDSAADAPTOR: 'yes'
385390
BPPP: 'yes'
391+
FROST: 'yes'
386392
CTIMETESTS: 'no'
387393

388394
steps:
@@ -443,6 +449,7 @@ jobs:
443449
MUSIG: 'yes'
444450
ECDSAADAPTOR: 'yes'
445451
BPPP: 'yes'
452+
FROST: 'yes'
446453
CTIMETESTS: 'no'
447454
SECP256K1_TEST_ITERS: 2
448455

@@ -502,6 +509,7 @@ jobs:
502509
MUSIG: 'yes'
503510
ECDSAADAPTOR: 'yes'
504511
BPPP: 'yes'
512+
FROST: 'yes'
505513
CTIMETESTS: 'no'
506514
CFLAGS: '-fsanitize=undefined,address -g'
507515
UBSAN_OPTIONS: 'print_stacktrace=1:halt_on_error=1'
@@ -567,6 +575,7 @@ jobs:
567575
MUSIG: 'yes'
568576
ECDSAADAPTOR: 'yes'
569577
BPPP: 'yes'
578+
FROST: 'yes'
570579
CTIMETESTS: 'yes'
571580
CC: 'clang'
572581
SECP256K1_TEST_ITERS: 32
@@ -622,6 +631,7 @@ jobs:
622631
MUSIG: 'yes'
623632
ECDSAADAPTOR: 'yes'
624633
BPPP: 'yes'
634+
FROST: 'yes'
625635
CTIMETESTS: 'no'
626636

627637
strategy:
@@ -678,15 +688,15 @@ jobs:
678688
fail-fast: false
679689
matrix:
680690
env_vars:
681-
- { WIDEMUL: 'int64', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes' }
691+
- { WIDEMUL: 'int64', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', FROST: 'yes' }
682692
- { WIDEMUL: 'int128_struct', ECMULTGENPRECISION: 2, ECMULTWINDOW: 4 }
683-
- { WIDEMUL: 'int128', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes' }
693+
- { WIDEMUL: 'int128', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', FROST: 'yes' }
684694
- { WIDEMUL: 'int128', RECOVERY: 'yes' }
685-
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes' }
686-
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', CC: 'gcc' }
687-
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', WRAPPER_CMD: 'valgrind --error-exitcode=42', SECP256K1_TEST_ITERS: 2 }
688-
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', CC: 'gcc', WRAPPER_CMD: 'valgrind --error-exitcode=42', SECP256K1_TEST_ITERS: 2 }
689-
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', CPPFLAGS: '-DVERIFY', CTIMETESTS: 'no' }
695+
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', FROST: 'yes' }
696+
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', FROST: 'yes', CC: 'gcc' }
697+
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', FROST: 'yes', WRAPPER_CMD: 'valgrind --error-exitcode=42', SECP256K1_TEST_ITERS: 2 }
698+
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', FROST: 'yes', CC: 'gcc', WRAPPER_CMD: 'valgrind --error-exitcode=42', SECP256K1_TEST_ITERS: 2 }
699+
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', EXPERIMENTAL: 'yes', ECDSA_S2C: 'yes', RANGEPROOF: 'yes', WHITELIST: 'yes', GENERATOR: 'yes', MUSIG: 'yes', ECDSAADAPTOR: 'yes', BPPP: 'yes', FROST: 'yes', CPPFLAGS: '-DVERIFY', CTIMETESTS: 'no' }
690700
- BUILD: 'distcheck'
691701

692702
steps:
@@ -805,6 +815,7 @@ jobs:
805815
MUSIG: 'yes'
806816
ECDSAADAPTOR: 'yes'
807817
BPPP: 'yes'
818+
FROST: 'yes'
808819

809820
steps:
810821
- name: Checkout

ci/ci.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ print_environment() {
1414
for var in WERROR_CFLAGS MAKEFLAGS BUILD \
1515
ECMULTWINDOW ECMULTGENPRECISION ASM WIDEMUL WITH_VALGRIND EXTRAFLAGS \
1616
EXPERIMENTAL ECDH RECOVERY SCHNORRSIG ELLSWIFT \
17-
ECDSA_S2C GENERATOR RANGEPROOF WHITELIST MUSIG ECDSAADAPTOR BPPP \
17+
ECDSA_S2C GENERATOR RANGEPROOF WHITELIST MUSIG ECDSAADAPTOR BPPP FROST \
1818
SECP256K1_TEST_ITERS BENCH SECP256K1_BENCH_ITERS CTIMETESTS\
1919
EXAMPLES \
2020
HOST WRAPPER_CMD \
@@ -82,6 +82,7 @@ esac
8282
--enable-module-rangeproof="$RANGEPROOF" --enable-module-whitelist="$WHITELIST" --enable-module-generator="$GENERATOR" \
8383
--enable-module-schnorrsig="$SCHNORRSIG" --enable-module-musig="$MUSIG" --enable-module-ecdsa-adaptor="$ECDSAADAPTOR" \
8484
--enable-module-schnorrsig="$SCHNORRSIG" \
85+
--enable-module-frost="$FROST" \
8586
--enable-examples="$EXAMPLES" \
8687
--enable-ctime-tests="$CTIMETESTS" \
8788
--with-valgrind="$WITH_VALGRIND" \

src/ctime_tests.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
#include "../include/secp256k1_musig.h"
4848
#endif
4949

50+
#ifdef ENABLE_MODULE_FROST
51+
#include "include/secp256k1_frost.h"
52+
#endif
53+
5054
static void run_tests(secp256k1_context *ctx, unsigned char *key);
5155

5256
int main(void) {
@@ -349,4 +353,79 @@ static void run_tests(secp256k1_context *ctx, unsigned char *key) {
349353
CHECK(ret == 1);
350354
}
351355
#endif
356+
357+
#ifdef ENABLE_MODULE_FROST
358+
{
359+
secp256k1_xonly_pubkey pk;
360+
unsigned char session_id[32];
361+
secp256k1_frost_secnonce secnonce[2];
362+
secp256k1_frost_pubnonce pubnonce[2];
363+
const secp256k1_frost_pubnonce *pubnonce_ptr[2];
364+
secp256k1_frost_tweak_cache cache;
365+
secp256k1_frost_session session;
366+
secp256k1_frost_partial_sig partial_sig;
367+
const secp256k1_frost_partial_sig *partial_sig_ptr[1];
368+
unsigned char extra_input[32];
369+
unsigned char sec_adaptor[32];
370+
secp256k1_pubkey adaptor;
371+
unsigned char pre_sig[64];
372+
int nonce_parity;
373+
secp256k1_frost_share shares[2];
374+
secp256k1_pubkey pubshares[2];
375+
size_t ids[2];
376+
377+
pubnonce_ptr[0] = &pubnonce[0];
378+
pubnonce_ptr[1] = &pubnonce[1];
379+
SECP256K1_CHECKMEM_DEFINE(key, 32);
380+
memcpy(extra_input, key, sizeof(extra_input));
381+
extra_input[0] = extra_input[0] + 1;
382+
memcpy(sec_adaptor, key, sizeof(sec_adaptor));
383+
sec_adaptor[0] = extra_input[0] + 2;
384+
memcpy(session_id, key, sizeof(session_id));
385+
session_id[0] = session_id[0] + 3;
386+
partial_sig_ptr[0] = &partial_sig;
387+
ids[0] = 1;
388+
ids[1] = 2;
389+
390+
/* shares_gen */
391+
SECP256K1_CHECKMEM_UNDEFINE(key, 32);
392+
ret = secp256k1_frost_shares_trusted_gen(ctx, shares, pubshares, &pk, key, 2, 2);
393+
SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret));
394+
CHECK(ret == 1);
395+
SECP256K1_CHECKMEM_UNDEFINE(&shares[0], sizeof(shares[0]));
396+
SECP256K1_CHECKMEM_UNDEFINE(&shares[1], sizeof(shares[1]));
397+
/* nonce_gen */
398+
SECP256K1_CHECKMEM_UNDEFINE(session_id, sizeof(session_id));
399+
CHECK(secp256k1_ec_pubkey_create(ctx, &adaptor, sec_adaptor));
400+
SECP256K1_CHECKMEM_UNDEFINE(extra_input, sizeof(extra_input));
401+
SECP256K1_CHECKMEM_UNDEFINE(sec_adaptor, sizeof(sec_adaptor));
402+
CHECK(secp256k1_frost_pubkey_tweak(ctx, &cache, &pk) == 1);
403+
ret = secp256k1_frost_nonce_gen(ctx, &secnonce[0], &pubnonce[0], session_id, &shares[0], msg, &pk, extra_input);
404+
SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret));
405+
CHECK(ret == 1);
406+
ret = secp256k1_frost_nonce_gen(ctx, &secnonce[1], &pubnonce[1], session_id, &shares[1], msg, &pk, extra_input);
407+
SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret));
408+
CHECK(ret == 1);
409+
/* partial_sign */
410+
CHECK(secp256k1_frost_nonce_process(ctx, &session, pubnonce_ptr, 2, msg, &pk, 1, ids, &cache, &adaptor) == 1);
411+
ret = secp256k1_keypair_create(ctx, &keypair, key);
412+
SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret));
413+
CHECK(ret == 1);
414+
ret = secp256k1_frost_partial_sign(ctx, &partial_sig, &secnonce[0], &shares[0], &session, &cache);
415+
SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret));
416+
CHECK(ret == 1);
417+
/* adapt */
418+
SECP256K1_CHECKMEM_DEFINE(&partial_sig, sizeof(partial_sig));
419+
CHECK(secp256k1_frost_partial_sig_agg(ctx, pre_sig, &session, partial_sig_ptr, 1));
420+
SECP256K1_CHECKMEM_DEFINE(pre_sig, sizeof(pre_sig));
421+
CHECK(secp256k1_frost_nonce_parity(ctx, &nonce_parity, &session));
422+
ret = secp256k1_frost_adapt(ctx, sig, pre_sig, sec_adaptor, nonce_parity);
423+
SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret));
424+
CHECK(ret == 1);
425+
/* extract_adaptor */
426+
ret = secp256k1_frost_extract_adaptor(ctx, sec_adaptor, sig, pre_sig, nonce_parity);
427+
SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret));
428+
CHECK(ret == 1);
429+
}
430+
#endif
352431
}

src/modules/frost/Makefile.am.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ noinst_HEADERS += src/modules/frost/keygen_impl.h
55
noinst_HEADERS += src/modules/frost/session.h
66
noinst_HEADERS += src/modules/frost/session_impl.h
77
noinst_HEADERS += src/modules/frost/adaptor_impl.h
8+
noinst_HEADERS += src/modules/frost/tests_impl.h

0 commit comments

Comments
 (0)