Skip to content

Commit a0626cc

Browse files
committed
fuzz: allow reaching MempoolAcceptResult::ResultType::DIFFERENT_WITNESS in tx_package_eval target
1 parent 21d9857 commit a0626cc

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/test/fuzz/package_eval.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void initialize_tx_pool()
4040
g_setup = testing_setup.get();
4141

4242
for (int i = 0; i < 2 * COINBASE_MATURITY; ++i) {
43-
COutPoint prevout{MineBlock(g_setup->m_node, P2WSH_OP_TRUE)};
43+
COutPoint prevout{MineBlock(g_setup->m_node, P2WSH_EMPTY)};
4444
if (i < COINBASE_MATURITY) {
4545
// Remember the txids to avoid expensive disk access later on
4646
g_outpoints_coinbase_init_mature.push_back(prevout);
@@ -195,7 +195,8 @@ FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool)
195195
// Create input
196196
const auto sequence = ConsumeSequence(fuzzed_data_provider);
197197
const auto script_sig = CScript{};
198-
const auto script_wit_stack = std::vector<std::vector<uint8_t>>{WITNESS_STACK_ELEM_OP_TRUE};
198+
const auto script_wit_stack = fuzzed_data_provider.ConsumeBool() ? P2WSH_EMPTY_TRUE_STACK : P2WSH_EMPTY_TWO_STACK;
199+
199200
CTxIn in;
200201
in.prevout = outpoint;
201202
in.nSequence = sequence;
@@ -207,7 +208,7 @@ FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool)
207208
const auto amount_fee = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(0, amount_in);
208209
const auto amount_out = (amount_in - amount_fee) / num_out;
209210
for (int i = 0; i < num_out; ++i) {
210-
tx_mut.vout.emplace_back(amount_out, P2WSH_OP_TRUE);
211+
tx_mut.vout.emplace_back(amount_out, P2WSH_EMPTY);
211212
}
212213
// TODO vary transaction sizes to catch size-related issues
213214
auto tx = MakeTransactionRef(tx_mut);

src/test/util/script.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ static const CScript P2WSH_OP_TRUE{
1818
return hash;
1919
}())};
2020

21+
static const std::vector<uint8_t> EMPTY{};
22+
static const CScript P2WSH_EMPTY{
23+
CScript{}
24+
<< OP_0
25+
<< ToByteVector([] {
26+
uint256 hash;
27+
CSHA256().Write(EMPTY.data(), EMPTY.size()).Finalize(hash.begin());
28+
return hash;
29+
}())};
30+
static const std::vector<std::vector<uint8_t>> P2WSH_EMPTY_TRUE_STACK{{static_cast<uint8_t>(OP_TRUE)}, {}};
31+
static const std::vector<std::vector<uint8_t>> P2WSH_EMPTY_TWO_STACK{{static_cast<uint8_t>(OP_2)}, {}};
32+
2133
/** Flags that are not forbidden by an assert in script validation */
2234
bool IsValidFlagCombination(unsigned flags);
2335

0 commit comments

Comments
 (0)