mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-05 11:28:49 +02:00
Merge bitcoin/bitcoin#26567: Wallet: estimate the size of signed inputs using descriptors
10546a569cwallet: accurately account for the size of the witness stack (Antoine Poinsot)9b7ec393b8wallet: use descriptor satisfaction size to estimate inputs size (Antoine Poinsot)8d870a9873script/signingprovider: introduce a MultiSigningProvider (Antoine Poinsot)fa7c46b503descriptor: introduce a method to get the satisfaction size (Antoine Poinsot)bdba7667d2miniscript: introduce a helper to get the maximum witness size (Antoine Poinsot)4ab382c2cdminiscript: make GetStackSize independent of P2WSH context (Antoine Poinsot) Pull request description: The wallet currently estimates the size of a signed input by doing a dry run of the signing logic. This is unnecessary since all outputs we can sign for can be represented by a descriptor, and we can derive the size of a satisfaction ("signature") directly from the descriptor itself. In addition, the current approach does not generalize well: dry runs of the signing logic are only possible for the most basic scripts. See for instance the discussion in #24149 around that. This introduces a method to get the maximum size of a satisfaction from a descriptor, and makes the wallet use that instead of the dry-run. ACKs for top commit: sipa: utACK10546a569cachow101: re-ACK10546a569cTree-SHA512: 43ed1529fbd30af709d903c8c5063235e8c6a03b500bc8f144273d6184e23a53edf0fea9ef898ed57d8a40d73208b5d935cc73b94a24fad3ad3c63b3b2027174
This commit is contained in:
@@ -112,7 +112,7 @@ static void TestDescriptor(const Descriptor& desc, FlatSigningProvider& sig_prov
|
||||
{
|
||||
// Trivial helpers.
|
||||
(void)desc.IsRange();
|
||||
(void)desc.IsSolvable();
|
||||
const bool is_solvable{desc.IsSolvable()};
|
||||
(void)desc.IsSingleType();
|
||||
(void)desc.GetOutputType();
|
||||
|
||||
@@ -131,7 +131,19 @@ static void TestDescriptor(const Descriptor& desc, FlatSigningProvider& sig_prov
|
||||
// If we could serialize to script we must be able to infer using the same provider.
|
||||
if (!out_scripts.empty()) {
|
||||
assert(InferDescriptor(out_scripts.back(), sig_provider));
|
||||
|
||||
// The ScriptSize() must match the size of the serialized Script. (ScriptSize() is set for all descs but 'combo()'.)
|
||||
const bool is_combo{!desc.IsSingleType()};
|
||||
assert(is_combo || desc.ScriptSize() == out_scripts.back().size());
|
||||
}
|
||||
|
||||
const auto max_sat_maxsig{desc.MaxSatisfactionWeight(true)};
|
||||
const auto max_sat_nonmaxsig{desc.MaxSatisfactionWeight(true)};
|
||||
const auto max_elems{desc.MaxSatisfactionElems()};
|
||||
// We must be able to estimate the max satisfaction size for any solvable descriptor (but combo).
|
||||
const bool is_nontop_or_nonsolvable{!is_solvable || !desc.GetOutputType()};
|
||||
const bool is_input_size_info_set{max_sat_maxsig && max_sat_nonmaxsig && max_elems};
|
||||
assert(is_input_size_info_set || is_nontop_or_nonsolvable);
|
||||
}
|
||||
|
||||
void initialize_descriptor_parse()
|
||||
|
||||
@@ -973,7 +973,7 @@ void TestNode(const NodeRef& node, FuzzedDataProvider& provider)
|
||||
|
||||
if (nonmal_success) {
|
||||
// Non-malleable satisfactions are bounded by GetStackSize().
|
||||
assert(witness_nonmal.stack.size() <= *node->GetStackSize());
|
||||
assert(witness_nonmal.stack.size() <= *node->GetStackSize() + 1);
|
||||
// If a non-malleable satisfaction exists, the malleable one must also exist, and be identical to it.
|
||||
assert(mal_success);
|
||||
assert(witness_nonmal.stack == witness_mal.stack);
|
||||
|
||||
Reference in New Issue
Block a user