Merge bitcoin/bitcoin#35316: musig: Reject empty pubkey list in GetMuSig2KeyAggCache

8ce84321ce musig: Reject empty pubkey list in GetMuSig2KeyAggCache (nervana21)

Pull request description:

  Per [BIP327](https://github.com/bitcoin/bips/blob/master/bip-0327.mediawiki?plain=1#L300), MuSig2 key aggregation is defined for `u` public keys where `0 < u < 2^32`.

  Previously, the code did not handle `u == 0`.

  This patch updates the code to reject an empty pubkey list and adds a regression test.

ACKs for top commit:
  achow101:
    ACK 8ce84321ce
  rkrux:
    lgtm ACK 8ce84321ce

Tree-SHA512: aa662eee92b6c637683b8535fd9e62431538ba58f38d32f4538259f0b534793625b74a3a10c0c5bb23a7ec7ec83925170b23e47574ef4ebde283a18a0b143d86
This commit is contained in:
Ava Chow
2026-05-21 11:26:26 -07:00
2 changed files with 10 additions and 0 deletions

View File

@@ -18,6 +18,10 @@ constexpr uint256 MUSIG_CHAINCODE{
static bool GetMuSig2KeyAggCache(const std::vector<CPubKey>& pubkeys, secp256k1_musig_keyagg_cache& keyagg_cache)
{
if (pubkeys.empty()) {
return false;
}
// Parse the pubkeys
std::vector<secp256k1_pubkey> secp_pubkeys;
std::vector<const secp256k1_pubkey*> pubkey_ptrs;

View File

@@ -89,6 +89,12 @@ BOOST_AUTO_TEST_CASE(valid_keys)
}
}
BOOST_AUTO_TEST_CASE(empty_pubkey_list)
{
const std::optional<CPubKey> aggregate_pubkey{MuSig2AggregatePubkeys({})};
BOOST_CHECK(!aggregate_pubkey.has_value());
}
BOOST_AUTO_TEST_CASE(invalid_key)
{
std::vector<std::string> test_vectors = {