diff --git a/src/musig.cpp b/src/musig.cpp index 9a1b34421cd..af998085d82 100644 --- a/src/musig.cpp +++ b/src/musig.cpp @@ -18,6 +18,10 @@ constexpr uint256 MUSIG_CHAINCODE{ static bool GetMuSig2KeyAggCache(const std::vector& pubkeys, secp256k1_musig_keyagg_cache& keyagg_cache) { + if (pubkeys.empty()) { + return false; + } + // Parse the pubkeys std::vector secp_pubkeys; std::vector pubkey_ptrs; diff --git a/src/test/bip328_tests.cpp b/src/test/bip328_tests.cpp index 9fffa00b6b0..630771d5b6a 100644 --- a/src/test/bip328_tests.cpp +++ b/src/test/bip328_tests.cpp @@ -89,6 +89,12 @@ BOOST_AUTO_TEST_CASE(valid_keys) } } +BOOST_AUTO_TEST_CASE(empty_pubkey_list) +{ + const std::optional aggregate_pubkey{MuSig2AggregatePubkeys({})}; + BOOST_CHECK(!aggregate_pubkey.has_value()); +} + BOOST_AUTO_TEST_CASE(invalid_key) { std::vector test_vectors = {