8000 Improve `crytpo::taproot` error type by tcharding · Pull Request #1895 · rust-bitcoin/rust-bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve crytpo::taproot error type #1895

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

Merged

Conversation

tcharding
Copy link
Member
@tcharding tcharding commented Jun 2, 2023

First three patches are preparatory cleanup, last patch renames crypto::taproot::Error to SigFromSliceError. See commit log for justification of the Sig prefix.

Done as part of the great error cleanup.

tcharding added 4 commits June 2, 2023 14:48
Add 'use Error::*' locally to make the code more terse.
We provide a `From<secp255k1::Error>` impl so we do not need to
explicitly convert the error return, just use `?`.
The rustdoc on the `taproot::Error::InvalidSighashType` is wrong, fix
it.
This error type is only used in the `from_slice` function. Use prefix
`Sig` because `taproot::FromSliceError` does not fully express how the
error came about.

Use specific identifier for the error, this aids usage but also prevents
us later adding "random" other variants into this error and using it in
other functions.
@tcharding tcharding force-pushed the 06-02-taproot-from-slice-error branch from 9bf5695 to 202d1cd Compare June 2, 2023 05:48
@Kixunil
Copy link
Collaborator
Kixunil commented Jun 2, 2023

Concept ACK but maybe simply SignatureError? Although it does match core::array::TryFromSliceError...

@tcharding
Copy link
Member Author

I agree its a bit long but I think the module is unusual in our code so a slightly long one here is better than non-uniform SignatureError since one would expect taproot::signature::Error based on the rest of our code.

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 202d1cd

Copy link
Collaborator
@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 202d1cd

.map_err(|_| Error::InvalidSighashType(*hash_ty))?;
let sig =
secp256k1::schnorr::Signature::from_slice(sig)?;
.map_err(|_| SigFromSliceError::InvalidSighashType(*hash_ty))?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe there should be From conversion?

Copy link
Member Author

Choose a reason for hiding this comment

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

sighash::Error needs splitting up, its on my todo list. Then the SigFromSliceErorr can have a variant that holds the error returned here.

In case you are interested, I audited all errors yesterday and there are actually not that many that need splitting up, we are close to having good errors I believe. My list of modules that contain errors that need improving is:

  • bip158
  • bip32
  • script/mod
  • crypto/ecdsa
  • crypto/key
  • crypto/sighash

@apoelstra apoelstra merged commit 7eeb3e6 into rust-bitcoin:master Jun 4, 2023
@tcharding tcharding deleted the 06-02-taproot-from-slice-error branch June 5, 2023 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0