Repository navigation
Conversation
… last push A custom job's coinbase_prefix is chosen by the client, and nothing in the scriptSig marked where it ends and the extranonce begins. A client holding two channels with different full extranonce sizes could build the same scriptSig on both, cut at two different places, and have each share accepted once on each channel. JobFactory::new_extended_job_from_custom_job now returns the new JobFactoryError::InvalidCoinbasePrefix unless coinbase_prefix is complete script operations followed by the opcode that pushes the full extranonce, a single byte up to 0x4b. Every accepted scriptSig then parses in one way and ends with the extranonce push, so equal scriptSigs imply equal extranonces. Jobs the JobFactory builds end with the extranonce push too, as long as the template's coinbase_prefix is complete script operations, and new_custom_job already sends that shape. The PrebuiltJob docs now say what a server that also accepts custom jobs owes in its own bytes. The client channel does not repeat the check on SetCustomMiningJob.Success: the Mining Protocol puts the rejection on the server, so a compliant server never confirms such a prefix. stratum-mining/sv2-spec#259
channels_sv2: reject a custom job unless its extranonce is the last push
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.
Library side of stratum-mining/sv2-spec#259, which is still open. It adds to §5.3.18 that a custom job's
coinbase_prefixMUST consist of complete script operations followed by the opcode that pushes the full Extended Extranonce, and that the server MUST respond withSetCustomMiningJob.Errorotherwise.companion stratum-mining/sv2-apps#1017
Closes #2522
The problem
JobFactory::new_extended_job_from_custom_jobonly checked the length ofcoinbase_prefix, and nothing in the scriptSig marked where it ends and the extranonce begins. A client holding two extended channels with different full extranonce sizes could send custom jobs that cut the same scriptSig at two places. Both coinbases, and every header built on them, were then the same, and each share was accepted once on each channel.The change
new_extended_job_from_custom_jobreturns the newJobFactoryError::InvalidCoinbasePrefixunlesscoinbase_prefixis complete script operations (parsed withbitcoin::Script::instructions) followed by one byte, at most0x4b, equal to the full extranonce size.ExtendedChannel::on_set_custom_mining_jobpasses it on wrapped inExtendedChannelError::JobFactoryError, before the job is added or the chain tip updated.Not changed, and why:
JobFactorybuilds already end their scriptSig with the push of the full extranonce, followed by nSequence, which is what §5.3.16 asks of a server that accepts custom jobs. This holds as long as the template'scoinbase_prefixis complete script operations, which the Template Distribution Protocol does not require but the BIP34 height push it begins with is.JobFactory::new_custom_jobalready sends this shape, so the in-tree JDC's jobs pass the check.SetCustomMiningJob.Success: the spec puts the rejection on the server.PrebuiltJobbytes are served as given; its docs now say what §5.3.16 asks of them.Side effects
JobFactoryError.channels_sv2is already at 10.0.0 onmain, above v1.13.0's 9.0.0, so no further bump.ScriptSigSizeTooLarge.Testing
A unit test rejects an empty prefix, a wrong push size, a truncated push and
0x4c(OP_PUSHDATA1). The custom job fixtures now end with the push of their channel's full extranonce.