|
8 | 8 | #include <key_io.h>
|
9 | 9 | #include <span.h>
|
10 | 10 | #include <streams.h>
|
| 11 | +#include <secp256k1_extrakeys.h> |
11 | 12 | #include <test/util/random.h>
|
12 | 13 | #include <test/util/setup_common.h>
|
13 | 14 | #include <uint256.h>
|
@@ -345,4 +346,31 @@ BOOST_AUTO_TEST_CASE(bip341_test_h)
|
345 | 346 | BOOST_CHECK(XOnlyPubKey::NUMS_H == H);
|
346 | 347 | }
|
347 | 348 |
|
| 349 | +BOOST_AUTO_TEST_CASE(key_schnorr_tweak_smoke_test) |
| 350 | +{ |
| 351 | + // Sanity check to ensure we get the same tweak using CPubKey vs secp256k1 functions |
| 352 | + secp256k1_context* secp256k1_context_sign = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); |
| 353 | + |
| 354 | + CKey key; |
| 355 | + key.MakeNewKey(true); |
| 356 | + uint256 merkle_root = InsecureRand256(); |
| 357 | + |
| 358 | + // secp256k1 functions |
| 359 | + secp256k1_keypair keypair; |
| 360 | + BOOST_CHECK(secp256k1_keypair_create(secp256k1_context_sign, &keypair, UCharCast(key.begin()))); |
| 361 | + secp256k1_xonly_pubkey xonly_pubkey; |
| 362 | + BOOST_CHECK(secp256k1_keypair_xonly_pub(secp256k1_context_sign, &xonly_pubkey, nullptr, &keypair)); |
| 363 | + unsigned char xonly_bytes[32]; |
| 364 | + BOOST_CHECK(secp256k1_xonly_pubkey_serialize(secp256k1_context_sign, xonly_bytes, &xonly_pubkey)); |
| 365 | + uint256 tweak_old = XOnlyPubKey(xonly_bytes).ComputeTapTweakHash(&merkle_root); |
| 366 | + |
| 367 | + // CPubKey |
| 368 | + CPubKey pubkey = key.GetPubKey(); |
| 369 | + uint256 tweak_new = XOnlyPubKey(pubkey).ComputeTapTweakHash(&merkle_root); |
| 370 | + |
| 371 | + BOOST_CHECK_EQUAL(tweak_old, tweak_new); |
| 372 | + |
| 373 | + secp256k1_context_destroy(secp256k1_context_sign); |
| 374 | +} |
| 375 | + |
348 | 376 | BOOST_AUTO_TEST_SUITE_END()
|
0 commit comments