AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
High 74 Bitcoin

txscript: reject SIGHASH_SINGLE signing without a matching output

Public commit record

What the developer wrote

Authored by Boris Nagaev

91/100 · Strong
txscript: reject SIGHASH_SINGLE signing without a matching output

When SIGHASH_SINGLE has no output corresponding to the input being
signed, legacy signing uses the constant hash one and segwit v0 signing
commits to no outputs. These signatures can allow funds to be
redirected.

Reject this case in RawTxInSignature and RawTxInWitnessSignature with
ErrInvalidSigHashSingleIndex, including when ANYONECANPAY is set.
Their callers inherit the protection; multisig signing omits refused
signatures through its existing error handling, as SignTxOutput now
documents.

The check masks the hash type with sigHashMask (0x1f) like the sighash
code, where Core masks with 3; the two agree for the standard hash
types. When the matching output is absent, Core also refuses
non-standard types such as 0x07, 0x0b and 0x13. btcd's sighash treats
those like SIGHASH_ALL, committing to every output, so they are still
signed. This divergence is intentional.

Leave sighash calculation unchanged to preserve consensus verification.
Taproot signing already rejects this case.

Add regression coverage for P2PKH, bare multisig, P2SH-P2PKH,
P2SH-multisig, P2WPKH and P2TR across the six standard explicit sighash
types, checking both missing-output rejection and successful signing of
supported combinations. Also cover the raw ECDSA signers with
non-standard hash types: without a matching output, 0x23, 0x43 and 0xc3
are refused, while 0x07, 0x0b and 0x13 are still signed.

Port of Bitcoin Core PR bitcoin/bitcoin#35984:
https://github.com/bitcoin/bitcoin/pull/35984
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a bug in btcd's transaction signing code. When a Bitcoin transaction is signed with the SIGHASH_SINGLE type, the signature normally commits to one specific output. If the input being signed has no matching output (for example, input index 1 when there is only one output), the signature would commit to nothing. That would let anyone holding the signature later change where the money goes while keeping the signature valid. The patch now refuses to create such signatures, preventing funds from being redirected.

Recommended action

Review and merge this commit promptly. It is a defensive signing fix that prevents production of dangerous signatures. Downstream wallets or services using btcd's signing functions should upgrade. No consensus rules change, so full node operators do not need special coordination.

Security signals we found

01

Funds redirection vulnerability from SIGHASH_SINGLE without matching output

02

New defensive error ErrInvalidSigHashSingleIndex

03

Signing hardening in RawTxInSignature and RawTxInWitnessSignature

04

Multisig signing inherits protection via existing error handling

05

Consensus-critical sighash calculation intentionally unchanged

06

Regression tests added for multiple script types and sighash combinations

07

Port of Bitcoin Core PR bitcoin/bitcoin#35984

Risk score

Why this scored 74/100

Our methodology →
Potential impact 22/30
Exploitability 16/25
Stealth signal 10/15
Affected reach 12/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.