Skip to content

handlers_sv2 hardening - #2499

Draft
bit-aloo wants to merge 8 commits into
stratum-mining:mainfrom
bit-aloo:2026-11-11-handlers-sv2-fixes
Draft

bit-aloo wants to merge 8 commits into
stratum-mining:mainfrom
bit-aloo:2026-11-11-handlers-sv2-fixes

Conversation

@bit-aloo

@bit-aloo bit-aloo commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Closes #2322
Closes #2324
Closes #2325
Closes #2326
Closes #2382
Closes #2393
Closes project-loupe/audit-stratum#25
Closes project-loupe/audit-stratum#141
Closes project-loupe/audit-stratum#31
Closes project-loupe/audit-stratum#226
Closes project-loupe/audit-stratum#50
Closes project-loupe/audit-stratum#137
Closes project-loupe/audit-stratum#187
Closes project-loupe/audit-stratum#257
Closes project-loupe/audit-stratum#63
Closes project-loupe/audit-stratum#138
Closes project-loupe/audit-stratum#143
Closes project-loupe/audit-stratum#188
Closes project-loupe/audit-stratum#224
Closes project-loupe/audit-stratum#259
Closes project-loupe/audit-stratum#258

companion stratum-mining/sv2-apps#997

…traits

The dispatcher never called it, so a policy returning false had no effect.
It cannot enforce it either: an unauthorized open is answered with an
OpenMiningChannel.Error, which only the implementor can send, so
authorization belongs in handle_open_*_mining_channel.
Handler docs called the TLV argument tlv_data, which is named tlv_fields, and
pointed at an extract_worker_identity_from_submit_shares helper that
extensions_sv2 does not have.
mining.rs, common.rs and both job declaration files imported a list of names
from a crate they also glob-imported.
The spec lets a client update any channel it opened, and a standard channel's
SetTarget bound refers to its latest accepted UpdateChannel.
The enum predates group channels holding extended channels: no variant let a
group-mode client receive the NewMiningJob its standard channels start with,
or run standard and extended channels side by side. Whether a message fits a
channel depends on per-channel state the implementor already tracks, so the
dispatchers now route by direction only. SetCustomMiningJob and its replies
stay gated on work selection, which SetupConnection negotiates.
… header

AnyMessage::try_from((Header, payload)) ignored the header's payload length
and channel_msg bit, so a frame whose header disagreed with its body still
decoded, and an intermediary routing on the header could read it differently
from the endpoint. Both now fail with dedicated ParserError variants, which
parse_message_frame_with_tlvs inherits.
With no extensions negotiated, the handlers decoded the payload from the
message type alone, so a frame under an extension namespace was dispatched as
a core message and the header's length and channel bit were never looked at.
All entry points now share one decoder that goes through AnyMessage::try_from
and only reads the TLV suffix when extensions were negotiated.
parsers_sv2, handlers_sv2 and stratum-core break their public API; mining_sv2
only changes a doc comment.
let (parsed, tlv_fields) =
parse_message_frame_with_tlvs(header, payload, &negotiated_extensions)
.map_err(Self::Error::parse_error)?;
let (parsed, tlv_fields) = crate::decode_frame(header, payload, &negotiated_extensions)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With the SupportedChannelTypes gate gone, every mining message reaches the implementor regardless of connection mode. Does sv2-apps#997 add the equivalent rejections (e.g. extended-channel messages on a REQUIRES_STANDARD_JOBS connection) in Pool/JDC/tproxy? It might also be worth a short note on the dispatcher trait listing what implementors are now expected to check.

let header = v.0;
let payload = v.1;
let (header, payload) = v;
if payload.len() != header.payload_length() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

try_from((Header, payload)) now requires payload.len() == header.payload_length(). Are there callers in sv2-apps that pass a larger, reused buffer slice? Worth grepping in #997 before un-drafting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants