bip-0375: fix P2WPKH scriptPubKeys and signatures in test vectors #2316

pull fametrano wants to merge 1 commits into bitcoin:master from fametrano:bip375-p2wpkh-vectors changing 1 files +122 −122
  1. fametrano commented at 6:39 PM on September 29, 2026: contributor

    The P2WPKH inputs in BIP-375's test vectors cannot be spent by the keys they carry, and none of the 42 signatures in the vectors verifies. Each P2WPKH program is SHA256(pubkey)[:20] instead of HASH160(pubkey), and the reference validator does not check signatures, so no test catches it.

    This PR repairs the file in place. Each P2WPKH program becomes HASH160(pubkey). The signatures are re-made with RFC 6979 and low S, under BIP 143 for P2WPKH and P2SH-P2WPKH and under the legacy sighash for P2PKH and the bare input. The SIGHASH_NONE vector now has a SIGHASH_NONE signature, as BIP 174 requires. The two signatures with no defined sighash, on the segwit v2 input and in the vector missing PSBT_OUT_SCRIPT, are removed; both vectors still fail for the same reason. The other 40 signatures now verify, and the runner's -vv output is unchanged: 43 passed. I did not regenerate the file, because that would also change unrelated values such as the prevout txids.

    #2317, which depends on this PR, makes the test runner check these signatures: on master's vectors it reports 39 of 43 failing, on this PR's none. #2256 and #2207 edit some of the same vectors, and their P2WPKH inputs have the same defect. Whichever of this PR and #2256 lands second needs a rebase and the same repair.

    Made with my usual tools: a computer, the Internet and an LLM. The mistakes, as usual, are all mine.

  2. bip-0375: fix P2WPKH scriptPubKeys and signatures in test vectors
    The P2WPKH inputs of the test vectors spend a witness program equal to
    SHA256(pubkey)[:20] instead of HASH160(pubkey), so the key each input
    carries cannot spend it. None of the stored ECDSA signatures verifies
    against the transaction its PSBT describes, whatever the input type. The
    reference validator does not check signatures, so no test fails.
    
    Set every P2WPKH witness program to HASH160 of the input's public key,
    in PSBT_IN_WITNESS_UTXO and in the supplementary witness_utxo and
    prevout_scriptpubkey. Re-sign the PSBT_IN_PARTIAL_SIG signatures
    deterministically (RFC 6979, low S): BIP 143 for P2WPKH and P2SH-P2WPKH,
    the legacy signature hash for P2PKH and for the bare OP_2 input. Where
    an input sets PSBT_IN_SIGHASH_TYPE, its signature uses that type, as BIP
    174 requires.
    
    Two vectors carried a signature with no defined signature hash: one on
    a segwit v2 input, one in the vector whose output lacks PSBT_OUT_SCRIPT.
    Remove both signatures, and mark the segwit v2 input as not signed in
    the supplementary material. Both vectors still fail for their stated
    reason.
    
    Inside the PSBTs only PSBT_IN_WITNESS_UTXO and PSBT_IN_PARTIAL_SIG
    change, and the test runner's result for every vector is unchanged.
    d4d3e08e38
  3. fametrano force-pushed on Sep 29, 2026

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-10-18 07:49 UTC