BIP375: correctly detect SegWit v2+ witness programs #2253

pull questfever wants to merge 1 commits into bitcoin:master from questfever:master changing 2 files +28 −2
  1. questfever commented at 9:31 AM on August 13, 2026: contributor

    Summary

    Update the BIP375 validator to reject actual SegWit v2–v16 witness programs instead of every scriptPubKey beginning with OP_2 through OP_16.

    Problem

    The input eligibility check currently determines whether an input spends a SegWit v2+ output by inspecting only the first byte of its scriptPubKey:

    if script and 0x51 < script[0] <= 0x60:
    

    However, an OP_2–OP_16 prefix alone does not make a scriptPubKey a witness program.

    A witness program must consist of a version opcode followed by a direct push of 2–40 bytes, with the push length matching the remaining script length.

    Consequently, a scriptPubKey containing only OP_2 (0x52) is incorrectly classified as a SegWit v2 witness program and rejected by the validator.

    Testing

    Before the fix, the new regression vector failed:

    41 passed, 1 failed

    After the fix, all BIP375 validation vectors pass:

    42 passed, 0 failed

  2. BIP375: correctly detect SegWit v2+ witness programs e726d13ade
  3. questfever commented at 9:47 AM on August 17, 2026: contributor

    @andrewtoth @theStack Hi, Could you please review this PR at your convenience? Thank you very much.

  4. jonatack added the label Fixups on Aug 17, 2026
  5. jonatack approved
  6. jonatack commented at 4:51 PM on August 17, 2026: member

    ACK e726d13ade44e2184635935c84a83d4082da3a63

  7. jonatack merged this on Aug 17, 2026
  8. jonatack closed this on Aug 17, 2026

Contributors
Labels

github-metadata-mirror

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

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