BIP-327: fix reference.py type errors failing tests.sh #2261

pull SatsAndSports wants to merge 1 commits into bitcoin:master from SatsAndSports:fix-bip327-tests-mypy changing 1 files +4 −4
  1. SatsAndSports commented at 4:43 PM on August 18, 2026: contributor

    Found during a review of BIP327's reference implementation and its shipped test gate.

    bip-0327/tests.sh (the BIP's own set -e quality gate: mypy --no-error-summary reference.py && python3 reference.py && python3 gen_vectors_helper.py) currently fails at its first step under the current mypy (2.3.1), before the vector suite ever runs:

    reference.py:354: error: Argument 1 to "int_from_bytes" has incompatible type "bytearray"; expected "bytes"  [arg-type]
    reference.py:355: error: Argument 1 to "int_from_bytes" has incompatible type "bytearray"; expected "bytes"  [arg-type]
    reference.py:672: error: Argument 1 to "int_from_bytes" has incompatible type "bytearray"; expected "bytes"  [arg-type]
    reference.py:673: error: Argument 1 to "int_from_bytes" has incompatible type "bytearray"; expected "bytes"  [arg-type]
    

    Cause: sign() and the tweak-test driver slice secnonce, which is a bytearray by design (mutable, for in-place zeroization); recent mypy/typeshed no longer accepts bytearray for a bytes parameter.

    Fix: convert to immutable bytes at the four call sites (int_from_bytes(bytes(secnonce[...]))). This keeps the int_from_bytes helper byte-identical to the BIP-340 reference implementation it was copied from, and is behavior-identical at runtime (int.from_bytes already accepts both types).

    Verification: full tests.sh gate now passes end-to-end in a clean container with mypy 2.3.1 (mypy clean + python3 reference.py — all vector suites and the randomized self-test — + gen_vectors_helper.py).

    History: this was accepted in older versions of mypy because it was more relaxed then. But from mypy 2.0, it is stricter per PEP 688, mypy no longer treats bytearray and memoryview values as assignable to the bytes type. https://github.com/python/mypy/pull/18371

  2. BIP-327: fix reference.py type errors failing tests.sh ccb5415095
  3. jonatack added the label Fixups on Aug 18, 2026
  4. jonatack commented at 3:14 PM on August 19, 2026: member

    Issue reproduced.

    ~/bitcoin/bips/bip-0327$ ./tests.sh 
    reference.py:354: error: Argument 1 to "int_from_bytes" has incompatible type "bytearray"; expected "bytes"  [arg-type]
    reference.py:355: error: Argument 1 to "int_from_bytes" has incompatible type "bytearray"; expected "bytes"  [arg-type]
    reference.py:672: error: Argument 1 to "int_from_bytes" has incompatible type "bytearray"; expected "bytes"  [arg-type]
    reference.py:673: error: Argument 1 to "int_from_bytes" has incompatible type "bytearray"; expected "bytes"  [arg-type]
    ~/bitcoin/bips/bip-0327$ mypy --version
    mypy 2.3.1 (compiled: yes)
    
  5. jonatack approved
  6. jonatack commented at 3:17 PM on August 19, 2026: member

    ACK

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

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