BIP174: restrict range of compact size integer (discussion) #868

pull dgpv wants to merge 1 commits into bitcoin:master from dgpv:patch-8 changing 1 files +1 −1
  1. dgpv commented at 9:02 AM on December 10, 2019: contributor

    Key types and proprietary subtypes are now defined as compact size integers. Previously compact size integers were used only to encode the size of data. It was decided that it would be fine to use compact size integer for extensibility of key types, to allow for types larger than that can be encoded by just one byte. One of the advantages of using compact size integers for key types was that the code to decode them in the implementations that work with PSBT.

    The problem is, the code that decodes compact size integers, at least in BitcoinCore, limits the upper range of compact size integer to MAX_SIZE = 0x2000000 (see ReadCompactSize() in serialize.h`). Other implementations might implement the same restrictions, to improve the chances to catch incorrect data.

    I think it should be discussed how this issue can be solved.

    It can be said that implementations should allow full range representable by compact integer (up to 2**64-1), and then some implementations will need to update their code, to have separate decoding function or add extra parameter to existing decoding function to be able to decode full-range compact size integers and retain the range check where it is needed.

    Or we can say that the range from 0 to 0x2000000 is enough for any key type or subtype, but then this should be spelled out in the BIP. (Note that ranges beyond MAX_SIZE up to 2**32-1 can be represented by straight non-compact-size 32-bit values).

    I'm not sure what is the right approach here, but I favour the second option.

  2. BIP174: restrict range of compact size integer b26b92cd01
  3. luke-jr commented at 3:30 AM on January 3, 2020: member
  4. luke-jr added the label Proposed BIP modification on Jan 3, 2020
  5. achow101 commented at 4:00 AM on January 3, 2020: member

    IMO this is really an implementation bug and shouldn't be part of the standard. I think we should allow all possible compact size uints.

  6. dgpv commented at 8:46 AM on January 3, 2020: contributor

    Fair, I will update my implementation. When Core updates its PSBT implementation to support variable-sized types for unknown and proprietary fields, it would also need to add an option to skip MAX_SIZE check in ReadCompactSize()

  7. dgpv commented at 8:53 AM on January 3, 2020: contributor

    If there's no other opinions, the issue can be closed.

  8. luke-jr closed this on Jan 17, 2020


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-04-14 11:10 UTC

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