From 1994e38b9072e597ba16785a018593a21b9060a6 Mon Sep 17 00:00:00 2001 From: fanquake Date: Sat, 6 May 2023 12:04:30 +0100 Subject: [PATCH 1/4] Merge bitcoin/bitcoin#17860: fuzz: BIP 30, CVE-2018-17144 fa2d8b61f9343d350b67357a12f39b613c8ee8ad fuzz: BIP 42, BIP 30, CVE-2018-17144 (MarcoFalke) faae7d5c00c99b0f3e99a1fbffbf369645716dd1 Move LoadVerifyActivateChainstate to ChainTestingSetup (MarcoFalke) fa26e3462a0fb1a9ad116ed58afa6897798f2c24 Avoid dereferencing interruption_point if it is nullptr (MarcoFalke) fa846ee074822160077f3f7476b2af62a876dec7 test: Add util to mine invalid blocks (MarcoFalke) Pull request description: Add a validation fuzz test for BIP 30 and CVE-2018-17144 ACKs for top commit: dergoegge: Code review ACK fa2d8b61f9343d350b67357a12f39b613c8ee8ad mzumsande: Tested ACK fa2d8b61f9343d350b67357a12f39b613c8ee8ad Tree-SHA512: 1f4620cc078709487abff24b304a6bb4eeab2e7628b392e2bc6de9cc0ce6745c413388ede6e93025d0c56eec905607ba9786633ef183e5779bf5183cc9ff92c0 --- src/Makefile.test.include | 1 + src/bench/block_assemble.cpp | 2 +- src/node/coinstats.cpp | 2 +- src/test/fuzz/tx_pool.cpp | 6 +- src/test/fuzz/utxo_total_supply.cpp | 167 ++++++++++++++++++++++++++++ src/test/util/mining.cpp | 48 +++++++- src/test/util/mining.h | 12 +- src/test/util/setup_common.h | 5 + 8 files changed, 229 insertions(+), 14 deletions(-) create mode 100644 src/test/fuzz/utxo_total_supply.cpp diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 432bf0a0688e..b313d2c02b8d 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -364,6 +364,7 @@ test_fuzz_fuzz_SOURCES = \ test/fuzz/tx_out.cpp \ test/fuzz/tx_pool.cpp \ test/fuzz/utxo_snapshot.cpp \ + test/fuzz/utxo_total_supply.cpp \ test/fuzz/validation_load_mempool.cpp \ test/fuzz/versionbits.cpp endif # ENABLE_FUZZ_BINARY diff --git a/src/bench/block_assemble.cpp b/src/bench/block_assemble.cpp index 01832712b706..7d077e02eab7 100644 --- a/src/bench/block_assemble.cpp +++ b/src/bench/block_assemble.cpp @@ -32,7 +32,7 @@ static void AssembleBlock(benchmark::Bench& bench) std::array txs; for (size_t b{0}; b < NUM_BLOCKS; ++b) { CMutableTransaction tx; - tx.vin.push_back(MineBlock(test_setup->m_node, SCRIPT_PUB)); + tx.vin.push_back(CTxIn{MineBlock(test_setup->m_node, SCRIPT_PUB)}); tx.vin.back().scriptSig = scriptSig; tx.vout.emplace_back(1337, SCRIPT_PUB); if (NUM_BLOCKS - b >= COINBASE_MATURITY) diff --git a/src/node/coinstats.cpp b/src/node/coinstats.cpp index c31509e15304..ae6c8f14042d 100644 --- a/src/node/coinstats.cpp +++ b/src/node/coinstats.cpp @@ -117,7 +117,7 @@ static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& uint256 prevkey; std::map outputs; while (pcursor->Valid()) { - interruption_point(); + if (interruption_point) interruption_point(); COutPoint key; Coin coin; if (pcursor->GetKey(key) && pcursor->GetValue(coin)) { diff --git a/src/test/fuzz/tx_pool.cpp b/src/test/fuzz/tx_pool.cpp index c973fa9582c5..4d81d17f6136 100644 --- a/src/test/fuzz/tx_pool.cpp +++ b/src/test/fuzz/tx_pool.cpp @@ -46,12 +46,12 @@ void initialize_tx_pool() g_setup = testing_setup.get(); for (int i = 0; i < 2 * COINBASE_MATURITY; ++i) { - CTxIn in = MineBlock(g_setup->m_node, CScript() << OP_TRUE); - // Remember the txids to avoid expensive disk acess later on + COutPoint prevout{MineBlock(g_setup->m_node, CScript() << OP_TRUE)}; + // Remember the txids to avoid expensive disk access later on auto& outpoints = i < COINBASE_MATURITY ? g_outpoints_coinbase_init_mature : g_outpoints_coinbase_init_immature; - outpoints.push_back(in.prevout); + outpoints.push_back(prevout); } SyncWithValidationInterfaceQueue(); } diff --git a/src/test/fuzz/utxo_total_supply.cpp b/src/test/fuzz/utxo_total_supply.cpp new file mode 100644 index 000000000000..85f075574fad --- /dev/null +++ b/src/test/fuzz/utxo_total_supply.cpp @@ -0,0 +1,167 @@ +// Copyright (c) 2020 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include +#include +#include +#include