fuzz: add raw deserialization targets for SV2 messages#81
Open
xyephy wants to merge 2 commits intostratum-mining:masterfrom
Open
fuzz: add raw deserialization targets for SV2 messages#81xyephy wants to merge 2 commits intostratum-mining:masterfrom
xyephy wants to merge 2 commits intostratum-mining:masterfrom
Conversation
6a558d5 to
b541e05
Compare
Sjors
reviewed
Jan 27, 2026
Collaborator
Sjors
left a comment
There was a problem hiding this comment.
Thanks, I didn't study the indivual fuzzers in great detail, but even limited coverage is better than no coverage.
src/test/fuzz/sv2_messages.cpp
Outdated
| @@ -0,0 +1,403 @@ | |||
| // Copyright (c) 2024-present The Bitcoin Core developers | |||
Collaborator
There was a problem hiding this comment.
nit: let's use the current year for new files
src/test/fuzz/sv2_messages.cpp
Outdated
|
|
||
| namespace { | ||
|
|
||
| void Initialize() |
Collaborator
There was a problem hiding this comment.
This function is (almost) identical to sv2_noise.cpp, can we move it to a reusable place?
src/test/fuzz/sv2_messages.cpp
Outdated
| } | ||
|
|
||
| // Helper to generate a fuzzed uint256 | ||
| uint256 FuzzedUint256(FuzzedDataProvider& provider) |
Collaborator
There was a problem hiding this comment.
At first glance I think a better approach is to add ConsumeUint256 to FuzzedDataProvider.
src/test/fuzz/sv2_messages.cpp
Outdated
| DataStream ss_out{}; | ||
| ss_out << msg; | ||
| } catch (const std::exception&) { | ||
| // Expected for malformed input |
Collaborator
There was a problem hiding this comment.
It seems like this fuzzer won't do anything useful if it catches every exception.
Same goes for some other fuzzers below.
b541e05 to
299b0c4
Compare
Add CheckGlobals to fuzz framework test_one_input() wrapper, matching upstream. Extract minimal Sv2FuzzInitialize() into sv2_fuzz_util.h, removing duplicated init from sv2_noise.cpp.
Cover all client-to-TP message types that accept untrusted input: SetupConnection, RequestTransactionData, SubmitSolution, CoinbaseOutputConstraints, NetHeader, and NetMsg. Types with both Serialize and Unserialize include roundtrip invariant checks.
299b0c4 to
9e9104f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rewritten to follow upstream Bitcoin Core fuzz patterns.
Closes #76