-
Notifications
You must be signed in to change notification settings - Fork 0
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
chg: implement cometBFT changes and adapt tests accordingly #8
chg: implement cometBFT changes and adapt tests accordingly #8
Conversation
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.
🙏 LGTM
option (amino.name) = "tendermint/PrivKeySecp256k1"; | ||
option (amino.message_encoding) = "key_field"; | ||
|
||
bytes key = 1; | ||
} | ||
|
||
// PrivKey defines a comet uncompressed secp256k1 private key. |
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 don't think we have (un)compressed private keys 😄
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.
Yeah but porting the changes from here https://github.com/0xPolygon/cometbft/blob/develop/crypto/secp256k1/secp256k1.go#L22 where we explicitly call PrivKeyName = "comet/PrivKeySecp256k1Uncompressed"
What do you suggest as a comment?
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 Uncompressed
was added as a suffix to have consistency with the naming; I don't think calling it that means there's actually an uncompressed priv key.
Again, it's just a nitpick. As a comment we might just say PrivKey defines a comet secp256k1 private key.
🤷
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.
WDYS @sergio-mena ?
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.
Yeah for sure it's not an "uncompressed private key", I kept there for reference to the naming.
But I see it can create confusion. Addressed here
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.
Sorry for delay coming here. In the PR (cometbft/cometbft#2534) I'm working on to upstream these changes to (vanilla) CometBFT I'm not using "uncompressed" because I felt in a similar way to what motivated this thread: I renamed it to cometbft/PrivKeySecp256k1Eth
.
Let me know if you'd like me to open two PRs (one here and one on peppermint) to keep the naming consistent.
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.
Yes, please.
Thanks @sergio-mena
some tests are failing under UPDATE: FIXED. |
ba398d3
to
f98b3ae
Compare
) | ||
|
||
func (privKey *PrivKeyOld) Bytes() []byte { |
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 performed an ad-hoc diff-of-diffs of this directory comparing it to the analogous code from 0xPolygon/cometbft#2.
I think it would ease maintenance if these functions resembled the ones here.
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.
Yeah that was my direction as well, but I tried to keep the diffs with upstream as small as possible.
For example, I did not change the order of the methods in crypto/keys/secp256k1/secp256k1.go
.
Also, some functions are left to crypto/keys/secp256k1/secp256k1_nocgo.go
where the original methods of the type (privKey *PrivKey) were defined (e.g. Sign
and VerifySignature
)
func (privKey *PrivKeyOld) Type() string { | ||
return keyType | ||
} | ||
func (privKey *PrivKeyOld) Sign(msg []byte) ([]byte, error) { |
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.
PrivKey
doesn't have method Sign
. Do we need it here?
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 is there, but not in the same file. I kept as it was originally for comos-sdk
, meaning crypto/keys/secp256k1/secp256k1_nocgo.go
, see here
crypto/keys/secp256k1/secp256k1.go
Outdated
|
||
// Address returns an ethereum style addresses | ||
func (pubKey *PubKeyOld) Address() crypto.Address { | ||
return pubKey.Address() |
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.
Isn't this method calling itself?
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.
Oh, forgot to push this 🤦
Here it is, thanks
crypto/keys/secp256k1/secp256k1.go
Outdated
// Address returns an ethereum style addresses | ||
func (pubKey *PubKeyOld) Address() crypto.Address { | ||
return pubKey.Address() | ||
} | ||
|
||
// Bytes returns the pubkey byte format. | ||
func (pubKey *PubKeyOld) Bytes() []byte { | ||
return pubKey.Key | ||
} | ||
|
||
func (pubKey *PubKeyOld) String() string { | ||
return fmt.Sprintf("PubKeySecp256k1{%X}", pubKey.Key) | ||
} | ||
|
||
func (pubKey *PubKeyOld) Type() string { | ||
return keyType | ||
} | ||
|
||
func (pubKey *PubKeyOld) Equals(other cryptotypes.PubKey) bool { | ||
return pubKey.Type() == other.Type() && bytes.Equal(pubKey.Bytes(), other.Bytes()) | ||
} | ||
|
||
func (pubKey *PubKeyOld) VerifySignature(msg []byte, sigStr []byte) bool { | ||
return pubKey.VerifySignature(msg, sigStr) | ||
} | ||
|
||
// MarshalAmino overrides Amino binary marshaling. | ||
func (pubKey PubKeyOld) MarshalAmino() ([]byte, error) { | ||
return pubKey.Key, nil | ||
} | ||
|
||
// UnmarshalAmino overrides Amino binary marshaling. | ||
func (pubKey *PubKeyOld) UnmarshalAmino(bz []byte) error { | ||
if len(bz) != PubKeySize { | ||
return errorsmod.Wrap(errors.ErrInvalidPubKey, "invalid pubkey size") | ||
} | ||
pubKey.Key = bz | ||
|
||
return nil | ||
} | ||
|
||
// MarshalAminoJSON overrides Amino JSON marshaling. | ||
func (pubKey PubKeyOld) MarshalAminoJSON() ([]byte, error) { | ||
// When we marshal to Amino JSON, we don't marshal the "key" field itself, | ||
// just its contents (i.e. the key bytes). | ||
return pubKey.MarshalAmino() | ||
} | ||
|
||
// UnmarshalAminoJSON overrides Amino JSON marshaling. | ||
func (pubKey *PubKeyOld) UnmarshalAminoJSON(bz []byte) error { | ||
return pubKey.UnmarshalAmino(bz) | ||
} |
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.
Similarly to the comment above, it might be simpler to maintain if this code resembled this one.
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.
See #8 (comment)
crypto/keys/secp256k1/secp256k1.go
Outdated
} | ||
|
||
func (pubKey *PubKeyOld) VerifySignature(msg []byte, sigStr []byte) bool { | ||
return pubKey.VerifySignature(msg, sigStr) |
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 have the impression this method is calling itself
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.
True, forgot to push this 🤦
Here it is, thanks
x.Key = value.Bytes() | ||
default: | ||
if fd.IsExtension() { | ||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.secp256k1.PubKeyOld")) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
if fd.IsExtension() { | ||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.secp256k1.PubKeyOld")) | ||
} | ||
panic(fmt.Errorf("message cosmos.crypto.secp256k1.PubKeyOld does not contain field %s", fd.FullName())) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
x.Key = value.Bytes() | ||
default: | ||
if fd.IsExtension() { | ||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.secp256k1.PubKey")) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
if fd.IsExtension() { | ||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.secp256k1.PubKey")) | ||
} | ||
panic(fmt.Errorf("message cosmos.crypto.secp256k1.PubKey does not contain field %s", fd.FullName())) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
x.Key = value.Bytes() | ||
default: | ||
if fd.IsExtension() { | ||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.secp256k1.PubKey")) | ||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.secp256k1.PrivKeyOld")) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
} | ||
panic(fmt.Errorf("message cosmos.crypto.secp256k1.PubKey does not contain field %s", fd.FullName())) | ||
panic(fmt.Errorf("message cosmos.crypto.secp256k1.PrivKeyOld does not contain field %s", fd.FullName())) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
345b042
to
f98b3ae
Compare
func (pubKey *PubKey) Address() crypto.Address { | ||
if len(pubKey.Key) != PubKeySize { | ||
panic("length of pubkey is incorrect") | ||
panic(fmt.Sprintf("length of pubkey is incorrect %d != %d", len(pubKey.Key), PubKeySize)) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
@@ -164,7 +164,7 @@ | |||
// in SDK except in a tendermint validator context. | |||
func (pubKey *PubKey) Address() crypto.Address { | |||
if len(pubKey.Key) != PubKeySize { | |||
panic("pubkey is incorrect size") | |||
panic(fmt.Sprintf("length of pubkey is incorrect %d != %d", len(pubKey.Key), PubKeySize)) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
// Address returns an ethereum style addresses | ||
func (pubKey *PubKeyOld) Address() crypto.Address { | ||
if len(pubKey.Key) != PubKeySize { | ||
panic(fmt.Sprintf("length of pubkey is incorrect %d != %d", len(pubKey.Key), PubKeySize)) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
This PR has been merged to This has been done because, after solving the conflicts from Feel free to keep commenting on this PR, especially for open discussions, and I'll make sure to port the changes upstream. |
This PR reflects the changes of
cometBFT
(peppermint
rebase) intocosmos-sdk
.