evm: cleanup, remove atlas/ (#1152)

* evm: cleanup, remove atlas/

* rm tparse action

* fix lint issue

* use cases.NoLower

* tidy
This commit is contained in:
Federico Kunze Küllmer
2022-06-27 11:58:44 +02:00
committed by GitHub
parent 27ade5d731
commit 3ac8b93a1c
18 changed files with 67 additions and 372 deletions
-181
View File
@@ -1,181 +0,0 @@
# x/evm
The `x/evm` module is responsible for executing Ethereum Virtual Machine (EVM) state transitions.
## Usage
1. Import the module and the dependency packages.
```go
import (
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/evmos/ethermint/app/ante"
ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm"
)
```
2. Add `AppModuleBasic` to your `ModuleBasics`.
```go
var (
ModuleBasics = module.NewBasicManager(
// ...
evm.AppModuleBasic{},
)
)
```
3. Create the module's parameter subspace in your application constructor.
```go
func NewApp(...) *App {
// ...
app.subspaces[evm.ModuleName] = app.ParamsKeeper.Subspace(evm.DefaultParamspace)
}
```
4. Define the Ethermint `ProtoAccount` for the `AccountKeeper`
```go
func NewApp(...) *App {
// ...
app.AccountKeeper = auth.NewAccountKeeper(
cdc, keys[auth.StoreKey], app.subspaces[auth.ModuleName], ethermint.ProtoAccount,
)
}
```
5. Create the keeper.
```go
func NewApp(...) *App {
// ...
app.EvmKeeper = evm.NewKeeper(
app.cdc, keys[evm.StoreKey], app.subspaces[evm.ModuleName], app.AccountKeeper,
)
}
```
6. Add the `x/evm` module to the app's `ModuleManager`.
```go
func NewApp(...) *App {
// ...
app.mm = module.NewManager(
// ...
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper),
// ...
)
}
```
7. Set the `x/evm` module `BeginBlock` and `EndBlock` ordering:
```go
app.mm.SetOrderBeginBlockers(
evm.ModuleName, ...
)
app.mm.SetOrderEndBlockers(
evm.ModuleName, ...
)
```
8. Set the `x/evm` module genesis order. The module must go after the `auth` and `bank` modules.
```go
func NewApp(...) *App {
// ...
app.mm.SetOrderInitGenesis(auth.ModuleName, bank.ModuleName, ... , evm.ModuleName, ...)
}
```
9. Set the Ethermint `AnteHandler` to support EVM transactions. Note,
the default `AnteHandler` provided by the `x/evm` module depends on the `x/auth` and `x/supply`
modules.
```go
func NewApp(...) *App {
// ...
app.SetAnteHandler(ante.NewAnteHandler(
app.AccountKeeper, app.EvmKeeper, app.SupplyKeeper
))
}
```
## Genesis
The `x/evm` module defines its genesis state as follows:
```go
type GenesisState struct {
Accounts []GenesisAccount `json:"accounts"`
TxsLogs []TransactionLogs `json:"txs_logs"`
ChainConfig ChainConfig `json:"chain_config"`
Params Params `json:"params"`
}
```
Which relies on the following types:
```go
type GenesisAccount struct {
Address string `json:"address"`
Balance sdk.Int `json:"balance"`
Code hexutil.Bytes `json:"code,omitempty"`
Storage Storage `json:"storage,omitempty"`
}
type TransactionLogs struct {
Hash common.Hash `json:"hash"`
Logs []*ethtypes.Log `json:"logs"`
}
type ChainConfig struct {
HomesteadBlock sdk.Int `json:"homestead_block" yaml:"homestead_block"` // Homestead switch block (< 0 no fork, 0 = already homestead)
DAOForkBlock sdk.Int `json:"dao_fork_block" yaml:"dao_fork_block"` // TheDAO hard-fork switch block (< 0 no fork)
DAOForkSupport bool `json:"dao_fork_support" yaml:"dao_fork_support"` // Whether the nodes supports or opposes the DAO hard-fork
// EIP150 implements the Gas price changes (https://github.com/ethereum/EIPs/issues/150)
EIP150Block sdk.Int `json:"eip150_block" yaml:"eip150_block"` // EIP150 HF block (< 0 no fork)
EIP150Hash string `json:"eip150_hash" yaml:"eip150_hash"` // EIP150 HF hash (needed for header only clients as only gas pricing changed)
EIP155Block sdk.Int `json:"eip155_block" yaml:"eip155_block"` // EIP155 HF block
EIP158Block sdk.Int `json:"eip158_block" yaml:"eip158_block"` // EIP158 HF block
ByzantiumBlock sdk.Int `json:"byzantium_block" yaml:"byzantium_block"` // Byzantium switch block (< 0 no fork, 0 = already on byzantium)
ConstantinopleBlock sdk.Int `json:"constantinople_block" yaml:"constantinople_block"` // Constantinople switch block (< 0 no fork, 0 = already activated)
PetersburgBlock sdk.Int `json:"petersburg_block" yaml:"petersburg_block"` // Petersburg switch block (< 0 same as Constantinople)
IstanbulBlock sdk.Int `json:"istanbul_block" yaml:"istanbul_block"` // Istanbul switch block (< 0 no fork, 0 = already on istanbul)
MuirGlacierBlock sdk.Int `json:"muir_glacier_block" yaml:"muir_glacier_block"` // Eip-2384 (bomb delay) switch block (< 0 no fork, 0 = already activated)
YoloV2Block sdk.Int `json:"yoloV2_block" yaml:"yoloV2_block"` // YOLO v1: https://github.com/ethereum/EIPs/pull/2657 (Ephemeral testnet)
EWASMBlock sdk.Int `json:"ewasm_block" yaml:"ewasm_block"` // EWASM switch block (< 0 no fork, 0 = already activated)
}
type Params struct {
// EVMDenom defines the token denomination used for state transitions on the
// EVM module.
EvmDenom string `json:"evm_denom" yaml:"evm_denom"`
// EnableCreate toggles state transitions that use the vm.Create function
EnableCreate bool `json:"enable_create" yaml:"enable_create"`
// EnableCall toggles state transitions that use the vm.Call function
EnableCall bool `json:"enable_call" yaml:"enable_call"`
// ExtraEIPs defines the additional EIPs for the vm.Config
ExtraEIPs []int `json:"extra_eips" yaml:"extra_eips"`
}
```
## Client
### JSON-RPC
See the Ethermint [JSON-RPC docs](https://evmos.dev/basics/json_rpc.html) for reference.
## Documentation and Specification
* Ethermint documentation: [https://evmos.dev](https://evmos.dev)
-34
View File
@@ -1,34 +0,0 @@
[module]
description = "The evm module executes Ethereum Virtual Machine (EVM) state transitions."
homepage = "https://github.com/evmos/ethermint"
keywords = [
"evm",
"ethereum",
"ethermint",
]
name = "x/evm"
[bug_tracker]
url = "https://github.com/evmos/ethermint/issues"
[[authors]]
name = "fedekunze"
[[authors]]
name = "austinabell"
[[authors]]
name = "alexanderbez"
[[authors]]
name = "noot"
[[authors]]
name = "araskachoi"
[version]
documentation = "https://raw.githubusercontent.com/tharsis/ethermint/main/x/evm/atlas/atlas-v0.3.1.md"
repo = "https://github.com/evmos/ethermint/releases/tag/v0.3.1"
sdk_compat = "v0.39.x"
version = "v0.3.1"
+4
View File
@@ -366,11 +366,13 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context, msg core.Message, trace
// should have already been checked on Ante Handler
return nil, sdkerrors.Wrap(err, "intrinsic gas failed")
}
// Should check again even if it is checked on Ante Handler, because eth_call don't go through Ante Handler.
if msg.Gas() < intrinsicGas {
// eth_estimateGas will check for this exact error
return nil, sdkerrors.Wrap(core.ErrIntrinsicGas, "apply message")
}
leftoverGas := msg.Gas() - intrinsicGas
// access list preparation is moved from ante handler to here, because it's needed when `ApplyMessage` is called
@@ -401,11 +403,13 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context, msg core.Message, trace
if msg.Gas() < leftoverGas {
return nil, sdkerrors.Wrap(types.ErrGasOverflow, "apply message")
}
temporaryGasUsed := msg.Gas() - leftoverGas
refund := GasToRefund(stateDB.GetRefund(), temporaryGasUsed, refundQuotient)
if refund > temporaryGasUsed {
return nil, sdkerrors.Wrap(types.ErrGasOverflow, "apply message")
}
temporaryGasUsed -= refund
// EVM execution error needs to be available for the JSON-RPC client
-10
View File
@@ -206,16 +206,6 @@ func (suite *KeeperTestSuite) TestGetEthIntrinsicGas() {
true,
params.TxGas + params.TxDataNonZeroGasFrontier*1,
},
// we are not able to test the ErrGasUintOverflow due to RAM limitation
// {
// "with big data size overflow",
// make([]byte, 271300000000000000),
// nil,
// 1,
// false,
// false,
// 0,
// },
{
"no data, one accesslist, not contract creation, not homestead, not istanbul",
nil,
+1 -1
View File
@@ -68,7 +68,7 @@ func (k Keeper) DeductTxCostsFromUserBalance(
if feeAmt.Sign() == 0 {
// zero fee, no need to deduct
return sdk.NewCoins(), nil
return sdk.Coins{}, nil
}
fees := sdk.Coins{sdk.NewCoin(denom, sdk.NewIntFromBigInt(feeAmt))}
+7 -5
View File
@@ -5,8 +5,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/evmos/ethermint/types"
)
@@ -23,7 +25,7 @@ func newAccessListTx(tx *ethtypes.Transaction) (*AccessListTx, error) {
}
if tx.Value() != nil {
amountInt, err := SafeNewIntFromBigInt(tx.Value())
amountInt, err := types.SafeNewIntFromBigInt(tx.Value())
if err != nil {
return nil, err
}
@@ -31,7 +33,7 @@ func newAccessListTx(tx *ethtypes.Transaction) (*AccessListTx, error) {
}
if tx.GasPrice() != nil {
gasPriceInt, err := SafeNewIntFromBigInt(tx.GasPrice())
gasPriceInt, err := types.SafeNewIntFromBigInt(tx.GasPrice())
if err != nil {
return nil, err
}
@@ -183,7 +185,7 @@ func (tx AccessListTx) Validate() error {
if gasPrice == nil {
return sdkerrors.Wrap(ErrInvalidGasPrice, "cannot be nil")
}
if !IsValidInt256(gasPrice) {
if !types.IsValidInt256(gasPrice) {
return sdkerrors.Wrap(ErrInvalidGasPrice, "out of bound")
}
@@ -196,11 +198,11 @@ func (tx AccessListTx) Validate() error {
if amount != nil && amount.Sign() == -1 {
return sdkerrors.Wrapf(ErrInvalidAmount, "amount cannot be negative %s", amount)
}
if !IsValidInt256(amount) {
if !types.IsValidInt256(amount) {
return sdkerrors.Wrap(ErrInvalidAmount, "out of bound")
}
if !IsValidInt256(tx.Fee()) {
if !types.IsValidInt256(tx.Fee()) {
return sdkerrors.Wrap(ErrInvalidGasFee, "out of bound")
}
+1 -1
View File
@@ -39,7 +39,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
// PackClientState constructs a new Any packed with the given tx data value. It returns
// an error if the client state can't be casted to a protobuf message or if the concrete
// implemention is not registered to the protobuf codec.
// implementation is not registered to the protobuf codec.
func PackTxData(txData TxData) (*codectypes.Any, error) {
msg, ok := txData.(proto.Message)
if !ok {
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/params"
)
// EVMConfig encapulates common parameters needed to create an EVM to execute a message
// EVMConfig encapsulates common parameters needed to create an EVM to execute a message
// It's mainly to reduce the number of method parameters
type EVMConfig struct {
Params Params
+7 -7
View File
@@ -26,7 +26,7 @@ func newDynamicFeeTx(tx *ethtypes.Transaction) (*DynamicFeeTx, error) {
}
if tx.Value() != nil {
amountInt, err := SafeNewIntFromBigInt(tx.Value())
amountInt, err := types.SafeNewIntFromBigInt(tx.Value())
if err != nil {
return nil, err
}
@@ -34,7 +34,7 @@ func newDynamicFeeTx(tx *ethtypes.Transaction) (*DynamicFeeTx, error) {
}
if tx.GasFeeCap() != nil {
gasFeeCapInt, err := SafeNewIntFromBigInt(tx.GasFeeCap())
gasFeeCapInt, err := types.SafeNewIntFromBigInt(tx.GasFeeCap())
if err != nil {
return nil, err
}
@@ -42,7 +42,7 @@ func newDynamicFeeTx(tx *ethtypes.Transaction) (*DynamicFeeTx, error) {
}
if tx.GasTipCap() != nil {
gasTipCapInt, err := SafeNewIntFromBigInt(tx.GasTipCap())
gasTipCapInt, err := types.SafeNewIntFromBigInt(tx.GasTipCap())
if err != nil {
return nil, err
}
@@ -211,11 +211,11 @@ func (tx DynamicFeeTx) Validate() error {
return sdkerrors.Wrapf(ErrInvalidGasCap, "gas fee cap cannot be negative %s", tx.GasFeeCap)
}
if !IsValidInt256(tx.GetGasTipCap()) {
if !types.IsValidInt256(tx.GetGasTipCap()) {
return sdkerrors.Wrap(ErrInvalidGasCap, "out of bound")
}
if !IsValidInt256(tx.GetGasFeeCap()) {
if !types.IsValidInt256(tx.GetGasFeeCap()) {
return sdkerrors.Wrap(ErrInvalidGasCap, "out of bound")
}
@@ -226,7 +226,7 @@ func (tx DynamicFeeTx) Validate() error {
)
}
if !IsValidInt256(tx.Fee()) {
if !types.IsValidInt256(tx.Fee()) {
return sdkerrors.Wrap(ErrInvalidGasFee, "out of bound")
}
@@ -235,7 +235,7 @@ func (tx DynamicFeeTx) Validate() error {
if amount != nil && amount.Sign() == -1 {
return sdkerrors.Wrapf(ErrInvalidAmount, "amount cannot be negative %s", amount)
}
if !IsValidInt256(amount) {
if !types.IsValidInt256(amount) {
return sdkerrors.Wrap(ErrInvalidAmount, "out of bound")
}
+5 -5
View File
@@ -22,7 +22,7 @@ func newLegacyTx(tx *ethtypes.Transaction) (*LegacyTx, error) {
}
if tx.Value() != nil {
amountInt, err := SafeNewIntFromBigInt(tx.Value())
amountInt, err := types.SafeNewIntFromBigInt(tx.Value())
if err != nil {
return nil, err
}
@@ -30,7 +30,7 @@ func newLegacyTx(tx *ethtypes.Transaction) (*LegacyTx, error) {
}
if tx.GasPrice() != nil {
gasPriceInt, err := SafeNewIntFromBigInt(tx.GasPrice())
gasPriceInt, err := types.SafeNewIntFromBigInt(tx.GasPrice())
if err != nil {
return nil, err
}
@@ -166,10 +166,10 @@ func (tx LegacyTx) Validate() error {
if gasPrice.Sign() == -1 {
return sdkerrors.Wrapf(ErrInvalidGasPrice, "gas price cannot be negative %s", gasPrice)
}
if !IsValidInt256(gasPrice) {
if !types.IsValidInt256(gasPrice) {
return sdkerrors.Wrap(ErrInvalidGasPrice, "out of bound")
}
if !IsValidInt256(tx.Fee()) {
if !types.IsValidInt256(tx.Fee()) {
return sdkerrors.Wrap(ErrInvalidGasFee, "out of bound")
}
@@ -178,7 +178,7 @@ func (tx LegacyTx) Validate() error {
if amount != nil && amount.Sign() == -1 {
return sdkerrors.Wrapf(ErrInvalidAmount, "amount cannot be negative %s", amount)
}
if !IsValidInt256(amount) {
if !types.IsValidInt256(amount) {
return sdkerrors.Wrap(ErrInvalidAmount, "out of bound")
}
-16
View File
@@ -2,7 +2,6 @@ package types
import (
"fmt"
"math/big"
"github.com/gogo/protobuf/proto"
@@ -13,8 +12,6 @@ import (
"github.com/ethereum/go-ethereum/crypto"
)
const maxBitLen = 256
var EmptyCodeHash = crypto.Keccak256(nil)
// DecodeTxResponse decodes an protobuf-encoded byte slice into TxResponse
@@ -92,16 +89,3 @@ func BinSearch(lo, hi uint64, executable func(uint64) (bool, *MsgEthereumTxRespo
}
return hi, nil
}
// SafeNewIntFromBigInt constructs Int from big.Int, return error if more than 256bits
func SafeNewIntFromBigInt(i *big.Int) (sdk.Int, error) {
if !IsValidInt256(i) {
return sdk.NewInt(0), fmt.Errorf("big int out of bound: %s", i)
}
return sdk.NewIntFromBigInt(i), nil
}
// IsValidInt256 check the bound of 256 bit number
func IsValidInt256(i *big.Int) bool {
return i == nil || i.BitLen() <= maxBitLen
}