Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Make MultiSigner use compressed ECDSA public key #4502

Merged
merged 4 commits into from Dec 31, 2019

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Dec 26, 2019

MultiSigner did not compressed the ECDSA public key before hashing it but MultiSignature expected that the public key is compressed when verifying a signature. Thus, the signature verification could never succeed.

This pr changes the following:

  • MultiSigner compresses the public key before hashing it with blake256.
  • Verify for ecdsa::Signature compresses given public key before comparing it.
  • ecdsa::Public is now an enum that distinguishes between the full and compressed format.

Fixes: #4498

@bkchr bkchr added the A0-please_review Pull request needs code review. label Dec 26, 2019
@bkchr bkchr requested a review from gavofyork December 26, 2019 13:00
@@ -246,7 +246,9 @@ impl traits::IdentifyAccount for MultiSigner {
match self {
MultiSigner::Ed25519(who) => <[u8; 32]>::from(who).into(),
MultiSigner::Sr25519(who) => <[u8; 32]>::from(who).into(),
MultiSigner::Ecdsa(who) => sp_io::hashing::blake2_256(who.as_ref()).into(),
MultiSigner::Ecdsa(who) => sp_io::hashing::blake2_256(
&who.as_compressed().expect("what should we do?")[..],
Copy link
Member Author

Choose a reason for hiding this comment

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

@gavofyork what should we do here? I think the best would be to propagate the error via IdentifyAccount.

Copy link
Member

Choose a reason for hiding this comment

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

i believe this cannot fail for any valid keypair, so .expect should be fine

@bkchr bkchr changed the title Don't use compressed ecdsa public key in verify Make MultiSigner Dec 27, 2019
@bkchr bkchr changed the title Make MultiSigner Make MultiSigner use compressed ECDSA public key Dec 27, 2019
@gavofyork
Copy link
Member

but... what's the point of supporting uncompressed public key format?

@bkchr
Copy link
Member Author

bkchr commented Dec 30, 2019

but... what's the point of supporting uncompressed public key format?

Good question, I just followed the initial implementation. However, I think that for ergonomic reasons the support for both sounds reasonable to me. If you say that people only use the compressed version, I can remove the support for full public keys.

@gavofyork
Copy link
Member

it does leave this annoying .expect thing in.

@gavofyork gavofyork merged commit 20a9b15 into master Dec 31, 2019
@gavofyork gavofyork deleted the bkchr-fix-ecdsa-verify branch December 31, 2019 19:04
bkchr added a commit that referenced this pull request Jan 17, 2020
Some fixes after: #4502

This removes the unwanted `expect`s from `MultiSigner`. Instead we
convert from full to compressed in `TryFrom` and can return an error on
invalid input.
gavofyork pushed a commit that referenced this pull request Jan 20, 2020
Some fixes after: #4502

This removes the unwanted `expect`s from `MultiSigner`. Instead we
convert from full to compressed in `TryFrom` and can return an error on
invalid input.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken MultiSignature verification for ECDSA keys
2 participants