musig: Move synthetic xpub construction to its own function
What changed, and why it matters
This commit simply moves a small block of code that builds a synthetic extended public key into its own reusable function. There is no change in behavior, no bug fix, and no security-relevant change.
No security action needed; this is a routine code-cleanup refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is a pure refactor: the code that populates a CExtPubKey with depth 0, zeroed parent fingerprint, child 0, the MuSig2 chaincode constant, and the aggregate pubkey is extracted from descriptor.cpp into a new helper CreateMuSig2SyntheticXpub() in musig.cpp/.h. The descriptor.cpp call site now uses that helper. Values, control flow, and resulting data structures are identical before and after.
Changed components
src/musig.cppsrc/musig.hsrc/script/descriptor.cppInspect captured patch +15 / −7
diff --git a/src/musig.cpp b/src/musig.cpp
index b3329543..85074796 100644
--- a/src/musig.cpp
+++ b/src/musig.cpp
@@ -51,3 +51,14 @@ std::optional<CPubKey> MuSig2AggregatePubkeys(const std::vector<CPubKey>& pubkey
}
return GetCPubKeyFromMuSig2KeyAggCache(keyagg_cache);
}
+
+CExtPubKey CreateMuSig2SyntheticXpub(const CPubKey& pubkey)
+{
+ CExtPubKey extpub;
+ extpub.nDepth = 0;
+ std::memset(extpub.vchFingerprint, 0, 4);
+ extpub.nChild = 0;
+ extpub.chaincode = MUSIG_CHAINCODE;
+ extpub.pubkey = pubkey;
+ return extpub;
+}
diff --git a/src/musig.h b/src/musig.h
index d46a67f6..0bc1f5ff 100644
--- a/src/musig.h
+++ b/src/musig.h
@@ -23,4 +23,7 @@ std::optional<CPubKey> GetCPubKeyFromMuSig2KeyAggCache(secp256k1_musig_keyagg_ca
//! Compute the full aggregate pubkey from the given participant pubkeys in their current order
std::optional<CPubKey> MuSig2AggregatePubkeys(const std::vector<CPubKey>& pubkeys);
+//! Construct the BIP 328 synthetic xpub for a pubkey
+CExtPubKey CreateMuSig2SyntheticXpub(const CPubKey& pubkey);
+
#endif // BITCOIN_MUSIG_H
diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp
index 3a402702..d0436702 100644
--- a/src/script/descriptor.cpp
+++ b/src/script/descriptor.cpp
@@ -641,13 +641,7 @@ public:
// Make our pubkey provider
if (IsRangedDerivation() || !m_path.empty()) {
// Make the synthetic xpub and construct the BIP32PubkeyProvider
- CExtPubKey extpub;
- extpub.nDepth = 0;
- std::memset(extpub.vchFingerprint, 0, 4);
- extpub.nChild = 0;
- extpub.chaincode = MUSIG_CHAINCODE;
- extpub.pubkey = m_aggregate_pubkey.value();
-
+ CExtPubKey extpub = CreateMuSig2SyntheticXpub(m_aggregate_pubkey.value());
m_aggregate_provider = std::make_unique<BIP32PubkeyProvider>(m_expr_index, extpub, m_path, m_derive, /*apostrophe=*/false);
} else {
m_aggregate_provider = std::make_unique<ConstPubkeyProvider>(m_expr_index, m_aggregate_pubkey.value(), /*xonly=*/false);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.