Repository navigation
fix(sv1_api): reject numeric ntime and nonce wider than 32 bits - #2496
Open
amartya1523 wants to merge 2 commits into
Open
amartya1523 wants to merge 2 commits into
amartya1523 wants to merge 2 commits into
Conversation
Submit accepted ntime and nonce as JSON numbers and narrowed them with as u32, so an ntime of 4294967296 parsed as 0 and the share was checked against a time the miner never sent. Convert them with u32::try_from and reject values that do not fit, keeping ImpossibleToParseAsU64 for numbers that are not unsigned integers at all.
Only mining.submit parsing changes, so sv1_api takes a patch bump.
agammann
reviewed
Nov 11, 2026
agammann
left a comment
There was a problem hiding this comment.
Using one numeric_u32 helper for both ntime and nonce in both five- and six-parameter submit forms prevents either branch from silently narrowing a JSON integer. The regression covers u32::MAX as accepted and 2^32 as rejected in both fields, which is the exact wraparound boundary the old as u32 cast missed.
Contributor
|
#2498 lists |
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 #2490.
Submit::try_fromacceptsntimeandnonceas JSON numbers in both the 5- and 6-param forms, and narrowed them withas u32. Anything aboveu32::MAXwas silently truncated to its low 32 bits. Anntimeof4294967296parsed as0, so the share was validated against a time the miner never sent, rather than being rejected as malformed.Commit 1: lossless conversion. Both numeric arms now go through one
numeric_u32helper. It usesu32::try_fromand returnsParsingMethodError::UnexpectedValuefor values that don't fit. A number that isn't an unsigned integer at all (negative, fractional) still getsImpossibleToParseAsU64, as before, so callers matching on that variant see no change. The hex-string forms already reject anything longer than 8 hex digits and are untouched.Commit 2:
sv1_api7.0.0 → 7.0.1. Only parsing changes, nothing public is added.Tests: for both the 5- and 6-param forms,
u32::MAXis accepted for both fields.2^32inntimeor innonceis rejected, and that case fails on main. The existing negative and fractional tests still pass.Overlap: #2485, #2486 and #2495 also bump
sv1_api, so whichever lands later needs a one-line rebase of its bump commit, which I'll do.