BIP375: validate scan-key keydata lengths #2318

pull myetcd wants to merge 1 commits into bitcoin:master from myetcd:master changing 3 files +107 −6
  1. myetcd commented at 3:37 AM on September 30, 2026: none

    BIP375 requires 33-byte scan-key keydata for PSBT_GLOBAL_SP_ECDH_SHARE, PSBT_GLOBAL_SP_DLEQ, PSBT_IN_SP_ECDH_SHARE, and PSBT_IN_SP_DLEQ.

    The reference structure validator currently checks the value lengths of these fields but ignores their keydata lengths. This change enforces the 33-byte keydata requirement for all four fields, with errors identifying the field and, for per-input fields, the input index.

    Add unit tests covering missing, short, and oversized keydata, accepted 33-byte keydata, and the existing value-length checks. Document the unit test command in the validation reference README.

  2. BIP375: validate scan-key keydata lengths
    Signed-off-by: myetcd <mytech@139.com>
    4ab0b00599
  3. fametrano commented at 7:56 PM on October 3, 2026: contributor

    ACK 4ab0b005991b16e9ee641f2d11b4562df1e43511

    Ran test_runner.py (43 passed) and test_structure.py (3 tests OK). On master (927b6de) an ECDH share whose keydata is 32 bytes is silently ignored: with the per-input share of the "can finalize: one input / one sp output with both global and per-input ECDH shares" vector re-keyed that way, the PSBT still passes because the global share covers the output; here it is rejected with "Input 0 ECDH share scan key has wrong length (32 bytes, expected 33)", and the same holds for the global share. The 33-byte requirement is what the field tables specify for all four keydata.

  4. jonatack added the label Fixups on Oct 18, 2026
  5. jonatack commented at 9:32 PM on October 18, 2026: member

    Labeled as fixups, pending more review to determine if this needs BIP author approval.

  6. macgyver13 commented at 11:09 PM on November 12, 2026: contributor

    Thanks for this. Checking the scan key keydata length alongside the existing value length checks makes sense to me for the reference validator. The field tables specify <33 byte scan key> for all four fields.

    Please drop test_structure.py and the README line for it. The BIP-375 reference validator is exercised through test_runner.py and the test vectors. I don't see a need for separate unit tests.

    I am also fine not adding test vectors for this. As the example above shows, an entry with malformed keydata never matches a scan key from PSBT_OUT_SP_V0_INFO, so it is ignored. It can only cause a signer to refuse to sign, never a wrong output.

    I looked at how a couple of other implementations handle this. Bitcoin Core and rust-psbt both reject fields like these at deserialization unless the keydata is a valid compressed point, not just 33 bytes. I will add point validation in a follow-up PR that I hope to have ready soon.

  7. macgyver13 referenced this in commit a27cf9680a on Nov 13, 2026
  8. macgyver13 referenced this in commit df08564386 on Nov 13, 2026
  9. murchandamus commented at 11:35 PM on November 16, 2026: member

    @macgyver13: It looks like @fametrano was banned from the bitcoin organization for 30 days, so if this needs further updates to be ready to merge, you’ll either have to wait a few weeks, or you could offer an alternative PR.

  10. macgyver13 commented at 11:53 PM on November 16, 2026: contributor

    If @myetcd does get to this in the next few days, I will include field length validation in my next PR.

    I am aware of the ban and will coordinate with fametrano directly.


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