Skip to content
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

refactor: Track rebase of our work onto cosmos-sdk v0.45.0 #59

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c3f499c
Add minimum commission rate to x/staking (#3)
sunnya97 May 17, 2021
ae7ec17
Fix error msg
ValarDragon Jun 7, 2021
7dd164f
Try fixing simulator setup of commission rate params
ValarDragon Jun 8, 2021
2228736
Turn off gocritic, nolintlint, and staticcheck. this isn't worth the …
ValarDragon Jun 12, 2021
07832f2
min commission rate check on create validator (#11)
antstalepresh Jun 22, 2021
724eaa2
Gate the change to processing of CreateValidatorMsg based on block he…
ValarDragon Aug 3, 2021
be91975
Add inplace decimal operations (#10)
mconcat Jun 22, 2021
1123355
Improve events heap allocations (#27)
ValarDragon Sep 2, 2021
595544d
Deduplicate bech32 encoding
ValarDragon Sep 2, 2021
d5195b4
Add SendManyCoins, SendCoinsFromModuleToManyAccount method to bank Mo…
mattverse Sep 11, 2021
c9f662d
fix bank keeper test
sunnya97 Nov 17, 2021
8573d75
A notable variety of CacheKVStore improvements (#34)
ValarDragon Sep 19, 2021
52af977
debug pubkey-raw
sunnya97 Nov 17, 2021
95315ff
Limit simulation fee token to only sdk.DefaultBondDenom (#42)
sunnya97 Oct 25, 2021
a75fdb1
ran make rosetta-dat
sunnya97 Nov 18, 2021
26abd7f
Add logging to RunMigrations
ValarDragon Dec 7, 2021
8481632
Expose Bank.NewAppModuleBasic
ValarDragon Dec 7, 2021
4cac942
Bank store migration fix for Osmosis
ValarDragon Dec 8, 2021
f421dcb
Cleanup prints during upgrade
ValarDragon Dec 9, 2021
ba9855a
Restore my old cacheKV store fix that got reverted >:(
ValarDragon Dec 9, 2021
282e9bb
Change default gas to 35k (#47)
mattverse Jan 1, 2022
ef80491
add hooks for superfluid (#51)
antstalepresh Jan 11, 2022
b87def6
fix: Change default pruning options (#52)
mattverse Jan 13, 2022
b47e802
Add safety check: restriction fn in bank module for mint perms (#50)
mattverse Jan 13, 2022
9799033
Stop bank migration panic in tests (#55)
ValarDragon Jan 13, 2022
9d5d0c6
feat: add default mint restriction (#57)
mattverse Jan 19, 2022
ee16076
Make rechecking a tx check the sequence number (#58)
ValarDragon Jan 20, 2022
66c9626
reset bankmsg validatebasic for ics20
antstalepresh Oct 13, 2021
c88c9c8
update bank send cli command generator
antstalepresh Oct 13, 2021
0dcf83b
fix liveness tests
mattverse Jan 24, 2022
88ad16d
fix proto checking against
sunnya97 Jan 24, 2022
f432981
Add iavl-cache-size config parsing to GetConfig
channa-figure Jan 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
debug pubkey-raw
  • Loading branch information
sunnya97 committed Jan 24, 2022
commit 52af9777597eaf2a2b279b631a2fbff1c23a4ead
85 changes: 85 additions & 0 deletions client/debug/legacybech32pubkey/bech32pubkey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package bech32pubkey

import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)

// Bech32PubKeyType defines a string type alias for a Bech32 public key type.
type Bech32PubKeyType string

// Bech32 conversion constants
const (
Bech32PubKeyTypeAccPub Bech32PubKeyType = "accpub"
Bech32PubKeyTypeValPub Bech32PubKeyType = "valpub"
Bech32PubKeyTypeConsPub Bech32PubKeyType = "conspub"
)

// Bech32ifyPubKey returns a Bech32 encoded string containing the appropriate
// prefix based on the key type provided for a given PublicKey.
// TODO: Remove Bech32ifyPubKey and all usages (cosmos/cosmos-sdk/issues/#7357)
func Bech32ifyPubKey(pkt Bech32PubKeyType, pubkey cryptotypes.PubKey) (string, error) {
var bech32Prefix string

switch pkt {
case Bech32PubKeyTypeAccPub:
bech32Prefix = sdk.GetConfig().GetBech32AccountPubPrefix()

case Bech32PubKeyTypeValPub:
bech32Prefix = sdk.GetConfig().GetBech32ValidatorPubPrefix()

case Bech32PubKeyTypeConsPub:
bech32Prefix = sdk.GetConfig().GetBech32ConsensusPubPrefix()

}

return bech32.ConvertAndEncode(bech32Prefix, legacy.Cdc.Amino.MustMarshalBinaryBare(pubkey))
}

// MustBech32ifyPubKey calls Bech32ifyPubKey except it panics on error.
func MustBech32ifyPubKey(pkt Bech32PubKeyType, pubkey cryptotypes.PubKey) string {
res, err := Bech32ifyPubKey(pkt, pubkey)
if err != nil {
panic(err)
}

return res
}

// GetPubKeyFromBech32 returns a PublicKey from a bech32-encoded PublicKey with
// a given key type.
func GetPubKeyFromBech32(pkt Bech32PubKeyType, pubkeyStr string) (cryptotypes.PubKey, error) {
var bech32Prefix string

switch pkt {
case Bech32PubKeyTypeAccPub:
bech32Prefix = sdk.GetConfig().GetBech32AccountPubPrefix()

case Bech32PubKeyTypeValPub:
bech32Prefix = sdk.GetConfig().GetBech32ValidatorPubPrefix()

case Bech32PubKeyTypeConsPub:
bech32Prefix = sdk.GetConfig().GetBech32ConsensusPubPrefix()

}

bz, err := sdk.GetFromBech32(pubkeyStr, bech32Prefix)
if err != nil {
return nil, err
}

return legacy.PubKeyFromBytes(bz)
}

// MustGetPubKeyFromBech32 calls GetPubKeyFromBech32 except it panics on error.
func MustGetPubKeyFromBech32(pkt Bech32PubKeyType, pubkeyStr string) cryptotypes.PubKey {
res, err := GetPubKeyFromBech32(pkt, pubkeyStr)
if err != nil {
panic(err)
}

return res
}
130 changes: 130 additions & 0 deletions client/debug/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package debug

import (
"encoding/base64"
"encoding/hex"
"fmt"
"strconv"
Expand All @@ -9,9 +10,18 @@ import (
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/version"

legacybech32prefix "github.com/cosmos/cosmos-sdk/client/debug/legacybech32pubkey"
)

var (
flagPubkeyType = "type"
)

// Cmd creates a main CLI command
Expand All @@ -23,6 +33,7 @@ func Cmd() *cobra.Command {
}

cmd.AddCommand(PubkeyCmd())
cmd.AddCommand(PubkeyRawCmd())
cmd.AddCommand(AddrCmd())
cmd.AddCommand(RawBytesCmd())

Expand Down Expand Up @@ -59,6 +70,125 @@ $ %s debug pubkey '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AurroA7jvfP
}
}

func bytesToPubkey(bz []byte, keytype string) (cryptotypes.PubKey, bool) {
if keytype == "ed25519" {
if len(bz) == ed25519.PubKeySize {
return &ed25519.PubKey{Key: bz}, true
}
}

if len(bz) == secp256k1.PubKeySize {
return &secp256k1.PubKey{Key: bz}, true
}
return nil, false
}

// getPubKeyFromRawString returns a PubKey (PubKeyEd25519 or PubKeySecp256k1) by attempting
// to decode the pubkey string from hex, base64, and finally bech32. If all
// encodings fail, an error is returned.
func getPubKeyFromRawString(pkstr string, keytype string) (cryptotypes.PubKey, error) {
// Try hex decoding
bz, err := hex.DecodeString(pkstr)
if err == nil {
pk, ok := bytesToPubkey(bz, keytype)
if ok {
return pk, nil
}
}

bz, err = base64.StdEncoding.DecodeString(pkstr)
if err == nil {
pk, ok := bytesToPubkey(bz, keytype)
if ok {
return pk, nil
}
}

pk, err := legacybech32prefix.GetPubKeyFromBech32(legacybech32prefix.Bech32PubKeyTypeAccPub, pkstr)
if err == nil {
return pk, nil
}

pk, err = legacybech32prefix.GetPubKeyFromBech32(legacybech32prefix.Bech32PubKeyTypeValPub, pkstr)
if err == nil {
return pk, nil
}

pk, err = legacybech32prefix.GetPubKeyFromBech32(legacybech32prefix.Bech32PubKeyTypeConsPub, pkstr)
if err == nil {
return pk, nil
}

return nil, fmt.Errorf("pubkey '%s' invalid; expected hex, base64, or bech32 of correct size", pkstr)
}

func PubkeyRawCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "pubkey-raw [pubkey] -t [{ed25519, secp256k1}]",
Short: "Decode a ED25519 or secp256k1 pubkey from hex, base64, or bech32",
Long: fmt.Sprintf(`Decode a pubkey from hex, base64, or bech32.
Example:
$ %s debug pubkey-raw TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
$ %s debug pubkey-raw cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
`, version.AppName, version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

pubkeyType, err := cmd.Flags().GetString(flagPubkeyType)
if err != nil {
return err
}
pubkeyType = strings.ToLower(pubkeyType)
if pubkeyType != "secp256k1" && pubkeyType != "ed25519" {
return errors.Wrapf(errors.ErrInvalidType, "invalid pubkey type, expected oneof ed25519 or secp256k1")
}

pk, err := getPubKeyFromRawString(args[0], pubkeyType)
if err != nil {
return err
}

var consensusPub string
edPK, ok := pk.(*ed25519.PubKey)
if ok && pubkeyType == "ed25519" {
consensusPub, err = legacybech32prefix.Bech32ifyPubKey(legacybech32prefix.Bech32PubKeyTypeConsPub, edPK)
if err != nil {
return err
}

cmd.Printf("Hex: %X\n", edPK.Key)
}
cmd.Println("Parsed key as", pk.Type())

pubKeyJSONBytes, err := clientCtx.LegacyAmino.MarshalJSON(pk)
if err != nil {
return err
}
accPub, err := legacybech32prefix.Bech32ifyPubKey(legacybech32prefix.Bech32PubKeyTypeAccPub, pk)
if err != nil {
return err
}
valPub, err := legacybech32prefix.Bech32ifyPubKey(legacybech32prefix.Bech32PubKeyTypeValPub, pk)
if err != nil {
return err
}
cmd.Println("Address:", pk.Address())
cmd.Println("JSON (base64):", string(pubKeyJSONBytes))
cmd.Println("Bech32 Acc:", accPub)
cmd.Println("Bech32 Validator Operator:", valPub)
if pubkeyType == "ed25519" {

cmd.Println("Bech32 Validator Consensus:", consensusPub)
}

return nil
},
}
cmd.Flags().StringP(flagPubkeyType, "t", "ed25519", "Pubkey type to decode (oneof secp256k1, ed25519)")
return cmd
}

func AddrCmd() *cobra.Command {
return &cobra.Command{
Use: "addr [address]",
Expand Down