Skip to content

Commit 293ab4f

Browse files
committed
Merge branch 'main' into alex/systemtests_pkg
* main: feat(serverv2): add benchmarks of (old) cacheKV vs branch (#22497) fix: match comets bls implmentation (#22613) feat(math): Upstream GDA based decimal type (#21982) fix(client/v2/autocli): prevent duplicate addition of customCommands (#22576) build(deps): Bump cosmossdk.io/math from 1.3.0 to 1.4.0 (#22580)
2 parents dc30084 + 3ebd7e5 commit 293ab4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+5961
-2724
lines changed

client/v2/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
5858
### Bug Fixes
5959

6060
* [#21853](https://github.com/cosmos/cosmos-sdk/pull/21853) Fix `*big.Int` unmarshalling in txs.
61+
* [#22576](https://github.com/cosmos/cosmos-sdk/pull/22576) Fix duplicate command addition in `autocli` when custom enhanced command has a different name than module name
6162

6263
## [v2.0.0-beta.5] - 2024-09-18
6364

client/v2/autocli/common.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,16 @@ func (b *Builder) enhanceCommandCommon(
140140

141141
// if we have a custom command use that instead of generating one
142142
if custom, ok := customCmds[moduleName]; ok {
143-
if hasModuleOptions { // check if we need to enhance the existing command
143+
// Custom may not be called the same as its module, so we need to have a separate check here
144+
if subCmd := findSubCommand(cmd, custom.Name()); subCmd != nil {
145+
if hasModuleOptions { // check if we need to enhance the existing command
146+
if err := enhanceCustomCmd(b, subCmd, cmdType, modOpts); err != nil {
147+
return err
148+
}
149+
}
150+
continue
151+
}
152+
if hasModuleOptions { // check if we need to enhance the new command
144153
if err := enhanceCustomCmd(b, custom, cmdType, modOpts); err != nil {
145154
return err
146155
}

client/v2/go.mod

+5-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ require (
3737
cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e // indirect
3838
cosmossdk.io/errors v1.0.1 // indirect
3939
cosmossdk.io/log v1.5.0
40-
cosmossdk.io/math v1.3.0
40+
cosmossdk.io/math v1.4.0
4141
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect
4242
cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect
4343
cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect
@@ -63,7 +63,6 @@ require (
6363
github.com/cometbft/cometbft/api v1.0.0-rc.1 // indirect
6464
github.com/cosmos/btcutil v1.0.5 // indirect
6565
github.com/cosmos/cosmos-db v1.0.3-0.20240911104526-ddc3f09bfc22 // indirect
66-
github.com/cosmos/crypto v0.1.2 // indirect
6766
github.com/cosmos/go-bip39 v1.0.0
6867
github.com/cosmos/gogogateway v1.2.0 // indirect
6968
github.com/cosmos/gogoproto v1.7.0
@@ -163,14 +162,14 @@ require (
163162
go.opencensus.io v0.24.0 // indirect
164163
go.uber.org/multierr v1.11.0 // indirect
165164
golang.org/x/crypto v0.29.0 // indirect
166-
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect
167-
golang.org/x/mod v0.18.0 // indirect
168-
golang.org/x/net v0.30.0 // indirect
165+
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
166+
golang.org/x/mod v0.22.0 // indirect
167+
golang.org/x/net v0.31.0 // indirect
169168
golang.org/x/sync v0.9.0 // indirect
170169
golang.org/x/sys v0.27.0 // indirect
171170
golang.org/x/term v0.26.0 // indirect
172171
golang.org/x/text v0.20.0 // indirect
173-
golang.org/x/tools v0.22.0 // indirect
172+
golang.org/x/tools v0.27.0 // indirect
174173
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
175174
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
176175
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect

client/v2/go.sum

+10-12
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
1616
cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U=
1717
cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g=
1818
cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI=
19-
cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
20-
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
19+
cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ=
20+
cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk=
2121
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc=
2222
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
2323
cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190 h1:XQJj9Dv9Gtze0l2TF79BU5lkP6MkUveTUuKICmxoz+o=
@@ -127,8 +127,6 @@ github.com/cosmos/cosmos-db v1.0.3-0.20240911104526-ddc3f09bfc22 h1:V3WlarcZwlYY
127127
github.com/cosmos/cosmos-db v1.0.3-0.20240911104526-ddc3f09bfc22/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA=
128128
github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA=
129129
github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec=
130-
github.com/cosmos/crypto v0.1.2 h1:Yn500sPY+9sKVdhiPUSDtt8JOpBGMB515dOmla4zfls=
131-
github.com/cosmos/crypto v0.1.2/go.mod h1:b6VWz3HczIpBaQPvI7KrbQeF3pXHh0al3T5e0uwMBQw=
132130
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
133131
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
134132
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
@@ -540,16 +538,16 @@ golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPh
540538
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
541539
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
542540
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
543-
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc h1:O9NuF4s+E/PvMIy+9IUZB9znFwUIXEWSstNjek6VpVg=
544-
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
541+
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo=
542+
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak=
545543
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
546544
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
547545
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
548546
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
549547
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
550548
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
551-
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
552-
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
549+
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
550+
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
553551
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
554552
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
555553
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -569,8 +567,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
569567
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
570568
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
571569
golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
572-
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
573-
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
570+
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
571+
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
574572
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
575573
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
576574
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -643,8 +641,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
643641
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
644642
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
645643
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
646-
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
647-
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
644+
golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o=
645+
golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q=
648646
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
649647
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
650648
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

crypto/codec/amino.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package codec
22

33
import (
4+
"github.com/cometbft/cometbft/crypto/bls12381"
5+
46
"cosmossdk.io/core/registry"
57

68
bls12_381 "github.com/cosmos/cosmos-sdk/crypto/keys/bls12_381"
@@ -18,13 +20,13 @@ func RegisterCrypto(registrar registry.AminoRegistrar) {
1820
ed25519.PubKeyName)
1921
registrar.RegisterConcrete(&secp256k1.PubKey{},
2022
secp256k1.PubKeyName)
21-
registrar.RegisterConcrete(&bls12_381.PubKey{}, bls12_381.PubKeyName)
23+
registrar.RegisterConcrete(&bls12_381.PubKey{}, bls12381.PubKeyName)
2224
registrar.RegisterConcrete(&kmultisig.LegacyAminoPubKey{},
2325
kmultisig.PubKeyAminoRoute)
2426
registrar.RegisterInterface((*cryptotypes.PrivKey)(nil), nil)
2527
registrar.RegisterConcrete(&ed25519.PrivKey{},
2628
ed25519.PrivKeyName)
2729
registrar.RegisterConcrete(&secp256k1.PrivKey{},
2830
secp256k1.PrivKeyName)
29-
registrar.RegisterConcrete(&bls12_381.PrivKey{}, bls12_381.PrivKeyName)
31+
registrar.RegisterConcrete(&bls12_381.PrivKey{}, bls12381.PrivKeyName)
3032
}

crypto/codec/pubkey.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package codec
22

33
import (
4+
"github.com/cometbft/cometbft/crypto/bls12381"
5+
46
"cosmossdk.io/errors"
57

68
cryptokeys "github.com/cosmos/cosmos-sdk/crypto/keys"
@@ -29,7 +31,7 @@ func PubKeyToProto(pk cryptokeys.JSONPubkey) (cryptotypes.PubKey, error) {
2931
return &secp256k1.PubKey{
3032
Key: pk.Value,
3133
}, nil
32-
case bls12_381.PubKeyName:
34+
case bls12381.PubKeyName:
3335
return &bls12_381.PubKey{
3436
Key: pk.Value,
3537
}, nil
@@ -60,7 +62,7 @@ func PubKeyFromProto(pk cryptotypes.PubKey) (cryptokeys.JSONPubkey, error) {
6062
}, nil
6163
case *bls12_381.PubKey:
6264
return cryptokeys.JSONPubkey{
63-
KeyType: bls12_381.PubKeyName,
65+
KeyType: bls12381.PubKeyName,
6466
Value: pk.Bytes(),
6567
}, nil
6668
default:

crypto/keys/bls12_381/const.go

-21
This file was deleted.

crypto/keys/bls12_381/key.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99

1010
"github.com/cometbft/cometbft/crypto"
11+
bls "github.com/cometbft/cometbft/crypto/bls12381"
1112

1213
"github.com/cosmos/cosmos-sdk/codec"
1314
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
@@ -54,7 +55,7 @@ func (privKey PrivKey) Equals(other cryptotypes.LedgerPrivKey) bool {
5455

5556
// Type returns the type.
5657
func (PrivKey) Type() string {
57-
return KeyType
58+
return bls.KeyType
5859
}
5960

6061
// Sign signs the given byte array. If msg is larger than
@@ -70,7 +71,7 @@ func (privKey PrivKey) MarshalAmino() ([]byte, error) {
7071

7172
// UnmarshalAmino overrides Amino binary marshaling.
7273
func (privKey *PrivKey) UnmarshalAmino(bz []byte) error {
73-
if len(bz) != PrivKeySize {
74+
if len(bz) != bls.PrivKeySize {
7475
return errors.New("invalid privkey size")
7576
}
7677
privKey.Key = bz
@@ -119,7 +120,7 @@ func (pubKey PubKey) Bytes() []byte {
119120

120121
// Type returns the key's type.
121122
func (PubKey) Type() string {
122-
return KeyType
123+
return bls.KeyType
123124
}
124125

125126
// Equals returns true if the other's type is the same and their bytes are deeply equal.

crypto/keys/bls12_381/key_cgo.go

+21-28
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010

1111
"github.com/cometbft/cometbft/crypto"
1212
"github.com/cometbft/cometbft/crypto/tmhash"
13-
14-
bls12381 "github.com/cosmos/crypto/curves/bls12381"
13+
"github.com/cometbft/cometbft/crypto/bls12381"
1514

1615
"github.com/cosmos/cosmos-sdk/codec"
1716
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
@@ -32,20 +31,20 @@ var (
3231

3332
// NewPrivateKeyFromBytes build a new key from the given bytes.
3433
func NewPrivateKeyFromBytes(bz []byte) (PrivKey, error) {
35-
secretKey, err := bls12381.SecretKeyFromBytes(bz)
34+
secretKey, err := bls12381.NewPrivateKeyFromBytes(bz)
3635
if err != nil {
3736
return PrivKey{}, err
3837
}
3938
return PrivKey{
40-
Key: secretKey.Marshal(),
39+
Key: secretKey.Bytes(),
4140
}, nil
4241
}
4342

4443
// GenPrivKey generates a new key.
4544
func GenPrivKey() (PrivKey, error) {
46-
secretKey, err := bls12381.RandKey()
45+
secretKey, err := bls12381.GenPrivKey()
4746
return PrivKey{
48-
Key: secretKey.Marshal(),
47+
Key: secretKey.Bytes(),
4948
}, err
5049
}
5150

@@ -57,13 +56,13 @@ func (privKey PrivKey) Bytes() []byte {
5756
// PubKey returns the private key's public key. If the privkey is not valid
5857
// it returns a nil value.
5958
func (privKey PrivKey) PubKey() cryptotypes.PubKey {
60-
secretKey, err := bls12381.SecretKeyFromBytes(privKey.Key)
59+
secretKey, err := bls12381.NewPrivateKeyFromBytes(privKey.Key)
6160
if err != nil {
6261
return nil
6362
}
6463

6564
return &PubKey{
66-
Key: secretKey.PublicKey().Marshal(),
65+
Key: secretKey.PubKey().Bytes(),
6766
}
6867
}
6968

@@ -74,24 +73,23 @@ func (privKey PrivKey) Equals(other cryptotypes.LedgerPrivKey) bool {
7473

7574
// Type returns the type.
7675
func (PrivKey) Type() string {
77-
return KeyType
76+
return bls12381.KeyType
7877
}
7978

8079
// Sign signs the given byte array. If msg is larger than
8180
// MaxMsgLen, SHA256 sum will be signed instead of the raw bytes.
8281
func (privKey PrivKey) Sign(msg []byte) ([]byte, error) {
83-
secretKey, err := bls12381.SecretKeyFromBytes(privKey.Key)
82+
secretKey, err := bls12381.NewPrivateKeyFromBytes(privKey.Key)
8483
if err != nil {
8584
return nil, err
8685
}
8786

88-
if len(msg) > MaxMsgLen {
87+
if len(msg) > bls12381.MaxMsgLen {
8988
hash := sha256.Sum256(msg)
90-
sig := secretKey.Sign(hash[:])
91-
return sig.Marshal(), nil
89+
return secretKey.Sign(hash[:])
9290
}
93-
sig := secretKey.Sign(msg)
94-
return sig.Marshal(), nil
91+
92+
return secretKey.Sign(msg)
9593
}
9694

9795
// MarshalAmino overrides Amino binary marshaling.
@@ -101,7 +99,7 @@ func (privKey PrivKey) MarshalAmino() ([]byte, error) {
10199

102100
// UnmarshalAmino overrides Amino binary marshaling.
103101
func (privKey *PrivKey) UnmarshalAmino(bz []byte) error {
104-
if len(bz) != PrivKeySize {
102+
if len(bz) != bls12381.PrivKeySize {
105103
return errors.New("invalid privkey size")
106104
}
107105
privKey.Key = bz
@@ -135,35 +133,30 @@ var _ cryptotypes.PubKey = &PubKey{}
135133
//
136134
// The function will panic if the public key is invalid.
137135
func (pubKey PubKey) Address() crypto.Address {
138-
pk, _ := bls12381.PublicKeyFromBytes(pubKey.Key)
139-
if len(pk.Marshal()) != PubKeySize {
136+
pk, _ := bls12381.NewPublicKeyFromBytes(pubKey.Key)
137+
if len(pk.Bytes()) != bls12381.PubKeySize {
140138
panic("pubkey is incorrect size")
141139
}
142140
return crypto.Address(tmhash.SumTruncated(pubKey.Key))
143141
}
144142

145143
// VerifySignature verifies the given signature.
146144
func (pubKey PubKey) VerifySignature(msg, sig []byte) bool {
147-
if len(sig) != SignatureLength {
145+
if len(sig) != bls12381.SignatureLength {
148146
return false
149147
}
150148

151-
pubK, err := bls12381.PublicKeyFromBytes(pubKey.Key)
149+
pubK, err := bls12381.NewPublicKeyFromBytes(pubKey.Key)
152150
if err != nil { // invalid pubkey
153151
return false
154152
}
155153

156-
if len(msg) > MaxMsgLen {
154+
if len(msg) > bls12381.MaxMsgLen {
157155
hash := sha256.Sum256(msg)
158156
msg = hash[:]
159157
}
160158

161-
ok, err := bls12381.VerifySignature(sig, [MaxMsgLen]byte(msg[:MaxMsgLen]), pubK)
162-
if err != nil { // bad signature
163-
return false
164-
}
165-
166-
return ok
159+
return pubK.VerifySignature(msg, sig)
167160
}
168161

169162
// Bytes returns the byte format.
@@ -173,7 +166,7 @@ func (pubKey PubKey) Bytes() []byte {
173166

174167
// Type returns the key's type.
175168
func (PubKey) Type() string {
176-
return KeyType
169+
return bls12381.KeyType
177170
}
178171

179172
// Equals returns true if the other's type is the same and their bytes are deeply equal.

crypto/keys/jsonkey.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package keys
22

33
import (
4+
bls "github.com/cometbft/cometbft/crypto/bls12381"
5+
46
"github.com/cosmos/cosmos-sdk/crypto/keys/bls12_381"
57
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
68
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
@@ -26,7 +28,7 @@ func (pk JSONPubkey) Address() types.Address {
2628
Key: pk.Value,
2729
}
2830
return secp256k1.Address()
29-
case bls12_381.PubKeyName:
31+
case bls.PubKeyName:
3032
bls12_381 := bls12_381.PubKey{
3133
Key: pk.Value,
3234
}

0 commit comments

Comments
 (0)