From c1b7bd047f47dcd3eb6897adfaf9a55594deff5d Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Fri, 17 Feb 2023 12:16:09 +0100 Subject: [PATCH] fuzz: avoid redundant dup key checks when creating Miniscript nodes Check it only once on the top level node. Running libfuzzer with -runs=0 against the qa-assets corpus (1b9ddc96586769d92b1b62775f397b7f1a63f142). Without this patch: miniscript_stable: Done 6616 runs in 118 second(s) miniscript_smart: Done 13182 runs in 253 second(s) With this patch: miniscript_stable: Done 6616 runs in 57 second(s) miniscript_smart: Done 13182 runs in 124 second(s) --- src/test/fuzz/miniscript.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/fuzz/miniscript.cpp b/src/test/fuzz/miniscript.cpp index 1b791fc19c..73096cd5ca 100644 --- a/src/test/fuzz/miniscript.cpp +++ b/src/test/fuzz/miniscript.cpp @@ -253,7 +253,9 @@ using Type = miniscript::Type; using miniscript::operator"" _mst; //! Construct a miniscript node as a shared_ptr. -template NodeRef MakeNodeRef(Args&&... args) { return miniscript::MakeNodeRef(KEY_COMP, std::forward(args)...); } +template NodeRef MakeNodeRef(Args&&... args) { + return miniscript::MakeNodeRef(miniscript::internal::NoDupCheck{}, std::forward(args)...); +} /** Information about a yet to be constructed Miniscript node. */ struct NodeInfo { @@ -762,6 +764,7 @@ NodeRef GenNode(F ConsumeNode, Type root_type = ""_mst, bool strict_valid = fals } } assert(stack.size() == 1); + stack[0]->DuplicateKeyCheck(KEY_COMP); return std::move(stack[0]); }