Skip to content

Commit 0b3cc93

Browse files
committed
all tests complete
1 parent 8f61bd8 commit 0b3cc93

File tree

5 files changed

+90
-41
lines changed

5 files changed

+90
-41
lines changed

examples/schnorr_adaptor.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <secp256k1_schnorr_adaptor.h>
1717

1818
#include "examples_util.h"
19-
/* TODO: what's Z+A+B?*/
19+
/* TODO: make is clear, like multi_hop_tests of ECDSA adaptor */
2020
int main(void) {
2121
unsigned char msg[12] = "Hello World!";
2222
unsigned char msg_hash[32];
@@ -96,8 +96,7 @@ int main(void) {
9696
assert(memcmp(sec_adaptor, extracted_sec_adaptor, sizeof(sec_adaptor)) == 0);
9797

9898
/* Alice subtracts out local blinding factor `b`, can now claim incoming
99-
* PTLC from Alice with sec_adaptor(=z+a)
100-
*/
99+
* PTLC from Alice with sec_adaptor(=z+a) */
101100

102101
printf("Success!\n\n");
103102
secp256k1_context_destroy(ctx);

schnorr_adaptor_example

0 Bytes
Binary file not shown.

src/modules/schnorr_adaptor/main_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************
2-
* Copyright (c) 2023 Zhe Pang *
2+
* Copyright (c) 2023-2024 Zhe Pang and Sivaram Dhakshinamoorthy *
33
* Distributed under the MIT software license, see the accompanying *
44
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
55
**********************************************************************/

src/modules/schnorr_adaptor/tests_impl.h

+51-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************
2-
* Copyright (c) 2023 Zhe Pang *
2+
* Copyright (c) 2023-2024 Zhe Pang and Sivaram Dhakshinamoorthy *
33
* Distributed under the MIT software license, see the accompanying *
44
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
55
**********************************************************************/
@@ -1200,6 +1200,55 @@ static void test_schnorr_adaptor_edge_cases(void) {
12001200
}
12011201
}
12021202

1203+
static void test_schnorr_adaptor_correctness(void) {
1204+
unsigned char alice_sk[32];
1205+
secp256k1_keypair alice_keypair;
1206+
secp256k1_xonly_pubkey alice_pk;
1207+
unsigned char sec_adaptor[32];
1208+
secp256k1_pubkey adaptor;
1209+
unsigned char extracted_sec_adaptor[32];
1210+
secp256k1_pubkey extracted_adaptor;
1211+
unsigned char msg[32];
1212+
unsigned char pre_sig[65];
1213+
unsigned char sig[64];
1214+
1215+
/* Alice setup */
1216+
secp256k1_testrand256(alice_sk);
1217+
CHECK(secp256k1_keypair_create(CTX, &alice_keypair, alice_sk) == 1);
1218+
CHECK(secp256k1_keypair_xonly_pub(CTX, &alice_pk, NULL, &alice_keypair) == 1);
1219+
1220+
/* t := sec_adaptor
1221+
* There exists an adaptor T = t*G, where t is unknown to Bob */
1222+
secp256k1_testrand256(sec_adaptor);
1223+
CHECK(secp256k1_ec_pubkey_create(CTX, &adaptor, sec_adaptor));
1224+
1225+
/* Alice creates a pre-siganture for the adaptor point T,
1226+
* and sends it to Bob. */
1227+
secp256k1_testrand256(msg);
1228+
CHECK(secp256k1_schnorr_adaptor_presign(CTX, pre_sig, msg, &alice_keypair, &adaptor, NULL) == 1);
1229+
1230+
/* Bob extracts the adaptor point from the pre-signature,
1231+
* and verifies if it is equal to T */
1232+
CHECK(secp256k1_schnorr_adaptor_extract(CTX, &extracted_adaptor, pre_sig, msg, &alice_pk) == 1);
1233+
CHECK(secp256k1_ec_pubkey_cmp(CTX, &extracted_adaptor, &adaptor) == 0);
1234+
1235+
/* Bob learns t (the discrete logarithm of T). For example, Bob can
1236+
* pay a Lightning invoice that reveals t, assuming Lightning uses
1237+
* PTLC (Point Time Locked Contracts). */
1238+
1239+
/* Bob adapts the pre-signature with the discrete logarithm of T to
1240+
* create a valid BIP 340 Schnorr signature. */
1241+
CHECK(secp256k1_schnorr_adaptor_adapt(CTX, sig, pre_sig, sec_adaptor) == 1);
1242+
CHECK(secp256k1_schnorrsig_verify(CTX, sig, msg, sizeof(msg), &alice_pk) == 1);
1243+
1244+
/* Alice learns the BIP340 signature after Bob publishes it on the blockchain. */
1245+
1246+
/* Alice extracts the discrete logarithm of T from the pre-signature and the
1247+
* BIP 340 signature. */
1248+
CHECK(secp256k1_schnorr_adaptor_extract_sec(CTX, extracted_sec_adaptor, pre_sig, sig) == 1);
1249+
CHECK(secp256k1_memcmp_var(extracted_sec_adaptor, sec_adaptor, sizeof(extracted_sec_adaptor)) == 0);
1250+
}
1251+
12031252
static void run_schnorr_adaptor_tests(void) {
12041253
int i;
12051254
run_nonce_function_schnorr_adaptor_tests();
@@ -1209,6 +1258,7 @@ static void run_schnorr_adaptor_tests(void) {
12091258
for (i = 0; i < COUNT; i++) {
12101259
test_schnorr_adaptor_edge_cases();
12111260
}
1261+
test_schnorr_adaptor_correctness();
12121262
}
12131263

12141264
#endif

src/tests.c

+36-36
Original file line numberDiff line numberDiff line change
@@ -7736,53 +7736,53 @@ int main(int argc, char **argv) {
77367736
/*** Run actual tests ***/
77377737

77387738
/* selftest tests */
7739-
/* run_selftest_tests(); */
7739+
run_selftest_tests();
77407740

77417741
/* context tests */
7742-
/* run_proper_context_tests(0); run_proper_context_tests(1);
7742+
run_proper_context_tests(0); run_proper_context_tests(1);
77437743
run_static_context_tests(0); run_static_context_tests(1);
7744-
run_deprecated_context_flags_test(); */
7744+
run_deprecated_context_flags_test();
77457745

77467746
/* scratch tests */
7747-
/* run_scratch_tests(); */
7747+
run_scratch_tests();
77487748

77497749
/* util tests */
7750-
/* run_util_tests(); */
7750+
run_util_tests();
77517751

77527752
/* integer arithmetic tests */
77537753
#ifdef SECP256K1_WIDEMUL_INT128
7754-
/* run_int128_tests(); */
7754+
run_int128_tests();
77557755
#endif
7756-
/* run_ctz_tests();
7756+
run_ctz_tests();
77577757
run_modinv_tests();
7758-
run_inverse_tests(); */
7758+
run_inverse_tests();
77597759

77607760
/* hash tests */
7761-
/* run_sha256_known_output_tests();
7761+
run_sha256_known_output_tests();
77627762
run_sha256_counter_tests();
77637763
run_hmac_sha256_tests();
77647764
run_rfc6979_hmac_sha256_tests();
7765-
run_tagged_sha256_tests(); */
7765+
run_tagged_sha256_tests();
77667766

77677767
/* scalar tests */
7768-
/* run_scalar_tests(); */
7768+
run_scalar_tests();
77697769

77707770
/* field tests */
7771-
/* run_field_half();
7771+
run_field_half();
77727772
run_field_misc();
77737773
run_field_convert();
77747774
run_field_be32_overflow();
77757775
run_fe_mul();
77767776
run_sqr();
7777-
run_sqrt(); */
7777+
run_sqrt();
77787778

77797779
/* group tests */
7780-
/* run_ge();
7780+
run_ge();
77817781
run_gej();
7782-
run_group_decompress(); */
7782+
run_group_decompress();
77837783

77847784
/* ecmult tests */
7785-
/* run_ecmult_pre_g();
7785+
run_ecmult_pre_g();
77867786
run_wnaf();
77877787
run_point_times_order();
77887788
run_ecmult_near_split_bound();
@@ -7792,88 +7792,88 @@ int main(int argc, char **argv) {
77927792
run_ecmult_const_tests();
77937793
run_ecmult_multi_tests();
77947794
run_ec_combine();
7795-
run_ec_commit(); */
7795+
run_ec_commit();
77967796

77977797
/* endomorphism tests */
7798-
/* run_endomorphism_tests(); */
7798+
run_endomorphism_tests();
77997799

78007800
/* EC point parser test */
7801-
/* run_ec_pubkey_parse_test(); */
7801+
run_ec_pubkey_parse_test();
78027802

78037803
/* EC key edge cases */
7804-
/* run_eckey_edge_case_test(); */
7804+
run_eckey_edge_case_test();
78057805

78067806
/* EC key arithmetic test */
7807-
/* run_eckey_negate_test(); */
7807+
run_eckey_negate_test();
78087808

78097809
#ifdef ENABLE_MODULE_BPPP
7810-
/* run_bppp_tests(); */
7810+
run_bppp_tests();
78117811
#endif
78127812

78137813
#ifdef ENABLE_MODULE_ECDH
78147814
/* ecdh tests */
7815-
/* run_ecdh_tests(); */
7815+
run_ecdh_tests();
78167816
#endif
78177817

78187818
#ifdef ENABLE_MODULE_MUSIG
7819-
/* run_musig_tests(); */
7819+
run_musig_tests();
78207820
#endif
78217821

78227822
/* ecdsa tests */
7823-
/* run_ec_illegal_argument_tests();
7823+
run_ec_illegal_argument_tests();
78247824
run_pubkey_comparison();
78257825
run_random_pubkeys();
78267826
run_ecdsa_der_parse();
78277827
run_ecdsa_sign_verify();
78287828
run_ecdsa_end_to_end();
78297829
run_ecdsa_edge_cases();
7830-
run_ecdsa_wycheproof(); */
7830+
run_ecdsa_wycheproof();
78317831

78327832
#ifdef ENABLE_MODULE_RECOVERY
78337833
/* ECDSA pubkey recovery tests */
7834-
/* run_recovery_tests(); */
7834+
run_recovery_tests();
78357835
#endif
78367836

78377837
#ifdef ENABLE_MODULE_GENERATOR
7838-
/* run_generator_tests(); */
7838+
run_generator_tests();
78397839
#endif
78407840

78417841
#ifdef ENABLE_MODULE_RANGEPROOF
7842-
/* run_rangeproof_tests(); */
7842+
run_rangeproof_tests();
78437843
#endif
78447844

78457845
#ifdef ENABLE_MODULE_WHITELIST
78467846
/* Key whitelisting tests */
7847-
/* run_whitelist_tests(); */
7847+
run_whitelist_tests();
78487848
#endif
78497849

78507850
#ifdef ENABLE_MODULE_SURJECTIONPROOF
7851-
/* run_surjection_tests(); */
7851+
run_surjection_tests();
78527852
#endif
78537853

78547854
#ifdef ENABLE_MODULE_EXTRAKEYS
7855-
/* run_extrakeys_tests(); */
7855+
run_extrakeys_tests();
78567856
#endif
78577857

78587858
#ifdef ENABLE_MODULE_SCHNORRSIG
7859-
/* run_schnorrsig_tests(); */
7859+
run_schnorrsig_tests();
78607860
#endif
78617861

78627862
#ifdef ENABLE_MODULE_SCHNORR_ADAPTOR
78637863
run_schnorr_adaptor_tests();
78647864
#endif
78657865

78667866
#ifdef ENABLE_MODULE_ELLSWIFT
7867-
/* run_ellswift_tests(); */
7867+
run_ellswift_tests();
78687868
#endif
78697869

78707870
#ifdef ENABLE_MODULE_ECDSA_S2C
78717871
/* ECDSA sign to contract */
7872-
/* run_ecdsa_s2c_tests(); */
7872+
run_ecdsa_s2c_tests();
78737873
#endif
78747874

78757875
#ifdef ENABLE_MODULE_ECDSA_ADAPTOR
7876-
/* run_ecdsa_adaptor_tests(); */
7876+
run_ecdsa_adaptor_tests();
78777877
#endif
78787878

78797879
/* util tests */

0 commit comments

Comments
 (0)