Repository navigation
fix(sv1_api): roll only the negotiated version-rolling mask - #2485
Open
amartya1523 wants to merge 4 commits into
Open
amartya1523 wants to merge 4 commits into
amartya1523 wants to merge 4 commits into
Conversation
BIP 310 only lets a miner roll the version bits it asked for and the server granted, and neither side may roll bits outside VERSION_ROLLING_MASK. negotiated_mask computes that mask from a grant and the requested mask, so the server and client paths can share it.
IsServer stored the mask from the mining.configure request before handle_configure decided what to grant, and mining.submit version bits were then checked against it, so a miner asking for ffffffff could roll reserved bits. Store only the negotiated mask once handle_configure returns, and narrow the grant in the response to that same mask. A session that did not request version rolling, or had it refused, keeps no mask, so submits without version bits stay valid. The example server now reads the requested mask from the request instead of the session state.
The mining.configure response handler stored the pool's mask as is, so a pool could hand the client reserved bits or bits it never asked for. Narrow the grant to the requested mask and to VERSION_ROLLING_MASK, and keep no mask when version rolling was not requested.
sv1_api gains VersionRollingParams::negotiated_mask, so it takes a minor bump. No other crate calls it, so their requirements stay at ^7.0.0.
amartya1523
force-pushed
the
fix/sv1-negotiated-version-mask
branch
from
November 6, 2026 14:47
573bbae to
d6c0c53
Compare
Contributor
|
tACK d6c0c53 Ran the sv1_api tests, and with main's configure logic put back the six new bug tests fail as described. Also threw random masks at both sides (500k configures and 2M submits on the server, 500k responses on the client): |
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.
Closes #2472.
Both sides of
mining.configureacted on a mask other than the negotiated one:IsServer::handle_parsed_requeststored the mask from the request beforehandle_configuredecided what to grant, andmining.submitversion bits were checked against that stored mask. A miner asking forffffffffcould then roll reserved bits, whatever the implementation granted.IsClient::handle_responsestored the pool's mask as received, so a pool could hand the client reserved bits, or bits the client never asked for.BIP 310 lets the miner roll only bits it requested and the server granted, and nothing outside
VERSION_ROLLING_MASK(1fffffe0). Both paths now compute exactly that.Commit 1:
VersionRollingParams::negotiated_mask. One shared helper,requested & granted & VERSION_ROLLING_MASK. It returnsNonewhen version rolling was not requested or was refused.Commit 2: server.
handle_configureruns first, and only the negotiated mask (and min-bit-count) is stored. The grant in the response is narrowed to that same mask, so what the miner is told matches what submits are checked against. A session that did not request version rolling, or had it refused, stores no mask, so submits without version bits stay valid as before. Thehandle_configuredocs now say the requested mask comes throughrequestand the session mask is set after it returns. The example server reads it from there.Commit 3: client. The response handler narrows the pool's grant to the mask
IsClient::configurerequested, rebuilt from the session state the same wayconfigurebuilds the request.Commit 4:
sv1_api7.0.0 → 7.1.0. Minor bump for the new public method. Nothing else calls it, so the^7.0.0requirements stay.Behaviour change for implementors:
set_version_rolling_maskis no longer called beforehandle_configure, so ahandle_configurethat read the session mask to learn the request should userequest.version_rolling_mask()instead. In sv2-apps the translator already does that (downstream_message_handler.rs). It grantsrequested & VERSION_ROLLING_MASK, which the narrowing leaves unchanged, so no companion PR is needed.Not in this PR:
server_to_client::Configure::try_fromstill parses the pool's mask as is. The client no longer acts on it unnarrowed, and #2415 is changing that parser, so I left it alone to avoid a conflict.Tests:
ffffffffagainst a request forffffffffanswers and stores1fffffe0, and a submit rolling bit 29 gets error 20. A request for00ff0000is not widened by a larger grant. A configure without version rolling keeps submits without version bits valid. A refused grant stores nothing.negotiated_mask.All of them except the no-version-rolling server case, which guards against a regression, fail on main.