fuzz: add a target for DifferenceFormatter Class
What changed, and why it matters
This commit adds a new automated fuzz test for a Bitcoin Core data-formatting helper called DifferenceFormatter. It does not change any production code, network behavior, or wallet logic. It only adds a test file and registers it in the build system. There is no security fix or vulnerability present in the diff.
No security action required. Treat as a normal test-infrastructure addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit introduces src/test/fuzz/difference_formatter.cpp and adds it to src/test/fuzz/CMakeLists.txt. The fuzz target deserializes arbitrary input into a BlockTransactionsRequest using DifferenceFormatter and asserts that the resulting indexes vector is strictly monotonic increasing with no duplicates. Malformed input is expected to throw std::ios_base::failure and is caught. No runtime, consensus, or protocol code is modified.
Changed components
src/test/fuzz/difference_formatter.cppsrc/test/fuzz/CMakeLists.txtInspect captured patch +33 / −0
diff --git a/src/test/fuzz/CMakeLists.txt b/src/test/fuzz/CMakeLists.txt
index 4d649a73..6f87844b 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 00000000..15aeda99
--- /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 <blockencodings.h>
+#include <streams.h>
+#include <random.h>
+#include <test/fuzz/fuzz.h>
+
+#include <vector>
+
+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
+ }
+}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.