mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 18:22:57 +02:00
descriptor: introduce a method to get the satisfaction size
In the wallet code, we are currently estimating the size of a signed
input by doing a dry run of the signing logic. This is unnecessary as
all outputs we are able to sign for can be represented by a descriptor,
and we can derive the size of a satisfaction ("signature") from the
descriptor itself directly.
In addition, this approach does not scale: getting the size of a
satisfaction through a dry run of the signing logic is only possible for
the most basic scripts.
This commit introduces the computation of the size of satisfaction per
descriptor. It's a bit intricate for 2 main reasons:
- We want to conserve the behaviour of the current dry-run logic used by
the wallet that sometimes assumes ECDSA signatures will be low-r,
sometimes not (when we don't create them).
- We need to account for the witness discount. A single descriptor may
sometimes benefit of it, sometimes not (for instance `pk()` if used as
top-level versus if used inside `wsh()`).
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,18 @@ 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)};
|
||||
// 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};
|
||||
assert(is_input_size_info_set || is_nontop_or_nonsolvable);
|
||||
}
|
||||
|
||||
void initialize_descriptor_parse()
|
||||
|
||||
Reference in New Issue
Block a user