Skip to content

Commit 76c5ea7

Browse files
committed
fuzz: Fix mini_miner_selection running out of coin
Fixes a bug in the mini_miner_selection fuzz test found by fuzzing: It was possible for the mini_miner_selection fuzz test to generated transactions that created fewer new spendable outputs than the two inputs they each spend. If the fuzz seed did so consistently, eventually it would cause a `pop_front()` on an empty available_coins. Fixed by: - asserting that available_coins is not empty before generating tx - allowing to build tx with a single coin if only one is available
1 parent b22408d commit 76c5ea7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/test/fuzz/mini_miner.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ FUZZ_TARGET_INIT(mini_miner_selection, initialize_miner)
118118
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 100)
119119
{
120120
CMutableTransaction mtx = CMutableTransaction();
121-
const size_t num_inputs = 2;
121+
assert(!available_coins.empty());
122+
const size_t num_inputs = std::min(size_t{2}, available_coins.size());
122123
const size_t num_outputs = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(2, 5);
123124
for (size_t n{0}; n < num_inputs; ++n) {
124-
auto prevout = available_coins.front();
125+
auto prevout = available_coins.at(0);
125126
mtx.vin.push_back(CTxIn(prevout, CScript()));
126127
available_coins.pop_front();
127128
}

0 commit comments

Comments
 (0)