-
Fixed
deser_compact_size
to correctly unpack the first byte instead of reading twice. -
Updated
scanning
to useOptional[Dict]
with safe default (None
→{}
) to prevent mutable default argument issues.
BIP352: fix byte unpacking and avoid mutable default argument #1916
pull fifalodm wants to merge 2 commits into bitcoin:master from fifalodm:fix/update changing 2 files +8 −8-
fifalodm commented at 3:42 pm on August 8, 2025: none
-
Update bitcoin_utils.py c9f989b05e
-
Update reference.py 948f137345
-
jonatack added the label Proposed BIP modification on Aug 8, 2025
-
murchandamus commented at 9:31 pm on August 18, 2025: contributorI’m not familiar enough with Python to know at first glance—is this fixing an actual bug in the reference implementation or is this just a stylistic improvement?
-
fifalodm commented at 8:46 am on August 19, 2025: none
Thanks for the review!
These are actual bug fixes, not just stylistic changes:
-
deser_compact_size
bug
The old code didb = f.read(1)
and then immediately calledstruct.unpack("<B", f.read(1))[0]
.
That skipped the first byte and unpacked the next one.- For values like
0xfd/0xfe/0xff
(multi-byte varints), the prefix byte was lost and parsing went out of sync. - Even for small values (≤252), the stream advanced one byte too far.
The fix correctly unpacks the already-read
b
, so the prefix is handled properly. - For values like
-
Mutable default argument in
scanning
Using{}
as a default creates a single shared dict across calls. This can leak state between function calls.
Switching tolabels: Optional[Dict[str, str]] = None
and initializing inside the function avoids that Python pitfall.
So both changes address correctness issues, not just style.
-
-
jonatack commented at 4:17 pm on August 19, 2025: membercc BIP authors @RubenSomsen @josibake for feedback
-
jonatack assigned RubenSomsen on Aug 19, 2025
-
jonatack added the label Pending acceptance on Aug 19, 2025
-
josibake commented at 10:21 am on September 2, 2025: member
Hi @fifalodm , thanks for taking a look!
Its a NACK from me on this PR only because changing reference code and code related to the test vectors can (rightly) raise a lot of alarms for downstream projects using these test vectors.
It’s my belief that this python code is correct enough for the use case, and the goal here is not to write best-in-class python code, but rather something that is readable enough when comparing to the specification in the BIP.
If you are interested in contributing to silent payments, there are plenty of other places where we need contributors/reviewers and I’d be more than happy to help get you situated! Don’t hesitate to reach out.
-
murchandamus commented at 10:37 pm on September 2, 2025: contributorI’m closing this, because the proposed change was rejected by the BIP authors.
-
murchandamus closed this on Sep 2, 2025
-
jonatack unassigned RubenSomsen on Sep 2, 2025
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: 2025-09-13 09:10 UTC
More mirrored repositories can be found on mirror.b10c.me