Skip to content

Commit

Permalink
Introduce combined sigs commit (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
n-hutton authored Nov 4, 2020
1 parent 7d893f4 commit 0d2783e
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 64 deletions.
2 changes: 2 additions & 0 deletions crypto/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ func ExamplePrintRegisteredTypes() {
//| PubKeySr25519 | tendermint/PubKeySr25519 | 0x0DFB1005 | 0x20 | |
//| PubKeySecp256k1 | tendermint/PubKeySecp256k1 | 0xEB5AE987 | 0x21 | |
//| PubKeyMultisigThreshold | tendermint/PubKeyMultisigThreshold | 0x22C1F7E2 | variable | |
//| PubKeyBls | tendermint/PubKeyBls | 0xB15C84D4 | 0xC0 | |
//| PrivKeyEd25519 | tendermint/PrivKeyEd25519 | 0xA3288910 | 0x40 | |
//| PrivKeySr25519 | tendermint/PrivKeySr25519 | 0x2F82D78B | 0x20 | |
//| PrivKeySecp256k1 | tendermint/PrivKeySecp256k1 | 0xE1B0F79B | 0x20 | |
//| PrivKeyBls | tendermint/PrivKeyBls | 0xF24EF9ED | 0x40 | |
}

func TestKeyEncodings(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ require (

replace github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4

replace github.com/tendermint/tendermint => github.com/fetchai/cosmos-consensus v0.13.0
replace github.com/tendermint/tendermint => github.com/fetchai/cosmos-consensus v0.13.1-0.20201102163518-089b2f12085c
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqL
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 h1:E2s37DuLxFhQDg5gKsWoLBOB0n+ZW8s599zru8FJ2/Y=
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fetchai/cosmos-consensus v0.13.0 h1:SwAAq4qvBGuHgJbueQM+yG3Q0AIgN+bmn9bfSlQ6ums=
github.com/fetchai/cosmos-consensus v0.13.0/go.mod h1:3uBzeHvXTweU0DE0ja1RmM/rxcf+tTajjRCfcF+DG3A=
github.com/fetchai/cosmos-consensus v0.13.1-0.20201102163518-089b2f12085c h1:SDLjK468/dYckZA4Y87hkfNJiID7nQZ0OkJkvnXHlBQ=
github.com/fetchai/cosmos-consensus v0.13.1-0.20201102163518-089b2f12085c/go.mod h1:3uBzeHvXTweU0DE0ja1RmM/rxcf+tTajjRCfcF+DG3A=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6 h1:u/UEqS66A5ckRmS4yNpjmVH56sVtS/RfclBAYocb4as=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
Expand Down
5 changes: 5 additions & 0 deletions x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ante
import (
"bytes"
"encoding/hex"
"github.com/tendermint/tendermint/crypto/bls12_381"

"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
Expand Down Expand Up @@ -300,6 +301,10 @@ func DefaultSigVerificationGasConsumer(
meter.ConsumeGas(params.SigVerifyCostED25519, "ante verify: ed25519")
return sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, "ED25519 public keys are unsupported")

case bls12_381.PubKeyBls:
meter.ConsumeGas(params.SigVerifyCostED25519, "ante verify: bls12_381")
return sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, "Bls12_381 public keys are unsupported")

case secp256k1.PubKeySecp256k1:
meter.ConsumeGas(params.SigVerifyCostSecp256k1, "ante verify: secp256k1")
return nil
Expand Down
7 changes: 4 additions & 3 deletions x/distribution/keeper/test_common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"github.com/tendermint/tendermint/crypto/bls12_381"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -41,9 +42,9 @@ var (
valAccAddr2 = sdk.AccAddress(valOpPk2.Address())
valAccAddr3 = sdk.AccAddress(valOpPk3.Address())

valConsPk1 = ed25519.GenPrivKey().PubKey()
valConsPk2 = ed25519.GenPrivKey().PubKey()
valConsPk3 = ed25519.GenPrivKey().PubKey()
valConsPk1 = bls12_381.GenPrivKey().PubKey()
valConsPk2 = bls12_381.GenPrivKey().PubKey()
valConsPk3 = bls12_381.GenPrivKey().PubKey()
valConsAddr1 = sdk.ConsAddress(valConsPk1.Address())
valConsAddr2 = sdk.ConsAddress(valConsPk2.Address())

Expand Down
3 changes: 2 additions & 1 deletion x/evidence/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper_test

import (
"encoding/hex"
"github.com/tendermint/tendermint/crypto/bls12_381"
"testing"

"github.com/cosmos/cosmos-sdk/simapp"
Expand Down Expand Up @@ -41,7 +42,7 @@ func newPubKey(pk string) (res crypto.PubKey) {
panic(err)
}

var pubkey ed25519.PubKeyEd25519
var pubkey bls12_381.PubKeyBls
copy(pubkey[:], pkBytes)

return pubkey
Expand Down
9 changes: 4 additions & 5 deletions x/genutil/types/genesis_state_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package types

import (
"github.com/tendermint/tendermint/crypto/bls12_381"
"testing"

"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"
)

var (
pk1 = ed25519.GenPrivKey().PubKey()
pk2 = ed25519.GenPrivKey().PubKey()
pk1 = bls12_381.GenPrivKey().PubKey()
pk2 = bls12_381.GenPrivKey().PubKey()
)

func TestValidateGenesisMultipleMessages(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions x/gov/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package gov
import (
"bytes"
"errors"
"github.com/tendermint/tendermint/crypto/bls12_381"
"log"
"sort"
"testing"

"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
Expand Down Expand Up @@ -216,9 +216,9 @@ func badProposalHandler(ctx sdk.Context, c types.Content) error {

var (
pubkeys = []crypto.PubKey{
ed25519.GenPrivKey().PubKey(),
ed25519.GenPrivKey().PubKey(),
ed25519.GenPrivKey().PubKey(),
bls12_381.GenPrivKey().PubKey(),
bls12_381.GenPrivKey().PubKey(),
bls12_381.GenPrivKey().PubKey(),
}
)

Expand Down
16 changes: 9 additions & 7 deletions x/slashing/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ package slashing

import (
"errors"
"testing"

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

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand All @@ -19,10 +17,14 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/cosmos-sdk/x/supply"
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
)

var (
priv1 = secp256k1.GenPrivKey()
priv0 = bls12_381.GenPrivKey() // validator public key
priv1 = secp256k1.GenPrivKey() // validator account
//priv1 = secp256k1.GenPrivKey()
addr1 = sdk.AccAddress(priv1.PubKey().Address())
coins = sdk.Coins{sdk.NewInt64Coin("foocoin", 10)}
)
Expand Down Expand Up @@ -142,7 +144,7 @@ func TestSlashingMsgs(t *testing.T) {
commission := staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())

createValidatorMsg := staking.NewMsgCreateValidator(
sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commission, types.DefaultMinSelfDelegation,
sdk.ValAddress(addr1), priv0.PubKey(), bondCoin, description, commission, types.DefaultMinSelfDelegation,
)

header := abci.Header{Height: mapp.LastBlockHeight() + 1}
Expand All @@ -156,7 +158,7 @@ func TestSlashingMsgs(t *testing.T) {
require.Equal(t, sdk.ValAddress(addr1), validator.OperatorAddress)
require.Equal(t, sdk.Bonded, validator.Status)
require.True(sdk.IntEq(t, bondTokens, validator.BondedTokens()))
unjailMsg := MsgUnjail{ValidatorAddr: sdk.ValAddress(validator.ConsPubKey.Address())}
unjailMsg := MsgUnjail{ValidatorAddr: validator.OperatorAddress}

// no signing info yet
checkValidatorSigningInfo(t, mapp, keeper, sdk.ConsAddress(addr1), false)
Expand Down
8 changes: 4 additions & 4 deletions x/slashing/internal/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package keeper

import (
"encoding/hex"
"github.com/tendermint/tendermint/crypto/bls12_381"
"testing"
"time"

"github.com/stretchr/testify/require"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

Expand Down Expand Up @@ -132,9 +132,9 @@ func newPubKey(pk string) (res crypto.PubKey) {
if err != nil {
panic(err)
}
var pkEd ed25519.PubKeyEd25519
copy(pkEd[:], pkBytes)
return pkEd
var pkBls bls12_381.PubKeyBls
copy(pkBls[:], pkBytes)
return pkBls
}

// Have to change these parameters for tests
Expand Down
2 changes: 1 addition & 1 deletion x/staking/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestStakingMsgs(t *testing.T) {
// create validator
description := NewDescription("foo_moniker", "", "", "", "")
createValidatorMsg := NewMsgCreateValidator(
sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commissionRates, types.DefaultMinSelfDelegation,
sdk.ValAddress(addr1), priv0.PubKey(), bondCoin, description, commissionRates, types.DefaultMinSelfDelegation,
)

header := abci.Header{Height: mApp.LastBlockHeight() + 1}
Expand Down
26 changes: 1 addition & 25 deletions x/staking/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/secp256k1"
tmtypes "github.com/tendermint/tendermint/types"

sdk "github.com/cosmos/cosmos-sdk/types"
keep "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/types"
abci "github.com/tendermint/tendermint/abci/types"
)

func TestValidatorByPowerIndex(t *testing.T) {
Expand Down Expand Up @@ -162,27 +159,6 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) {
assert.Equal(t, Description{}, validator.Description)
}

func TestInvalidPubKeyTypeMsgCreateValidator(t *testing.T) {
ctx, _, keeper, _ := keep.CreateTestInput(t, false, 1000)

addr := sdk.ValAddress(keep.Addrs[0])
invalidPk := secp256k1.GenPrivKey().PubKey()

// invalid pukKey type should not be allowed
msgCreateValidator := NewTestMsgCreateValidator(addr, invalidPk, sdk.NewInt(10))
res, err := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)
require.Error(t, err)
require.Nil(t, res)

ctx = ctx.WithConsensusParams(&abci.ConsensusParams{
Validator: &abci.ValidatorParams{PubKeyTypes: []string{tmtypes.ABCIPubKeyTypeSecp256k1}},
})

res, err = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)
require.NoError(t, err)
require.NotNil(t, res)
}

func TestLegacyValidatorDelegations(t *testing.T) {
ctx, _, keeper, _ := keep.CreateTestInput(t, false, int64(1000))

Expand Down
10 changes: 5 additions & 5 deletions x/staking/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper // noalias
import (
"bytes"
"encoding/hex"
"github.com/tendermint/tendermint/crypto/bls12_381"
"math/rand"
"strconv"
"testing"
Expand All @@ -11,7 +12,6 @@ import (

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/libs/log"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"
Expand Down Expand Up @@ -100,7 +100,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, initPower int64) (sdk.Context
ctx = ctx.WithConsensusParams(
&abci.ConsensusParams{
Validator: &abci.ValidatorParams{
PubKeyTypes: []string{tmtypes.ABCIPubKeyTypeEd25519},
PubKeyTypes: []string{tmtypes.ABCIPubKeyTypeBls12_381},
},
},
)
Expand Down Expand Up @@ -172,9 +172,9 @@ func NewPubKey(pk string) (res crypto.PubKey) {
panic(err)
}
//res, err = crypto.PubKeyFromBytes(pkBytes)
var pkEd ed25519.PubKeyEd25519
copy(pkEd[:], pkBytes)
return pkEd
var pkBls bls12_381.PubKeyBls
copy(pkBls[:], pkBytes)
return pkBls
}

// for incode address generation
Expand Down
2 changes: 2 additions & 0 deletions x/staking/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package staking

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

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -11,6 +12,7 @@ import (

// nolint:deadcode,unused,varcheck
var (
priv0 = bls12_381.GenPrivKey()
priv1 = secp256k1.GenPrivKey()
addr1 = sdk.AccAddress(priv1.PubKey().Address())
priv2 = secp256k1.GenPrivKey()
Expand Down
6 changes: 6 additions & 0 deletions x/staking/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package types
import (
"bytes"
"encoding/json"
"fmt"

"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/bls12_381"
yaml "gopkg.in/yaml.v2"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -50,6 +52,10 @@ func NewMsgCreateValidator(
description Description, commission CommissionRates, minSelfDelegation sdk.Int,
) MsgCreateValidator {

if _, ok := pubKey.(bls12_381.PubKeyBls); !ok && pubKey != nil {
panic(fmt.Sprintf("Attempt to create validator with non bls based public key is invalid!\n"))
}

return MsgCreateValidator{
Description: description,
DelegatorAddress: sdk.AccAddress(valAddr),
Expand Down
11 changes: 5 additions & 6 deletions x/staking/types/test_utils.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package types

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

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/bls12_381"
)

// nolint:deadcode,unused
var (
pk1 = ed25519.GenPrivKey().PubKey()
pk2 = ed25519.GenPrivKey().PubKey()
pk3 = ed25519.GenPrivKey().PubKey()
pk1 = bls12_381.GenPrivKey().PubKey()
pk2 = bls12_381.GenPrivKey().PubKey()
pk3 = bls12_381.GenPrivKey().PubKey()
addr1 = pk1.Address()
addr2 = pk2.Address()
addr3 = pk3.Address()
Expand Down

0 comments on commit 0d2783e

Please sign in to comment.