parent
9cc464b5e4
commit
3bb76e8533
@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Improvements
|
||||||
|
|
||||||
|
* (evm) [\#627](https://github.com/cosmos/ethermint/issues/627) Add extra EIPs parameter to apply custom EVM jump tables.
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
* (evm) [\#621](https://github.com/cosmos/ethermint/issues/621) EVM `GenesisAccount` fields now share the same format as the auth module `Account`.
|
* (evm) [\#621](https://github.com/cosmos/ethermint/issues/621) EVM `GenesisAccount` fields now share the same format as the auth module `Account`.
|
||||||
|
@ -8,6 +8,8 @@ import (
|
|||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/params"
|
"github.com/cosmos/cosmos-sdk/x/params"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
|
|
||||||
ethermint "github.com/cosmos/ethermint/types"
|
ethermint "github.com/cosmos/ethermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,6 +23,7 @@ var (
|
|||||||
ParamStoreKeyEVMDenom = []byte("EVMDenom")
|
ParamStoreKeyEVMDenom = []byte("EVMDenom")
|
||||||
ParamStoreKeyEnableCreate = []byte("EnableCreate")
|
ParamStoreKeyEnableCreate = []byte("EnableCreate")
|
||||||
ParamStoreKeyEnableCall = []byte("EnableCall")
|
ParamStoreKeyEnableCall = []byte("EnableCall")
|
||||||
|
ParamStoreKeyExtraEIPs = []byte("EnableExtraEIPs")
|
||||||
)
|
)
|
||||||
|
|
||||||
// ParamKeyTable returns the parameter key table.
|
// ParamKeyTable returns the parameter key table.
|
||||||
@ -37,14 +40,17 @@ type Params struct {
|
|||||||
EnableCreate bool `json:"enable_create" yaml:"enable_create"`
|
EnableCreate bool `json:"enable_create" yaml:"enable_create"`
|
||||||
// EnableCall toggles state transitions that use the vm.Call function
|
// EnableCall toggles state transitions that use the vm.Call function
|
||||||
EnableCall bool `json:"enable_call" yaml:"enable_call"`
|
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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewParams creates a new Params instance
|
// NewParams creates a new Params instance
|
||||||
func NewParams(evmDenom string, enableCreate, enableCall bool) Params {
|
func NewParams(evmDenom string, enableCreate, enableCall bool, extraEIPs ...int) Params {
|
||||||
return Params{
|
return Params{
|
||||||
EvmDenom: evmDenom,
|
EvmDenom: evmDenom,
|
||||||
EnableCreate: enableCreate,
|
EnableCreate: enableCreate,
|
||||||
EnableCall: enableCall,
|
EnableCall: enableCall,
|
||||||
|
ExtraEIPs: extraEIPs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +60,7 @@ func DefaultParams() Params {
|
|||||||
EvmDenom: ethermint.AttoPhoton,
|
EvmDenom: ethermint.AttoPhoton,
|
||||||
EnableCreate: true,
|
EnableCreate: true,
|
||||||
EnableCall: true,
|
EnableCall: true,
|
||||||
|
ExtraEIPs: []int(nil), // TODO: define default values
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,12 +76,17 @@ func (p *Params) ParamSetPairs() params.ParamSetPairs {
|
|||||||
params.NewParamSetPair(ParamStoreKeyEVMDenom, &p.EvmDenom, validateEVMDenom),
|
params.NewParamSetPair(ParamStoreKeyEVMDenom, &p.EvmDenom, validateEVMDenom),
|
||||||
params.NewParamSetPair(ParamStoreKeyEnableCreate, &p.EnableCreate, validateBool),
|
params.NewParamSetPair(ParamStoreKeyEnableCreate, &p.EnableCreate, validateBool),
|
||||||
params.NewParamSetPair(ParamStoreKeyEnableCall, &p.EnableCall, validateBool),
|
params.NewParamSetPair(ParamStoreKeyEnableCall, &p.EnableCall, validateBool),
|
||||||
|
params.NewParamSetPair(ParamStoreKeyExtraEIPs, &p.ExtraEIPs, validateEIPs),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate performs basic validation on evm parameters.
|
// Validate performs basic validation on evm parameters.
|
||||||
func (p Params) Validate() error {
|
func (p Params) Validate() error {
|
||||||
return sdk.ValidateDenom(p.EvmDenom)
|
if err := sdk.ValidateDenom(p.EvmDenom); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return validateEIPs(p.ExtraEIPs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateEVMDenom(i interface{}) error {
|
func validateEVMDenom(i interface{}) error {
|
||||||
@ -93,3 +105,18 @@ func validateBool(i interface{}) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateEIPs(i interface{}) error {
|
||||||
|
eips, ok := i.([]int)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("invalid EIP slice type: %T", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, eip := range eips {
|
||||||
|
if !vm.ValidEip(eip) {
|
||||||
|
return fmt.Errorf("EIP %d is not activateable", eip)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -15,7 +15,7 @@ func TestParamsValidate(t *testing.T) {
|
|||||||
{"default", DefaultParams(), false},
|
{"default", DefaultParams(), false},
|
||||||
{
|
{
|
||||||
"valid",
|
"valid",
|
||||||
NewParams("ara", true, true),
|
NewParams("ara", true, true, 2929, 1884, 1344),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -30,6 +30,14 @@ func TestParamsValidate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"invalid eip",
|
||||||
|
Params{
|
||||||
|
EvmDenom: "stake",
|
||||||
|
ExtraEIPs: []int{1},
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
@ -48,8 +56,10 @@ func TestParamsValidatePriv(t *testing.T) {
|
|||||||
require.NoError(t, validateEVMDenom("aphoton"))
|
require.NoError(t, validateEVMDenom("aphoton"))
|
||||||
require.Error(t, validateBool(""))
|
require.Error(t, validateBool(""))
|
||||||
require.NoError(t, validateBool(true))
|
require.NoError(t, validateBool(true))
|
||||||
|
require.Error(t, validateEIPs(""))
|
||||||
|
require.NoError(t, validateEIPs([]int{1884}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParams_String(t *testing.T) {
|
func TestParams_String(t *testing.T) {
|
||||||
require.Equal(t, "evm_denom: aphoton\nenable_create: true\nenable_call: true\n", DefaultParams().String())
|
require.Equal(t, "evm_denom: aphoton\nenable_create: true\nenable_call: true\nextra_eips: []\n", DefaultParams().String())
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,7 @@ func (st StateTransition) newEVM(
|
|||||||
gasLimit uint64,
|
gasLimit uint64,
|
||||||
gasPrice *big.Int,
|
gasPrice *big.Int,
|
||||||
config ChainConfig,
|
config ChainConfig,
|
||||||
|
extraEIPs []int,
|
||||||
) *vm.EVM {
|
) *vm.EVM {
|
||||||
// Create context for evm
|
// Create context for evm
|
||||||
context := vm.Context{
|
context := vm.Context{
|
||||||
@ -92,7 +93,11 @@ func (st StateTransition) newEVM(
|
|||||||
GasPrice: gasPrice,
|
GasPrice: gasPrice,
|
||||||
}
|
}
|
||||||
|
|
||||||
return vm.NewEVM(context, csdb, config.EthereumConfig(st.ChainID), vm.Config{})
|
vmConfig := vm.Config{
|
||||||
|
ExtraEips: extraEIPs,
|
||||||
|
}
|
||||||
|
|
||||||
|
return vm.NewEVM(context, csdb, config.EthereumConfig(st.ChainID), vmConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TransitionDb will transition the state by applying the current transaction and
|
// TransitionDb will transition the state by applying the current transaction and
|
||||||
@ -139,7 +144,7 @@ func (st StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (*Ex
|
|||||||
return nil, errors.New("gas price cannot be nil")
|
return nil, errors.New("gas price cannot be nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
evm := st.newEVM(ctx, csdb, gasLimit, gasPrice.Int, config)
|
evm := st.newEVM(ctx, csdb, gasLimit, gasPrice.Int, config, params.ExtraEIPs)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ret []byte
|
ret []byte
|
||||||
|
Loading…
Reference in New Issue
Block a user