Skip to content

Revert "consensus: Add CompactSize range check to deserialization"#6160

Closed
bigspider wants to merge 1 commit into
rust-bitcoin:0.32.xfrom
bigspider:revert-compactsize
Closed

Revert "consensus: Add CompactSize range check to deserialization"#6160
bigspider wants to merge 1 commit into
rust-bitcoin:0.32.xfrom
bigspider:revert-compactsize

Conversation

@bigspider

Copy link
Copy Markdown
Contributor

This reverts commit 91a6e64 in the 0.32.x branch.

Closes: #6138

@github-actions github-actions Bot added the C-bitcoin PRs modifying the bitcoin crate label May 11, 2026
/// VarInt was encoded in a non-minimal way.
NonMinimalVarInt,
/// VarInt value exceeds the maximum allowed size.
OversizedVarInt,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 8bd7444:

You cannot delete a variant from a public enum like this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding is backwards compatible, but not removing. You may just lock the lockfile to the previous version since it seems like you're trying to just undo the commit.

/// the size is encoded as a CompactSize.
///
/// ref: <https://github.com/bitcoin/bitcoin/blob/a7c29df0e5ace05b6186612671d6103c112ec922/src/serialize.h#L32>
pub const MAX_COMPACT_SIZE: usize = 0x0200_0000;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 8bd7444:

...nor can you delete this constant.

@bigspider

bigspider commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

It seems I misunderstood the suggestion to revert from the issue, and I am therefore closing the PR and leaving the issue to someone else, if there's interest. I already removed the dependency from VarInt of my affected crate, so this was more for the sake of other people that might be affected.

I am not an expert in Rust, therefore I am not as well-versed in the best practices.

However, here is why I think that a revert would be acceptable in this case:

  • It's 0.32.9 that made a breaking change in the contract of VarInt. The fact that the code still compiles, to me, makes that worse: in the crate I'm maintaining, it was only discovered in the CI. Had there be no tests covering it, it could very easily reach a release and only be discovered with a production panic. In fact, that could still happen on software wallets depending on the ledger_bitcoin_client if they update rust-bitcoin to 0.32.9 but not ledger_bitcoin_client.
  • Reverting the commit restores to the behavior of 0.32.8, so there is no breaking change unless you're relying on the behavior introduced in 0.32.9. Therefore, I think that not compiling is in fact better in this case, precisely to avoid the kind of runtime bugs that a backwards-compatible fix might cause.

@bigspider bigspider closed this May 11, 2026
@apoelstra

Copy link
Copy Markdown
Member

That's a reasonable viewpoint, but unfortunately it differs from the Rust semver rules, as forced on users by cargo's version-matching rules.

So in order to revert this, we need to leave the error variant and constant in place, document that they're never used (and deprecate them if possible), and remove the code that produces them.

I agree that this sort of "silent" behavior change can be insidious. Hopefully, because we are reverting to the same behavior as an earlier version of the crate, and because this is in a non-central part of the API, it will be okay.

@tcharding

Copy link
Copy Markdown
Member

I"ll pick this up. Thanks @bigspider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-bitcoin PRs modifying the bitcoin crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants