sign: skip signing SIGHASH_SINGLE inputs with no corresponding output #35984

pull furszy wants to merge 1 commits into bitcoin:master from furszy:2026_psbt_sighash-single changing 2 files +37 −8
  1. furszy commented at 6:17 PM on August 15, 2026: member

    SIGHASH_SINGLE only commits to the output at the input's index. If the output at such position doesn't exist, it commits to no output at all (legacy uses a fixed sighash of 1, segwit v0 zeroes hashOutputs), which means the signature stays valid even when outputs are swapped, which is a footgun that lets funds be redirected without the owner's consent.

    SignTransaction() already skipped these inputs, but SignPSBTInput() did not, so walletprocesspsbt signed them. This moves the check into the CreateSig so both paths, and any future one, skip producing the detached signature.

    Note: if there is a valid use for the segwit v0 case, I would rather re-allow it through an explicit opt-in arg than by default, so it is always a deliberate choice.

    Fixes #35977

  2. DrahtBot commented at 6:17 PM on August 15, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35984.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Concept ACK l0rinc

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  3. wallet: skip signing SIGHASH_SINGLE inputs with no corresponding output
    SIGHASH_SINGLE only commits to the output at the input's index. If the
    output at such position doesn't exist, it commits to no output at all
    (legacy uses a fixed sighash of 1, segwit v0 zeroes hashOutputs), which
    means the signature stays valid even when outputs are swapped, which
    is a footgun that lets funds be redirected without the owner's consent.
    
    SignTransaction() already skipped these inputs, but SignPSBTInput()
    did not, so walletprocesspsbt signed them. This moves the check into
    the CreateSig so both paths, and any future one, skip producing the
    detached signature.
    0fa39483fb
  4. furszy force-pushed on Aug 15, 2026
  5. DrahtBot added the label CI failed on Aug 15, 2026
  6. l0rinc commented at 6:59 PM on August 15, 2026: contributor

    Thanks for pushing a fix for #35977 so quickly (with extra segwit-v0 coverage, guess you rediscovered it independently). Could you add Fixes [#35977](/bitcoin-bitcoin/35977/) to the PR description so the issue auto-closes on merge?

  7. furszy commented at 7:25 PM on August 15, 2026: member

    Thanks for pushing a fix for #35977 so quickly (with extra segwit-v0 coverage, guess you rediscovered it independently). Could you add Fixes #35977 to the PR description so the issue auto-closes on merge?

    Funny, I didn't check the open issues, only PRs. Done.

  8. l0rinc commented at 7:49 PM on August 15, 2026: contributor

    Concept ACK If you think it would help, consider adding a characterization test commit before the fix commit to document the previous behavior and to simplify the fix commit.

  9. DrahtBot removed the label CI failed on Aug 15, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-08-17 04:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me