Skip to content

Commit 6a91791

Browse files
committed
fuzz: allow fake and duplicate inputs in tx_package_eval target
1 parent a0626cc commit 6a91791

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/test/fuzz/package_eval.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool)
205205

206206
tx_mut.vin.push_back(in);
207207
}
208+
209+
// Duplicate an input
210+
bool dup_input = fuzzed_data_provider.ConsumeBool();
211+
if (dup_input) {
212+
tx_mut.vin.push_back(tx_mut.vin.back());
213+
}
214+
215+
// Refer to a non-existant input
216+
if (fuzzed_data_provider.ConsumeBool()) {
217+
tx_mut.vin.emplace_back();
218+
}
219+
208220
const auto amount_fee = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(0, amount_in);
209221
const auto amount_out = (amount_in - amount_fee) / num_out;
210222
for (int i = 0; i < num_out; ++i) {
@@ -215,7 +227,8 @@ FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool)
215227
// Restore previously removed outpoints, except in-package outpoints
216228
if (!last_tx) {
217229
for (const auto& in : tx->vin) {
218-
Assert(outpoints.insert(in.prevout).second);
230+
// It's a fake input, or a new input, or a duplicate
231+
Assert(in == CTxIn() || outpoints.insert(in.prevout).second || dup_input);
219232
}
220233
// Cache the in-package outpoints being made
221234
for (size_t i = 0; i < tx->vout.size(); ++i) {

0 commit comments

Comments
 (0)