diff --git a/src/test/fuzz/CMakeLists.txt b/src/test/fuzz/CMakeLists.txt index 4d649a737f3..6f87844b695 100644 --- a/src/test/fuzz/CMakeLists.txt +++ b/src/test/fuzz/CMakeLists.txt @@ -41,6 +41,7 @@ add_executable(fuzz decode_tx.cpp descriptor_parse.cpp deserialize.cpp + difference_formatter.cpp eval_script.cpp feefrac.cpp fee_rate.cpp diff --git a/src/test/fuzz/difference_formatter.cpp b/src/test/fuzz/difference_formatter.cpp new file mode 100644 index 00000000000..15aeda99b6d --- /dev/null +++ b/src/test/fuzz/difference_formatter.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2025 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 + +FUZZ_TARGET(difference_formatter) +{ + const auto block_hash = InsecureRandomContext{{}}.rand256(); + DataStream ss{}; + ss << block_hash << std::span{buffer}; + + // Test deserialization + try { + BlockTransactionsRequest test_container; + ss >> test_container; + assert(test_container.blockhash == block_hash); + + // Invariant: strictly monotonic increasing (no duplicates allowed) + for (size_t i = 1; i < test_container.indexes.size(); ++i) { + assert(test_container.indexes[i] > test_container.indexes[i-1]); + } + + } catch (const std::ios_base::failure&) { + // Expected for malformed input + } +}