Skip to content

Commit

Permalink
Extend x/evm module params with enabled_precompiles
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed Apr 30, 2024
1 parent d9ad138 commit f385a8d
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 141 deletions.
17 changes: 11 additions & 6 deletions proto/ethermint/evm/v1/evm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ message Params {
repeated int64 extra_eips = 4 [(gogoproto.customname) = "ExtraEIPs", (gogoproto.moretags) = "yaml:\"extra_eips\""];
// chain_config defines the EVM chain configuration parameters
ChainConfig chain_config = 5 [(gogoproto.moretags) = "yaml:\"chain_config\"", (gogoproto.nullable) = false];
// list of allowed eip712 msgs and their types
// eip712_allowed_msgs contains list of allowed eip712 msgs and their types
repeated EIP712AllowedMsg eip712_allowed_msgs = 6
[(gogoproto.customname) = "EIP712AllowedMsgs", (gogoproto.nullable) = false];
// allow_unprotected_txs defines if replay-protected (i.e non EIP155
// signed) transactions can be executed on the state machine.
bool allow_unprotected_txs = 7;
// enabled_precompiles contains list of hex-encoded evm addresses of enabled precompiled contracts.
// Precompile must be registered before it can be enabled.
repeated string enabled_precompiles = 8;
}

// ChainConfig defines the Ethereum ChainConfig parameters using *sdk.Int values
Expand Down Expand Up @@ -246,20 +249,20 @@ message TraceConfig {

// EIP712AllowedMsg stores an allowed legacy msg and its eip712 type.
message EIP712AllowedMsg {
// msg's proto type name. ie "/cosmos.bank.v1beta1.MsgSend"
// msg_type_url is a msg's proto type name. ie "/cosmos.bank.v1beta1.MsgSend"
string msg_type_url = 1;

// name of the eip712 value type. ie "MsgValueSend"
// msg_value_type_name is a name of the eip712 value type. ie "MsgValueSend"
string msg_value_type_name = 2;

// types of the msg value
// value_types is a list of msg value types
repeated EIP712MsgAttrType value_types = 3 [(gogoproto.nullable) = false];

// nested types of the msg value
// nested_types is a list of msg value nested types
repeated EIP712NestedMsgType nested_types = 4 [(gogoproto.nullable) = false];
}

// EIP712MsgType is the eip712 type of a single message.
// EIP712NestedMsgType is the eip712 type of a single message.
message EIP712NestedMsgType {
// name of the nested type. ie "Fee", "Coin"
string name = 1;
Expand All @@ -270,6 +273,8 @@ message EIP712NestedMsgType {

// EIP712MsgAttrType is the eip712 type of a single message attribute.
message EIP712MsgAttrType {
// name
string name = 1;
// type
string type = 2;
}
45 changes: 45 additions & 0 deletions x/evm/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
legacytestutil "github.com/evmos/ethermint/x/evm/types/legacy/testutil"
)

const (
validEthAddress1 = "0xc0ffee254729296a45a3885639AC7E10F9d54979"
validEthAddress2 = "0xdF789447f8c5b3863bEB07F0272B78d1778EE11E"
)

func (suite *KeeperTestSuite) TestParams() {
params := suite.app.EvmKeeper.GetParams(suite.ctx)
suite.app.EvmKeeper.SetParams(suite.ctx, params)
Expand Down Expand Up @@ -101,6 +106,46 @@ func (suite *KeeperTestSuite) TestParams() {
},
true,
},
{
"success - EnabledPrecompiles param is set to empty slice and will be retrieved as nil",
func() interface{} {
params.EnabledPrecompiles = []string{}
suite.app.EvmKeeper.SetParams(suite.ctx, params)
var typedNil []string = nil // NOTE: despite we set EnabledPrecompiles as []string{}, it will be retrieved as nil
return typedNil
},
func() interface{} {
evmParams := suite.app.EvmKeeper.GetParams(suite.ctx)
return evmParams.GetEnabledPrecompiles()
},
true,
},
{
"success - EnabledPrecompiles param is set to nil and can be retrieved correctly",
func() interface{} {
params.EnabledPrecompiles = nil
suite.app.EvmKeeper.SetParams(suite.ctx, params)
return params.EnabledPrecompiles
},
func() interface{} {
evmParams := suite.app.EvmKeeper.GetParams(suite.ctx)
return evmParams.GetEnabledPrecompiles()
},
true,
},
{
"success - EnabledPrecompiles param is set to []string{\"0x100\", \"0x101\"} and can be retrieved correctly",
func() interface{} {
params.EnabledPrecompiles = []string{validEthAddress1, validEthAddress2}
suite.app.EvmKeeper.SetParams(suite.ctx, params)
return params.EnabledPrecompiles
},
func() interface{} {
evmParams := suite.app.EvmKeeper.GetParams(suite.ctx)
return evmParams.GetEnabledPrecompiles()
},
true,
},
}
for _, tc := range testCases {
suite.Run(tc.name, func() {
Expand Down

0 comments on commit f385a8d

Please sign in to comment.