Skip to content

Commit e1f3041

Browse files
committed
Simplify miniscript fuzzer NodeInfo struct
Since we now keep track of all expected child node types (even if rudimentary) in both miniscript_stable and miniscript_smart fuzzers, there is no need anymore for the former shortcut NodeInfo constructors without sub types.
1 parent 5abb0f5 commit e1f3041

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/test/fuzz/miniscript.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,6 @@ template<typename... Args> NodeRef MakeNodeRef(Args&&... args) {
261261
struct NodeInfo {
262262
//! The type of this node
263263
Fragment fragment;
264-
//! Number of subs of this node
265-
uint8_t n_subs;
266264
//! The timelock value for older() and after(), the threshold value for multi() and thresh()
267265
uint32_t k;
268266
//! Keys for this node, if it has some
@@ -272,15 +270,13 @@ struct NodeInfo {
272270
//! The type requirements for the children of this node.
273271
std::vector<Type> subtypes;
274272

275-
NodeInfo(Fragment frag): fragment(frag), n_subs(0), k(0) {}
276-
NodeInfo(Fragment frag, CPubKey key): fragment(frag), n_subs(0), k(0), keys({key}) {}
277-
NodeInfo(Fragment frag, uint32_t _k): fragment(frag), n_subs(0), k(_k) {}
278-
NodeInfo(Fragment frag, std::vector<unsigned char> h): fragment(frag), n_subs(0), k(0), hash(std::move(h)) {}
279-
NodeInfo(uint8_t subs, Fragment frag): fragment(frag), n_subs(subs), k(0), subtypes(subs, ""_mst) {}
280-
NodeInfo(uint8_t subs, Fragment frag, uint32_t _k): fragment(frag), n_subs(subs), k(_k), subtypes(subs, ""_mst) {}
281-
NodeInfo(std::vector<Type> subt, Fragment frag): fragment(frag), n_subs(subt.size()), k(0), subtypes(std::move(subt)) {}
282-
NodeInfo(std::vector<Type> subt, Fragment frag, uint32_t _k): fragment(frag), n_subs(subt.size()), k(_k), subtypes(std::move(subt)) {}
283-
NodeInfo(Fragment frag, uint32_t _k, std::vector<CPubKey> _keys): fragment(frag), n_subs(0), k(_k), keys(std::move(_keys)) {}
273+
NodeInfo(Fragment frag): fragment(frag), k(0) {}
274+
NodeInfo(Fragment frag, CPubKey key): fragment(frag), k(0), keys({key}) {}
275+
NodeInfo(Fragment frag, uint32_t _k): fragment(frag), k(_k) {}
276+
NodeInfo(Fragment frag, std::vector<unsigned char> h): fragment(frag), k(0), hash(std::move(h)) {}
277+
NodeInfo(std::vector<Type> subt, Fragment frag): fragment(frag), k(0), subtypes(std::move(subt)) {}
278+
NodeInfo(std::vector<Type> subt, Fragment frag, uint32_t _k): fragment(frag), k(_k), subtypes(std::move(subt)) {}
279+
NodeInfo(Fragment frag, uint32_t _k, std::vector<CPubKey> _keys): fragment(frag), k(_k), keys(std::move(_keys)) {}
284280
};
285281

286282
/** Pick an index in a collection from a single byte in the fuzzer's output. */
@@ -795,11 +791,11 @@ NodeRef GenNode(F ConsumeNode, Type root_type, bool strict_valid = false) {
795791
NodeInfo& info = *todo.back().second;
796792
// Gather children from the back of stack.
797793
std::vector<NodeRef> sub;
798-
sub.reserve(info.n_subs);
799-
for (size_t i = 0; i < info.n_subs; ++i) {
800-
sub.push_back(std::move(*(stack.end() - info.n_subs + i)));
794+
sub.reserve(info.subtypes.size());
795+
for (size_t i = 0; i < info.subtypes.size(); ++i) {
796+
sub.push_back(std::move(*(stack.end() - info.subtypes.size() + i)));
801797
}
802-
stack.erase(stack.end() - info.n_subs, stack.end());
798+
stack.erase(stack.end() - info.subtypes.size(), stack.end());
803799
// Construct new NodeRef.
804800
NodeRef node;
805801
if (info.keys.empty()) {

0 commit comments

Comments
 (0)