-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Migrate Tendermint PubKey types to the SDK #7047
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7047 +/- ##
==========================================
- Coverage 54.81% 54.60% -0.21%
==========================================
Files 542 547 +5
Lines 36907 37121 +214
==========================================
+ Hits 20230 20270 +40
- Misses 15021 15192 +171
- Partials 1656 1659 +3 |
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.
How come ed25519 was brought over? If you will be using the same interface as Tendermint then might as well just import ed25519?
|
Also you suggested us having our own types here @marbar3778 #7008 (comment) |
Ah the address thing sorry. Yea I said that but thought it would be a different interface. Ignore my comment. Super happy to see this moving forward. I will transfer the secp issues we have in Tendermint to the sek in the morning. |
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 👍
crypto/benchmarking/bench.go
Outdated
@@ -0,0 +1,88 @@ | |||
package benchmarking |
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.
crypto/
already has some folders (hd, keyring, ledger). Would it make more sense to put all these files into crypto/pubkey/
?
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.
crypto/(key, keys)
because it houses private keys as well
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 didn't have a preference here, either way seems fine to me. Will move to crypto/keys
if that seems better
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 also prefer keys
than key
.
crypto/ed25519/ed25519.go
Outdated
} | ||
|
||
// PrivKeyEd25519 implements crypto.PrivKey. | ||
type PrivKeyEd25519 [64]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.
you will not want sized byte arrays in the sdk, this was discussed in an issue, cant recall which. the current tendermint impl uses unsized to make it easier but this does bring an extra need for carfulness.
crypto/sr25519/pubkey.go
Outdated
const PubKeySr25519Size = 32 | ||
|
||
// PubKeySr25519 implements crypto.PubKey for the Sr25519 signature scheme. | ||
type PubKeySr25519 [PubKeySr25519Size]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.
Should be unsized.
I understand this is a copy of what is in Tendermint but maybe the sdk should first start with migrating what it uses (secp256k1). I understand I said we should migrate the other keys but if the other keys are not used then it is better to start with the minimum (secp256k1) and build up from there? I am up for a discussion on this.
I am proposing this because when I switched sims to ed25519 keys they failed. This makes me think there is a reliance on key type currently?
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.
thoughts @aaronc @alexanderbez
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 we can start with just SECP256K1 for now. Also, they should be unsized if we want to be able to use oneof
I think?
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.
We do want unsized byte arrays, is it okay if we do that in a separate PR? The intention here was mainly to do an exact copy so we don't have to get both the copying and the changes at once
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.
Should the copy be of master? Much of these changes are already made.
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.
Okay, we'll need to update this against master then.
@marbar3778 our intention here is to just copy and then in separate PRs:
What do you think ? |
sounds good. will this be the base PR or will it be merged into master |
The idea is to merge this into master and then proceed with separate PRs against master. |
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.
ACK
My desire here is to just do a clean copy of code from tendermint into the SDK and for modifications to go in separate PRs so that the diffs is clean. With that in mind, all I want to know is - did the code get copied correctly from tendermint. For efficiency, that would be my request of other reviewers.
To verify, I checked out tendermint master (42e4e8b58ebc58ebd663c114d2bcd7ab045b1c55
) and ran diffs on the code:
~/tendermint/crypto/secp256k1 master ❯ diff . ~/cosmos-sdk/crypto/keys/secp256k1/
diff ./bench_test.go /Users/arc/cosmos-sdk/crypto/keys/secp256k1/bench_test.go
8c8,9
< "github.com/tendermint/tendermint/crypto/internal/benchmarking"
---
>
> "github.com/cosmos/cosmos-sdk/crypto/keys/benchmarking"
Only in .: encoding.go
Common subdirectories: ./internal and /Users/arc/cosmos-sdk/crypto/keys/secp256k1/internal
Only tmjson changes (encoding.go
deleted).
~/tendermint/crypto/ed25519 master ❯ diff . ~/cosmos-sdk/crypto/keys/ed25519
diff ./bench_test.go /Users/arc/cosmos-sdk/crypto/keys/ed25519/bench_test.go
8c8,9
< "github.com/tendermint/tendermint/crypto/internal/benchmarking"
---
>
> "github.com/cosmos/cosmos-sdk/crypto/keys/benchmarking"
diff ./ed25519.go /Users/arc/cosmos-sdk/crypto/keys/ed25519/ed25519.go
13d12
< tmjson "github.com/tendermint/tendermint/libs/json"
21,22d19
< PrivKeyName = "tendermint/PrivKeyEd25519"
< PubKeyName = "tendermint/PubKeyEd25519"
37,41d33
< func init() {
< tmjson.RegisterType(PubKey{}, PubKeyName)
< tmjson.RegisterType(PrivKey{}, PrivKeyName)
< }
<
Again, only tmjson changes.
~/tendermint/crypto/sr25519 master ❯ diff . ~/cosmos-sdk/crypto/keys/sr25519
diff ./bench_test.go /Users/arc/cosmos-sdk/crypto/keys/sr25519/bench_test.go
8c8,9
< "github.com/tendermint/tendermint/crypto/internal/benchmarking"
---
>
> "github.com/cosmos/cosmos-sdk/crypto/keys/benchmarking"
diff ./encoding.go /Users/arc/cosmos-sdk/crypto/keys/sr25519/encoding.go
5d4
< tmjson "github.com/tendermint/tendermint/libs/json"
11,13d9
< PrivKeyName = "tendermint/PrivKeySr25519"
< PubKeyName = "tendermint/PubKeySr25519"
<
18,23d13
<
< func init() {
<
< tmjson.RegisterType(PubKey{}, PubKeyName)
< tmjson.RegisterType(PrivKey{}, PrivKeyName)
< }
Again, only tmjson changes.
~/tendermint/crypto/internal/benchmarking master ❯ diff . ~/cosmos-sdk/crypto/keys/benchmarking 19:09:05
diff ./bench.go /Users/arc/cosmos-sdk/crypto/keys/benchmarking/bench.go
40,44c40
< _, err := priv.Sign(message)
<
< if err != nil {
< b.FailNow()
< }
---
> priv.Sign(message)
Why is the error handled differently here @sahith-narahari? This seems to be the only substantive difference but doesn't seem critical as this is in bench code.
I also checked go.mod and the only major difference is that tendermint uses:
golang.org/x/crypto v0.0.0-20200406173513-056763e48d71
which appears to be an older version. I'm assuming that's okay because it's more recent? There is one newer commit here btw: https://github.com/golang/crypto/commits/master
@aaronc the two changes wrt tendermint are intended. As cosmos-sdk still uses tendermint, registering with tmjson again panics, as it already happens in tendermint/crypto. |
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 overall 👍 .
I understand removing tmjson.Register()...
, but can you explain why this part is removed?
< _, err := priv.Sign(message)
<
< if err != nil {
< b.FailNow()
< }
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.
Looks good. I would prefer to have a TODO and comment out the code that panics instead of removing it. Also for packages, I would suggest to address that via a separate PR. We can add a todo item to the tracking issue
This was updated later in tm master, whereas this code was from 0.34-rc3. I updated the code to fail with error now, as in master |
I personally don't prefer commenting out code, and tmjson as I understand is tendermint's way of dealing with amino json. I'm not sure if we'll be doing the same after migration. I can add a todo if we'll be using the same approach in sdk too. |
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!
tmjson is not needed. Removing it is correct |
Description
This PR imports secp256k1, ed25519, sr25519 packages from
tendermint/crypto
. I'll do a followup PR to update the references to contain this PR as is.ref: #7008
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerCodecov Report
in the comment section below once CI passes