8000 `channels_sv2`: reject a custom job unless its extranonce is the last push by plebhash · Pull Request #2520 · stratum-mining/stratum · GitHub
[go: up one dir, main page]

Skip to content

channels_sv2: reject a custom job unless its extranonce is the last push - #2520

Draft
plebhash wants to merge 1 commit into
stratum-mining:mainfrom
plebhash:2026-11-27-custom-job-extranonce-push
Draft

plebhash wants to merge 1 commit into
stratum-mining:mainfrom
plebhash:2026-11-27-custom-job-extranonce-push

Conversation

@plebhash
@plebhash plebhash commented Nov 27, 2026 •
Copy link
Copy Markdown
Member

Library side of stratum-mining/sv2-spec#259, which is still open. It adds to §5.3.18 that a custom job's coinbase_prefix MUST consist of complete script operations followed by the opcode that pushes the full Extended Extranonce, and that the server MUST respond with SetCustomMiningJob.Error otherwise.

companion stratum-mining/sv2-apps#1017

Closes #2522

The problem

JobFactory::new_extended_job_from_custom_job only checked the length of coinbase_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_job returns the new JobFactoryError::InvalidCoinbasePrefix unless coinbase_prefix is complete script operations (parsed with bitcoin::Script::instructions) followed by one byte, at most 0x4b, equal to the full extranonce size. ExtendedChannel::on_set_custom_mining_job passes it on wrapped in ExtendedChannelError::JobFactoryError, before the job is added or the chain tip updated.

Not changed, and why:

  • Jobs JobFactory builds 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's coinbase_prefix is complete script operations, which the Template Distribution Protocol does not require but the BIP34 height push it begins with is.
  • JobFactory::new_custom_job already sends this shape, so the in-tree JDC's jobs pass the check.
  • The client channel does not repeat the check on SetCustomMiningJob.Success: the spec puts the rejection on the server.
  • PrebuiltJob bytes are served as given; its docs now say what §5.3.16 asks of them.

Side effects

  • Breaking API: a new variant on the exhaustive JobFactoryError. channels_sv2 is already at 10.0.0 on main, above v1.13.0's 9.0.0, so no further bump.
  • A rejected custom job still uses up a job id, as it already did for 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.

… 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
@plebhash plebhash changed the title feat(channels_sv2)!: reject a custom job unless its extranonce is the… channels_sv2: reject a custom job unless its extranonce is the last push Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

channels_sv2: server ExtendedChannel accepts a custom job whose coinbase_prefix lets one scriptSig belong to two channels

1 participant

0