Skip to content

Commit

Permalink
Merge PR #3763: Disable ED25519 Account Keys
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored and jackzampolin committed Mar 1, 2019
1 parent 172e265 commit 5d8b949
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 27 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

* [\#3669] Ensure consistency in message naming, codec registration, and JSON
tags.
* [\#3751] Disable (temporarily) support for ED25519 account key pairs.

### Tendermint

Expand Down
16 changes: 13 additions & 3 deletions x/auth/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ func processSig(
consumeSimSigGas(ctx.GasMeter(), pubKey, sig, params)
}

consumeSigVerificationGas(ctx.GasMeter(), sig.Signature, pubKey, params)
if res := consumeSigVerificationGas(ctx.GasMeter(), sig.Signature, pubKey, params); !res.IsOK() {
return nil, res
}

if !simulate && !pubKey.VerifyBytes(signBytes, sig.Signature) {
return nil, sdk.ErrUnauthorized("signature verification failed").Result()
}
Expand Down Expand Up @@ -256,24 +259,31 @@ func ProcessPubKey(acc Account, sig StdSignature, simulate bool) (crypto.PubKey,
// by the concrete type.
//
// TODO: Design a cleaner and flexible way to match concrete public key types.
func consumeSigVerificationGas(meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params Params) {
func consumeSigVerificationGas(
meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params Params,
) sdk.Result {

pubkeyType := strings.ToLower(fmt.Sprintf("%T", pubkey))

switch {
case strings.Contains(pubkeyType, "ed25519"):
meter.ConsumeGas(params.SigVerifyCostED25519, "ante verify: ed25519")
return sdk.ErrInvalidPubKey("ED25519 public keys are unsupported").Result()

case strings.Contains(pubkeyType, "secp256k1"):
meter.ConsumeGas(params.SigVerifyCostSecp256k1, "ante verify: secp256k1")
return sdk.Result{}

case strings.Contains(pubkeyType, "multisigthreshold"):
var multisignature multisig.Multisignature
codec.Cdc.MustUnmarshalBinaryBare(sig, &multisignature)

multisigPubKey := pubkey.(multisig.PubKeyMultisigThreshold)
consumeMultisignatureVerificationGas(meter, multisignature, multisigPubKey, params)
return sdk.Result{}

default:
panic(fmt.Sprintf("unrecognized signature type: %s", pubkeyType))
return sdk.ErrInvalidPubKey(fmt.Sprintf("unrecognized public key type: %s", pubkeyType)).Result()
}
}

Expand Down
12 changes: 7 additions & 5 deletions x/auth/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,19 +585,21 @@ func TestConsumeSignatureVerificationGas(t *testing.T) {
name string
args args
gasConsumed uint64
wantPanic bool
shouldErr bool
}{
{"PubKeyEd25519", args{sdk.NewInfiniteGasMeter(), nil, ed25519.GenPrivKey().PubKey(), params}, DefaultSigVerifyCostED25519, false},
{"PubKeyEd25519", args{sdk.NewInfiniteGasMeter(), nil, ed25519.GenPrivKey().PubKey(), params}, DefaultSigVerifyCostED25519, true},
{"PubKeySecp256k1", args{sdk.NewInfiniteGasMeter(), nil, secp256k1.GenPrivKey().PubKey(), params}, DefaultSigVerifyCostSecp256k1, false},
{"Multisig", args{sdk.NewInfiniteGasMeter(), multisignature1.Marshal(), multisigKey1, params}, expectedCost1, false},
{"unknown key", args{sdk.NewInfiniteGasMeter(), nil, nil, params}, 0, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.wantPanic {
require.Panics(t, func() { consumeSigVerificationGas(tt.args.meter, tt.args.sig, tt.args.pubkey, tt.args.params) })
res := consumeSigVerificationGas(tt.args.meter, tt.args.sig, tt.args.pubkey, tt.args.params)

if tt.shouldErr {
require.False(t, res.IsOK())
} else {
consumeSigVerificationGas(tt.args.meter, tt.args.sig, tt.args.pubkey, tt.args.params)
require.True(t, res.IsOK())
require.Equal(t, tt.gasConsumed, tt.args.meter.GasConsumed(), fmt.Sprintf("%d != %d", tt.gasConsumed, tt.args.meter.GasConsumed()))
}
})
Expand Down
4 changes: 2 additions & 2 deletions x/auth/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package auth
import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"

Expand Down Expand Up @@ -67,7 +67,7 @@ func newCoins() sdk.Coins {
}

func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) {
key := ed25519.GenPrivKey()
key := secp256k1.GenPrivKey()
pub := key.PubKey()
addr := sdk.AccAddress(pub.Address())
return key, pub, addr
Expand Down
10 changes: 5 additions & 5 deletions x/bank/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
)

type (
Expand All @@ -32,12 +32,12 @@ type (
)

var (
priv1 = ed25519.GenPrivKey()
priv1 = secp256k1.GenPrivKey()
addr1 = sdk.AccAddress(priv1.PubKey().Address())
priv2 = ed25519.GenPrivKey()
priv2 = secp256k1.GenPrivKey()
addr2 = sdk.AccAddress(priv2.PubKey().Address())
addr3 = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
priv4 = ed25519.GenPrivKey()
addr3 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
priv4 = secp256k1.GenPrivKey()
addr4 = sdk.AccAddress(priv4.PubKey().Address())

coins = sdk.Coins{sdk.NewInt64Coin("foocoin", 10)}
Expand Down
4 changes: 2 additions & 2 deletions x/ibc/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/mock"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
)

// initialize the mock application for this module
Expand All @@ -36,7 +36,7 @@ func TestIBCMsgs(t *testing.T) {
sourceChain := "source-chain"
destChain := "dest-chain"

priv1 := ed25519.GenPrivKey()
priv1 := secp256k1.GenPrivKey()
addr1 := sdk.AccAddress(priv1.PubKey().Address())
coins := sdk.Coins{sdk.NewInt64Coin("foocoin", 10)}
var emptyCoins sdk.Coins
Expand Down
6 changes: 3 additions & 3 deletions x/mock/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func CreateGenAccounts(numAccs int, genCoins sdk.Coins) (genAccs []auth.Account,
addrKeysSlice := AddrKeysSlice{}

for i := 0; i < numAccs; i++ {
privKey := ed25519.GenPrivKey()
privKey := secp256k1.GenPrivKey()
pubKey := privKey.PubKey()
addr := sdk.AccAddress(pubKey.Address())

Expand Down Expand Up @@ -235,12 +235,12 @@ func GenTx(msgs []sdk.Msg, accnums []uint64, seq []uint64, priv ...crypto.PrivKe
return auth.NewStdTx(msgs, fee, sigs, memo)
}

// GeneratePrivKeys generates a total n Ed25519 private keys.
// GeneratePrivKeys generates a total n secp256k1 private keys.
func GeneratePrivKeys(n int) (keys []crypto.PrivKey) {
// TODO: Randomize this between ed25519 and secp256k1
keys = make([]crypto.PrivKey, n)
for i := 0; i < n; i++ {
keys[i] = ed25519.GenPrivKey()
keys[i] = secp256k1.GenPrivKey()
}

return
Expand Down
4 changes: 2 additions & 2 deletions x/slashing/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand All @@ -15,7 +15,7 @@ import (
)

var (
priv1 = ed25519.GenPrivKey()
priv1 = secp256k1.GenPrivKey()
addr1 = sdk.AccAddress(priv1.PubKey().Address())
coins = sdk.Coins{sdk.NewInt64Coin("foocoin", 10)}
)
Expand Down
10 changes: 5 additions & 5 deletions x/staking/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package staking

import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

var (
priv1 = ed25519.GenPrivKey()
priv1 = secp256k1.GenPrivKey()
addr1 = sdk.AccAddress(priv1.PubKey().Address())
priv2 = ed25519.GenPrivKey()
priv2 = secp256k1.GenPrivKey()
addr2 = sdk.AccAddress(priv2.PubKey().Address())
addr3 = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
priv4 = ed25519.GenPrivKey()
addr3 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
priv4 = secp256k1.GenPrivKey()
addr4 = sdk.AccAddress(priv4.PubKey().Address())
coins = sdk.Coins{sdk.NewCoin("foocoin", sdk.NewInt(10))}
fee = auth.NewStdFee(
Expand Down

0 comments on commit 5d8b949

Please sign in to comment.