-
Notifications
You must be signed in to change notification settings - Fork 117
fix(p2pk): allow listing and spending p2pk utxos created with uncompressed pubkeys #2410
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
base: dev
Are you sure you want to change the base?
Changes from all commits
38a1be2
1477355
7b180f2
a125a0a
296b904
7366240
4d5523c
d3d4ab2
f866969
4645f9b
2d055ec
e65a9f0
4a1188e
1eaf3e8
c5c62d2
93d0376
5e69799
c2ec918
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,7 +37,18 @@ impl Public { | |||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| pub fn address_hash(&self) -> H160 { dhash160(self) } | ||||||||||||||||||||||||||||||||||||||||||||||
| pub fn address_hash(&self) -> H160 { | ||||||||||||||||||||||||||||||||||||||||||||||
| match self { | ||||||||||||||||||||||||||||||||||||||||||||||
| Public::Compressed(public) => dhash160(public.as_slice()), | ||||||||||||||||||||||||||||||||||||||||||||||
| // If the public key isn't compressed, we wanna compress it then get the hash. | ||||||||||||||||||||||||||||||||||||||||||||||
| // No body uses the uncompressed form to get an address hash. | ||||||||||||||||||||||||||||||||||||||||||||||
| Public::Normal(public) => match PublicKey::from_slice(public.as_slice()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| Ok(public) => dhash160(&public.serialize()), | ||||||||||||||||||||||||||||||||||||||||||||||
| // This should never happen, as then the public key would be invalid. If so, return a dummy value. | ||||||||||||||||||||||||||||||||||||||||||||||
| Err(_) => H160::default(), | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+47
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks fishy. If this should never happen then put
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it indeed looks fishy 😂 i just prefer errors over panics, but this one is a utility func that's used everywhere and hard to be made fallible. there is only this place https://github.com/KomodoPlatform/komodo-defi-framework/blob/5e697997585e70a8bbc01dbc756d330f7b1e5f68/mm2src/mm2_bitcoin/script/src/script.rs#L415 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On KDF I do prefer errors over panics as well, but the comment says I would create 2 functions instead of trying to handle infallible/fallible calls from a single function:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seams reasonable 👍 |
||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| pub fn verify(&self, message: &Message, signature: &Signature) -> Result<bool, Error> { | ||||||||||||||||||||||||||||||||||||||||||||||
| let public = match self { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -82,7 +93,12 @@ impl Public { | |||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #[inline(always)] | ||||||||||||||||||||||||||||||||||||||||||||||
| pub fn to_secp256k1_pubkey(&self) -> Result<PublicKey, SecpError> { PublicKey::from_slice(self.deref()) } | ||||||||||||||||||||||||||||||||||||||||||||||
| pub fn to_secp256k1_pubkey(&self) -> Result<PublicKey, SecpError> { | ||||||||||||||||||||||||||||||||||||||||||||||
| match self { | ||||||||||||||||||||||||||||||||||||||||||||||
| Public::Compressed(public) => PublicKey::from_slice(&**public), | ||||||||||||||||||||||||||||||||||||||||||||||
| Public::Normal(public) => PublicKey::from_slice(&**public), | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+96
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pretty sure new rustc will complain and suggest similar code
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can let this throw for now and the other PR will fix it. but i can fix it here if u want too. |
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
borngraced marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| impl Deref for Public { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to have this as doc comment i guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it's gonna be confusing, esp that this is a very legacy edge case that doesn't happen in day to day.