diff --git a/crypto/ethsecp256k1/ethsecp256k1.go b/crypto/ethsecp256k1/ethsecp256k1.go index c921738a..3e148ccf 100644 --- a/crypto/ethsecp256k1/ethsecp256k1.go +++ b/crypto/ethsecp256k1/ethsecp256k1.go @@ -6,11 +6,10 @@ import ( "crypto/subtle" "fmt" - ethcrypto "github.com/ethereum/go-ethereum/crypto" - "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/ethereum/go-ethereum/crypto" tmcrypto "github.com/tendermint/tendermint/crypto" ) @@ -43,13 +42,13 @@ var ( // GenerateKey generates a new random private key. It returns an error upon // failure. func GenerateKey() (*PrivKey, error) { - priv, err := ethcrypto.GenerateKey() + priv, err := crypto.GenerateKey() if err != nil { return nil, err } return &PrivKey{ - Key: ethcrypto.FromECDSA(priv), + Key: crypto.FromECDSA(priv), }, nil } @@ -62,7 +61,7 @@ func (privKey PrivKey) Bytes() []byte { func (privKey PrivKey) PubKey() cryptotypes.PubKey { ecdsaPrivKey := privKey.ToECDSA() return &PubKey{ - Key: ethcrypto.CompressPubkey(&ecdsaPrivKey.PublicKey), + Key: crypto.CompressPubkey(&ecdsaPrivKey.PublicKey), } } @@ -107,17 +106,17 @@ func (privKey *PrivKey) UnmarshalAminoJSON(bz []byte) error { // provided hash of the message. The produced signature is 65 bytes // where the last byte contains the recovery ID. func (privKey PrivKey) Sign(digestBz []byte) ([]byte, error) { - if len(digestBz) != ethcrypto.DigestLength { - digestBz = ethcrypto.Keccak256Hash(digestBz).Bytes() + if len(digestBz) != crypto.DigestLength { + digestBz = crypto.Keccak256Hash(digestBz).Bytes() } - return ethcrypto.Sign(digestBz, privKey.ToECDSA()) + return crypto.Sign(digestBz, privKey.ToECDSA()) } // ToECDSA returns the ECDSA private key as a reference to ecdsa.PrivateKey type. // The function will panic if the private key is invalid. func (privKey PrivKey) ToECDSA() *ecdsa.PrivateKey { - key, err := ethcrypto.ToECDSA(privKey.Bytes()) + key, err := crypto.ToECDSA(privKey.Bytes()) if err != nil { panic(err) } @@ -135,12 +134,12 @@ var ( // Address returns the address of the ECDSA public key. // The function will panic if the public key is invalid. func (pubKey PubKey) Address() tmcrypto.Address { - pubk, err := ethcrypto.DecompressPubkey(pubKey.Key) + pubk, err := crypto.DecompressPubkey(pubKey.Key) if err != nil { panic(err) } - return tmcrypto.Address(ethcrypto.PubkeyToAddress(*pubk).Bytes()) + return tmcrypto.Address(crypto.PubkeyToAddress(*pubk).Bytes()) } // Bytes returns the raw bytes of the ECDSA public key. @@ -196,11 +195,11 @@ func (pubKey *PubKey) UnmarshalAminoJSON(bz []byte) error { // // CONTRACT: The signature should be in [R || S] format. func (pubKey PubKey) VerifySignature(msg []byte, sig []byte) bool { - if len(sig) == ethcrypto.SignatureLength { + if len(sig) == crypto.SignatureLength { // remove recovery ID (V) if contained in the signature sig = sig[:len(sig)-1] } // the signature needs to be in [R || S] format when provided to VerifySignature - return ethcrypto.VerifySignature(pubKey.Key, ethcrypto.Keccak256Hash(msg).Bytes(), sig) + return crypto.VerifySignature(pubKey.Key, crypto.Keccak256Hash(msg).Bytes(), sig) } diff --git a/crypto/ethsecp256k1/ethsecp256k1_test.go b/crypto/ethsecp256k1/ethsecp256k1_test.go index e3eb51f3..c6b9d55e 100644 --- a/crypto/ethsecp256k1/ethsecp256k1_test.go +++ b/crypto/ethsecp256k1/ethsecp256k1_test.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" - ethcrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -28,12 +28,12 @@ func TestPrivKey(t *testing.T) { // validate Ethereum address equality addr := privKey.PubKey().Address() - expectedAddr := ethcrypto.PubkeyToAddress(privKey.ToECDSA().PublicKey) + expectedAddr := crypto.PubkeyToAddress(privKey.ToECDSA().PublicKey) require.Equal(t, expectedAddr.Bytes(), addr.Bytes()) // validate we can sign some bytes msg := []byte("hello world") - sigHash := ethcrypto.Keccak256Hash(msg) + sigHash := crypto.Keccak256Hash(msg) expectedSig, err := secp256k1.Sign(sigHash.Bytes(), privKey.Bytes()) require.NoError(t, err) diff --git a/crypto/hd/algorithm.go b/crypto/hd/algorithm.go index b2377644..25a25044 100644 --- a/crypto/hd/algorithm.go +++ b/crypto/hd/algorithm.go @@ -5,8 +5,8 @@ import ( "github.com/btcsuite/btcutil/hdkeychain" bip39 "github.com/tyler-smith/go-bip39" - ethaccounts "github.com/ethereum/go-ethereum/accounts" - ethcrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/accounts" + "github.com/ethereum/go-ethereum/crypto" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -59,7 +59,7 @@ func (s ethSecp256k1Algo) Name() hd.PubKeyType { // Derive derives and returns the eth_secp256k1 private key for the given mnemonic and HD path. func (s ethSecp256k1Algo) Derive() hd.DeriveFn { return func(mnemonic string, bip39Passphrase, path string) ([]byte, error) { - hdpath, err := ethaccounts.ParseDerivationPath(path) + hdpath, err := accounts.ParseDerivationPath(path) if err != nil { return nil, err } @@ -88,7 +88,7 @@ func (s ethSecp256k1Algo) Derive() hd.DeriveFn { } privateKeyECDSA := privateKey.ToECDSA() - derivedKey := ethcrypto.FromECDSA(privateKeyECDSA) + derivedKey := crypto.FromECDSA(privateKeyECDSA) return derivedKey, nil } diff --git a/docs/architecture/adr-002-evm-hooks.md b/docs/architecture/adr-002-evm-hooks.md index 9f2adad2..be2ef242 100644 --- a/docs/architecture/adr-002-evm-hooks.md +++ b/docs/architecture/adr-002-evm-hooks.md @@ -29,9 +29,9 @@ add custom logic to process transaction logs. This ADR proposes to add an `EvmHooks` interface and a method to register hooks in the `EvmKeeper`: -```golang +```go type EvmHooks interface { - PostTxProcessing(ctx sdk.Context, txHash ethcmn.Hash, logs []*ethtypes.Log) error + PostTxProcessing(ctx sdk.Context, txHash common.Hash, logs []*ethtypes.Log) error } func (k *EvmKeeper) SetHooks(eh types.EvmHooks) *Keeper; @@ -48,9 +48,13 @@ func (k *EvmKeeper) SetHooks(eh types.EvmHooks) *Keeper; The EVM state transition method `ApplyTransaction` should be changed like this: -```golang +```go // Need to create a snapshot explicitly to cover both tx processing and post processing logic -revision := k.Snapshot() +var revision int +if k.hooks != nil { + revision = k.Snapshot() +} + res, err := k.ApplyMessage(evm, msg, ethCfg, false) if err != nil { @@ -96,50 +100,50 @@ function withdraw_to_native_token(amount uint256) public { And the application registers a `BankSendHook` to `EvmKeeper`, it recognizes the log and converts it to a call to the bank module's `SendCoinsFromAccountToAccount` method: -```golang +```go var ( - // BankSendEvent represent the signature of - // `event __CosmosNativeBankSend(address recipient, uint256 amount, string denom)` - BankSendEvent abi.Event + // BankSendEvent represent the signature of + // `event __CosmosNativeBankSend(address recipient, uint256 amount, string denom)` + BankSendEvent abi.Event ) func init() { - addressType, _ := abi.NewType("address", "", nil) - uint256Type, _ := abi.NewType("uint256", "", nil) - stringType, _ := abi.NewType("string", "", nil) - BankSendEvent = abi.NewEvent( - "__CosmosNativeBankSend", - "__CosmosNativeBankSend", - false, - abi.Arguments{abi.Argument{ - Name: "recipient", - Type: addressType, - Indexed: false, - }, abi.Argument{ - Name: "amount", - Type: uint256Type, - Indexed: false, - }, abi.Argument{ - Name: "denom", - Type: stringType, - Indexed: false, - }}, - ) + addressType, _ := abi.NewType("address", "", nil) + uint256Type, _ := abi.NewType("uint256", "", nil) + stringType, _ := abi.NewType("string", "", nil) + BankSendEvent = abi.NewEvent( + "__CosmosNativeBankSend", + "__CosmosNativeBankSend", + false, + abi.Arguments{abi.Argument{ + Name: "recipient", + Type: addressType, + Indexed: false, + }, abi.Argument{ + Name: "amount", + Type: uint256Type, + Indexed: false, + }, abi.Argument{ + Name: "denom", + Type: stringType, + Indexed: false, + }}, + ) } type BankSendHook struct { - bankKeeper bankkeeper.Keeper + bankKeeper bankkeeper.Keeper } func NewBankSendHook(bankKeeper bankkeeper.Keeper) *BankSendHook { - return &BankSendHook{ - bankKeeper: bankKeeper, - } + return &BankSendHook{ + bankKeeper: bankKeeper, + } } -func (h BankSendHook) PostTxProcessing(ctx sdk.Context, txHash ethcmn.Hash, logs []*ethtypes.Log) error { - for _, log := range logs { - if len(log.Topics) == 0 || log.Topics[0] != BankSendEvent.ID { +func (h BankSendHook) PostTxProcessing(ctx sdk.Context, txHash common.Hash, logs []*ethtypes.Log) error { + for _, log := range logs { + if len(log.Topics) == 0 || log.Topics[0] != BankSendEvent.ID { continue } if !ContractAllowed(log.Address) { @@ -152,21 +156,21 @@ func (h BankSendHook) PostTxProcessing(ctx sdk.Context, txHash ethcmn.Hash, logs continue } contract := sdk.AccAddress(log.Address.Bytes()) - recipient := sdk.AccAddress(unpacked[0].(ethcmn.Address).Bytes()) + recipient := sdk.AccAddress(unpacked[0].(common.Address).Bytes()) coins := sdk.NewCoins(sdk.NewCoin(unpacked[2].(string), sdk.NewIntFromBigInt(unpacked[1].(*big.Int)))) err = h.bankKeeper.SendCoins(ctx, contract, recipient, coins) if err != nil { return err } - } - } - return nil + } + } + return nil } ``` Register the hook in `app.go`: -```golang +```go evmKeeper.SetHooks(NewBankSendHook(bankKeeper)); ``` diff --git a/tests/importer/chain_ctx.go b/tests/importer/chain_ctx.go index 424375c8..7ee12ffc 100644 --- a/tests/importer/chain_ctx.go +++ b/tests/importer/chain_ctx.go @@ -3,7 +3,7 @@ package importer import ( "math/big" - ethcmn "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" ethcons "github.com/ethereum/go-ethereum/consensus" ethstate "github.com/ethereum/go-ethereum/core/state" ethtypes "github.com/ethereum/go-ethereum/core/types" @@ -20,7 +20,7 @@ import ( // NOTE: Ethermint will distribute the fees out to validators, so the structure // and functionality of this is a WIP and subject to change. type ChainContext struct { - Coinbase ethcmn.Address + Coinbase common.Address headersByNumber map[uint64]*ethtypes.Header } @@ -48,7 +48,7 @@ func (cc *ChainContext) SetHeader(number uint64, header *ethtypes.Header) { // // TODO: The Cosmos SDK supports retreiving such information in contexts and // multi-store, so this will be need to be integrated. -func (cc *ChainContext) GetHeader(_ ethcmn.Hash, number uint64) *ethtypes.Header { +func (cc *ChainContext) GetHeader(_ common.Hash, number uint64) *ethtypes.Header { if header, ok := cc.headersByNumber[number]; ok { return header } @@ -62,7 +62,7 @@ func (cc *ChainContext) GetHeader(_ ethcmn.Hash, number uint64) *ethtypes.Header // // NOTE: Ethermint will distribute the fees out to validators, so the structure // and functionality of this is a WIP and subject to change. -func (cc *ChainContext) Author(_ *ethtypes.Header) (ethcmn.Address, error) { +func (cc *ChainContext) Author(_ *ethtypes.Header) (common.Address, error) { return cc.Coinbase, nil } @@ -119,8 +119,8 @@ func (cc *ChainContext) Seal(_ ethcons.ChainHeaderReader, _ *ethtypes.Block, _ c // SealHash implements Ethereum's consensus.Engine interface. It returns the // hash of a block prior to it being sealed. -func (cc *ChainContext) SealHash(header *ethtypes.Header) ethcmn.Hash { - return ethcmn.Hash{} +func (cc *ChainContext) SealHash(header *ethtypes.Header) common.Hash { + return common.Hash{} } // VerifyHeader implements Ethereum's consensus.Engine interface. It currently diff --git a/tests/importer/chain_ctx_test.go b/tests/importer/chain_ctx_test.go index 9bd4b3d1..cbd6f53e 100644 --- a/tests/importer/chain_ctx_test.go +++ b/tests/importer/chain_ctx_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" - ethcmn "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" ethcons "github.com/ethereum/go-ethereum/consensus" ethcore "github.com/ethereum/go-ethereum/core" ethtypes "github.com/ethereum/go-ethereum/core/types" @@ -47,8 +47,8 @@ func TestChainContextGetHeader(t *testing.T) { } cc.SetHeader(uint64(header.Number.Int64()), header) - require.Equal(t, header, cc.GetHeader(ethcmn.Hash{}, uint64(header.Number.Int64()))) - require.Nil(t, cc.GetHeader(ethcmn.Hash{}, 0)) + require.Equal(t, header, cc.GetHeader(common.Hash{}, uint64(header.Number.Int64()))) + require.Nil(t, cc.GetHeader(common.Hash{}, 0)) } func TestChainContextAuthor(t *testing.T) { diff --git a/tests/importer/importer_test.go b/tests/importer/importer_test.go index a0d4a60d..7e17a747 100644 --- a/tests/importer/importer_test.go +++ b/tests/importer/importer_test.go @@ -35,12 +35,12 @@ package importer // evmkeeper "github.com/tharsis/ethermint/x/evm/keeper" // evmtypes "github.com/tharsis/ethermint/x/evm/types" -// ethcmn "github.com/ethereum/go-ethereum/common" +// "github.com/ethereum/go-ethereum/common" // "github.com/ethereum/go-ethereum/consensus/ethash" // ethcore "github.com/ethereum/go-ethereum/core" // ethtypes "github.com/ethereum/go-ethereum/core/types" // ethvm "github.com/ethereum/go-ethereum/core/vm" -// ethcrypto "github.com/ethereum/go-ethereum/crypto" +// "github.com/ethereum/go-ethereum/crypto" // ethparams "github.com/ethereum/go-ethereum/params" // ethrlp "github.com/ethereum/go-ethereum/rlp" @@ -56,7 +56,7 @@ package importer // flagBlockchain string // flagCPUProfile string -// genInvestor = ethcmn.HexToAddress("0x756F45E3FA69347A9A973A725E3C98bC4db0b5a0") +// genInvestor = common.HexToAddress("0x756F45E3FA69347A9A973A725E3C98bC4db0b5a0") // logger = tmlog.NewNopLogger() @@ -125,7 +125,7 @@ package importer // sort.Strings(genAddrs) // for _, addrStr := range genAddrs { -// addr := ethcmn.HexToAddress(addrStr) +// addr := common.HexToAddress(addrStr) // acc := genBlock.Alloc[addr] // evmKeeper.AddBalance(addr, acc.Balance) @@ -348,7 +348,7 @@ package importer // // Function is also pulled from go-ethereum 1.9 because of the incompatible usage // // Ref: https://github.com/ethereum/go-ethereum/blob/52f2461774bcb8cdd310f86b4bc501df5b783852/core/state_processor.go#L88 // func applyTransaction( -// config *ethparams.ChainConfig, bc ethcore.ChainContext, author *ethcmn.Address, +// config *ethparams.ChainConfig, bc ethcore.ChainContext, author *common.Address, // gp *ethcore.GasPool, evmKeeper *evmkeeper.Keeper, header *ethtypes.Header, // tx *ethtypes.Transaction, usedGas *uint64, cfg ethvm.Config, // ) (*ethtypes.Receipt, uint64, error) { @@ -376,7 +376,7 @@ package importer // return nil, execResult.UsedGas, err // } -// root := ethcmn.Hash{}.Bytes() +// root := common.Hash{}.Bytes() // *usedGas += execResult.UsedGas // // Create a new receipt for the transaction, storing the intermediate root and gas used by the tx @@ -387,7 +387,7 @@ package importer // // if the transaction created a contract, store the creation address in the receipt. // if msg.To() == nil { -// receipt.ContractAddress = ethcrypto.CreateAddress(vmenv.TxContext.Origin, tx.Nonce()) +// receipt.ContractAddress = crypto.CreateAddress(vmenv.TxContext.Origin, tx.Nonce()) // } // // Set the receipt logs and create a bloom for filtering diff --git a/tests/rpc/personal_test.go b/tests/rpc/personal_test.go index 315f776c..7206edcb 100644 --- a/tests/rpc/personal_test.go +++ b/tests/rpc/personal_test.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - ethcrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto" ) func TestPersonal_ListAccounts(t *testing.T) { @@ -47,18 +47,18 @@ func TestPersonal_Sign(t *testing.T) { } func TestPersonal_ImportRawKey(t *testing.T) { - privkey, err := ethcrypto.GenerateKey() + privkey, err := crypto.GenerateKey() require.NoError(t, err) // parse priv key to hex - hexPriv := common.Bytes2Hex(ethcrypto.FromECDSA(privkey)) + hexPriv := common.Bytes2Hex(crypto.FromECDSA(privkey)) rpcRes := Call(t, "personal_importRawKey", []string{hexPriv, "password"}) var res hexutil.Bytes err = json.Unmarshal(rpcRes.Result, &res) require.NoError(t, err) - addr := ethcrypto.PubkeyToAddress(privkey.PublicKey) + addr := crypto.PubkeyToAddress(privkey.PublicKey) resAddr := common.BytesToAddress(res) require.Equal(t, addr.String(), resAddr.String()) diff --git a/tests/rpc/rpc_test.go b/tests/rpc/rpc_test.go index 5a2ee1d6..f7066f9f 100644 --- a/tests/rpc/rpc_test.go +++ b/tests/rpc/rpc_test.go @@ -23,7 +23,7 @@ import ( ethermint "github.com/tharsis/ethermint/types" evmtypes "github.com/tharsis/ethermint/x/evm/types" - ethcmn "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" ethtypes "github.com/ethereum/go-ethereum/core/types" ) @@ -339,7 +339,7 @@ func TestEth_blockNumber(t *testing.T) { } func TestEth_coinbase(t *testing.T) { - zeroAddress := hexutil.Bytes(ethcmn.Address{}.Bytes()) + zeroAddress := hexutil.Bytes(common.Address{}.Bytes()) rpcRes := call(t, "eth_coinbase", []string{}) var res hexutil.Bytes @@ -470,7 +470,7 @@ func TestEth_GetFilterChanges_BlockFilter(t *testing.T) { time.Sleep(5 * time.Second) changesRes := call(t, "eth_getFilterChanges", []string{ID}) - var hashes []ethcmn.Hash + var hashes []common.Hash err = json.Unmarshal(changesRes.Result, &hashes) require.NoError(t, err) require.GreaterOrEqual(t, len(hashes), 1) @@ -579,7 +579,7 @@ func TestEth_GetTransactionReceipt_ContractDeployment(t *testing.T) { require.NoError(t, err) require.Equal(t, "0x1", receipt["status"].(string)) - require.NotEqual(t, ethcmn.Address{}.String(), receipt["contractAddress"].(string)) + require.NotEqual(t, common.Address{}.String(), receipt["contractAddress"].(string)) require.NotNil(t, receipt["logs"]) } diff --git a/types/account.go b/types/account.go index 4c7750cd..1ae654b2 100644 --- a/types/account.go +++ b/types/account.go @@ -5,7 +5,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/ethereum/go-ethereum/common" - ethcrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto" ) var ( @@ -23,7 +23,7 @@ var ( func ProtoAccount() authtypes.AccountI { return &EthAccount{ BaseAccount: &authtypes.BaseAccount{}, - CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).String(), + CodeHash: common.BytesToHash(crypto.Keccak256(nil)).String(), } } diff --git a/types/validation.go b/types/validation.go index 9f895655..6e98f236 100644 --- a/types/validation.go +++ b/types/validation.go @@ -3,24 +3,23 @@ package types import ( "bytes" - ethcmn "github.com/ethereum/go-ethereum/common" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/ethereum/go-ethereum/common" ) // IsEmptyHash returns true if the hash corresponds to an empty ethereum hex hash. func IsEmptyHash(hash string) bool { - return bytes.Equal(ethcmn.HexToHash(hash).Bytes(), ethcmn.Hash{}.Bytes()) + return bytes.Equal(common.HexToHash(hash).Bytes(), common.Hash{}.Bytes()) } // IsZeroAddress returns true if the address corresponds to an empty ethereum hex address. func IsZeroAddress(address string) bool { - return bytes.Equal(ethcmn.HexToAddress(address).Bytes(), ethcmn.Address{}.Bytes()) + return bytes.Equal(common.HexToAddress(address).Bytes(), common.Address{}.Bytes()) } // ValidateAddress returns an error if the provided string is either not a hex formatted string address func ValidateAddress(address string) error { - if !ethcmn.IsHexAddress(address) { + if !common.IsHexAddress(address) { return sdkerrors.Wrapf( sdkerrors.ErrInvalidAddress, "address '%s' is not a valid ethereum hex address", address, diff --git a/types/validation_test.go b/types/validation_test.go index 7b04d272..50a143f0 100644 --- a/types/validation_test.go +++ b/types/validation_test.go @@ -3,9 +3,8 @@ package types import ( "testing" + "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" - - ethcmn "github.com/ethereum/go-ethereum/common" ) func TestIsEmptyHash(t *testing.T) { @@ -18,11 +17,11 @@ func TestIsEmptyHash(t *testing.T) { "empty string", "", true, }, { - "zero hash", ethcmn.Hash{}.String(), true, + "zero hash", common.Hash{}.String(), true, }, { - "non-empty hash", ethcmn.BytesToHash([]byte{1, 2, 3, 4}).String(), false, + "non-empty hash", common.BytesToHash([]byte{1, 2, 3, 4}).String(), false, }, } @@ -41,11 +40,11 @@ func TestIsZeroAddress(t *testing.T) { "empty string", "", true, }, { - "zero address", ethcmn.Address{}.String(), true, + "zero address", common.Address{}.String(), true, }, { - "non-empty address", ethcmn.BytesToAddress([]byte{1, 2, 3, 4}).String(), false, + "non-empty address", common.BytesToAddress([]byte{1, 2, 3, 4}).String(), false, }, } diff --git a/x/evm/atlas/atlas-v0.3.1.md b/x/evm/atlas/atlas-v0.3.1.md index aa7880f3..0c768f9e 100644 --- a/x/evm/atlas/atlas-v0.3.1.md +++ b/x/evm/atlas/atlas-v0.3.1.md @@ -130,7 +130,7 @@ type GenesisAccount struct { type TransactionLogs struct { - Hash ethcmn.Hash `json:"hash"` + Hash common.Hash `json:"hash"` Logs []*ethtypes.Log `json:"logs"` } diff --git a/x/evm/genesis.go b/x/evm/genesis.go index f207c92e..f2406d5f 100644 --- a/x/evm/genesis.go +++ b/x/evm/genesis.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - ethcmn "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" abci "github.com/tendermint/tendermint/abci/types" ethermint "github.com/tharsis/ethermint/types" @@ -31,7 +31,7 @@ func InitGenesis( } for _, account := range data.Accounts { - address := ethcmn.HexToAddress(account.Address) + address := common.HexToAddress(account.Address) accAddress := sdk.AccAddress(address.Bytes()) // check that the EVM balance the matches the account balance acc := accountKeeper.GetAccount(ctx, accAddress) @@ -48,15 +48,15 @@ func InitGenesis( ) } - k.SetCode(address, ethcmn.Hex2Bytes(account.Code)) + k.SetCode(address, common.Hex2Bytes(account.Code)) for _, storage := range account.Storage { - k.SetState(address, ethcmn.HexToHash(storage.Key), ethcmn.HexToHash(storage.Value)) + k.SetState(address, common.HexToHash(storage.Key), common.HexToHash(storage.Value)) } } for _, txLog := range data.TxsLogs { - k.SetLogs(ethcmn.HexToHash(txLog.Hash), txLog.EthLogs()) + k.SetLogs(common.HexToHash(txLog.Hash), txLog.EthLogs()) } return []abci.ValidatorUpdate{} @@ -83,7 +83,7 @@ func ExportGenesis(ctx sdk.Context, k *keeper.Keeper, ak types.AccountKeeper) *t genAccount := types.GenesisAccount{ Address: addr.String(), - Code: ethcmn.Bytes2Hex(k.GetCode(addr)), + Code: common.Bytes2Hex(k.GetCode(addr)), Storage: storage, } diff --git a/x/evm/handler_test.go b/x/evm/handler_test.go index ed063d8d..fc8046ba 100644 --- a/x/evm/handler_test.go +++ b/x/evm/handler_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/suite" - ethcmn "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/cosmos/cosmos-sdk/codec" @@ -33,7 +33,7 @@ type EvmTestSuite struct { signer keyring.Signer ethSigner ethtypes.Signer - from ethcmn.Address + from common.Address to sdk.AccAddress } @@ -57,7 +57,7 @@ func (suite *EvmTestSuite) SetupTest() { suite.signer = tests.NewSigner(privKey) suite.ethSigner = ethtypes.LatestSignerForChainID(suite.chainID) - suite.from = ethcmn.BytesToAddress(privKey.PubKey().Address().Bytes()) + suite.from = common.BytesToAddress(privKey.PubKey().Address().Bytes()) } @@ -77,7 +77,7 @@ func TestEvmTestSuite(t *testing.T) { // { // "passed", // func() { -// to := ethcmn.BytesToAddress(suite.to) +// to := common.BytesToAddress(suite.to) // tx = types.NewTx(suite.chainID, 0, &to, big.NewInt(100), 0, big.NewInt(10000), nil, nil) // tx.From = suite.from.String() @@ -181,10 +181,10 @@ func TestEvmTestSuite(t *testing.T) { // suite.Require().Equal(len(txResponse.Logs[0].Topics), 2) // hash := []byte{1} -// suite.app.EvmKeeper.SetLogs(ethcmn.BytesToHash(hash), types.LogsToEthereum(txResponse.Logs)) +// suite.app.EvmKeeper.SetLogs(common.BytesToHash(hash), types.LogsToEthereum(txResponse.Logs)) // suite.Require().NoError(err) -// logs := suite.app.EvmKeeper.GetTxLogs(ethcmn.BytesToHash(hash)) +// logs := suite.app.EvmKeeper.GetTxLogs(common.BytesToHash(hash)) // suite.Require().Equal(logs, txResponse.Logs) // } @@ -302,7 +302,7 @@ func TestEvmTestSuite(t *testing.T) { // gasPrice := big.NewInt(0x55ae82600) // // send simple value transfer with gasLimit=21000 -// tx := types.NewTx(suite.chainID, 1, ðcmn.Address{0x1}, big.NewInt(1), gasLimit, gasPrice, nil, nil) +// tx := types.NewTx(suite.chainID, 1, &common.Address{0x1}, big.NewInt(1), gasLimit, gasPrice, nil, nil) // tx.From = suite.from.String() // err := tx.Sign(suite.ethSigner, suite.signer) // suite.Require().NoError(err) diff --git a/x/evm/keeper/grpc_query.go b/x/evm/keeper/grpc_query.go index b706b2f7..3931dead 100644 --- a/x/evm/keeper/grpc_query.go +++ b/x/evm/keeper/grpc_query.go @@ -15,7 +15,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" - ethcmn "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core" ethtypes "github.com/ethereum/go-ethereum/core/types" @@ -40,7 +40,7 @@ func (k Keeper) Account(c context.Context, req *types.QueryAccountRequest) (*typ ) } - addr := ethcmn.HexToAddress(req.Address) + addr := common.HexToAddress(req.Address) ctx := sdk.UnwrapSDKContext(c) k.WithContext(ctx) @@ -66,7 +66,7 @@ func (k Keeper) CosmosAccount(c context.Context, req *types.QueryCosmosAccountRe ctx := sdk.UnwrapSDKContext(c) k.WithContext(ctx) - ethAddr := ethcmn.HexToAddress(req.Address) + ethAddr := common.HexToAddress(req.Address) cosmosAddr := sdk.AccAddress(ethAddr.Bytes()) account := k.accountKeeper.GetAccount(ctx, cosmosAddr) @@ -134,7 +134,7 @@ func (k Keeper) Balance(c context.Context, req *types.QueryBalanceRequest) (*typ ctx := sdk.UnwrapSDKContext(c) k.WithContext(ctx) - balanceInt := k.GetBalance(ethcmn.HexToAddress(req.Address)) + balanceInt := k.GetBalance(common.HexToAddress(req.Address)) return &types.QueryBalanceResponse{ Balance: balanceInt.String(), @@ -157,8 +157,8 @@ func (k Keeper) Storage(c context.Context, req *types.QueryStorageRequest) (*typ ctx := sdk.UnwrapSDKContext(c) k.WithContext(ctx) - address := ethcmn.HexToAddress(req.Address) - key := ethcmn.HexToHash(req.Key) + address := common.HexToAddress(req.Address) + key := common.HexToHash(req.Key) state := k.GetState(address, key) stateHex := state.Hex() @@ -184,7 +184,7 @@ func (k Keeper) Code(c context.Context, req *types.QueryCodeRequest) (*types.Que ctx := sdk.UnwrapSDKContext(c) k.WithContext(ctx) - address := ethcmn.HexToAddress(req.Address) + address := common.HexToAddress(req.Address) code := k.GetCode(address) return &types.QueryCodeResponse{ @@ -208,7 +208,7 @@ func (k Keeper) TxLogs(c context.Context, req *types.QueryTxLogsRequest) (*types ctx := sdk.UnwrapSDKContext(c) k.WithContext(ctx) - hash := ethcmn.HexToHash(req.Hash) + hash := common.HexToHash(req.Hash) logs := k.GetTxLogs(hash) return &types.QueryTxLogsResponse{ diff --git a/x/evm/keeper/grpc_query_test.go b/x/evm/keeper/grpc_query_test.go index 7de674ad..f0e91d4c 100644 --- a/x/evm/keeper/grpc_query_test.go +++ b/x/evm/keeper/grpc_query_test.go @@ -8,10 +8,9 @@ import ( "google.golang.org/grpc/metadata" "github.com/ethereum/go-ethereum/common" - ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" ethtypes "github.com/ethereum/go-ethereum/core/types" - ethcrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto" sdk "github.com/cosmos/cosmos-sdk/types" @@ -40,7 +39,7 @@ func (suite *KeeperTestSuite) TestQueryAccount() { func() { expAccount = &types.QueryAccountResponse{ Balance: "0", - CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).Hex(), + CodeHash: common.BytesToHash(crypto.Keccak256(nil)).Hex(), Nonce: 0, } req = &types.QueryAccountRequest{ @@ -60,7 +59,7 @@ func (suite *KeeperTestSuite) TestQueryAccount() { expAccount = &types.QueryAccountResponse{ Balance: "100", - CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).Hex(), + CodeHash: common.BytesToHash(crypto.Keccak256(nil)).Hex(), Nonce: 0, } req = &types.QueryAccountRequest{ @@ -105,7 +104,7 @@ func (suite *KeeperTestSuite) TestQueryCosmosAccount() { {"invalid address", func() { expAccount = &types.QueryCosmosAccountResponse{ - CosmosAddress: sdk.AccAddress(ethcmn.Address{}.Bytes()).String(), + CosmosAddress: sdk.AccAddress(common.Address{}.Bytes()).String(), } req = &types.QueryCosmosAccountRequest{ Address: invalidAddress, @@ -248,8 +247,8 @@ func (suite *KeeperTestSuite) TestQueryStorage() { { "success", func() { - key := ethcmn.BytesToHash([]byte("key")) - value := ethcmn.BytesToHash([]byte("value")) + key := common.BytesToHash([]byte("key")) + value := common.BytesToHash([]byte("value")) expValue = value.String() suite.app.EvmKeeper.SetState(suite.address, key, value) req = &types.QueryStorageRequest{ @@ -350,14 +349,14 @@ func (suite *KeeperTestSuite) TestQueryTxLogs() { {"empty hash", func() { req = &types.QueryTxLogsRequest{ - Hash: ethcmn.Hash{}.String(), + Hash: common.Hash{}.String(), } }, false, }, {"logs not found", func() { - hash := ethcmn.BytesToHash([]byte("hash")) + hash := common.BytesToHash([]byte("hash")) req = &types.QueryTxLogsRequest{ Hash: hash.String(), } @@ -367,17 +366,17 @@ func (suite *KeeperTestSuite) TestQueryTxLogs() { { "success", func() { - hash := ethcmn.BytesToHash([]byte("tx_hash")) + hash := common.BytesToHash([]byte("tx_hash")) expLogs = []*types.Log{ { Address: suite.address.String(), - Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()}, + Topics: []string{common.BytesToHash([]byte("topic")).String()}, Data: []byte("data"), BlockNumber: 1, TxHash: hash.String(), TxIndex: 1, - BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), + BlockHash: common.BytesToHash([]byte("block_hash")).String(), Index: 0, Removed: false, }, @@ -427,14 +426,14 @@ func (suite *KeeperTestSuite) TestQueryBlockLogs() { {"empty hash", func() { req = &types.QueryBlockLogsRequest{ - Hash: ethcmn.Hash{}.String(), + Hash: common.Hash{}.String(), } }, false, }, {"logs not found", func() { - hash := ethcmn.BytesToHash([]byte("hash")) + hash := common.BytesToHash([]byte("hash")) req = &types.QueryBlockLogsRequest{ Hash: hash.String(), } @@ -445,46 +444,46 @@ func (suite *KeeperTestSuite) TestQueryBlockLogs() { "success", func() { - hash := ethcmn.BytesToHash([]byte("block_hash")) + hash := common.BytesToHash([]byte("block_hash")) expLogs = []types.TransactionLogs{ { - Hash: ethcmn.BytesToHash([]byte("tx_hash_0")).String(), + Hash: common.BytesToHash([]byte("tx_hash_0")).String(), Logs: []*types.Log{ { Address: suite.address.String(), - Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()}, + Topics: []string{common.BytesToHash([]byte("topic")).String()}, Data: []byte("data"), BlockNumber: 1, - TxHash: ethcmn.BytesToHash([]byte("tx_hash_0")).String(), + TxHash: common.BytesToHash([]byte("tx_hash_0")).String(), TxIndex: 1, - BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), + BlockHash: common.BytesToHash([]byte("block_hash")).String(), Index: 0, Removed: false, }, }, }, { - Hash: ethcmn.BytesToHash([]byte("tx_hash_1")).String(), + Hash: common.BytesToHash([]byte("tx_hash_1")).String(), Logs: []*types.Log{ { Address: suite.address.String(), - Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()}, + Topics: []string{common.BytesToHash([]byte("topic")).String()}, Data: []byte("data"), BlockNumber: 1, - TxHash: ethcmn.BytesToHash([]byte("tx_hash_1")).String(), + TxHash: common.BytesToHash([]byte("tx_hash_1")).String(), TxIndex: 1, - BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), + BlockHash: common.BytesToHash([]byte("block_hash")).String(), Index: 1, Removed: false, }, { Address: suite.address.String(), - Topics: []string{ethcmn.BytesToHash([]byte("topic_1")).String()}, + Topics: []string{common.BytesToHash([]byte("topic_1")).String()}, Data: []byte("data_1"), BlockNumber: 1, - TxHash: ethcmn.BytesToHash([]byte("tx_hash_1")).String(), + TxHash: common.BytesToHash([]byte("tx_hash_1")).String(), TxIndex: 1, - BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), + BlockHash: common.BytesToHash([]byte("block_hash")).String(), Index: 2, Removed: false, }, @@ -492,8 +491,8 @@ func (suite *KeeperTestSuite) TestQueryBlockLogs() { }, } - suite.app.EvmKeeper.SetLogs(ethcmn.BytesToHash([]byte("tx_hash_0")), types.LogsToEthereum(expLogs[0].Logs)) - suite.app.EvmKeeper.SetLogs(ethcmn.BytesToHash([]byte("tx_hash_1")), types.LogsToEthereum(expLogs[1].Logs)) + suite.app.EvmKeeper.SetLogs(common.BytesToHash([]byte("tx_hash_0")), types.LogsToEthereum(expLogs[0].Logs)) + suite.app.EvmKeeper.SetLogs(common.BytesToHash([]byte("tx_hash_1")), types.LogsToEthereum(expLogs[1].Logs)) req = &types.QueryBlockLogsRequest{ Hash: hash.String(), @@ -618,7 +617,7 @@ func (suite *KeeperTestSuite) TestQueryValidatorAccount() { {"invalid address", func() { expAccount = &types.QueryValidatorAccountResponse{ - AccountAddress: sdk.AccAddress(ethcmn.Address{}.Bytes()).String(), + AccountAddress: sdk.AccAddress(common.Address{}.Bytes()).String(), } req = &types.QueryValidatorAccountRequest{ ConsAddress: "", diff --git a/x/evm/keeper/hooks.go b/x/evm/keeper/hooks.go index 66057f4c..104d00e9 100644 --- a/x/evm/keeper/hooks.go +++ b/x/evm/keeper/hooks.go @@ -3,7 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - ethcmn "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/tharsis/ethermint/x/evm/types" ) @@ -21,7 +21,7 @@ func NewMultiEvmHooks(hooks ...types.EvmHooks) MultiEvmHooks { } // PostTxProcessing delegate the call to underlying hooks -func (mh MultiEvmHooks) PostTxProcessing(ctx sdk.Context, txHash ethcmn.Hash, logs []*ethtypes.Log) error { +func (mh MultiEvmHooks) PostTxProcessing(ctx sdk.Context, txHash common.Hash, logs []*ethtypes.Log) error { for i := range mh { if err := mh[i].PostTxProcessing(ctx, txHash, logs); err != nil { return sdkerrors.Wrapf(err, "EVM hook %T failed", mh[i]) diff --git a/x/evm/keeper/keeper_test.go b/x/evm/keeper/keeper_test.go index aa177977..d5019807 100644 --- a/x/evm/keeper/keeper_test.go +++ b/x/evm/keeper/keeper_test.go @@ -28,11 +28,9 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" - ethcrypto "github.com/ethereum/go-ethereum/crypto" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/tmhash" @@ -72,7 +70,7 @@ type KeeperTestSuite struct { ctx sdk.Context app *app.EthermintApp queryClient types.QueryClient - address ethcmn.Address + address common.Address consAddress sdk.ConsAddress // for generate test tx @@ -90,7 +88,7 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) { // account key priv, err := ethsecp256k1.GenerateKey() require.NoError(t, err) - suite.address = ethcmn.BytesToAddress(priv.PubKey().Address().Bytes()) + suite.address = common.BytesToAddress(priv.PubKey().Address().Bytes()) suite.signer = tests.NewSigner(priv) // consensus key @@ -130,7 +128,7 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) { acc := ðermint.EthAccount{ BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), nil, 0, 0), - CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).String(), + CodeHash: common.BytesToHash(crypto.Keccak256(nil)).String(), } suite.app.AccountKeeper.SetAccount(suite.ctx, acc) diff --git a/x/evm/keeper/statedb_test.go b/x/evm/keeper/statedb_test.go index 30defc08..210a3c22 100644 --- a/x/evm/keeper/statedb_test.go +++ b/x/evm/keeper/statedb_test.go @@ -16,7 +16,6 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/tharsis/ethermint/tests" "github.com/tharsis/ethermint/x/evm/types" - evmtypes "github.com/tharsis/ethermint/x/evm/types" ) func (suite *KeeperTestSuite) TestCreateAccount() { @@ -533,8 +532,8 @@ func (suite *KeeperTestSuite) TestSnapshot() { } } -func (suite *KeeperTestSuite) CreateTestTx(msg *evmtypes.MsgEthereumTx, priv cryptotypes.PrivKey) authsigning.Tx { - option, err := codectypes.NewAnyWithValue(&evmtypes.ExtensionOptionsEthereumTx{}) +func (suite *KeeperTestSuite) CreateTestTx(msg *types.MsgEthereumTx, priv cryptotypes.PrivKey) authsigning.Tx { + option, err := codectypes.NewAnyWithValue(&types.ExtensionOptionsEthereumTx{}) suite.Require().NoError(err) txBuilder := suite.clientCtx.TxConfig.NewTxBuilder() @@ -558,14 +557,14 @@ func (suite *KeeperTestSuite) TestAddLog() { msg.From = addr.Hex() tx := suite.CreateTestTx(msg, privKey) - msg, _ = tx.GetMsgs()[0].(*evmtypes.MsgEthereumTx) + msg, _ = tx.GetMsgs()[0].(*types.MsgEthereumTx) txHash := msg.AsTransaction().Hash() msg2 := types.NewTx(big.NewInt(1), 1, &suite.address, big.NewInt(1), 100000, big.NewInt(1), []byte("test"), nil) msg2.From = addr.Hex() tx2 := suite.CreateTestTx(msg2, privKey) - msg2, _ = tx2.GetMsgs()[0].(*evmtypes.MsgEthereumTx) + msg2, _ = tx2.GetMsgs()[0].(*types.MsgEthereumTx) txHash2 := msg2.AsTransaction().Hash() testCases := []struct { diff --git a/x/evm/types/access_list.go b/x/evm/types/access_list.go index 4a0196df..7ebc63fd 100644 --- a/x/evm/types/access_list.go +++ b/x/evm/types/access_list.go @@ -1,7 +1,7 @@ package types import ( - ethcmn "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" ) @@ -39,14 +39,14 @@ func (al AccessList) ToEthAccessList() *ethtypes.AccessList { var ethAccessList ethtypes.AccessList for _, tuple := range al { - storageKeys := make([]ethcmn.Hash, len(tuple.StorageKeys)) + storageKeys := make([]common.Hash, len(tuple.StorageKeys)) for i := range tuple.StorageKeys { - storageKeys[i] = ethcmn.HexToHash(tuple.StorageKeys[i]) + storageKeys[i] = common.HexToHash(tuple.StorageKeys[i]) } ethAccessList = append(ethAccessList, ethtypes.AccessTuple{ - Address: ethcmn.HexToAddress(tuple.Address), + Address: common.HexToAddress(tuple.Address), StorageKeys: storageKeys, }) } diff --git a/x/evm/types/genesis_test.go b/x/evm/types/genesis_test.go index d5f961bc..9a36177b 100644 --- a/x/evm/types/genesis_test.go +++ b/x/evm/types/genesis_test.go @@ -3,10 +3,9 @@ package types import ( "testing" + "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/suite" - ethcmn "github.com/ethereum/go-ethereum/common" - "github.com/tharsis/ethermint/crypto/ethsecp256k1" ) @@ -14,7 +13,7 @@ type GenesisTestSuite struct { suite.Suite address string - hash ethcmn.Hash + hash common.Hash code string } @@ -22,9 +21,9 @@ func (suite *GenesisTestSuite) SetupTest() { priv, err := ethsecp256k1.GenerateKey() suite.Require().NoError(err) - suite.address = ethcmn.BytesToAddress(priv.PubKey().Address().Bytes()).String() - suite.hash = ethcmn.BytesToHash([]byte("hash")) - suite.code = ethcmn.Bytes2Hex([]byte{1, 2, 3}) + suite.address = common.BytesToAddress(priv.PubKey().Address().Bytes()).String() + suite.hash = common.BytesToHash([]byte("hash")) + suite.code = common.Bytes2Hex([]byte{1, 2, 3}) } func TestGenesisTestSuite(t *testing.T) { @@ -141,7 +140,7 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { genState: &GenesisState{ Accounts: []GenesisAccount{ { - Address: ethcmn.Address{}.String(), + Address: common.Address{}.String(), }, }, }, @@ -234,7 +233,7 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { }, }, }, - TxsLogs: []TransactionLogs{NewTransactionLogs(ethcmn.Hash{}, nil)}, + TxsLogs: []TransactionLogs{NewTransactionLogs(common.Hash{}, nil)}, }, expPass: false, }, diff --git a/x/evm/types/interfaces.go b/x/evm/types/interfaces.go index 642b7b9f..4efd2142 100644 --- a/x/evm/types/interfaces.go +++ b/x/evm/types/interfaces.go @@ -4,7 +4,7 @@ import ( 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" - ethcmn "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" ) @@ -43,5 +43,5 @@ type StakingKeeper interface { // EvmHooks event hooks for evm tx processing type EvmHooks interface { // Must be called after tx is processed successfully, if return an error, the whole transaction is reverted. - PostTxProcessing(ctx sdk.Context, txHash ethcmn.Hash, logs []*ethtypes.Log) error + PostTxProcessing(ctx sdk.Context, txHash common.Hash, logs []*ethtypes.Log) error } diff --git a/x/evm/types/key.go b/x/evm/types/key.go index 02de5939..4057c44d 100644 --- a/x/evm/types/key.go +++ b/x/evm/types/key.go @@ -3,8 +3,8 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" - ethcmn "github.com/ethereum/go-ethereum/common" - ethcrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" ) const ( @@ -73,18 +73,18 @@ func BloomKey(height int64) []byte { } // AddressStoragePrefix returns a prefix to iterate over a given account storage. -func AddressStoragePrefix(address ethcmn.Address) []byte { +func AddressStoragePrefix(address common.Address) []byte { return append(KeyPrefixStorage, address.Bytes()...) } // StateKey defines the full key under which an account state is stored. -func StateKey(address ethcmn.Address, key []byte) []byte { +func StateKey(address common.Address, key []byte) []byte { return append(AddressStoragePrefix(address), key...) } // KeyAddressStorage returns the key hash to access a given account state. The composite key // (address + hash) is hashed using Keccak256. -func KeyAddressStorage(address ethcmn.Address, hash ethcmn.Hash) ethcmn.Hash { +func KeyAddressStorage(address common.Address, hash common.Hash) common.Hash { prefix := address.Bytes() key := hash.Bytes() @@ -93,5 +93,5 @@ func KeyAddressStorage(address ethcmn.Address, hash ethcmn.Hash) ethcmn.Hash { copy(compositeKey, prefix) copy(compositeKey[len(prefix):], key) - return ethcrypto.Keccak256Hash(compositeKey) + return crypto.Keccak256Hash(compositeKey) } diff --git a/x/evm/types/logs.go b/x/evm/types/logs.go index 47f2e0d6..636424c9 100644 --- a/x/evm/types/logs.go +++ b/x/evm/types/logs.go @@ -4,14 +4,14 @@ import ( "errors" "fmt" - ethcmn "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" ethermint "github.com/tharsis/ethermint/types" ) // NewTransactionLogs creates a new NewTransactionLogs instance. -func NewTransactionLogs(hash ethcmn.Hash, logs []*Log) TransactionLogs { // nolint: interfacer +func NewTransactionLogs(hash common.Hash, logs []*Log) TransactionLogs { // nolint: interfacer return TransactionLogs{ Hash: hash.String(), Logs: logs, @@ -19,7 +19,7 @@ func NewTransactionLogs(hash ethcmn.Hash, logs []*Log) TransactionLogs { // noli } // NewTransactionLogsFromEth creates a new NewTransactionLogs instance using []*ethtypes.Log. -func NewTransactionLogsFromEth(hash ethcmn.Hash, ethlogs []*ethtypes.Log) TransactionLogs { // nolint: interfacer +func NewTransactionLogsFromEth(hash common.Hash, ethlogs []*ethtypes.Log) TransactionLogs { // nolint: interfacer return TransactionLogs{ Hash: hash.String(), Logs: NewLogsFromEth(ethlogs), @@ -70,20 +70,20 @@ func (log *Log) Validate() error { // ToEthereum returns the Ethereum type Log from a Ethermint proto compatible Log. func (log *Log) ToEthereum() *ethtypes.Log { - var topics []ethcmn.Hash // nolint: prealloc + var topics []common.Hash // nolint: prealloc for i := range log.Topics { - topics = append(topics, ethcmn.HexToHash(log.Topics[i])) + topics = append(topics, common.HexToHash(log.Topics[i])) } return ðtypes.Log{ - Address: ethcmn.HexToAddress(log.Address), + Address: common.HexToAddress(log.Address), Topics: topics, Data: log.Data, BlockNumber: log.BlockNumber, - TxHash: ethcmn.HexToHash(log.TxHash), + TxHash: common.HexToHash(log.TxHash), TxIndex: uint(log.TxIndex), Index: uint(log.Index), - BlockHash: ethcmn.HexToHash(log.BlockHash), + BlockHash: common.HexToHash(log.BlockHash), Removed: log.Removed, } } diff --git a/x/evm/types/logs_test.go b/x/evm/types/logs_test.go index 17ec38c0..1302d3fe 100644 --- a/x/evm/types/logs_test.go +++ b/x/evm/types/logs_test.go @@ -7,14 +7,14 @@ import ( "github.com/tharsis/ethermint/crypto/ethsecp256k1" - ethcmn "github.com/ethereum/go-ethereum/common" - ethcrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" ) func TestTransactionLogsValidate(t *testing.T) { priv, err := ethsecp256k1.GenerateKey() require.NoError(t, err) - addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String() + addr := crypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String() testCases := []struct { name string @@ -24,16 +24,16 @@ func TestTransactionLogsValidate(t *testing.T) { { "valid log", TransactionLogs{ - Hash: ethcmn.BytesToHash([]byte("tx_hash")).String(), + Hash: common.BytesToHash([]byte("tx_hash")).String(), Logs: []*Log{ { Address: addr, - Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()}, + Topics: []string{common.BytesToHash([]byte("topic")).String()}, Data: []byte("data"), BlockNumber: 1, - TxHash: ethcmn.BytesToHash([]byte("tx_hash")).String(), + TxHash: common.BytesToHash([]byte("tx_hash")).String(), TxIndex: 1, - BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), + BlockHash: common.BytesToHash([]byte("block_hash")).String(), Index: 1, Removed: false, }, @@ -44,14 +44,14 @@ func TestTransactionLogsValidate(t *testing.T) { { "empty hash", TransactionLogs{ - Hash: ethcmn.Hash{}.String(), + Hash: common.Hash{}.String(), }, false, }, { "invalid log", TransactionLogs{ - Hash: ethcmn.BytesToHash([]byte("tx_hash")).String(), + Hash: common.BytesToHash([]byte("tx_hash")).String(), Logs: []*Log{{}}, }, false, @@ -59,16 +59,16 @@ func TestTransactionLogsValidate(t *testing.T) { { "hash mismatch log", TransactionLogs{ - Hash: ethcmn.BytesToHash([]byte("tx_hash")).String(), + Hash: common.BytesToHash([]byte("tx_hash")).String(), Logs: []*Log{ { Address: addr, - Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()}, + Topics: []string{common.BytesToHash([]byte("topic")).String()}, Data: []byte("data"), BlockNumber: 1, - TxHash: ethcmn.BytesToHash([]byte("other_hash")).String(), + TxHash: common.BytesToHash([]byte("other_hash")).String(), TxIndex: 1, - BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), + BlockHash: common.BytesToHash([]byte("block_hash")).String(), Index: 1, Removed: false, }, @@ -92,7 +92,7 @@ func TestTransactionLogsValidate(t *testing.T) { func TestValidateLog(t *testing.T) { priv, err := ethsecp256k1.GenerateKey() require.NoError(t, err) - addr := ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String() + addr := crypto.PubkeyToAddress(priv.ToECDSA().PublicKey).String() testCases := []struct { name string @@ -103,12 +103,12 @@ func TestValidateLog(t *testing.T) { "valid log", &Log{ Address: addr, - Topics: []string{ethcmn.BytesToHash([]byte("topic")).String()}, + Topics: []string{common.BytesToHash([]byte("topic")).String()}, Data: []byte("data"), BlockNumber: 1, - TxHash: ethcmn.BytesToHash([]byte("tx_hash")).String(), + TxHash: common.BytesToHash([]byte("tx_hash")).String(), TxIndex: 1, - BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), + BlockHash: common.BytesToHash([]byte("block_hash")).String(), Index: 1, Removed: false, }, @@ -120,7 +120,7 @@ func TestValidateLog(t *testing.T) { { "zero address", &Log{ - Address: ethcmn.Address{}.String(), + Address: common.Address{}.String(), }, false, }, @@ -128,7 +128,7 @@ func TestValidateLog(t *testing.T) { "empty block hash", &Log{ Address: addr, - BlockHash: ethcmn.Hash{}.String(), + BlockHash: common.Hash{}.String(), }, false, }, @@ -136,7 +136,7 @@ func TestValidateLog(t *testing.T) { "zero block number", &Log{ Address: addr, - BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), + BlockHash: common.BytesToHash([]byte("block_hash")).String(), BlockNumber: 0, }, false, @@ -145,9 +145,9 @@ func TestValidateLog(t *testing.T) { "empty tx hash", &Log{ Address: addr, - BlockHash: ethcmn.BytesToHash([]byte("block_hash")).String(), + BlockHash: common.BytesToHash([]byte("block_hash")).String(), BlockNumber: 1, - TxHash: ethcmn.Hash{}.String(), + TxHash: common.Hash{}.String(), }, false, }, diff --git a/x/evm/types/msg_test.go b/x/evm/types/msg_test.go index f9396be9..456b96f3 100644 --- a/x/evm/types/msg_test.go +++ b/x/evm/types/msg_test.go @@ -12,9 +12,7 @@ import ( "github.com/tharsis/ethermint/tests" "github.com/ethereum/go-ethereum/common" - ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" ) @@ -24,8 +22,8 @@ type MsgsTestSuite struct { suite.Suite signer keyring.Signer - from ethcmn.Address - to ethcmn.Address + from common.Address + to common.Address chainID *big.Int } @@ -74,12 +72,12 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_ValidateBasic() { amount *sdk.Int gasPrice *sdk.Int from string - accessList *ethtypes.AccessList + accessList *types.AccessList chainID *sdk.Int expectPass bool }{ {msg: "pass with recipient - Legacy Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &hundredInt, expectPass: true}, - {msg: "pass with recipient - AccessList Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: ðtypes.AccessList{}, chainID: &hundredInt, expectPass: true}, + {msg: "pass with recipient - AccessList Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: &types.AccessList{}, chainID: &hundredInt, expectPass: true}, {msg: "pass contract - Legacy Tx", to: "", amount: &hundredInt, gasPrice: &hundredInt, expectPass: true}, // {msg: "invalid recipient", to: invalidFromAddress, amount: &minusOneInt, gasPrice: &hundredInt, expectPass: false}, {msg: "nil amount - Legacy Tx", to: suite.to.Hex(), amount: nil, gasPrice: &hundredInt, expectPass: true}, @@ -88,13 +86,13 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_ValidateBasic() { {msg: "negative gas price - Legacy Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &minusOneInt, expectPass: false}, {msg: "zero gas price - Legacy Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, expectPass: true}, {msg: "invalid from address - Legacy Tx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, from: invalidFromAddress, expectPass: false}, - {msg: "nil amount - AccessListTx", to: suite.to.Hex(), amount: nil, gasPrice: &hundredInt, accessList: ðtypes.AccessList{}, chainID: &hundredInt, expectPass: true}, - {msg: "negative amount - AccessListTx", to: suite.to.Hex(), amount: &minusOneInt, gasPrice: &hundredInt, accessList: ðtypes.AccessList{}, chainID: nil, expectPass: false}, - {msg: "nil gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: nil, accessList: ðtypes.AccessList{}, chainID: &hundredInt, expectPass: false}, - {msg: "negative gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &minusOneInt, accessList: ðtypes.AccessList{}, chainID: nil, expectPass: false}, - {msg: "zero gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: ðtypes.AccessList{}, chainID: &hundredInt, expectPass: true}, - {msg: "invalid from address - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, from: invalidFromAddress, accessList: ðtypes.AccessList{}, chainID: &hundredInt, expectPass: false}, - {msg: "chain ID not set on AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: ðtypes.AccessList{}, chainID: nil, expectPass: false}, + {msg: "nil amount - AccessListTx", to: suite.to.Hex(), amount: nil, gasPrice: &hundredInt, accessList: &types.AccessList{}, chainID: &hundredInt, expectPass: true}, + {msg: "negative amount - AccessListTx", to: suite.to.Hex(), amount: &minusOneInt, gasPrice: &hundredInt, accessList: &types.AccessList{}, chainID: nil, expectPass: false}, + {msg: "nil gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: nil, accessList: &types.AccessList{}, chainID: &hundredInt, expectPass: false}, + {msg: "negative gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &minusOneInt, accessList: &types.AccessList{}, chainID: nil, expectPass: false}, + {msg: "zero gas price - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: &types.AccessList{}, chainID: &hundredInt, expectPass: true}, + {msg: "invalid from address - AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, from: invalidFromAddress, accessList: &types.AccessList{}, chainID: &hundredInt, expectPass: false}, + {msg: "chain ID not set on AccessListTx", to: suite.to.Hex(), amount: &hundredInt, gasPrice: &zeroInt, accessList: &types.AccessList{}, chainID: nil, expectPass: false}, } for i, tc := range testCases { @@ -128,49 +126,49 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_Sign() { testCases := []struct { msg string tx *MsgEthereumTx - ethSigner ethtypes.Signer + ethSigner types.Signer malleate func(tx *MsgEthereumTx) expectPass bool }{ { "pass - EIP2930 signer", NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), &types.AccessList{}), - ethtypes.NewEIP2930Signer(suite.chainID), + types.NewEIP2930Signer(suite.chainID), func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() }, true, }, { "pass - EIP155 signer", NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), nil), - ethtypes.NewEIP155Signer(suite.chainID), + types.NewEIP155Signer(suite.chainID), func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() }, true, }, { "pass - Homestead signer", NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), nil), - ethtypes.HomesteadSigner{}, + types.HomesteadSigner{}, func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() }, true, }, { "pass - Frontier signer", NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), nil), - ethtypes.FrontierSigner{}, + types.FrontierSigner{}, func(tx *MsgEthereumTx) { tx.From = suite.from.Hex() }, true, }, { "no from address ", NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), &types.AccessList{}), - ethtypes.NewEIP2930Signer(suite.chainID), + types.NewEIP2930Signer(suite.chainID), func(tx *MsgEthereumTx) { tx.From = "" }, false, }, { "from address ≠ signer address", NewTx(suite.chainID, 0, &suite.to, nil, 100000, nil, []byte("test"), &types.AccessList{}), - ethtypes.NewEIP2930Signer(suite.chainID), + types.NewEIP2930Signer(suite.chainID), func(tx *MsgEthereumTx) { tx.From = suite.to.Hex() }, false, }, diff --git a/x/evm/types/storage.go b/x/evm/types/storage.go index 1201832e..783930d6 100644 --- a/x/evm/types/storage.go +++ b/x/evm/types/storage.go @@ -4,10 +4,9 @@ import ( "fmt" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/ethereum/go-ethereum/common" "github.com/tharsis/ethermint/types" - - ethcmn "github.com/ethereum/go-ethereum/common" ) // Storage represents the account Storage map as a slice of single key value @@ -59,7 +58,7 @@ func (s State) Validate() error { } // NewState creates a new State instance -func NewState(key, value ethcmn.Hash) State { // nolint: interfacer +func NewState(key, value common.Hash) State { // nolint: interfacer return State{ Key: key.String(), Value: value.String(), diff --git a/x/evm/types/storage_test.go b/x/evm/types/storage_test.go index 95ba19c5..d5f0628e 100644 --- a/x/evm/types/storage_test.go +++ b/x/evm/types/storage_test.go @@ -3,9 +3,8 @@ package types import ( "testing" + "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" - - ethcmn "github.com/ethereum/go-ethereum/common" ) func TestStorageValidate(t *testing.T) { @@ -17,22 +16,22 @@ func TestStorageValidate(t *testing.T) { { "valid storage", Storage{ - NewState(ethcmn.BytesToHash([]byte{1, 2, 3}), ethcmn.BytesToHash([]byte{1, 2, 3})), + NewState(common.BytesToHash([]byte{1, 2, 3}), common.BytesToHash([]byte{1, 2, 3})), }, true, }, { "empty storage key bytes", Storage{ - {Key: ethcmn.Hash{}.String()}, + {Key: common.Hash{}.String()}, }, false, }, { "duplicated storage key", Storage{ - {Key: ethcmn.BytesToHash([]byte{1, 2, 3}).String()}, - {Key: ethcmn.BytesToHash([]byte{1, 2, 3}).String()}, + {Key: common.BytesToHash([]byte{1, 2, 3}).String()}, + {Key: common.BytesToHash([]byte{1, 2, 3}).String()}, }, false, }, @@ -57,13 +56,13 @@ func TestStorageCopy(t *testing.T) { { "single storage", Storage{ - NewState(ethcmn.BytesToHash([]byte{1, 2, 3}), ethcmn.BytesToHash([]byte{1, 2, 3})), + NewState(common.BytesToHash([]byte{1, 2, 3}), common.BytesToHash([]byte{1, 2, 3})), }, }, { "empty storage key value bytes", Storage{ - {Key: ethcmn.Hash{}.String(), Value: ethcmn.Hash{}.String()}, + {Key: common.Hash{}.String(), Value: common.Hash{}.String()}, }, }, { @@ -79,7 +78,7 @@ func TestStorageCopy(t *testing.T) { } func TestStorageString(t *testing.T) { - storage := Storage{NewState(ethcmn.BytesToHash([]byte("key")), ethcmn.BytesToHash([]byte("value")))} + storage := Storage{NewState(common.BytesToHash([]byte("key")), common.BytesToHash([]byte("value")))} str := "key:\"0x00000000000000000000000000000000000000000000000000000000006b6579\" value:\"0x00000000000000000000000000000000000000000000000000000076616c7565\" \n" require.Equal(t, str, storage.String()) } diff --git a/x/evm/types/utils_test.go b/x/evm/types/utils_test.go index b1fa74b9..e98e4642 100644 --- a/x/evm/types/utils_test.go +++ b/x/evm/types/utils_test.go @@ -17,18 +17,17 @@ import ( "github.com/stretchr/testify/require" "github.com/ethereum/go-ethereum/common" - ethcmn "github.com/ethereum/go-ethereum/common" - ethcrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto" ) // GenerateEthAddress generates an Ethereum address. -func GenerateEthAddress() ethcmn.Address { +func GenerateEthAddress() common.Address { priv, err := ethsecp256k1.GenerateKey() if err != nil { panic(err) } - return ethcrypto.PubkeyToAddress(priv.ToECDSA().PublicKey) + return crypto.PubkeyToAddress(priv.ToECDSA().PublicKey) } func TestEvmDataEncoding(t *testing.T) {