Repository navigation
fix(channels_sv2)!: coinbase witness handling gaps - #2457
Merged
plebhash merged 2 commits intoNov 3, 2026
Merged
Conversation
plebhash
reviewed
Nov 3, 2026
Jolah1
force-pushed
the
fix-coinbase-witness-handling
branch
from
November 3, 2026 13:28
d2a61bc to
a9a3b67
Compare
plebhash
approved these changes
Nov 3, 2026
try_strip_bip141 strips the marker, the flag and the last witness stack, and only checked that this stack is framed like a coinbase's. A two-input transaction whose inputs each carry one 32-byte witness item passed that check: the first input's witness stayed in the "stripped" suffix and the prefix kept the two-input count, so the client built jobs from bytes that are not a transaction. The stripped stack is the whole witness section only when there is a single input, so read the input count after the marker and flag and return the new StripBip141Error::UnexpectedInputCount for anything other than one. stratum-mining#2397
The job factory and the client custom job always gave the coinbase input the 32-byte witness reserved value. BIP141 only allows a block to leave out the witness commitment when none of its transactions has witness data, so a template without a commitment output turned into blocks Bitcoin Core rejects as unexpected-witness, from both extended and standard channels. Attach the reserved value only when the outputs carry a commitment. Without a witness the coinbase serializes without the marker and flag, so the prefix/suffix split indexes count them only when there is one, and the strip sites use bytes that have nothing to strip as they are. ExtendedChannelError::FailedToStripBip141 had no other use and goes away. Prebuilt jobs are untouched: their bytes come from the application, which owns their witness. stratum-mining#2397
SV2-bot
force-pushed
the
fix-coinbase-witness-handling
branch
from
November 3, 2026 15:05
a9a3b67 to
7f20b56
Compare
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.
close #2397
close https://github.com/project-loupe/audit-stratum/issues/240
close https://github.com/project-loupe/audit-stratum/issues/252
Two commits, one per defect in the issue.
try_strip_bip141now returns the newStripBip141Error::UnexpectedInputCountunless the coinbase has exactly one input, since it only strips the last witness stack. The existing test fixtures gain the input count byte.The coinbase built by
JobFactoryand by the client'son_set_custom_mining_job_successonly gets the witness reserved value when its outputs carry a witness commitment. Without a witness there's no marker and flag either, sothe prefix/suffix split indexes count them only when present, and the strip sites use bytes with nothing to strip as they are. Standard channels get this through the factory's coinbase since #2445. Prebuilt jobs are left alone.
Tests:
bip141: input counts other than one are rejected, including a real two-input SegWit transaction.unexpected-witnesson main and is accepted with this branch.Side effects:
StripBip141Errorvariant, and the now unusedExtendedChannelError::FailedToStripBip141is removed. channels_sv2 is already at 9.0.0 vs 8.0.0 on crates.io, and sv2-apps uses neither; I ran sv2-apps' testsagainst this branch locally.