Skip to content

BIP375: correctly detect SegWit v2+ witness programs - #2253

Merged
jonatack merged 1 commit into
bitcoin:masterfrom
questfever:master
Aug 17, 2026
Merged

BIP375: correctly detect SegWit v2+ witness programs#2253
jonatack merged 1 commit into
bitcoin:masterfrom
questfever:master

Conversation

@questfever

Copy link
Copy Markdown
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

@questfever

Copy link
Copy Markdown
Contributor Author

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

@jonatack jonatack added the Fixups Minor fixups not worth bothering the BIP author(s) for label Aug 17, 2026

@jonatack jonatack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK e726d13

@jonatack
jonatack merged commit a30de51 into bitcoin:master Aug 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fixups Minor fixups not worth bothering the BIP author(s) for

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants