Skip to content

Commit 4936567

Browse files
committed
desc spkm: Return SigningProvider only if we have the privkey
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.
1 parent c9e67e2 commit 4936567

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/script/signingprovider.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ bool FlatSigningProvider::GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info)
6262
if (ret) info = std::move(out.second);
6363
return ret;
6464
}
65+
bool FlatSigningProvider::HaveKey(const CKeyID &keyid) const
66+
{
67+
CKey key;
68+
return LookupHelper(keys, keyid, key);
69+
}
6570
bool FlatSigningProvider::GetKey(const CKeyID& keyid, CKey& key) const { return LookupHelper(keys, keyid, key); }
6671
bool FlatSigningProvider::GetTaprootSpendData(const XOnlyPubKey& output_key, TaprootSpendData& spenddata) const
6772
{

src/script/signingprovider.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ struct FlatSigningProvider final : public SigningProvider
215215
bool GetCScript(const CScriptID& scriptid, CScript& script) const override;
216216
bool GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const override;
217217
bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override;
218+
bool HaveKey(const CKeyID &keyid) const override;
218219
bool GetKey(const CKeyID& keyid, CKey& key) const override;
219220
bool GetTaprootSpendData(const XOnlyPubKey& output_key, TaprootSpendData& spenddata) const override;
220221
bool GetTaprootBuilder(const XOnlyPubKey& output_key, TaprootBuilder& builder) const override;

src/wallet/scriptpubkeyman.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,11 @@ std::unique_ptr<FlatSigningProvider> DescriptorScriptPubKeyMan::GetSigningProvid
24562456
int32_t index = it->second;
24572457

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

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

0 commit comments

Comments
 (0)