BIP-352: add test vectors for malleated p2pkh pubkey extraction #2323

pull fametrano wants to merge 2 commits into bitcoin:master from fametrano:bip352-malleated-p2pkh-vector changing 2 files +175 −1
  1. fametrano commented at 7:48 AM on October 2, 2026: contributor

    This adds two test vectors, each with a p2pkh input whose scriptSig also pushes another valid pubkey.

    The first uses the scriptSig from the test in bitcoin/bitcoin#36338 by @theStack: <sig> <pubkey> <bogus_sig> OP_OVER OP_CHECKSIG OP_IF <other_pubkey> OP_ENDIF. Evaluating this scriptSig with a checker that accepts any signature leaves <other_pubkey> on top of the stack. The existing malleated p2pkh vector does not cover this.

    The second is the <dummy> OP_DROP <sig> <pubkey> case @jonatack suggested in that PR, with a valid pubkey as the dummy. It catches an extractor that takes the first 33-byte push without checking its hash.

    The expected values come from reference.py. btclib-wallet's vector tests also pass on the new file.

    I ran Bitcoin Core's bip352_tests with the new file in place of its vendored copy:

    • at the head of #36338 (cdfaa534), all 30 vectors pass;
    • on master's code, the first new vector fails;
    • on #36338 without its Hash160 check, the second new vector fails.

    Core's test does not compare input_pub_keys, so each failure shows on the receiving side: the wrong key gives a wrong tweak, and no output is found.

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

  2. fametrano commented at 9:02 PM on October 7, 2026: contributor

    With bitcoin/bitcoin#36338 merged, Core's master (db0bde16) passes all 30 vectors in this file, so Core and reference.py now agree on them.

  3. jonatack added the label Fixups on Oct 18, 2026
  4. BIP-352: add test vectors for malleated p2pkh pubkey extraction
    Add two p2pkh inputs whose scriptSig also pushes another valid pubkey.
    
    In `<sig> <pubkey> <bogus_sig> OP_OVER OP_CHECKSIG OP_IF <other_pubkey>
    OP_ENDIF`, evaluating the scriptSig with a checker that accepts any
    signature leaves <other_pubkey> on top of the stack. This is the
    scriptSig of the test added in bitcoin/bitcoin#36338.
    
    In `<other_pubkey> OP_DROP <sig> <pubkey>`, taking the first 33-byte
    push without checking its hash finds <other_pubkey>.
    f2e3928d6b
  5. BIP-352: update changelog e8603368af
  6. fametrano commented at 10:43 PM on November 10, 2026: contributor

    @theStack @jonatack, a review of these two vectors would be welcome when you have time.

  7. jonatack added the label Tests on Nov 10, 2026
  8. jonatack removed the label Fixups on Nov 10, 2026
  9. jonatack commented at 5:59 PM on November 14, 2026: member

    ACK, could squash

  10. AdityaKaushal17 commented at 2:51 PM on November 17, 2026: none

    Tested e8603368 on macos<arm64>, ''Python 3.11.7'' . Steps: 1. Fetched pull/2323/head and copied bip-0352/send_and_receive_test_vectors.json into the Code Orange silent-payments lab (an educational Python BIP352 implementation: my own send/receive code, lab-provided input-key extraction). 2. Ran its send and receive graders. Result: 31/31 passing on both, including the two new vectors. Observation: the lab extracts the P2PKH key by checking every 33-byte window of the scriptSig against the scriptPubKey's hash160. A naive first-33-byte extractor returns the decoy key (02c6047f...) on "another pubkey pushed first", and the correct key on "failing OP_CHECKSIG". So the first vector doesn't catch naive extractors. Per the PR description, it targets evaluators with a permissive checker, which I didn't test.

  11. Yudis-bit commented at 4:33 AM on November 22, 2026: contributor

    ACK e8603368af23ae185eb81500923fa23421d650c8

    Ran reference.py against the updated vectors and checked both new scriptSig encodings, Hash160 matches, tweaks, and BIP-340 signatures. The changelog entry and version bump to 1.1.3 look good too.


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-11-24 00:10 UTC

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