Skip to content

fix(channels_sv2)!: bound the client custom job scriptSig - #2422

Open
Jolah1 wants to merge 2 commits into
stratum-mining:mainfrom
Jolah1:fix-client-custom-job-script-sig-size
Open

Jolah1 wants to merge 2 commits into
stratum-mining:mainfrom
Jolah1:fix-client-custom-job-script-sig-size

Conversation

@Jolah1

@Jolah1 Jolah1 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

close #2398
close https://github.com/project-loupe/audit-stratum/issues/245

ExtendedChannel::on_set_custom_mining_job_success built the coinbase scriptSig from the job's coinbase_prefix and the full extranonce without checking the 100-byte consensus limit. With a 32-byte extranonce, any prefix from
69 bytes up activated a job for a consensus-invalid coinbase, and from 221 bytes the scriptSig length takes three bytes, so the prefix/suffix split, which counts it as one, landed two bytes early.

It now returns a new ExtendedChannelError::ScriptSigSizeTooLarge when coinbase_prefix.len() + full_extranonce_size > MAX_SCRIPT_SIG_SIZE, before touching the channel, same as the server's JobFactory check for
SetCustomMiningJob. The + 1 // bytes in script term gets the same comment the server has.

MAX_SCRIPT_SIG_SIZE moves from server::jobs::factory to the crate root, since server isn't built with no_std and the client needs it there.

Tests:

  • test_custom_job_success_rejects_oversized_script_sig: a prefix that fills the 100 bytes exactly is accepted, one byte over and the issue's 252 + 32 case are rejected, and the rejected jobs leave the active and past jobs
    untouched. It fails without the check.

Side effects:

  • The in-tree JDC builds its custom jobs with JobFactory::new_custom_job, which already enforces the budget with the same channel's full extranonce size, so its behaviour doesn't change. If the check ever fires there, the
    JDC's _ arm treats it as a fallback error.
  • Breaking: a new variant on the client ExtendedChannelError, and MAX_SCRIPT_SIG_SIZE changes path. channels_sv2 goes 9.0.0 -> 10.0.0. stratum_translation exposes a channels_sv2 error type and stratum-core re-exports both, so they go to 0.7.0 and 0.8.0.
  • No companion PR: sv2-apps doesn't use MAX_SCRIPT_SIG_SIZE, and its match on the client error has a _ arm. sv2-apps main builds against this branch.

ExtendedChannel::on_set_custom_mining_job_success built the coinbase
scriptSig from the job's coinbase_prefix and the full extranonce without
checking it against the 100-byte consensus limit. An oversized prefix
activated a job for a consensus-invalid coinbase, and from 253 bytes the
scriptSig length takes three bytes, so the prefix/suffix split, which
counts it as one, landed two bytes early.

Reject such a job with a new ExtendedChannelError::ScriptSigSizeTooLarge
before touching the channel, as the server JobFactory already does for
SetCustomMiningJob, and document why the split can count the length as
one byte.

MAX_SCRIPT_SIG_SIZE moves from server::jobs::factory to the crate root,
since the server module is not built with no_std and the client needs
it there.

stratum-mining#2398
channels_sv2 breaks its API, so it takes a major bump. stratum_translation
exposes channels_sv2::bip141::StripBip141Error in StratumTranslationError,
and stratum-core re-exports both, so taking channels_sv2 10 breaks them too.
@Jolah1
Jolah1 force-pushed the fix-client-custom-job-script-sig-size branch from bb0f57a to 574dd73 Compare November 13, 2026 03:19
@Jolah1

Jolah1 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on main, conflicts are gone. Added a commit bumping channels_sv2 to 10.0.0 since 9.0.0 is published now, plus stratum_translation and stratum-core which expose it. Ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant