mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-15 07:03:40 +01:00
descriptors: disallow hybrid public keys
The descriptor documentation (doc/descriptors.md) and BIP380 explicitly require that hex-encoded public keys start with 02 or 03 (compressed) or 04 (uncompressed). However, the current parsing/inference code permit 06 and 07 (hybrid) encoding as well. Fix this.
This commit is contained in:
@@ -1290,6 +1290,10 @@ std::unique_ptr<PubkeyProvider> ParsePubkeyInner(uint32_t key_exp_index, const S
|
||||
if (IsHex(str)) {
|
||||
std::vector<unsigned char> data = ParseHex(str);
|
||||
CPubKey pubkey(data);
|
||||
if (pubkey.IsValid() && !pubkey.IsValidNonHybrid()) {
|
||||
error = "Hybrid public keys are not allowed";
|
||||
return nullptr;
|
||||
}
|
||||
if (pubkey.IsFullyValid()) {
|
||||
if (permit_uncompressed || pubkey.IsCompressed()) {
|
||||
return std::make_unique<ConstPubkeyProvider>(key_exp_index, pubkey, false);
|
||||
@@ -1448,7 +1452,7 @@ struct KeyParser {
|
||||
{
|
||||
assert(m_in);
|
||||
CPubKey pubkey(begin, end);
|
||||
if (pubkey.IsValid()) {
|
||||
if (pubkey.IsValidNonHybrid()) {
|
||||
Key key = m_keys.size();
|
||||
m_keys.push_back(InferPubkey(pubkey, ParseScriptContext::P2WSH, *m_in));
|
||||
return key;
|
||||
@@ -1795,7 +1799,7 @@ std::unique_ptr<DescriptorImpl> InferScript(const CScript& script, ParseScriptCo
|
||||
|
||||
if (txntype == TxoutType::PUBKEY && (ctx == ParseScriptContext::TOP || ctx == ParseScriptContext::P2SH || ctx == ParseScriptContext::P2WSH)) {
|
||||
CPubKey pubkey(data[0]);
|
||||
if (pubkey.IsValid()) {
|
||||
if (pubkey.IsValidNonHybrid()) {
|
||||
return std::make_unique<PKDescriptor>(InferPubkey(pubkey, ctx, provider));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user