Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return error when constructing pubkey from slice #2576

Merged
merged 1 commit into from Mar 14, 2024

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Mar 12, 2024

This PR fixes a bug introduced by me in #2473, and uncovered by #2563 - amazing that it was found so quickly!

Constructing a pubkey using PublicKey::from_slice can fail for reasons other than just incorrect length - we should not be using expect but rather returning the error.

A purist might argue that we are now returning a nested error type with an unreachable variant:

ParsePublicKeyError::Encoding(FromSliceError::InvalidLength)

Is this acceptable or do we want to further improve this?

Constructing a pubkey using `PublicKey::from_slice` can fail for reasons
other than just incorrect length - we should not be using `expect` but
rather returning the error.

A purist might argue that we are now returning a nested error type with
an unreachable variant:

  `ParsePublicKeyError::Encoding(FromSliceError::InvalidLength)`

Is this acceptable or do we want to further improve this?
@github-actions github-actions bot added the C-bitcoin PRs modifying the bitcoin crate label Mar 12, 2024
@tcharding
Copy link
Member Author

tcharding commented Mar 12, 2024

Mad props to @Sh0g0-1758 for finding this bug literally days after I introduced it - amazing, that could easily have gotten through to the next release.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 8256499696

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 84.043%

Totals Coverage Status
Change from base Build 8251085872: 0.0%
Covered Lines: 19540
Relevant Lines: 23250

💛 - Coveralls

Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

ACK 6ecc41d

@apoelstra
Copy link
Member

Personally I think the unreachable variant is fine. It'd be really hard and annoying to restructure this code to avoid it.

Plausibly upstream we should add a pair of PublicKey::from_array methods that can't return any length-checking errors. But here this code is fine.

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 6ecc41d

@tcharding tcharding added this to the 0.32.0 milestone Mar 14, 2024
@tcharding
Copy link
Member Author

Andrew, kick your merge bot for me bro, I can't reach it from here :)

@apoelstra apoelstra merged commit e0d58a9 into rust-bitcoin:master Mar 14, 2024
187 checks passed
@tcharding tcharding deleted the 03-13-hex-bug branch March 19, 2024 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug C-bitcoin PRs modifying the bitcoin crate P-high High priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants