Repository navigation
fix(sv1_api): reject extranonce2 sizes a submit cannot carry - #2495
Open
amartya1523 wants to merge 2 commits into
Open
amartya1523 wants to merge 2 commits into
amartya1523 wants to merge 2 commits into
Conversation
SetExtranonce and the mining.subscribe response parser accepted any u64 extranonce2 size and cast it with as usize. A size above 32 bytes left the client unable to build a mining.submit, since extranonce2 travels as an Extranonce, and on 32-bit targets the cast truncated the value. Reject sizes above the new Extranonce::MAX_LEN in both parsers before converting them, so the conversion is lossless.
sv1_api gains Extranonce::MAX_LEN, so it takes a minor bump. No other crate uses it, so their requirements stay at ^7.0.0.
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 #2478.
SetExtranonce::try_fromand themining.subscriberesponse parser accepted anyu64extranonce2 size and narrowed it withas usize. That causes two problems:mining.submit, becauseSubmit::extra_nonce2is anExtranonce(aB032). The session is configured, but no share it finds can ever be sent.4294967300becomes4, so the client silently works with a size the server never sent.Commit 1: bound the size before converting it.
Extranoncegetspub const MAX_LEN: usize = 32, and both parsers go through one helper that rejects anything above it withParsingMethodError::UnexpectedValue. The existing variants are kept for values that are not au64at all, so callers matching on those see no change. The conversion only happens after the bound check, so it is lossless on every target.Commit 2:
sv1_api7.0.0 → 7.1.0, for the new public constant. No other crate uses it, so the^7.0.0requirements stay.I reused
UnexpectedValueinstead of adding aParsingMethodErrorvariant, because that enum is not#[non_exhaustive]and a new variant would be a major bump.Tests:
0and32are accepted by both parsers.33,4294967300(which a 32-bit cast would turn into4) andu64::MAXare rejected by both. The rejection cases fail on main.Overlap: #2485 and #2486 also bump
sv1_api, so whichever of them lands after another needs a one-line rebase of its bump commit, which I'll do.