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)
This commit is contained in:
Antoine Poinsot 2023-02-17 12:16:09 +01:00
parent 73966f75f6
commit c1b7bd047f
No known key found for this signature in database
GPG key ID: E13FC145CD3F4304

View file

@ -253,7 +253,9 @@ using Type = miniscript::Type;
using miniscript::operator"" _mst;
//! Construct a miniscript node as a shared_ptr.
template<typename... Args> NodeRef MakeNodeRef(Args&&... args) { return miniscript::MakeNodeRef<CPubKey>(KEY_COMP, std::forward<Args>(args)...); }
template<typename... Args> NodeRef MakeNodeRef(Args&&... args) {
return miniscript::MakeNodeRef<CPubKey>(miniscript::internal::NoDupCheck{}, std::forward<Args>(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]);
}