aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorPieter Wuille <pieter@wuille.net>2023-10-04 10:56:52 -0400
committerPieter Wuille <pieter@wuille.net>2023-10-04 11:28:13 -0400
commitc1e6c542af6d89a499e2a65465865aec651c4d67 (patch)
treeccd9db4d6ea1b8f12f7fc9a47c56e84249c50ba4 /src/script
parentdb7b5dfcc502a8a81c51f56fe753990ae8b3a202 (diff)
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.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/descriptor.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp
index 2f3f2c7a1d..896fb0b5b3 100644
--- a/src/script/descriptor.cpp
+++ b/src/script/descriptor.cpp
@@ -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));
}
}