-
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
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: 2025-08-19 23:10 UTC
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-08-19 23:10 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me
More mirrored repositories can be found on mirror.b10c.me