8000 Add MessageSignature type for dealing with signed messages by stevenroose · Pull Request #413 · rust-bitcoin/rust-bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add MessageSignature type for dealing with signed messages #413

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
merged 2 commits into from
Oct 14, 2020

Conversation

stevenroose
Copy link
Collaborator
@stevenroose stevenroose commented Mar 5, 2020

I do realize that adding a dependency might be controversial. Also, if anyone knows a better base64 crate, please let me know. The one I used is one I created some months ago based on the base64 crate but making it compatible with Rust v1.19.0, something they refused to do.

@codecov-io
Copy link
codecov-io commented Mar 6, 2020

Codecov Report

Merging #413 into master will increase coverage by 0.01%.
The diff coverage is 86.6%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #413      +/-   ##
==========================================
+ Coverage   85.81%   85.83%   +0.01%     
==========================================
  Files          40       40              
  Lines        7461     7575     +114     
==========================================
+ Hits         6403     6502      +99     
- Misses       1058     1073      +15
Impacted Files Coverage Δ
src/lib.rs 100% <ø> (ø) ⬆️
src/util/misc.rs 89.71% <86.6%> (-5.37%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cff794...c94189e. Read the comment docs.

@instagibbs
Copy link
Contributor

concept ACK, would be nice to have this out of the box

@elichai
Copy link
Member
elichai commented Mar 8, 2020

Too bad you didn't make https://github.com/stevenroose/rust-base64-compat as a fork so we can easily see what's changed and can also easily see changes in upstream.

for anyone who wants to review the changes this is the only commit with logic change: stevenroose/rust-base64-compat@ae7de46

@stevenroose
Copy link
Collaborator Author

Too bad you didn't make https://github.com/stevenroose/rust-base64-compat as a fork so we can easily see what's changed and can also easily see changes in upstream.

for anyone who wants to review the changes this is the only commit with logic change: stevenroose/rust-base64-compat@ae7de46

It is a fork. It's a Git fork, not a GitHub fork. The Git history is preserved..

@stevenroose stevenroose force-pushed the message-signature branch 2 times, most recently from e3a90c7 to 0026764 Compare March 23, 2020 14:46
apoelstra
apoelstra previously approved these changes Mar 23, 2020
Copy link
Member
8000
@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.

utACK the code

concept ACK adding the dependency. cc @TheBlueMatt are you ok with this? it is Steven's base64 compat library.

@TheBlueMatt
Copy link
Member

Ah, for a second I was about to scream. His fork seems reasonable, though it would be nice to pull it into the org if we're gonna depend on it. Independently, given its for a feature not all users are going to use, is there any real cost to making it optional?

@stevenroose
Copy link
Collaborator Author

@TheBlueMatt @elichai I made the base64-compat crate opt-out with a base64 feature.

I also exported the base64 crate (for easier usage of the base64 error type). Let me know if that's ok for you.

8000
@stevenroose stevenroose force-pushed the message-signature branch 2 times, most recently from 94fad7a to 4318dc2 Compare May 18, 2020 18:19
@stevenroose stevenroose force-pushed the message-signature branch 3 times, most recently from af03df2 to 6dee624 Compare October 7, 2020 18:29
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.

Tests don't build on f26dd11bfad2701b0574c2fb564797c1e5138278

@RCasatta
Copy link
Collaborator
RCasatta commented Oct 8, 2020

I noticed we still need https://github.com/stevenroose/rust-base64-compat because rust-base64 has MSRV 1.34.0 but since rust-bitcoin bumped to 1.29.0 things like rotate_left doesn't need anymore to be implemented in rust-base64-compat (rotate_left introduced in 1.26.0)

@stevenroose
Copy link
Collaborator Author
stevenroose commented Oct 8, 2020

I noticed we still need https://github.com/stevenroose/rust-base64-compat because rust-base64 has MSRV 1.34.0 but since rust-bitcoin bumped to 1.29.0 things like rotate_left doesn't need anymore to be implemented in rust-base64-compat (rotate_left introduced in 1.26.0)

@RCasatta yeah plus the base64 broke semver before, so we shouldn't go back to using them again, they might break it again.

Does it matter much to implement them manually or use stdlib? Do you think the stdlib variants have some better compiler optimizations perhaps? Otherwise I wouldn't mind keeping base64-compat compatible with 1.19 forever until we really need some feature or so.

@stevenroose
Copy link
Collaborator Author

I'm ok with pulling the base64-compat crate into the org, though, as @TheBlueMatt suggested. Though ideally the crate would never be updated and we can fix the version with =1.0.0.

@RCasatta
Copy link
Collaborator
RCasatta commented Oct 8, 2020

@RCasatta yeah plus the base64 broke semver before, so we shouldn't go back to using them again, they might break it again.

Does it matter much to implement them manually or use stdlib? Do you think the stdlib variants have some better compiler optimizations perhaps? Otherwise I wouldn't mind keeping base64-compat compatible with 1.19 forever until we really need some feature or so.

Didn't know the other problem on base64, it's fine to have rotate_left implemented manually and base64-compat stick to 1.19

@apoelstra
Copy link
Member

See my comment #330 (comment) .. I think we shouldn't feature-gate the enum variants if we can avoid it.

A couple options would be

  • Add the variant but make it take a String or other dummy type in the case that base64 dep is unavailable
  • Always make it take a String or Box<dyn Error>, and don't change it at all based on base64 dep availability

@apoelstra apoelstra added the API break This PR requires a version bump for the next release label Oct 8, 2020
@stevenroose
Copy link
Collaborator Author

@apoelstra Why does this PR have API break?

@stevenroose stevenroose force-pushed the message-signature branch 2 times, most recently from 0de9238 to 4b19d23 Compare October 9, 2020 11:58
@RCasatta
Copy link
Collaborator

Why does this PR have API break?

I think because of
https://github.com/rust-bitcoin/rust-bitcoin/pull/413/files#diff-5a4d9ba252c30cd7253663cfddf71a0dR39-R41

which is a feature-gated enum variant and @apoelstra said they could break compatibility in #330 (comment)

fuzztarget = ["secp256k1/fuzztarget", "bitcoin_hashes/fuzztarget"]
unstable = []
rand = ["secp256k1/rand-std"]
use-serde = ["serde", "bitcoin_hashes/serde", "secp256k1/serde"]
secp-recovery = ["secp256k1/recovery"]
Copy link
Member

Choose a reason for hiding this comment

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

This is a breaking change, you can add that to default features, but removing a feature is a breaking change

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if this has been released yet, @apoelstra ? It's only recently added by @RCasatta .

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I mean we can still release the secp-recovery feature in 0.25.1 and then remove it in 0.26.0? Making it a default feature means that all the code in this PR needs to be feature-gated.

Copy link
Member

Choose a reason for hiding this comment

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

@apoelstra says that it wasn't yet released, so you can restore this back? sorry.
I'm not sure if people still want this to be feature gated or not, personally I'm fine with it not feature gated.

@apoelstra
Copy link
Member

I don't remember why I added the API break label; I think it applied to an older version of this code which modified existing enums right now. Adding a new enum, even one that had feature-gated variants, wouldn't have been breaking in my mind.

Regarding @elichai's comment about deleting a feature, yeah, that would be breaking except that #486 has not been released. So this is fine to go into 0.25.1.

@apoelstra apoelstra removed the API break This PR requires a version bump for the next release label Oct 10, 2020
@stevenroose
Copy link
Collaborator Author

@elichai noted that it's a breaking change that the secp-recovery feature is removed because recovery is always enabled to support this type. I'd be ok with feature-gating this new type and enabling the feature by default. Let me do that.

@stevenroose
Copy link
Collaborator Author

Added back the feature.

Copy link
Member
@elichai elichai left a comment

Choose a reason for hiding this comment

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

Left one comment, other than that verified that it matches the logic by bitcoin core: https://github.com/bitcoin/bitcoin/blob/61b8c04d78fb116e1722659ac455ad27856c6604/src/pubkey.cpp#L187
and by my own tool :) https://github.com/elichai/bitsign/blob/master/src/main.rs#L155

src/util/misc.rs Outdated
Comment on lines 159 to 163
Some(AddressType::P2wpkh) => {
// Only compressed pubkeys are allowed in p2wpkh.
pubkey.compressed &&
*address == Address::p2wpkh(&pubkey, address.network).expect("compressed pk")
}
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. It looks like Core will only run verifymessage on p2pkh addresses. I think we should replicate this @stevenroose and implement BIP322 in a separate PR for new-style addresses.

@apoelstra apoelstra mentioned this pull request Oct 14, 2020
apoelstra
apoelstra previously approved these changes Oct 14, 2020
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 9c4d2eff8abdbf211dd0a5f74457bee6b7c2309a

elichai
elichai previously approved these changes Oct 14, 2020
Copy link
Member
@elichai elichai left a comment

Choose a reason for hiding this comment

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

ACK

@stevenroose stevenroose dismissed stale reviews from elichai and apoelstra via 3f65fb1 October 14, 2020 14:50
Copy link
Member
@elichai elichai left a comment

Choose a reason for hiding this comment

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

reACK

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 3f65fb1

@apoelstra apoelstra merged commit e7980ac into rust-bitcoin:master Oct 14, 2020
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.

9 participants
0