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

Use infallible conversions from hashes to secp256k1::Message #824

Closed
Kixunil opened this issue Feb 9, 2022 · 13 comments · Fixed by #1118
Closed

Use infallible conversions from hashes to secp256k1::Message #824

Kixunil opened this issue Feb 9, 2022 · 13 comments · Fixed by #1118
Assignees
Labels
code quality Makes code easier to understand and less likely to lead to problems error handling Issues and PRs related to error handling, mainly error refactoring epic good first issue

Comments

@Kixunil
Copy link
Collaborator

Kixunil commented Feb 9, 2022

#819 (comment)

And check/fix other cases as well.

@Kixunil Kixunil added code quality Makes code easier to understand and less likely to lead to problems error handling Issues and PRs related to error handling, mainly error refactoring epic labels Feb 9, 2022
@arturomf94
Copy link
Contributor

Hi @Kixunil / @bruteforcecat - is this still an open issue?

I see #851 has been opened as a draft, but I don't know if it's up for grabs now?

@Kixunil
Copy link
Collaborator Author

Kixunil commented Jul 13, 2022

I think #830 should've been resolved by #1065 and #1066, so feel free to give it a try!

@arturomf94
Copy link
Contributor

Thanks! I think I'll have a stab! Could you assign it to me please? 🙏

@tcharding
Copy link
Member

Go for it man! Thanks

@arturomf94
Copy link
Contributor

Hi @tcharding / @Kixunil - I'm having some trouble with this one. I've replaced all instances of secp256k1::Message::from_slice(_).expect(_) to secp256k1::Message::from(_). There is one particular case in which I'm getting an error:

let msg = secp256k1::Message::from_slice(&msg_hash[..])

The error I'm getting is:

error[E0277]: the trait bound `hashes::sha256d::Hash: secp256k1::ThirtyTwoByteHash` is not satisfied
   --> src/util/misc.rs:143:23
    |
143 |             let msg = secp256k1::Message::from(msg_hash);
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `secp256k1::ThirtyTwoByteHash` is not implemented for `hashes::sha256d::Hash`
    |
    = note: required because of the requirements on the impl of `std::convert::From<hashes::sha256d::Hash>` for `secp256k1::Message`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `bitcoin` due to previous error

This is confusing me because such impl does exist.

Digging deeper, I believe this might be due to a mismatch between the versions of bitcoin_hashes used in rust-bitcoin and rust-secp256k1, which are 0.11.0 and 0.10.0, respectively.

Interestingly, I think the approach taken here does not work due to 58f94be.

I'm unsure about which could be the appropriate direction here 🤔 My bet is on matching the bitcoin_hashes version, but I'd love to read your thoughts...

@apoelstra
Copy link
Member

We should update rust-secp I guess. Annoying because this will require a major version bump there. We should've coordinated this better ... I think I literally forgot that rust-secp depended on bitcoin_hashes and that we'd have to update things in order.

@arturomf94
Copy link
Contributor

Sorry to be the bearer of these bad news! :/

Question: is there a specific reason why rust-secp256k1 does not have a more relaxed restriction on bitcoin_hashes? Something like, ">=0.10"?

@tcharding
Copy link
Member

I think I literally forgot that rust-secp depended on bitcoin_hashes and that we'd have to update things in order

I'll take the rap for that one, I did the release PR without checking if this would break things.

@apoelstra
Copy link
Member

Sorry to be the bearer of these bad news! :/

Question: is there a specific reason why rust-secp256k1 does not have a more relaxed restriction on bitcoin_hashes? Something like, ">=0.10"?

Prior to 1.0, cargo treats the minor version number as a major version number. There is no way you can tell it "use 0.10 or 0.11 or...", nor would we want to, because there are breaking changes between those releases.

@arturomf94
Copy link
Contributor

Prior to 1.0, cargo treats the minor version number as a major version number. There is no way you can tell it "use 0.10 or 0.11 or...", nor would we want to, because there are breaking changes between those releases.

Got it. Thanks for the clarification.

@tcharding
Copy link
Member

I've tried to clean up my mess, please see:

@Kixunil
Copy link
Collaborator Author

Kixunil commented Jul 19, 2022

@apoelstra

There is no way you can tell it "use 0.10 or 0.11 or..."

You can using >= as @arturomf94 suggested but we definitely don't want to.

@tcharding no need to beat yourself up about this one. It would've easily slipped anyone. The only way I can think of avoiding it is to have a good release checklist with a reminder to use it.

@apoelstra
Copy link
Member

I don't think a checklist would've helped, given that this would've been caught by #1104 but only if we'd thought of it beforehand..

arturomf94 added a commit to arturomf94/rust-bitcoin that referenced this issue Jul 21, 2022
Replace all instances of
`secp256k1::Message::from_slice(_).expect(_)` with
`secp256k1::Message::from(_)`.

Solves rust-bitcoin#824
arturomf94 added a commit to arturomf94/rust-bitcoin that referenced this issue Jul 21, 2022
Replace all instances of
`secp256k1::Message::from_slice(_).expect(_)` with
`secp256k1::Message::from(_)`.

Also adds an implementation of ThirtyTwoByteHash for
TapSighashHash.

Solves rust-bitcoin#824
arturomf94 added a commit to arturomf94/rust-bitcoin that referenced this issue Jul 21, 2022
Replace all instances of
`secp256k1::Message::from_slice(_).expect(_)` with
`secp256k1::Message::from(_)`.

Also adds an implementation of ThirtyTwoByteHash for
TapSighashHash.

Solves rust-bitcoin#824
arturomf94 added a commit to arturomf94/rust-bitcoin that referenced this issue Jul 21, 2022
Replace all instances of
`secp256k1::Message::from_slice(_).expect(_)` with
`secp256k1::Message::from(_)`.

Also adds an implementation of ThirtyTwoByteHash for
TapSighashHash.

Solves rust-bitcoin#824
ChallengeDev210 pushed a commit to ChallengeDev210/rust-bitcoin that referenced this issue Aug 1, 2022
Replace all instances of
`secp256k1::Message::from_slice(_).expect(_)` with
`secp256k1::Message::from(_)`.

Also adds an implementation of ThirtyTwoByteHash for
TapSighashHash.

Solves rust-bitcoin/rust-bitcoin#824
ChallengeDev210 pushed a commit to ChallengeDev210/rust-bitcoin that referenced this issue Aug 1, 2022
…sh` -> `secp256k1::Message`

aeede12 Infallible conversions: `Hash` -> `Message` (Arturo Marquez)

Pull request description:

  Replaces all instances of `secp256k1::Message::from_slice(_).expect(_)` with `secp256k1::Message::from(_)`. This also implements `ThirtyTwoByteHash` for `TapSighashHash`.

  Closes rust-bitcoin/rust-bitcoin#824

ACKs for top commit:
  Kixunil:
    ACK aeede12
  tcharding:
    ACK aeede12
  apoelstra:
    ACK aeede12

Tree-SHA512: cd392f0e93e2560680c579a889a46f7e4484380058b2d8d03b6ecec351d880efa9beea5e3be128158e9e26243b7dfcef1f48a448028d9155958a5af62bcc9ec2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Makes code easier to understand and less likely to lead to problems error handling Issues and PRs related to error handling, mainly error refactoring epic good first issue
Projects
None yet
4 participants