aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/descriptor_parse.cpp
diff options
context:
space:
mode:
authorAntoine Poinsot <darosior@protonmail.com>2022-08-19 18:33:54 +0200
committerAntoine Poinsot <darosior@protonmail.com>2023-08-25 12:40:11 +0200
commitfa7c46b503f0b69630f55dc43021d2099e3515ba (patch)
treeac592c760fe8d2d4f0391f29a6d419d3d8c6f453 /src/test/fuzz/descriptor_parse.cpp
parentbdba7667d2d65f31484760a8e8420c488fc5f801 (diff)
downloadbitcoin-fa7c46b503f0b69630f55dc43021d2099e3515ba.tar.xz
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()`).
Diffstat (limited to 'src/test/fuzz/descriptor_parse.cpp')
-rw-r--r--src/test/fuzz/descriptor_parse.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/test/fuzz/descriptor_parse.cpp b/src/test/fuzz/descriptor_parse.cpp
index 8ed659323c..a866cdca9a 100644
--- a/src/test/fuzz/descriptor_parse.cpp
+++ b/src/test/fuzz/descriptor_parse.cpp
@@ -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()