Skip to content

Commit fa03d0a

Browse files
author
MarcoFalke
committed
fuzz: Create a block template in tx_pool targets
1 parent fa61ce5 commit fa03d0a

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

src/test/fuzz/tx_pool.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <consensus/validation.h>
6+
#include <miner.h>
67
#include <test/fuzz/FuzzedDataProvider.h>
78
#include <test/fuzz/fuzz.h>
89
#include <test/fuzz/util.h>
@@ -77,6 +78,29 @@ void SetMempoolConstraints(ArgsManager& args, FuzzedDataProvider& fuzzed_data_pr
7778
ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 999)));
7879
}
7980

81+
void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, CChainState& chainstate)
82+
{
83+
WITH_LOCK(::cs_main, tx_pool.check(chainstate));
84+
{
85+
BlockAssembler::Options options;
86+
options.nBlockMaxWeight = fuzzed_data_provider.ConsumeIntegralInRange(0U, MAX_BLOCK_WEIGHT);
87+
options.blockMinFeeRate = CFeeRate{ConsumeMoney(fuzzed_data_provider)};
88+
auto assembler = BlockAssembler{chainstate, *static_cast<CTxMemPool*>(&tx_pool), ::Params(), options};
89+
auto block_template = assembler.CreateNewBlock(CScript{} << OP_TRUE);
90+
Assert(block_template->block.vtx.size() >= 1);
91+
}
92+
const auto info_all = tx_pool.infoAll();
93+
if (!info_all.empty()) {
94+
const auto& tx_to_remove = *PickValue(fuzzed_data_provider, info_all).tx;
95+
WITH_LOCK(tx_pool.cs, tx_pool.removeRecursive(tx_to_remove, /* dummy */ MemPoolRemovalReason::BLOCK));
96+
std::vector<uint256> all_txids;
97+
tx_pool.queryHashes(all_txids);
98+
assert(all_txids.size() < info_all.size());
99+
WITH_LOCK(::cs_main, tx_pool.check(chainstate));
100+
}
101+
SyncWithValidationInterfaceQueue();
102+
}
103+
80104
void MockTime(FuzzedDataProvider& fuzzed_data_provider, const CChainState& chainstate)
81105
{
82106
const auto time = ConsumeTime(fuzzed_data_provider,
@@ -245,17 +269,7 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
245269
}
246270
}
247271
}
248-
WITH_LOCK(::cs_main, tx_pool.check(chainstate));
249-
const auto info_all = tx_pool.infoAll();
250-
if (!info_all.empty()) {
251-
const auto& tx_to_remove = *PickValue(fuzzed_data_provider, info_all).tx;
252-
WITH_LOCK(tx_pool.cs, tx_pool.removeRecursive(tx_to_remove, /* dummy */ MemPoolRemovalReason::BLOCK));
253-
std::vector<uint256> all_txids;
254-
tx_pool.queryHashes(all_txids);
255-
assert(all_txids.size() < info_all.size());
256-
WITH_LOCK(::cs_main, tx_pool.check(chainstate));
257-
}
258-
SyncWithValidationInterfaceQueue();
272+
Finish(fuzzed_data_provider, tx_pool, chainstate);
259273
}
260274

261275
FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
@@ -308,8 +322,7 @@ FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
308322
if (accepted) {
309323
txids.push_back(tx->GetHash());
310324
}
311-
312-
SyncWithValidationInterfaceQueue();
313325
}
326+
Finish(fuzzed_data_provider, tx_pool, chainstate);
314327
}
315328
} // namespace

test/sanitizer_suppressions/ubsan

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# names can be used.
66
# See https://github.com/google/sanitizers/issues/1364
77
signed-integer-overflow:txmempool.cpp
8+
# https://github.com/bitcoin/bitcoin/pull/21798#issuecomment-829180719
9+
signed-integer-overflow:policy/feerate.cpp
810

911
# -fsanitize=integer suppressions
1012
# ===============================

0 commit comments

Comments
 (0)