@@ -1413,8 +1413,16 @@ std::unique_ptr<PubkeyProvider> ParsePubkey(uint32_t key_exp_index, const Span<c
1413
1413
return std::make_unique<OriginPubkeyProvider>(key_exp_index, std::move (info), std::move (provider), apostrophe);
1414
1414
}
1415
1415
1416
- std::unique_ptr<PubkeyProvider> InferPubkey (const CPubKey& pubkey, ParseScriptContext, const SigningProvider& provider)
1416
+ std::unique_ptr<PubkeyProvider> InferPubkey (const CPubKey& pubkey, ParseScriptContext ctx , const SigningProvider& provider)
1417
1417
{
1418
+ // Key cannot be hybrid
1419
+ if (!pubkey.IsValidNonHybrid ()) {
1420
+ return nullptr ;
1421
+ }
1422
+ // Uncompressed is only allowed in TOP and P2SH contexts
1423
+ if (ctx != ParseScriptContext::TOP && ctx != ParseScriptContext::P2SH && !pubkey.IsCompressed ()) {
1424
+ return nullptr ;
1425
+ }
1418
1426
std::unique_ptr<PubkeyProvider> key_provider = std::make_unique<ConstPubkeyProvider>(0 , pubkey, false );
1419
1427
KeyOriginInfo info;
1420
1428
if (provider.GetKeyOrigin (pubkey.GetID (), info)) {
@@ -1497,11 +1505,9 @@ struct KeyParser {
1497
1505
}
1498
1506
} else if (!miniscript::IsTapscript (m_script_ctx)) {
1499
1507
CPubKey pubkey (begin, end);
1500
- if (pubkey.IsValidNonHybrid ()) {
1501
- if (auto pubkey_provider = InferPubkey (pubkey, ParseContext (), *m_in)) {
1502
- m_keys.push_back (std::move (pubkey_provider));
1503
- return key;
1504
- }
1508
+ if (auto pubkey_provider = InferPubkey (pubkey, ParseContext (), *m_in)) {
1509
+ m_keys.push_back (std::move (pubkey_provider));
1510
+ return key;
1505
1511
}
1506
1512
}
1507
1513
return {};
@@ -1855,10 +1861,8 @@ std::unique_ptr<DescriptorImpl> InferScript(const CScript& script, ParseScriptCo
1855
1861
1856
1862
if (txntype == TxoutType::PUBKEY && (ctx == ParseScriptContext::TOP || ctx == ParseScriptContext::P2SH || ctx == ParseScriptContext::P2WSH)) {
1857
1863
CPubKey pubkey (data[0 ]);
1858
- if (pubkey.IsValidNonHybrid ()) {
1859
- if (auto pubkey_provider = InferPubkey (pubkey, ctx, provider)) {
1860
- return std::make_unique<PKDescriptor>(std::move (pubkey_provider));
1861
- }
1864
+ if (auto pubkey_provider = InferPubkey (pubkey, ctx, provider)) {
1865
+ return std::make_unique<PKDescriptor>(std::move (pubkey_provider));
1862
1866
}
1863
1867
}
1864
1868
if (txntype == TxoutType::PUBKEYHASH && (ctx == ParseScriptContext::TOP || ctx == ParseScriptContext::P2SH || ctx == ParseScriptContext::P2WSH)) {
@@ -1876,7 +1880,7 @@ std::unique_ptr<DescriptorImpl> InferScript(const CScript& script, ParseScriptCo
1876
1880
CKeyID keyid (hash);
1877
1881
CPubKey pubkey;
1878
1882
if (provider.GetPubKey (keyid, pubkey)) {
1879
- if (auto pubkey_provider = InferPubkey (pubkey, ctx , provider)) {
1883
+ if (auto pubkey_provider = InferPubkey (pubkey, ParseScriptContext::P2WPKH , provider)) {
1880
1884
return std::make_unique<WPKHDescriptor>(std::move (pubkey_provider));
1881
1885
}
1882
1886
}
0 commit comments