forked from cerc-io/laconicd-deprecated
crypto: refactor for stargate (#559)
* changelog * update changelog * crypto: refactor for stargate * fixes * fix keys * changelog
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -20,7 +20,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/cosmos/ethermint/app"
|
||||
"github.com/cosmos/ethermint/crypto"
|
||||
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
||||
ethermint "github.com/cosmos/ethermint/types"
|
||||
"github.com/cosmos/ethermint/x/evm"
|
||||
"github.com/cosmos/ethermint/x/evm/keeper"
|
||||
@@ -55,7 +55,7 @@ func TestEvmTestSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func (suite *EvmTestSuite) TestHandleMsgEthereumTx() {
|
||||
privkey, err := crypto.GenerateKey()
|
||||
privkey, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err)
|
||||
sender := ethcmn.HexToAddress(privkey.PubKey().Address().String())
|
||||
|
||||
@@ -219,7 +219,7 @@ func (suite *EvmTestSuite) TestHandlerLogs() {
|
||||
gasLimit := uint64(100000)
|
||||
gasPrice := big.NewInt(1000000)
|
||||
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err, "failed to create key")
|
||||
|
||||
bytecode := common.FromHex("0x6080604052348015600f57600080fd5b5060117f775a94827b8fd9b519d36cd827093c664f93347070a554f65e4a6f56cd73889860405160405180910390a2603580604b6000396000f3fe6080604052600080fdfea165627a7a723058206cab665f0f557620554bb45adf266708d2bd349b8a4314bdff205ee8440e3c240029")
|
||||
@@ -250,7 +250,7 @@ func (suite *EvmTestSuite) TestQueryTxLogs() {
|
||||
gasLimit := uint64(100000)
|
||||
gasPrice := big.NewInt(1000000)
|
||||
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err, "failed to create key")
|
||||
|
||||
// send contract deployment transaction with an event in the constructor
|
||||
@@ -349,7 +349,7 @@ func (suite *EvmTestSuite) TestDeployAndCallContract() {
|
||||
gasLimit := uint64(100000000)
|
||||
gasPrice := big.NewInt(10000)
|
||||
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err, "failed to create key")
|
||||
|
||||
bytecode := common.FromHex("0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a73560405160405180910390a36102c4806100dc6000396000f3fe608060405234801561001057600080fd5b5060043610610053576000357c010000000000000000000000000000000000000000000000000000000090048063893d20e814610058578063a6f9dae1146100a2575b600080fd5b6100606100e6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100e4600480360360208110156100b857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061010f565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146101d1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f43616c6c6572206973206e6f74206f776e65720000000000000000000000000081525060200191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a73560405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505056fea265627a7a72315820f397f2733a89198bc7fed0764083694c5b828791f39ebcbc9e414bccef14b48064736f6c63430005100032")
|
||||
@@ -400,7 +400,7 @@ func (suite *EvmTestSuite) TestSendTransaction() {
|
||||
gasLimit := uint64(21000)
|
||||
gasPrice := big.NewInt(0x55ae82600)
|
||||
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err, "failed to create key")
|
||||
pub := priv.ToECDSA().Public().(*ecdsa.PublicKey)
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
"github.com/cosmos/ethermint/crypto"
|
||||
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
||||
ethermint "github.com/cosmos/ethermint/types"
|
||||
"github.com/cosmos/ethermint/x/evm/types"
|
||||
)
|
||||
@@ -328,7 +328,7 @@ func (suite *KeeperTestSuite) TestStateDB_CreateAccount() {
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestStateDB_ClearStateObj() {
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err)
|
||||
|
||||
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
|
||||
@@ -341,7 +341,7 @@ func (suite *KeeperTestSuite) TestStateDB_ClearStateObj() {
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestStateDB_Reset() {
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err)
|
||||
|
||||
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
|
||||
@@ -444,7 +444,7 @@ func (suite *KeeperTestSuite) TestSuiteDB_Suicide() {
|
||||
suite.Require().True(suite.app.EvmKeeper.HasSuicided(suite.ctx, suite.address), tc.name)
|
||||
} else {
|
||||
//Suicide only works for an account with non-zero balance/nonce
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err)
|
||||
|
||||
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/ethermint/crypto"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
||||
)
|
||||
|
||||
func TestValidateGenesisAccount(t *testing.T) {
|
||||
@@ -77,7 +78,7 @@ func TestValidateGenesisAccount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateGenesis(t *testing.T) {
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
require.NoError(t, err)
|
||||
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
"github.com/cosmos/ethermint/crypto"
|
||||
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
||||
ethermint "github.com/cosmos/ethermint/types"
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ func newTestCodec() *sdkcodec.Codec {
|
||||
|
||||
RegisterCodec(cdc)
|
||||
sdk.RegisterCodec(cdc)
|
||||
crypto.RegisterCodec(cdc)
|
||||
ethsecp256k1.RegisterCodec(cdc)
|
||||
sdkcodec.RegisterCrypto(cdc)
|
||||
auth.RegisterCodec(cdc)
|
||||
ethermint.RegisterCodec(cdc)
|
||||
@@ -51,7 +51,7 @@ func newTestCodec() *sdkcodec.Codec {
|
||||
func (suite *JournalTestSuite) SetupTest() {
|
||||
suite.setup()
|
||||
|
||||
privkey, err := crypto.GenerateKey()
|
||||
privkey, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.address = ethcmn.BytesToAddress(privkey.PubKey().Address().Bytes())
|
||||
|
||||
@@ -3,17 +3,16 @@ package types
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
"github.com/cosmos/ethermint/crypto"
|
||||
)
|
||||
|
||||
func TestTransactionLogsValidate(t *testing.T) {
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
require.NoError(t, err)
|
||||
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
|
||||
|
||||
@@ -91,7 +90,7 @@ func TestTransactionLogsValidate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateLog(t *testing.T) {
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
require.NoError(t, err)
|
||||
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/cosmos/ethermint/crypto"
|
||||
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
||||
|
||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
@@ -164,8 +163,8 @@ func TestMsgEthereumTxRLPDecode(t *testing.T) {
|
||||
func TestMsgEthereumTxSig(t *testing.T) {
|
||||
chainID := big.NewInt(3)
|
||||
|
||||
priv1, _ := crypto.GenerateKey()
|
||||
priv2, _ := crypto.GenerateKey()
|
||||
priv1, _ := ethsecp256k1.GenerateKey()
|
||||
priv2, _ := ethsecp256k1.GenerateKey()
|
||||
addr1 := ethcmn.BytesToAddress(priv1.PubKey().Address().Bytes())
|
||||
addr2 := ethcmn.BytesToAddress(priv2.PubKey().Address().Bytes())
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/cosmos/ethermint/crypto"
|
||||
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
||||
ethermint "github.com/cosmos/ethermint/types"
|
||||
"github.com/cosmos/ethermint/x/evm/types"
|
||||
|
||||
@@ -22,7 +22,7 @@ func (suite *StateDBTestSuite) TestTransitionDb() {
|
||||
_ = acc.SetCoins(sdk.NewCoins(balance))
|
||||
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
||||
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err)
|
||||
recipient := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
"github.com/cosmos/ethermint/app"
|
||||
"github.com/cosmos/ethermint/crypto"
|
||||
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
||||
ethermint "github.com/cosmos/ethermint/types"
|
||||
"github.com/cosmos/ethermint/x/evm/types"
|
||||
|
||||
@@ -43,7 +43,7 @@ func (suite *StateDBTestSuite) SetupTest() {
|
||||
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1})
|
||||
suite.stateDB = suite.app.EvmKeeper.CommitStateDB.WithContext(suite.ctx)
|
||||
|
||||
privkey, err := crypto.GenerateKey()
|
||||
privkey, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.address = ethcmn.BytesToAddress(privkey.PubKey().Address().Bytes())
|
||||
@@ -377,7 +377,7 @@ func (suite *StateDBTestSuite) TestStateDB_CreateAccount() {
|
||||
}
|
||||
|
||||
func (suite *StateDBTestSuite) TestStateDB_ClearStateObj() {
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err)
|
||||
|
||||
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
|
||||
@@ -390,7 +390,7 @@ func (suite *StateDBTestSuite) TestStateDB_ClearStateObj() {
|
||||
}
|
||||
|
||||
func (suite *StateDBTestSuite) TestStateDB_Reset() {
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err)
|
||||
|
||||
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
|
||||
@@ -497,7 +497,7 @@ func (suite *StateDBTestSuite) TestSuiteDB_Suicide() {
|
||||
suite.Require().True(suite.stateDB.HasSuicided(suite.address), tc.name)
|
||||
} else {
|
||||
//Suicide only works for an account with non-zero balance/nonce
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
suite.Require().NoError(err)
|
||||
|
||||
addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey)
|
||||
|
||||
@@ -5,7 +5,8 @@ import (
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
"github.com/cosmos/ethermint/crypto"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/crypto/sha3"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -16,13 +17,12 @@ import (
|
||||
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/crypto/sha3"
|
||||
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
||||
)
|
||||
|
||||
// GenerateEthAddress generates an Ethereum address.
|
||||
func GenerateEthAddress() ethcmn.Address {
|
||||
priv, err := crypto.GenerateKey()
|
||||
priv, err := ethsecp256k1.GenerateKey()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -47,9 +47,8 @@ func ValidateSigner(signBytes, sig []byte, signer ethcmn.Address) error {
|
||||
|
||||
func rlpHash(x interface{}) (hash ethcmn.Hash) {
|
||||
hasher := sha3.NewLegacyKeccak256()
|
||||
//nolint:gosec,errcheck
|
||||
rlp.Encode(hasher, x)
|
||||
hasher.Sum(hash[:0])
|
||||
_ = rlp.Encode(hasher, x)
|
||||
_ = hasher.Sum(hash[:0])
|
||||
|
||||
return hash
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user