Skip to content

Commit

Permalink
desc spkm: Return SigningProvider only if we have the privkey
Browse files Browse the repository at this point in the history
If we know about a pubkey that's in our descriptor, but we don't have
the private key, don't return a SigningProvider for that pubkey.

This is specifically an issue for Taproot outputs that use the H point
as the resulting PSBTs may end up containing irrelevant information
because the H point was detected as a pubkey each unrelated descriptor
knew about.
  • Loading branch information
achow101 committed Nov 7, 2024
1 parent c9e67e2 commit 4936567
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/script/signingprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ bool FlatSigningProvider::GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info)
if (ret) info = std::move(out.second);
return ret;
}
bool FlatSigningProvider::HaveKey(const CKeyID &keyid) const
{
CKey key;
return LookupHelper(keys, keyid, key);
}
bool FlatSigningProvider::GetKey(const CKeyID& keyid, CKey& key) const { return LookupHelper(keys, keyid, key); }
bool FlatSigningProvider::GetTaprootSpendData(const XOnlyPubKey& output_key, TaprootSpendData& spenddata) const
{
Expand Down
1 change: 1 addition & 0 deletions src/script/signingprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ struct FlatSigningProvider final : public SigningProvider
bool GetCScript(const CScriptID& scriptid, CScript& script) const override;
bool GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const override;
bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override;
bool HaveKey(const CKeyID &keyid) const override;
bool GetKey(const CKeyID& keyid, CKey& key) const override;
bool GetTaprootSpendData(const XOnlyPubKey& output_key, TaprootSpendData& spenddata) const override;
bool GetTaprootBuilder(const XOnlyPubKey& output_key, TaprootBuilder& builder) const override;
Expand Down
6 changes: 5 additions & 1 deletion src/wallet/scriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,11 @@ std::unique_ptr<FlatSigningProvider> DescriptorScriptPubKeyMan::GetSigningProvid
int32_t index = it->second;

// Always try to get the signing provider with private keys. This function should only be called during signing anyways
return GetSigningProvider(index, true);
std::unique_ptr<FlatSigningProvider> out = GetSigningProvider(index, true);
if (!out->HaveKey(pubkey.GetID())) {
return nullptr;
}
return out;
}

std::unique_ptr<FlatSigningProvider> DescriptorScriptPubKeyMan::GetSigningProvider(int32_t index, bool include_private) const
Expand Down

0 comments on commit 4936567

Please sign in to comment.