diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index d17805926ca..f761757f3f5 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -1873,7 +1873,7 @@ static DeriveType ParseDeriveType(std::vector>& split, boo } /** Parse a public key that excludes origin information. */ -std::vector> ParsePubkeyInner(uint32_t key_exp_index, const std::span& sp, ParseScriptContext ctx, FlatSigningProvider& out, bool& apostrophe, std::string& error) +std::vector> ParsePubkeyInner(uint32_t& key_exp_index, const std::span& sp, ParseScriptContext ctx, FlatSigningProvider& out, bool& apostrophe, std::string& error) { std::vector> ret; bool permit_uncompressed = ctx == ParseScriptContext::TOP || ctx == ParseScriptContext::P2SH; @@ -1898,6 +1898,7 @@ std::vector> ParsePubkeyInner(uint32_t key_exp_i if (pubkey.IsFullyValid()) { if (permit_uncompressed || pubkey.IsCompressed()) { ret.emplace_back(std::make_unique(key_exp_index, pubkey, false)); + ++key_exp_index; return ret; } else { error = "Uncompressed keys are not allowed"; @@ -1909,6 +1910,7 @@ std::vector> ParsePubkeyInner(uint32_t key_exp_i pubkey.Set(std::begin(fullkey), std::end(fullkey)); if (pubkey.IsFullyValid()) { ret.emplace_back(std::make_unique(key_exp_index, pubkey, true)); + ++key_exp_index; return ret; } } @@ -1921,6 +1923,7 @@ std::vector> ParsePubkeyInner(uint32_t key_exp_i CPubKey pubkey = key.GetPubKey(); out.keys.emplace(pubkey.GetID(), key); ret.emplace_back(std::make_unique(key_exp_index, pubkey, ctx == ParseScriptContext::P2TR)); + ++key_exp_index; return ret; } else { error = "Uncompressed keys are not allowed"; @@ -1944,6 +1947,7 @@ std::vector> ParsePubkeyInner(uint32_t key_exp_i for (auto& path : paths) { ret.emplace_back(std::make_unique(key_exp_index, extpubkey, std::move(path), type, apostrophe)); } + ++key_exp_index; return ret; } @@ -2001,7 +2005,6 @@ std::vector> ParsePubkey(uint32_t& key_exp_index max_multipath_len = std::max(max_multipath_len, pk.size()); providers.emplace_back(std::move(pk)); - key_exp_index++; } if (!any_key_parsed) { error = "musig(): Must contain key expressions"; @@ -2093,6 +2096,7 @@ std::vector> ParsePubkey(uint32_t& key_exp_index // No multipath derivation, MuSigPubkeyProvider uses the first (and only) participant pubkey providers, and the first (and only) path emplace_final_provider(0, 0); } + ++key_exp_index; // Increment key expression index for the MuSigPubkeyProvider too return ret; } @@ -2133,7 +2137,7 @@ std::vector> ParsePubkey(uint32_t& key_exp_index if (providers.empty()) return {}; ret.reserve(providers.size()); for (auto& prov : providers) { - ret.emplace_back(std::make_unique(key_exp_index, info, std::move(prov), apostrophe)); + ret.emplace_back(std::make_unique(prov->m_expr_index, info, std::move(prov), apostrophe)); } return ret; } @@ -2207,7 +2211,6 @@ struct KeyParser { assert(m_out); Key key = m_keys.size(); auto pk = ParsePubkey(m_expr_index, {&*begin, &*end}, ParseContext(), *m_out, m_key_parsing_error); - ++m_expr_index; if (pk.empty()) return {}; m_keys.emplace_back(std::move(pk)); return key; @@ -2279,7 +2282,6 @@ std::vector> ParseScript(uint32_t& key_exp_index error = strprintf("pk(): %s", error); return {}; } - ++key_exp_index; for (auto& pubkey : pubkeys) { ret.emplace_back(std::make_unique(std::move(pubkey), ctx == ParseScriptContext::P2TR)); } @@ -2291,7 +2293,6 @@ std::vector> ParseScript(uint32_t& key_exp_index error = strprintf("pkh(): %s", error); return {}; } - ++key_exp_index; for (auto& pubkey : pubkeys) { ret.emplace_back(std::make_unique(std::move(pubkey))); } @@ -2303,7 +2304,6 @@ std::vector> ParseScript(uint32_t& key_exp_index error = strprintf("combo(): %s", error); return {}; } - ++key_exp_index; for (auto& pubkey : pubkeys) { ret.emplace_back(std::make_unique(std::move(pubkey))); } @@ -2343,7 +2343,6 @@ std::vector> ParseScript(uint32_t& key_exp_index script_size += pks.at(0)->GetSize() + 1; max_providers_len = std::max(max_providers_len, pks.size()); providers.emplace_back(std::move(pks)); - key_exp_index++; } if ((multi || sortedmulti) && (providers.empty() || providers.size() > MAX_PUBKEYS_PER_MULTISIG)) { error = strprintf("Cannot have %u keys in multisig; must have between 1 and %d keys, inclusive", providers.size(), MAX_PUBKEYS_PER_MULTISIG); @@ -2413,7 +2412,6 @@ std::vector> ParseScript(uint32_t& key_exp_index error = strprintf("wpkh(): %s", error); return {}; } - key_exp_index++; for (auto& pubkey : pubkeys) { ret.emplace_back(std::make_unique(std::move(pubkey))); } @@ -2466,7 +2464,6 @@ std::vector> ParseScript(uint32_t& key_exp_index return {}; } size_t max_providers_len = internal_keys.size(); - ++key_exp_index; std::vector>> subscripts; //!< list of multipath expanded script subexpressions std::vector depths; //!< depth in the tree of each subexpression (same length subscripts) if (expr.size()) { @@ -2570,7 +2567,6 @@ std::vector> ParseScript(uint32_t& key_exp_index error = strprintf("rawtr(): %s", error); return {}; } - ++key_exp_index; for (auto& pubkey : output_keys) { ret.emplace_back(std::make_unique(std::move(pubkey))); }