Skip to content

Commit

Permalink
Merge bitcoin#31555: descriptor: remove unreachable verification for …
Browse files Browse the repository at this point in the history
…`pkh`

366ae00 descriptor: Assume `ParseScript` is not being called with a P2WPKH context (brunoerg)
e366408 descriptor: remove unreachable verification for `pkh` (brunoerg)

Pull request description:

  This PR removes an unreachable verification in the `ParseScript` function. It returns an error if `pkh` is not being used at top level, sh, wsh or tr. However, any usage of `pkh` without these contexts will not reach this verification but other ones like "invalid keys" (e.g. `wpkh(pkh(L4gM1FBdyHNpkzsFh9ipnofLhpZRp2mwobpeULy1a6dBTvw8Ywtd))`).

ACKs for top commit:
  davidgumberg:
    crACK bitcoin@366ae00
  achow101:
    ACK 366ae00
  tdb3:
    cr ACK 366ae00
  sipa:
    crACK 366ae00

Tree-SHA512: b954221a77eed623aeed5eb54f14e82c49540a151d3388831924caa7a784e48a2a975e418af1e13d491e4f8cded3b1797aa39e0e4e39e302a991105df09cdec0
  • Loading branch information
achow101 committed Dec 30, 2024
2 parents 9b97522 + 366ae00 commit 228aba2
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/script/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ struct KeyParser {
std::vector<std::unique_ptr<DescriptorImpl>> ParseScript(uint32_t& key_exp_index, Span<const char>& sp, ParseScriptContext ctx, FlatSigningProvider& out, std::string& error)
{
using namespace script;

Assume(ctx == ParseScriptContext::TOP || ctx == ParseScriptContext::P2SH || ctx == ParseScriptContext::P2WSH || ctx == ParseScriptContext::P2TR);
std::vector<std::unique_ptr<DescriptorImpl>> ret;
auto expr = Expr(sp);
if (Func("pk", expr)) {
Expand All @@ -1787,10 +1787,6 @@ std::vector<std::unique_ptr<DescriptorImpl>> ParseScript(uint32_t& key_exp_index
ret.emplace_back(std::make_unique<PKHDescriptor>(std::move(pubkey)));
}
return ret;
} else if (ctx != ParseScriptContext::P2TR && Func("pkh", expr)) {
// Under Taproot, always the Miniscript parser deal with it.
error = "Can only have pkh at top level, in sh(), wsh(), or in tr()";
return {};
}
if (ctx == ParseScriptContext::TOP && Func("combo", expr)) {
auto pubkeys = ParsePubkey(key_exp_index, expr, ctx, out, error);
Expand Down

0 comments on commit 228aba2

Please sign in to comment.