Skip to content

fuzz: add raw deserialization targets for SV2 messages#81

Open
xyephy wants to merge 2 commits intostratum-mining:masterfrom
xyephy:2025/12/fuzz-sv2-message-roundtrip
Open

fuzz: add raw deserialization targets for SV2 messages#81
xyephy wants to merge 2 commits intostratum-mining:masterfrom
xyephy:2025/12/fuzz-sv2-message-roundtrip

Conversation

@xyephy
Copy link
Copy Markdown
Contributor

@xyephy xyephy commented Jan 23, 2026

Rewritten to follow upstream Bitcoin Core fuzz patterns.

  • Align fuzz framework with upstream CheckGlobals pattern
  • Extract shared Sv2FuzzInitialize() into sv2_fuzz_util.h
  • Add 6 raw deserialization targets covering all client-to-TP message types
  • Types with Serialize include roundtrip invariant checks
  • Template helpers eliminate per-target boilerplate

Closes #76

@xyephy xyephy force-pushed the 2025/12/fuzz-sv2-message-roundtrip branch from 6a558d5 to b541e05 Compare January 23, 2026 09:07
Copy link
Copy Markdown
Collaborator

@Sjors Sjors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I didn't study the indivual fuzzers in great detail, but even limited coverage is better than no coverage.

@@ -0,0 +1,403 @@
// Copyright (c) 2024-present The Bitcoin Core developers
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's use the current year for new files


namespace {

void Initialize()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is (almost) identical to sv2_noise.cpp, can we move it to a reusable place?

}

// Helper to generate a fuzzed uint256
uint256 FuzzedUint256(FuzzedDataProvider& provider)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first glance I think a better approach is to add ConsumeUint256 to FuzzedDataProvider.

DataStream ss_out{};
ss_out << msg;
} catch (const std::exception&) {
// Expected for malformed input
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this fuzzer won't do anything useful if it catches every exception.

Same goes for some other fuzzers below.

@xyephy xyephy force-pushed the 2025/12/fuzz-sv2-message-roundtrip branch from b541e05 to 299b0c4 Compare February 11, 2026 21:08
xyephy added 2 commits March 31, 2026 20:19
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.
@xyephy xyephy force-pushed the 2025/12/fuzz-sv2-message-roundtrip branch from 299b0c4 to 9e9104f Compare March 31, 2026 18:00
@xyephy xyephy changed the title fuzz: add sv2 message serialization fuzz targets fuzz: add raw deserialization targets for SV2 messages Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fuzz: add sv2_message_roundtrip fuzz target

2 participants