From f385a8d6d43481a1fb003a68f0bc4ea7a1214a32 Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Tue, 30 Apr 2024 15:08:19 -0400 Subject: [PATCH 01/12] Extend x/evm module params with enabled_precompiles --- proto/ethermint/evm/v1/evm.proto | 17 +- x/evm/keeper/params_test.go | 45 +++++ x/evm/types/evm.pb.go | 286 +++++++++++++++++++------------ x/evm/types/params.go | 21 ++- x/evm/types/params_test.go | 82 ++++++--- 5 files changed, 310 insertions(+), 141 deletions(-) diff --git a/proto/ethermint/evm/v1/evm.proto b/proto/ethermint/evm/v1/evm.proto index 875619ffec..be36686576 100644 --- a/proto/ethermint/evm/v1/evm.proto +++ b/proto/ethermint/evm/v1/evm.proto @@ -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 @@ -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; @@ -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; } diff --git a/x/evm/keeper/params_test.go b/x/evm/keeper/params_test.go index 38fc687f10..0ff251b734 100644 --- a/x/evm/keeper/params_test.go +++ b/x/evm/keeper/params_test.go @@ -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) @@ -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() { diff --git a/x/evm/types/evm.pb.go b/x/evm/types/evm.pb.go index 1849162a56..ee4b4be350 100644 --- a/x/evm/types/evm.pb.go +++ b/x/evm/types/evm.pb.go @@ -42,6 +42,9 @@ type Params struct { // allow_unprotected_txs defines if replay-protected (i.e non EIP155 // signed) transactions can be executed on the state machine. AllowUnprotectedTxs bool `protobuf:"varint,7,opt,name=allow_unprotected_txs,json=allowUnprotectedTxs,proto3" json:"allow_unprotected_txs,omitempty"` + // enabled_precompiles contains list of hex-encoded evm addresses of enabled precompiled contracts. + // Precompile must be registered before it can be enabled. + EnabledPrecompiles []string `protobuf:"bytes,8,rep,name=enabled_precompiles,json=enabledPrecompiles,proto3" json:"enabled_precompiles,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -126,6 +129,13 @@ func (m *Params) GetAllowUnprotectedTxs() bool { return false } +func (m *Params) GetEnabledPrecompiles() []string { + if m != nil { + return m.EnabledPrecompiles + } + return nil +} + // ChainConfig defines the Ethereum ChainConfig parameters using *sdk.Int values // instead of *big.Int. type ChainConfig struct { @@ -882,121 +892,122 @@ func init() { func init() { proto.RegisterFile("ethermint/evm/v1/evm.proto", fileDescriptor_d21ecc92c8c8583e) } var fileDescriptor_d21ecc92c8c8583e = []byte{ - // 1810 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x58, 0x4d, 0x6f, 0x1b, 0xb9, - 0x19, 0x8e, 0xad, 0xb1, 0x3d, 0xa2, 0x64, 0x69, 0x4c, 0x29, 0x5e, 0x25, 0x41, 0x3d, 0xee, 0x14, - 0x2d, 0x5c, 0x60, 0x63, 0xaf, 0xbd, 0x30, 0x12, 0x6c, 0xd0, 0x0f, 0xcb, 0xf1, 0xee, 0xda, 0x4d, + // 1838 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x58, 0xdd, 0x6e, 0x1b, 0xb9, + 0x15, 0x8e, 0xad, 0xb1, 0x3d, 0xa2, 0x64, 0x69, 0x4c, 0x29, 0x5e, 0x25, 0x41, 0x3d, 0xee, 0x14, + 0x2d, 0x5c, 0x60, 0x63, 0xaf, 0xbd, 0x30, 0x12, 0x6c, 0xd0, 0x1f, 0xcb, 0xf1, 0xee, 0xda, 0x4d, 0x5c, 0x83, 0x71, 0x5a, 0xa0, 0x40, 0x31, 0xa0, 0x66, 0xb8, 0xa3, 0x89, 0x67, 0x86, 0x02, 0xc9, - 0x51, 0xa4, 0xb6, 0x3f, 0xa0, 0x40, 0x2f, 0xfd, 0x05, 0xc5, 0xfe, 0x9c, 0x45, 0x4f, 0x7b, 0x2c, - 0x7a, 0x18, 0x14, 0xce, 0xcd, 0x47, 0x9f, 0x7a, 0x6b, 0xc1, 0x0f, 0x7d, 0xda, 0xdb, 0xae, 0x7d, - 0x12, 0xdf, 0xaf, 0xe7, 0xe1, 0xfb, 0xf2, 0xe5, 0x90, 0x14, 0x78, 0x4c, 0x44, 0x97, 0xb0, 0x34, - 0xce, 0xc4, 0x0e, 0xe9, 0xa7, 0x3b, 0xfd, 0x5d, 0xf9, 0xb3, 0xdd, 0x63, 0x54, 0x50, 0xe8, 0x8c, - 0x6d, 0xdb, 0x52, 0xd9, 0xdf, 0x7d, 0xdc, 0x8c, 0x68, 0x44, 0x95, 0x71, 0x47, 0x8e, 0xb4, 0x9f, - 0xf7, 0xef, 0x12, 0x58, 0x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3f, 0x99, 0x9c, 0x34, 0xf3, - 0x1e, 0x1e, 0xaa, 0x8f, 0x54, 0x07, 0xa6, 0xfe, 0x4d, 0xb0, 0xd4, 0x49, 0x28, 0x4d, 0x55, 0x27, - 0x54, 0x91, 0x16, 0x20, 0x52, 0x55, 0x53, 0xab, 0x5c, 0x52, 0x17, 0xfb, 0x1f, 0xde, 0x5c, 0xe5, - 0xb9, 0x56, 0x69, 0xaf, 0x9b, 0xcb, 0x7d, 0x4d, 0x73, 0x9b, 0x78, 0x4f, 0xd6, 0x56, 0xb5, 0x92, - 0x03, 0x4a, 0x8c, 0x08, 0xb5, 0x68, 0x55, 0x24, 0x87, 0xf0, 0x31, 0xb0, 0x19, 0xe9, 0x13, 0x26, - 0x48, 0xa8, 0x16, 0xc7, 0x46, 0x63, 0x19, 0x3e, 0x02, 0x76, 0x84, 0xb9, 0x9f, 0x73, 0x12, 0xea, - 0x95, 0x40, 0x2b, 0x11, 0xe6, 0x6f, 0x39, 0x09, 0x3f, 0xb3, 0xfe, 0xfc, 0xb5, 0xfb, 0xc0, 0xc3, - 0xa0, 0x72, 0x10, 0x04, 0x84, 0xf3, 0xf3, 0xbc, 0x97, 0x90, 0xff, 0xd1, 0x61, 0x7b, 0xa0, 0xca, - 0x05, 0x65, 0x38, 0x22, 0xfe, 0x05, 0x19, 0x9a, 0x3e, 0xd3, 0x5d, 0x63, 0xf4, 0xbf, 0x22, 0x43, - 0x8e, 0xa6, 0x05, 0x43, 0xf1, 0xb5, 0x05, 0x2a, 0xe7, 0x0c, 0x07, 0xc4, 0xdc, 0xf0, 0x65, 0xaf, - 0x4a, 0x91, 0x19, 0x0a, 0x23, 0x49, 0x6e, 0x11, 0xa7, 0x84, 0xe6, 0xc2, 0xec, 0xa7, 0x91, 0x28, - 0x23, 0x18, 0x21, 0x03, 0x12, 0xa8, 0x32, 0x5a, 0xc8, 0x48, 0x70, 0x1f, 0xac, 0x86, 0x31, 0x57, - 0xaf, 0x33, 0x2e, 0x70, 0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, 0xf7, 0x64, 0x6e, 0x55, 0x29, 0x39, 0xa0, 0xc4, 0x88, 0x50, 0x9b, + 0x56, 0x45, 0x72, 0x08, 0x1f, 0x03, 0x9b, 0x91, 0x3e, 0x61, 0x82, 0x84, 0x6a, 0x73, 0x6c, 0x34, + 0x96, 0xe1, 0x23, 0x60, 0x47, 0x98, 0xfb, 0x39, 0x27, 0xa1, 0xde, 0x09, 0xb4, 0x12, 0x61, 0xfe, + 0x96, 0x93, 0xf0, 0x33, 0xeb, 0xcf, 0x5f, 0xbb, 0x0f, 0x3c, 0x0c, 0x2a, 0x07, 0x41, 0x40, 0x38, + 0x3f, 0xcf, 0x7b, 0x09, 0xf9, 0x1f, 0x15, 0xb6, 0x07, 0xaa, 0x5c, 0x50, 0x86, 0x23, 0xe2, 0x5f, + 0x90, 0xa1, 0xa9, 0x33, 0x5d, 0x35, 0x46, 0xff, 0x2b, 0x32, 0xe4, 0x68, 0x5a, 0x30, 0x14, 0x5f, + 0x5b, 0xa0, 0x72, 0xce, 0x70, 0x40, 0xcc, 0x0d, 0x5f, 0xd6, 0xaa, 0x14, 0x99, 0xa1, 0x30, 0x92, + 0xe4, 0x16, 0x71, 0x4a, 0x68, 0x2e, 0xcc, 0x79, 0x1a, 0x89, 0x72, 0x06, 0x23, 0x64, 0x40, 0x02, + 0x95, 0x46, 0x0b, 0x19, 0x09, 0xee, 0x83, 0xd5, 0x30, 0xe6, 0xea, 0x39, 0xc7, 0x05, 0x0e, 0x2e, + 0x74, 0xf8, 0x6d, 0xe7, 0xaa, 0x70, 0xab, 0xc6, 0xf0, 0x46, 0xea, 0xd1, 0x8c, 0x04, 0x5f, 0x80, + 0xfa, 0x64, 0x9a, 0x5a, 0xad, 0xca, 0x8d, 0xdd, 0x86, 0x57, 0x85, 0x5b, 0x1b, 0xbb, 0x2a, 0x0b, + 0x9a, 0x93, 0xe5, 0x4e, 0x87, 0xa4, 0x93, 0x47, 0xaa, 0xf8, 0x6c, 0xa4, 0x05, 0xa9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f, 0xfa, 0xae, 0x67, 0xf3, 0x6b, 0x1e, 0x1d, 0x08, 0xc1, 0xe4, 0xec, 0xb6, + 0x25, 0x0f, 0x25, 0x02, 0xfd, 0x11, 0x1c, 0x87, 0xa7, 0xa0, 0x9a, 0xc9, 0x77, 0x64, 0x68, 0xc0, + 0x2c, 0x05, 0xf6, 0xe3, 0xef, 0x02, 0x3b, 0x55, 0xbe, 0xaf, 0xf5, 0xd2, 0x0d, 0x5c, 0x45, 0x03, + 0x28, 0x3c, 0xef, 0x1d, 0x68, 0xdc, 0xe2, 0x29, 0xbf, 0xdf, 0x2a, 0x24, 0xd3, 0x38, 0xe4, 0x18, + 0xfe, 0x02, 0x2c, 0x61, 0x21, 0xd8, 0xa8, 0x73, 0xdc, 0x21, 0x00, 0x3d, 0xcf, 0x7b, 0x01, 0xd6, + 0x6e, 0x78, 0xdc, 0xca, 0x04, 0x81, 0x25, 0xa3, 0x33, 0x09, 0x55, 0xe3, 0xf6, 0x2f, 0xbf, 0xb9, + 0xdc, 0x58, 0xf8, 0xf6, 0x72, 0x63, 0xe1, 0xdf, 0x97, 0x1b, 0x0b, 0x7f, 0xfd, 0xb0, 0xf1, 0xe0, + 0xdb, 0x0f, 0x1b, 0x0f, 0xfe, 0xf9, 0x61, 0xe3, 0xc1, 0xef, 0xa6, 0x5b, 0x39, 0xe9, 0xcb, 0x4e, + 0x3e, 0xf9, 0x2b, 0x69, 0xa0, 0xfe, 0x4c, 0x52, 0xa9, 0xea, 0x2c, 0xab, 0x3f, 0x89, 0x3e, 0xfd, + 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe0, 0x37, 0x66, 0x64, 0x6a, 0x12, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -1019,6 +1030,15 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.EnabledPrecompiles) > 0 { + for iNdEx := len(m.EnabledPrecompiles) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.EnabledPrecompiles[iNdEx]) + copy(dAtA[i:], m.EnabledPrecompiles[iNdEx]) + i = encodeVarintEvm(dAtA, i, uint64(len(m.EnabledPrecompiles[iNdEx]))) + i-- + dAtA[i] = 0x42 + } + } if m.AllowUnprotectedTxs { i-- if m.AllowUnprotectedTxs { @@ -1939,6 +1959,12 @@ func (m *Params) Size() (n int) { if m.AllowUnprotectedTxs { n += 2 } + if len(m.EnabledPrecompiles) > 0 { + for _, s := range m.EnabledPrecompiles { + l = len(s) + n += 1 + l + sovEvm(uint64(l)) + } + } return n } @@ -2534,6 +2560,38 @@ func (m *Params) Unmarshal(dAtA []byte) error { } } m.AllowUnprotectedTxs = bool(v != 0) + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EnabledPrecompiles", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvm + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthEvm + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvm + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EnabledPrecompiles = append(m.EnabledPrecompiles, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipEvm(dAtA[iNdEx:]) diff --git a/x/evm/types/params.go b/x/evm/types/params.go index b95870128b..c931075d7a 100644 --- a/x/evm/types/params.go +++ b/x/evm/types/params.go @@ -19,6 +19,7 @@ import ( "fmt" "math/big" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/params" sdk "github.com/cosmos/cosmos-sdk/types" @@ -105,7 +106,15 @@ func (p Params) Validate() error { return err } - return validateEIP712AllowedMsgs(p.EIP712AllowedMsgs) + if err := validateEIP712AllowedMsgs(p.EIP712AllowedMsgs); err != nil { + return err + } + + if err := validateEnabledPrecompiles(p.EnabledPrecompiles); err != nil { + return err + } + + return nil } // EIP712AllowedMsgFromMsgType returns the EIP712AllowedMsg for a given message type url. @@ -186,6 +195,16 @@ func validateEIP712AllowedMsgs(i interface{}) error { return nil } +func validateEnabledPrecompiles(enabledPrecompiles []string) error { + for _, addr := range enabledPrecompiles { + if !common.IsHexAddress(addr) { + return fmt.Errorf("invalid hex address: %v in enabled precompiles list", addr) + } + } + + return nil +} + // IsLondon returns if london hardfork is enabled. func IsLondon(ethConfig *params.ChainConfig, height int64) bool { return ethConfig.IsLondon(big.NewInt(height)) diff --git a/x/evm/types/params_test.go b/x/evm/types/params_test.go index eefb1773ed..b9947c4634 100644 --- a/x/evm/types/params_test.go +++ b/x/evm/types/params_test.go @@ -8,43 +8,78 @@ import ( "github.com/stretchr/testify/require" ) +const ( + validEthAddress = "0xc0ffee254729296a45a3885639AC7E10F9d54979" + invalidEthAddress = "0xc0ffee254729296a45a3885639AC7E10F9d5497" +) + func TestParamsValidate(t *testing.T) { extraEips := []int64{2929, 1884, 1344} testCases := []struct { - name string - params Params - expError bool + name string + getParams func() Params + expError bool }{ - {"default", DefaultParams(), false}, { - "valid", - NewParams("ara", false, true, true, DefaultChainConfig(), extraEips, []EIP712AllowedMsg{}), - false, + name: "default", + getParams: DefaultParams, + expError: false, }, { - "empty", - Params{}, - true, + name: "valid", + getParams: func() Params { + return NewParams("ara", false, true, true, DefaultChainConfig(), extraEips, []EIP712AllowedMsg{}) + }, + expError: false, }, { - "invalid evm denom", - Params{ - EvmDenom: "@!#!@$!@5^32", + name: "empty", + getParams: func() Params { + return Params{} }, - true, + expError: true, }, { - "invalid eip", - Params{ - EvmDenom: "stake", - ExtraEIPs: []int64{1}, + name: "invalid evm denom", + getParams: func() Params { + return Params{ + EvmDenom: "@!#!@$!@5^32", + } }, - true, + expError: true, + }, + { + name: "invalid eip", + getParams: func() Params { + return Params{ + EvmDenom: "stake", + ExtraEIPs: []int64{1}, + } + }, + expError: true, + }, + { + name: "valid enabled precompiles", + getParams: func() Params { + params := DefaultParams() + params.EnabledPrecompiles = []string{validEthAddress} + return params + }, + expError: false, + }, + { + name: "invalid enabled precompiles", + getParams: func() Params { + params := DefaultParams() + params.EnabledPrecompiles = []string{invalidEthAddress} + return params + }, + expError: true, }, } for _, tc := range testCases { - err := tc.params.Validate() + err := tc.getParams().Validate() if tc.expError { require.Error(t, err, tc.name) @@ -69,6 +104,13 @@ func TestParamsValidatePriv(t *testing.T) { require.NoError(t, validateBool(true)) require.Error(t, validateEIPs("")) require.NoError(t, validateEIPs([]int64{1884})) + + require.Error(t, validateEnabledPrecompiles([]string{""})) + require.Error(t, validateEnabledPrecompiles([]string{invalidEthAddress})) + require.Error(t, validateEnabledPrecompiles([]string{validEthAddress, invalidEthAddress})) + require.NoError(t, validateEnabledPrecompiles(nil)) + require.NoError(t, validateEnabledPrecompiles([]string{})) + require.NoError(t, validateEnabledPrecompiles([]string{validEthAddress})) } func TestValidateChainConfig(t *testing.T) { From 6e25d3724f20589e9a03c54903296b6e90a2a846 Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Tue, 30 Apr 2024 20:46:24 -0400 Subject: [PATCH 02/12] Added enabled-precompiles param validation in InitGenesis --- x/evm/genesis.go | 12 ++++++-- x/evm/types/params.go | 21 +++++++++++-- x/evm/types/params_test.go | 62 +++++++++++++++++++++++++++++++++++++- 3 files changed, 90 insertions(+), 5 deletions(-) diff --git a/x/evm/genesis.go b/x/evm/genesis.go index 5df8066d8d..86b0075ea2 100644 --- a/x/evm/genesis.go +++ b/x/evm/genesis.go @@ -24,7 +24,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" - + precompile_modules "github.com/ethereum/go-ethereum/precompile/modules" ethermint "github.com/evmos/ethermint/types" "github.com/evmos/ethermint/x/evm/keeper" "github.com/evmos/ethermint/x/evm/types" @@ -39,7 +39,15 @@ func InitGenesis( ) []abci.ValidatorUpdate { k.WithChainID(ctx) - err := k.SetParams(ctx, data.Params) + err := types.CheckIfEnabledPrecompilesAreRegistered( + precompile_modules.RegisteredModules(), + data.Params.GetEnabledPrecompiles(), + ) + if err != nil { + panic(err) + } + + err = k.SetParams(ctx, data.Params) if err != nil { panic(fmt.Errorf("error setting params %s", err)) } diff --git a/x/evm/types/params.go b/x/evm/types/params.go index c931075d7a..d5940b8f5c 100644 --- a/x/evm/types/params.go +++ b/x/evm/types/params.go @@ -19,11 +19,12 @@ import ( "fmt" "math/big" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/params" + precompile_modules "github.com/ethereum/go-ethereum/precompile/modules" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ethereum/go-ethereum/core/vm" "github.com/evmos/ethermint/types" ) @@ -209,3 +210,19 @@ func validateEnabledPrecompiles(enabledPrecompiles []string) error { func IsLondon(ethConfig *params.ChainConfig, height int64) bool { return ethConfig.IsLondon(big.NewInt(height)) } + +func CheckIfEnabledPrecompilesAreRegistered(registeredModules []precompile_modules.Module, enabledPrecompiles []string) error { + registeredAddrs := make(map[string]struct{}, len(registeredModules)) + + for _, module := range registeredModules { + registeredAddrs[module.Address.String()] = struct{}{} + } + + for _, enabledPrecompile := range enabledPrecompiles { + if _, ok := registeredAddrs[enabledPrecompile]; !ok { + return fmt.Errorf("precompile %v is enabled but not registered", enabledPrecompile) + } + } + + return nil +} diff --git a/x/evm/types/params_test.go b/x/evm/types/params_test.go index b9947c4634..f7fbdb16ce 100644 --- a/x/evm/types/params_test.go +++ b/x/evm/types/params_test.go @@ -3,8 +3,9 @@ package types import ( "testing" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/params" - + precompile_modules "github.com/ethereum/go-ethereum/precompile/modules" "github.com/stretchr/testify/require" ) @@ -169,3 +170,62 @@ func TestIsLondon(t *testing.T) { require.Equal(t, IsLondon(ethConfig, tc.height), tc.result) } } + +func TestCheckIfEnabledPrecompilesAreRegistered(t *testing.T) { + m := func(addr string) precompile_modules.Module { + return precompile_modules.Module{ + Address: common.HexToAddress(addr), + } + } + a := func(addr string) string { + return common.HexToAddress(addr).String() + } + + testCases := []struct { + name string + registeredModules []precompile_modules.Module + enabledPrecompiles []string + expError bool + }{ + { + name: "test-case #1", + registeredModules: []precompile_modules.Module{m("0x1"), m("0x2"), m("0x3")}, + enabledPrecompiles: []string{a("0x1"), a("0x2"), a("0x3")}, + expError: false, + }, + { + name: "test-case #2", + registeredModules: []precompile_modules.Module{m("0x1"), m("0x2"), m("0x3")}, + enabledPrecompiles: []string{a("0x1"), a("0x3")}, + expError: false, + }, + { + name: "test-case #3", + registeredModules: []precompile_modules.Module{m("0x1"), m("0x2"), m("0x3")}, + enabledPrecompiles: []string{}, + expError: false, + }, + { + name: "test-case #4", + registeredModules: []precompile_modules.Module{}, + enabledPrecompiles: []string{}, + expError: false, + }, + { + name: "test-case #5", + registeredModules: []precompile_modules.Module{m("0x1"), m("0x2"), m("0x3")}, + enabledPrecompiles: []string{"0x4"}, + expError: true, + }, + } + + for _, tc := range testCases { + err := CheckIfEnabledPrecompilesAreRegistered(tc.registeredModules, tc.enabledPrecompiles) + + if tc.expError { + require.Error(t, err, tc.name) + } else { + require.NoError(t, err, tc.name) + } + } +} From ee18475b9f93270919fdaf038783e88aa73cfb43 Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Wed, 1 May 2024 11:08:11 -0400 Subject: [PATCH 03/12] Validate order and uniqueness of enabled precompiles --- x/evm/types/params.go | 45 ++++++++++++++++++ x/evm/types/params_test.go | 95 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) diff --git a/x/evm/types/params.go b/x/evm/types/params.go index d5940b8f5c..e17aac5d67 100644 --- a/x/evm/types/params.go +++ b/x/evm/types/params.go @@ -16,6 +16,7 @@ package types import ( + "bytes" "fmt" "math/big" @@ -203,6 +204,50 @@ func validateEnabledPrecompiles(enabledPrecompiles []string) error { } } + if err := checkIfSortedInBytesRepr(enabledPrecompiles); err != nil { + return fmt.Errorf("enabled precompiles are not sorted: %v", err) + } + + if err := checkIfUniqueInBytesRepr(enabledPrecompiles); err != nil { + return fmt.Errorf("enabled precompiles are not unique: %v", err) + } + + return nil +} + +func checkIfSortedInBytesRepr(hexAddrs []string) error { + n := len(hexAddrs) + addrs := make([]common.Address, n) + for i, addr := range hexAddrs { + addrs[i] = common.HexToAddress(addr) + } + + for i := 0; i < n-1; i++ { + cmp := bytes.Compare(addrs[i].Bytes(), addrs[i+1].Bytes()) + if cmp == 1 { + return fmt.Errorf("addresses are not sorted, %v > %v", addrs[i].Hex(), addrs[i+1].Hex()) + } + } + + return nil +} + +func checkIfUniqueInBytesRepr(hexAddrs []string) error { + n := len(hexAddrs) + addrs := make([]common.Address, n) + for i, hexAddr := range hexAddrs { + addrs[i] = common.HexToAddress(hexAddr) + } + + exists := make(map[common.Address]struct{}, n) + for _, addr := range addrs { + if _, ok := exists[addr]; ok { + return fmt.Errorf("addr %v not unique", addr.Hex()) + } + + exists[addr] = struct{}{} + } + return nil } diff --git a/x/evm/types/params_test.go b/x/evm/types/params_test.go index f7fbdb16ce..a4b675e4c3 100644 --- a/x/evm/types/params_test.go +++ b/x/evm/types/params_test.go @@ -112,6 +112,17 @@ func TestParamsValidatePriv(t *testing.T) { require.NoError(t, validateEnabledPrecompiles(nil)) require.NoError(t, validateEnabledPrecompiles([]string{})) require.NoError(t, validateEnabledPrecompiles([]string{validEthAddress})) + + addr1 := "0x1000000000000000000000000000000000000000" + addr2 := "0x2000000000000000000000000000000000000000" + + // check if sorted + require.NoError(t, validateEnabledPrecompiles([]string{addr1, addr2})) + require.Error(t, validateEnabledPrecompiles([]string{addr2, addr1})) + + // check if unique + require.NoError(t, validateEnabledPrecompiles([]string{addr1, addr2})) + require.Error(t, validateEnabledPrecompiles([]string{addr1, addr1})) } func TestValidateChainConfig(t *testing.T) { @@ -229,3 +240,87 @@ func TestCheckIfEnabledPrecompilesAreRegistered(t *testing.T) { } } } + +func TestCheckIfSortedInBytesRepr(t *testing.T) { + addr1 := "0x1000000000000000000000000000000000000000" + addr2 := "0x2000000000000000000000000000000000000000" + + // NOTE: we sort in bytes representation, so proper order will be []string{mixedCaseAddr, upperCaseAddr}, + // and it differs from lexicographically sorted strings + upperCaseAddr := "0xAB00000000000000000000000000000000000000" + mixedCaseAddr := "0xaA00000000000000000000000000000000000000" + + testCases := []struct { + name string + addrs []string + sorted bool + }{ + { + name: "test-case #1", + addrs: []string{addr1, addr2}, + sorted: true, + }, + { + name: "test-case #2", + addrs: []string{addr2, addr1}, + sorted: false, + }, + { + name: "test-case #3", + addrs: []string{mixedCaseAddr, upperCaseAddr}, + sorted: true, + }, + } + + for _, tc := range testCases { + err := checkIfSortedInBytesRepr(tc.addrs) + + if tc.sorted { + require.NoError(t, err, tc.name) + } else { + require.Error(t, err, tc.name) + } + } +} + +func TestCheckIfUniqueInBytesRepr(t *testing.T) { + addr1 := "0x1000000000000000000000000000000000000000" + addr2 := "0x2000000000000000000000000000000000000000" + + // NOTE: we check uniqueness in bytes representation, so lowerCaseAddr and mixedCaseAddr are the same, + // despite it differs in string representation + lowerCaseAddr := "0xab00000000000000000000000000000000000000" + mixedCaseAddr := "0xAb00000000000000000000000000000000000000" + + testCases := []struct { + name string + addrs []string + unique bool + }{ + { + name: "test-case #1", + addrs: []string{addr1, addr2}, + unique: true, + }, + { + name: "test-case #2", + addrs: []string{addr1, addr1}, + unique: false, + }, + { + name: "test-case #3", + addrs: []string{lowerCaseAddr, mixedCaseAddr}, + unique: false, + }, + } + + for _, tc := range testCases { + err := checkIfUniqueInBytesRepr(tc.addrs) + + if tc.unique { + require.NoError(t, err, tc.name) + } else { + require.Error(t, err, tc.name) + } + } +} From 30aaf561bc4d0512ffc6de296120a09fee5cf43f Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Wed, 1 May 2024 11:43:19 -0400 Subject: [PATCH 04/12] Added tests for InitGenesis in x/evm --- x/evm/genesis.go | 3 +- x/evm/genesis_test.go | 209 ++++++++++++++++++++++++++++-------------- x/evm/module.go | 11 +-- 3 files changed, 146 insertions(+), 77 deletions(-) diff --git a/x/evm/genesis.go b/x/evm/genesis.go index 86b0075ea2..67ef6c33cc 100644 --- a/x/evm/genesis.go +++ b/x/evm/genesis.go @@ -36,11 +36,12 @@ func InitGenesis( k *keeper.Keeper, accountKeeper types.AccountKeeper, data types.GenesisState, + registeredModules []precompile_modules.Module, ) []abci.ValidatorUpdate { k.WithChainID(ctx) err := types.CheckIfEnabledPrecompilesAreRegistered( - precompile_modules.RegisteredModules(), + registeredModules, data.Params.GetEnabledPrecompiles(), ) if err != nil { diff --git a/x/evm/genesis_test.go b/x/evm/genesis_test.go index e060c5d965..0359a29664 100644 --- a/x/evm/genesis_test.go +++ b/x/evm/genesis_test.go @@ -3,9 +3,10 @@ package evm_test import ( "math/big" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/ethereum/go-ethereum/common" + precompile_modules "github.com/ethereum/go-ethereum/precompile/modules" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/evmos/ethermint/crypto/ethsecp256k1" etherminttypes "github.com/evmos/ethermint/types" "github.com/evmos/ethermint/x/evm" @@ -18,106 +19,121 @@ func (suite *EvmTestSuite) TestInitGenesis() { suite.Require().NoError(err) address := common.HexToAddress(privkey.PubKey().Address().String()) + hexAddr1 := "0x1000000000000000000000000000000000000000" + hexAddr2 := "0x2000000000000000000000000000000000000000" var vmdb *statedb.StateDB testCases := []struct { - name string - malleate func() - genState *types.GenesisState - expPanic bool + name string + malleate func() + getGenState func() *types.GenesisState + registeredModules []precompile_modules.Module + expPanic bool }{ { - "default", - func() {}, - types.DefaultGenesisState(), - false, + name: "default", + malleate: func() {}, + getGenState: func() *types.GenesisState { + return types.DefaultGenesisState() + }, + expPanic: false, }, { - "valid account", - func() { + name: "valid account", + malleate: func() { vmdb.AddBalance(address, big.NewInt(1)) }, - &types.GenesisState{ - Params: types.DefaultParams(), - Accounts: []types.GenesisAccount{ - { - Address: address.String(), - Storage: types.Storage{ - {Key: common.BytesToHash([]byte("key")).String(), Value: common.BytesToHash([]byte("value")).String()}, + getGenState: func() *types.GenesisState { + return &types.GenesisState{ + Params: types.DefaultParams(), + Accounts: []types.GenesisAccount{ + { + Address: address.String(), + Storage: types.Storage{ + {Key: common.BytesToHash([]byte("key")).String(), Value: common.BytesToHash([]byte("value")).String()}, + }, }, }, - }, + } }, - false, + expPanic: false, }, { - "account not found", - func() {}, - &types.GenesisState{ - Params: types.DefaultParams(), - Accounts: []types.GenesisAccount{ - { - Address: address.String(), + name: "account not found", + malleate: func() {}, + getGenState: func() *types.GenesisState { + return &types.GenesisState{ + Params: types.DefaultParams(), + Accounts: []types.GenesisAccount{ + { + Address: address.String(), + }, }, - }, + } }, - true, + expPanic: true, }, { - "invalid account type", - func() { + name: "invalid account type", + malleate: func() { acc := authtypes.NewBaseAccountWithAddress(address.Bytes()) suite.app.AccountKeeper.SetAccount(suite.ctx, acc) }, - &types.GenesisState{ - Params: types.DefaultParams(), - Accounts: []types.GenesisAccount{ - { - Address: address.String(), + getGenState: func() *types.GenesisState { + return &types.GenesisState{ + Params: types.DefaultParams(), + Accounts: []types.GenesisAccount{ + { + Address: address.String(), + }, }, - }, + } }, - true, + expPanic: true, }, { - "invalid code hash", - func() { + name: "invalid code hash", + malleate: func() { acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, address.Bytes()) suite.app.AccountKeeper.SetAccount(suite.ctx, acc) }, - &types.GenesisState{ - Params: types.DefaultParams(), - Accounts: []types.GenesisAccount{ - { - Address: address.String(), - Code: "ffffffff", + getGenState: func() *types.GenesisState { + return &types.GenesisState{ + Params: types.DefaultParams(), + Accounts: []types.GenesisAccount{ + { + Address: address.String(), + Code: "ffffffff", + }, }, - }, + } }, - true, + expPanic: true, }, { - "ignore empty account code checking", - func() { + name: "ignore empty account code checking", + malleate: func() { acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, address.Bytes()) suite.app.AccountKeeper.SetAccount(suite.ctx, acc) }, - &types.GenesisState{ - Params: types.DefaultParams(), - Accounts: []types.GenesisAccount{ - { - Address: address.String(), - Code: "", + getGenState: func() *types.GenesisState { + return &types.GenesisState{ + Params: types.DefaultParams(), + Accounts: []types.GenesisAccount{ + { + Address: address.String(), + Code: "", + }, }, - }, + } }, - false, + expPanic: false, }, { - "ignore empty account code checking with non-empty codehash", - func() { + name: "ignore empty account code checking with non-empty codehash", + malleate: func() { ethAcc := ðerminttypes.EthAccount{ BaseAccount: authtypes.NewBaseAccount(address.Bytes(), nil, 0, 0), CodeHash: common.BytesToHash([]byte{1, 2, 3}).Hex(), @@ -125,16 +141,69 @@ func (suite *EvmTestSuite) TestInitGenesis() { suite.app.AccountKeeper.SetAccount(suite.ctx, ethAcc) }, - &types.GenesisState{ - Params: types.DefaultParams(), - Accounts: []types.GenesisAccount{ - { - Address: address.String(), - Code: "", + getGenState: func() *types.GenesisState { + return &types.GenesisState{ + Params: types.DefaultParams(), + Accounts: []types.GenesisAccount{ + { + Address: address.String(), + Code: "", + }, }, - }, + } + }, + expPanic: false, + }, + { + name: "precompile is enabled and registered", + malleate: func() {}, + getGenState: func() *types.GenesisState { + defaultGen := types.DefaultGenesisState() + defaultGen.Params.EnabledPrecompiles = []string{hexAddr1} + return defaultGen + }, + registeredModules: []precompile_modules.Module{ + {Address: common.HexToAddress(hexAddr1)}, + }, + expPanic: false, + }, + { + name: "precompile is enabled, but not registered", + malleate: func() {}, + getGenState: func() *types.GenesisState { + defaultGen := types.DefaultGenesisState() + defaultGen.Params.EnabledPrecompiles = []string{hexAddr1} + return defaultGen + }, + registeredModules: nil, + expPanic: true, + }, + { + name: "enabled precompiles are not sorted", + malleate: func() {}, + getGenState: func() *types.GenesisState { + defaultGen := types.DefaultGenesisState() + defaultGen.Params.EnabledPrecompiles = []string{hexAddr2, hexAddr1} + return defaultGen + }, + registeredModules: []precompile_modules.Module{ + {Address: common.HexToAddress(hexAddr1)}, + {Address: common.HexToAddress(hexAddr2)}, + }, + expPanic: true, + }, + { + name: "enabled precompiles are not unique", + malleate: func() {}, + getGenState: func() *types.GenesisState { + defaultGen := types.DefaultGenesisState() + defaultGen.Params.EnabledPrecompiles = []string{hexAddr1, hexAddr1} + return defaultGen + }, + registeredModules: []precompile_modules.Module{ + {Address: common.HexToAddress(hexAddr1)}, }, - false, + expPanic: true, }, } @@ -149,13 +218,13 @@ func (suite *EvmTestSuite) TestInitGenesis() { if tc.expPanic { suite.Require().Panics( func() { - _ = evm.InitGenesis(suite.ctx, suite.app.EvmKeeper, suite.app.AccountKeeper, *tc.genState) + _ = evm.InitGenesis(suite.ctx, suite.app.EvmKeeper, suite.app.AccountKeeper, *tc.getGenState(), tc.registeredModules) }, ) } else { suite.Require().NotPanics( func() { - _ = evm.InitGenesis(suite.ctx, suite.app.EvmKeeper, suite.app.AccountKeeper, *tc.genState) + _ = evm.InitGenesis(suite.ctx, suite.app.EvmKeeper, suite.app.AccountKeeper, *tc.getGenState(), tc.registeredModules) }, ) } diff --git a/x/evm/module.go b/x/evm/module.go index 80ac05269b..353f887a96 100644 --- a/x/evm/module.go +++ b/x/evm/module.go @@ -20,18 +20,17 @@ import ( "encoding/json" "fmt" - "github.com/gorilla/mux" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/cometbft/cometbft/abci/types" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + precompile_modules "github.com/ethereum/go-ethereum/precompile/modules" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" "github.com/evmos/ethermint/x/evm/client/cli" "github.com/evmos/ethermint/x/evm/keeper" @@ -166,7 +165,7 @@ func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.V func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - InitGenesis(ctx, am.keeper, am.ak, genesisState) + InitGenesis(ctx, am.keeper, am.ak, genesisState, precompile_modules.RegisteredModules()) return []abci.ValidatorUpdate{} } From c8f023e74aac2dc0fb88cdfa5865c7316661c1af Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Wed, 1 May 2024 16:10:25 -0400 Subject: [PATCH 05/12] CR's fixes: improve params tests --- x/evm/keeper/params_test.go | 53 ++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/x/evm/keeper/params_test.go b/x/evm/keeper/params_test.go index 0ff251b734..be3839323c 100644 --- a/x/evm/keeper/params_test.go +++ b/x/evm/keeper/params_test.go @@ -17,14 +17,13 @@ import ( legacytestutil "github.com/evmos/ethermint/x/evm/types/legacy/testutil" ) -const ( - validEthAddress1 = "0xc0ffee254729296a45a3885639AC7E10F9d54979" - validEthAddress2 = "0xdF789447f8c5b3863bEB07F0272B78d1778EE11E" -) - func (suite *KeeperTestSuite) TestParams() { + addr1 := "0x1000000000000000000000000000000000000000" + addr2 := "0x2000000000000000000000000000000000000000" + params := suite.app.EvmKeeper.GetParams(suite.ctx) - suite.app.EvmKeeper.SetParams(suite.ctx, params) + err := suite.app.EvmKeeper.SetParams(suite.ctx, params) + suite.Require().NoError(err) testCases := []struct { name string paramsFun func() interface{} @@ -45,7 +44,8 @@ func (suite *KeeperTestSuite) TestParams() { "success - EvmDenom param is set to \"inj\" and can be retrieved correctly", func() interface{} { params.EvmDenom = "inj" - suite.app.EvmKeeper.SetParams(suite.ctx, params) + err := suite.app.EvmKeeper.SetParams(suite.ctx, params) + suite.Require().NoError(err) return params.EvmDenom }, func() interface{} { @@ -58,7 +58,8 @@ func (suite *KeeperTestSuite) TestParams() { "success - Check EnableCreate param is set to false and can be retrieved correctly", func() interface{} { params.EnableCreate = false - suite.app.EvmKeeper.SetParams(suite.ctx, params) + err := suite.app.EvmKeeper.SetParams(suite.ctx, params) + suite.Require().NoError(err) return params.EnableCreate }, func() interface{} { @@ -71,7 +72,8 @@ func (suite *KeeperTestSuite) TestParams() { "success - Check EnableCall param is set to false and can be retrieved correctly", func() interface{} { params.EnableCall = false - suite.app.EvmKeeper.SetParams(suite.ctx, params) + err := suite.app.EvmKeeper.SetParams(suite.ctx, params) + suite.Require().NoError(err) return params.EnableCall }, func() interface{} { @@ -84,7 +86,8 @@ func (suite *KeeperTestSuite) TestParams() { "success - Check AllowUnprotectedTxs param is set to false and can be retrieved correctly", func() interface{} { params.AllowUnprotectedTxs = false - suite.app.EvmKeeper.SetParams(suite.ctx, params) + err := suite.app.EvmKeeper.SetParams(suite.ctx, params) + suite.Require().NoError(err) return params.AllowUnprotectedTxs }, func() interface{} { @@ -97,7 +100,8 @@ func (suite *KeeperTestSuite) TestParams() { "success - Check ChainConfig param is set to the default value and can be retrieved correctly", func() interface{} { params.ChainConfig = types.DefaultChainConfig() - suite.app.EvmKeeper.SetParams(suite.ctx, params) + err := suite.app.EvmKeeper.SetParams(suite.ctx, params) + suite.Require().NoError(err) return params.ChainConfig }, func() interface{} { @@ -110,7 +114,8 @@ func (suite *KeeperTestSuite) TestParams() { "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) + err := suite.app.EvmKeeper.SetParams(suite.ctx, params) + suite.Require().NoError(err) var typedNil []string = nil // NOTE: despite we set EnabledPrecompiles as []string{}, it will be retrieved as nil return typedNil }, @@ -124,7 +129,8 @@ func (suite *KeeperTestSuite) TestParams() { "success - EnabledPrecompiles param is set to nil and can be retrieved correctly", func() interface{} { params.EnabledPrecompiles = nil - suite.app.EvmKeeper.SetParams(suite.ctx, params) + err := suite.app.EvmKeeper.SetParams(suite.ctx, params) + suite.Require().NoError(err) return params.EnabledPrecompiles }, func() interface{} { @@ -134,10 +140,11 @@ func (suite *KeeperTestSuite) TestParams() { true, }, { - "success - EnabledPrecompiles param is set to []string{\"0x100\", \"0x101\"} and can be retrieved correctly", + "success - EnabledPrecompiles param is set to []string{addr1, addr2} and can be retrieved correctly", func() interface{} { - params.EnabledPrecompiles = []string{validEthAddress1, validEthAddress2} - suite.app.EvmKeeper.SetParams(suite.ctx, params) + params.EnabledPrecompiles = []string{addr1, addr2} + err := suite.app.EvmKeeper.SetParams(suite.ctx, params) + suite.Require().NoError(err) return params.EnabledPrecompiles }, func() interface{} { @@ -146,6 +153,20 @@ func (suite *KeeperTestSuite) TestParams() { }, true, }, + { + "failure - EnabledPrecompiles param is set to []string{addr2, addr1} which fails is_sorted validation", + func() interface{} { + params.EnabledPrecompiles = []string{addr2, addr1} + err := suite.app.EvmKeeper.SetParams(suite.ctx, params) + suite.Require().Error(err) + return params.EnabledPrecompiles + }, + func() interface{} { + evmParams := suite.app.EvmKeeper.GetParams(suite.ctx) + return evmParams.GetEnabledPrecompiles() + }, + false, + }, } for _, tc := range testCases { suite.Run(tc.name, func() { From 108eb159bce95c2fe78d702381e6b4a5a285a503 Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Thu, 2 May 2024 08:46:00 -0400 Subject: [PATCH 06/12] CR's fixes: reduce code duplication --- x/evm/types/params.go | 25 +++++++++++-------------- x/evm/types/params_test.go | 32 ++++++++++++++++---------------- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/x/evm/types/params.go b/x/evm/types/params.go index e17aac5d67..f8091ca179 100644 --- a/x/evm/types/params.go +++ b/x/evm/types/params.go @@ -204,23 +204,24 @@ func validateEnabledPrecompiles(enabledPrecompiles []string) error { } } - if err := checkIfSortedInBytesRepr(enabledPrecompiles); err != nil { + addrs := make([]common.Address, len(enabledPrecompiles)) + for i, precompile := range enabledPrecompiles { + addrs[i] = common.HexToAddress(precompile) + } + + if err := checkIfSortedInBytesRepr(addrs); err != nil { return fmt.Errorf("enabled precompiles are not sorted: %v", err) } - if err := checkIfUniqueInBytesRepr(enabledPrecompiles); err != nil { + if err := checkIfUniqueInBytesRepr(addrs); err != nil { return fmt.Errorf("enabled precompiles are not unique: %v", err) } return nil } -func checkIfSortedInBytesRepr(hexAddrs []string) error { - n := len(hexAddrs) - addrs := make([]common.Address, n) - for i, addr := range hexAddrs { - addrs[i] = common.HexToAddress(addr) - } +func checkIfSortedInBytesRepr(addrs []common.Address) error { + n := len(addrs) for i := 0; i < n-1; i++ { cmp := bytes.Compare(addrs[i].Bytes(), addrs[i+1].Bytes()) @@ -232,12 +233,8 @@ func checkIfSortedInBytesRepr(hexAddrs []string) error { return nil } -func checkIfUniqueInBytesRepr(hexAddrs []string) error { - n := len(hexAddrs) - addrs := make([]common.Address, n) - for i, hexAddr := range hexAddrs { - addrs[i] = common.HexToAddress(hexAddr) - } +func checkIfUniqueInBytesRepr(addrs []common.Address) error { + n := len(addrs) exists := make(map[common.Address]struct{}, n) for _, addr := range addrs { diff --git a/x/evm/types/params_test.go b/x/evm/types/params_test.go index a4b675e4c3..0299eeb3ad 100644 --- a/x/evm/types/params_test.go +++ b/x/evm/types/params_test.go @@ -242,32 +242,32 @@ func TestCheckIfEnabledPrecompilesAreRegistered(t *testing.T) { } func TestCheckIfSortedInBytesRepr(t *testing.T) { - addr1 := "0x1000000000000000000000000000000000000000" - addr2 := "0x2000000000000000000000000000000000000000" + addr1 := common.HexToAddress("0x1000000000000000000000000000000000000000") + addr2 := common.HexToAddress("0x2000000000000000000000000000000000000000") // NOTE: we sort in bytes representation, so proper order will be []string{mixedCaseAddr, upperCaseAddr}, // and it differs from lexicographically sorted strings - upperCaseAddr := "0xAB00000000000000000000000000000000000000" - mixedCaseAddr := "0xaA00000000000000000000000000000000000000" + upperCaseAddr := common.HexToAddress("0xAB00000000000000000000000000000000000000") + mixedCaseAddr := common.HexToAddress("0xaA00000000000000000000000000000000000000") testCases := []struct { name string - addrs []string + addrs []common.Address sorted bool }{ { name: "test-case #1", - addrs: []string{addr1, addr2}, + addrs: []common.Address{addr1, addr2}, sorted: true, }, { name: "test-case #2", - addrs: []string{addr2, addr1}, + addrs: []common.Address{addr2, addr1}, sorted: false, }, { name: "test-case #3", - addrs: []string{mixedCaseAddr, upperCaseAddr}, + addrs: []common.Address{mixedCaseAddr, upperCaseAddr}, sorted: true, }, } @@ -284,32 +284,32 @@ func TestCheckIfSortedInBytesRepr(t *testing.T) { } func TestCheckIfUniqueInBytesRepr(t *testing.T) { - addr1 := "0x1000000000000000000000000000000000000000" - addr2 := "0x2000000000000000000000000000000000000000" + addr1 := common.HexToAddress("0x1000000000000000000000000000000000000000") + addr2 := common.HexToAddress("0x2000000000000000000000000000000000000000") // NOTE: we check uniqueness in bytes representation, so lowerCaseAddr and mixedCaseAddr are the same, // despite it differs in string representation - lowerCaseAddr := "0xab00000000000000000000000000000000000000" - mixedCaseAddr := "0xAb00000000000000000000000000000000000000" + lowerCaseAddr := common.HexToAddress("0xab00000000000000000000000000000000000000") + mixedCaseAddr := common.HexToAddress("0xAb00000000000000000000000000000000000000") testCases := []struct { name string - addrs []string + addrs []common.Address unique bool }{ { name: "test-case #1", - addrs: []string{addr1, addr2}, + addrs: []common.Address{addr1, addr2}, unique: true, }, { name: "test-case #2", - addrs: []string{addr1, addr1}, + addrs: []common.Address{addr1, addr1}, unique: false, }, { name: "test-case #3", - addrs: []string{lowerCaseAddr, mixedCaseAddr}, + addrs: []common.Address{lowerCaseAddr, mixedCaseAddr}, unique: false, }, } From fb6eea57e188c1ee94389ac993765882d5e30626 Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Thu, 2 May 2024 10:00:38 -0400 Subject: [PATCH 07/12] CR's fixes: improve params tests --- x/evm/types/params_test.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/x/evm/types/params_test.go b/x/evm/types/params_test.go index 0299eeb3ad..9ba2f692a3 100644 --- a/x/evm/types/params_test.go +++ b/x/evm/types/params_test.go @@ -1,6 +1,7 @@ package types import ( + "fmt" "testing" "github.com/ethereum/go-ethereum/common" @@ -196,45 +197,46 @@ func TestCheckIfEnabledPrecompilesAreRegistered(t *testing.T) { name string registeredModules []precompile_modules.Module enabledPrecompiles []string - expError bool + errorMsg string }{ { name: "test-case #1", registeredModules: []precompile_modules.Module{m("0x1"), m("0x2"), m("0x3")}, enabledPrecompiles: []string{a("0x1"), a("0x2"), a("0x3")}, - expError: false, + errorMsg: "", }, { name: "test-case #2", registeredModules: []precompile_modules.Module{m("0x1"), m("0x2"), m("0x3")}, enabledPrecompiles: []string{a("0x1"), a("0x3")}, - expError: false, + errorMsg: "", }, { name: "test-case #3", registeredModules: []precompile_modules.Module{m("0x1"), m("0x2"), m("0x3")}, enabledPrecompiles: []string{}, - expError: false, + errorMsg: "", }, { name: "test-case #4", registeredModules: []precompile_modules.Module{}, enabledPrecompiles: []string{}, - expError: false, + errorMsg: "", }, { name: "test-case #5", registeredModules: []precompile_modules.Module{m("0x1"), m("0x2"), m("0x3")}, - enabledPrecompiles: []string{"0x4"}, - expError: true, + enabledPrecompiles: []string{a("0x4")}, + errorMsg: fmt.Sprintf("precompile %v is enabled but not registered", a("0x4")), }, } for _, tc := range testCases { err := CheckIfEnabledPrecompilesAreRegistered(tc.registeredModules, tc.enabledPrecompiles) - if tc.expError { + if tc.errorMsg != "" { require.Error(t, err, tc.name) + require.Contains(t, err.Error(), tc.errorMsg) } else { require.NoError(t, err, tc.name) } From 770e0bad937b9bafdf085e546b678d75cc803839 Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Thu, 2 May 2024 10:55:01 -0400 Subject: [PATCH 08/12] CR's fixes: descriptive test names --- x/evm/types/params_test.go | 66 +++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/x/evm/types/params_test.go b/x/evm/types/params_test.go index 9ba2f692a3..6312838be0 100644 --- a/x/evm/types/params_test.go +++ b/x/evm/types/params_test.go @@ -200,31 +200,31 @@ func TestCheckIfEnabledPrecompilesAreRegistered(t *testing.T) { errorMsg string }{ { - name: "test-case #1", + name: "success: all enabled precompiles are registered #1", registeredModules: []precompile_modules.Module{m("0x1"), m("0x2"), m("0x3")}, enabledPrecompiles: []string{a("0x1"), a("0x2"), a("0x3")}, errorMsg: "", }, { - name: "test-case #2", + name: "success: all enabled precompiles are registered #2", registeredModules: []precompile_modules.Module{m("0x1"), m("0x2"), m("0x3")}, enabledPrecompiles: []string{a("0x1"), a("0x3")}, errorMsg: "", }, { - name: "test-case #3", + name: "success: no enabled precompiles", registeredModules: []precompile_modules.Module{m("0x1"), m("0x2"), m("0x3")}, enabledPrecompiles: []string{}, errorMsg: "", }, { - name: "test-case #4", + name: "success: no enabled precompiles and no registered modules", registeredModules: []precompile_modules.Module{}, enabledPrecompiles: []string{}, errorMsg: "", }, { - name: "test-case #5", + name: "failure: precompile is enabled, but not registered", registeredModules: []precompile_modules.Module{m("0x1"), m("0x2"), m("0x3")}, enabledPrecompiles: []string{a("0x4")}, errorMsg: fmt.Sprintf("precompile %v is enabled but not registered", a("0x4")), @@ -232,14 +232,16 @@ func TestCheckIfEnabledPrecompilesAreRegistered(t *testing.T) { } for _, tc := range testCases { - err := CheckIfEnabledPrecompilesAreRegistered(tc.registeredModules, tc.enabledPrecompiles) + t.Run(tc.name, func(t *testing.T) { + err := CheckIfEnabledPrecompilesAreRegistered(tc.registeredModules, tc.enabledPrecompiles) - if tc.errorMsg != "" { - require.Error(t, err, tc.name) - require.Contains(t, err.Error(), tc.errorMsg) - } else { - require.NoError(t, err, tc.name) - } + if tc.errorMsg != "" { + require.Error(t, err, tc.name) + require.Contains(t, err.Error(), tc.errorMsg) + } else { + require.NoError(t, err, tc.name) + } + }) } } @@ -258,30 +260,32 @@ func TestCheckIfSortedInBytesRepr(t *testing.T) { sorted bool }{ { - name: "test-case #1", + name: "success: addresses are sorted", addrs: []common.Address{addr1, addr2}, sorted: true, }, { - name: "test-case #2", + name: "failure: addresses are in reverse order", addrs: []common.Address{addr2, addr1}, sorted: false, }, { - name: "test-case #3", + name: "success: addresses are sorted in bytes representation", addrs: []common.Address{mixedCaseAddr, upperCaseAddr}, sorted: true, }, } for _, tc := range testCases { - err := checkIfSortedInBytesRepr(tc.addrs) + t.Run(tc.name, func(t *testing.T) { + err := checkIfSortedInBytesRepr(tc.addrs) - if tc.sorted { - require.NoError(t, err, tc.name) - } else { - require.Error(t, err, tc.name) - } + if tc.sorted { + require.NoError(t, err, tc.name) + } else { + require.Error(t, err, tc.name) + } + }) } } @@ -300,29 +304,31 @@ func TestCheckIfUniqueInBytesRepr(t *testing.T) { unique bool }{ { - name: "test-case #1", + name: "success: addresses are unique", addrs: []common.Address{addr1, addr2}, unique: true, }, { - name: "test-case #2", + name: "failure: addresses are not unique", addrs: []common.Address{addr1, addr1}, unique: false, }, { - name: "test-case #3", + name: "failure: addresses are not unique in bytes representation", addrs: []common.Address{lowerCaseAddr, mixedCaseAddr}, unique: false, }, } for _, tc := range testCases { - err := checkIfUniqueInBytesRepr(tc.addrs) + t.Run(tc.name, func(t *testing.T) { + err := checkIfUniqueInBytesRepr(tc.addrs) - if tc.unique { - require.NoError(t, err, tc.name) - } else { - require.Error(t, err, tc.name) - } + if tc.unique { + require.NoError(t, err, tc.name) + } else { + require.Error(t, err, tc.name) + } + }) } } From 013442b8d2b2a10d5b74b6e9b5c0b9c671b73bea Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Thu, 2 May 2024 21:59:56 -0400 Subject: [PATCH 09/12] CR's fixes: test only public API --- x/evm/types/params_test.go | 311 ++++++++++++++++++++++--------------- 1 file changed, 189 insertions(+), 122 deletions(-) diff --git a/x/evm/types/params_test.go b/x/evm/types/params_test.go index 6312838be0..2b913af6a5 100644 --- a/x/evm/types/params_test.go +++ b/x/evm/types/params_test.go @@ -10,11 +10,6 @@ import ( "github.com/stretchr/testify/require" ) -const ( - validEthAddress = "0xc0ffee254729296a45a3885639AC7E10F9d54979" - invalidEthAddress = "0xc0ffee254729296a45a3885639AC7E10F9d5497" -) - func TestParamsValidate(t *testing.T) { extraEips := []int64{2929, 1884, 1344} testCases := []struct { @@ -60,34 +55,212 @@ func TestParamsValidate(t *testing.T) { }, expError: true, }, + } + + for _, tc := range testCases { + err := tc.getParams().Validate() + + if tc.expError { + require.Error(t, err, tc.name) + } else { + require.NoError(t, err, tc.name) + } + } +} + +func TestEnabledPrecompilesAddressCorrectness(t *testing.T) { + const ( + validEthAddress = "0xc0ffee254729296a45a3885639AC7E10F9d54979" + invalidEthAddress = "0xc0ffee254729296a45a3885639AC7E10F9d5497" + ) + + testCases := []struct { + name string + getParams func() Params + errorMsg string + }{ { - name: "valid enabled precompiles", + name: "failure: empty address", getParams: func() Params { params := DefaultParams() - params.EnabledPrecompiles = []string{validEthAddress} + params.EnabledPrecompiles = []string{""} return params }, - expError: false, + errorMsg: "invalid hex address", }, { - name: "invalid enabled precompiles", + name: "failure: invalid address #1", getParams: func() Params { params := DefaultParams() params.EnabledPrecompiles = []string{invalidEthAddress} return params }, - expError: true, + errorMsg: "invalid hex address", + }, + { + name: "failure: invalid address #2", + getParams: func() Params { + params := DefaultParams() + params.EnabledPrecompiles = []string{validEthAddress, invalidEthAddress} + return params + }, + errorMsg: "invalid hex address", + }, + { + name: "success: pass nil as enabled precompiles", + getParams: func() Params { + params := DefaultParams() + params.EnabledPrecompiles = nil + return params + }, + errorMsg: "", + }, + { + name: "success: pass empty slice as enabled precompiles", + getParams: func() Params { + params := DefaultParams() + params.EnabledPrecompiles = []string{} + return params + }, + errorMsg: "", + }, + { + name: "success: valid address", + getParams: func() Params { + params := DefaultParams() + params.EnabledPrecompiles = []string{validEthAddress} + return params + }, + errorMsg: "", }, } for _, tc := range testCases { - err := tc.getParams().Validate() + t.Run(tc.name, func(t *testing.T) { + err := tc.getParams().Validate() - if tc.expError { - require.Error(t, err, tc.name) - } else { - require.NoError(t, err, tc.name) - } + if tc.errorMsg == "" { + require.NoError(t, err, tc.name) + } else { + require.ErrorContains(t, err, tc.errorMsg, tc.name) + } + }) + } +} + +func TestEnabledPrecompilesOrderInBytesRepr(t *testing.T) { + const ( + addr1 = "0x1000000000000000000000000000000000000000" + addr2 = "0x2000000000000000000000000000000000000000" + + // NOTE: we sort in bytes representation, so proper order will be []string{mixedCaseAddr, upperCaseAddr}, + // and it differs from lexicographically sorted strings + upperCaseAddr = "0xAB00000000000000000000000000000000000000" + mixedCaseAddr = "0xaA00000000000000000000000000000000000000" + ) + + testCases := []struct { + name string + getParams func() Params + errorMsg string + }{ + { + name: "success: addresses are sorted", + getParams: func() Params { + params := DefaultParams() + params.EnabledPrecompiles = []string{addr1, addr2} + return params + }, + errorMsg: "", + }, + { + name: "failure: addresses are in reverse order", + getParams: func() Params { + params := DefaultParams() + params.EnabledPrecompiles = []string{addr2, addr1} + return params + }, + errorMsg: "enabled precompiles are not sorted", + }, + { + name: "success: addresses are sorted in bytes representation", + getParams: func() Params { + params := DefaultParams() + params.EnabledPrecompiles = []string{mixedCaseAddr, upperCaseAddr} + return params + }, + errorMsg: "", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + err := tc.getParams().Validate() + + if tc.errorMsg == "" { + require.NoError(t, err, tc.name) + } else { + require.ErrorContains(t, err, tc.errorMsg, tc.name) + } + }) + } +} + +func TestEnabledPrecompilesUniquenessInBytesRepr(t *testing.T) { + const ( + addr1 = "0x1000000000000000000000000000000000000000" + addr2 = "0x2000000000000000000000000000000000000000" + + // NOTE: we check uniqueness in bytes representation, so lowerCaseAddr and mixedCaseAddr are the same, + // despite it differs in string representation + lowerCaseAddr = "0xab00000000000000000000000000000000000000" + mixedCaseAddr = "0xAb00000000000000000000000000000000000000" + ) + + testCases := []struct { + name string + getParams func() Params + errorMsg string + }{ + { + name: "success: addresses are unique", + getParams: func() Params { + params := DefaultParams() + params.EnabledPrecompiles = []string{addr1, addr2} + return params + }, + errorMsg: "", + }, + { + name: "failure: addresses are not unique", + getParams: func() Params { + params := DefaultParams() + params.EnabledPrecompiles = []string{addr1, addr1} + return params + }, + errorMsg: "enabled precompiles are not unique", + }, + { + name: "failure: addresses are not unique in bytes representation", + getParams: func() Params { + params := DefaultParams() + params.EnabledPrecompiles = []string{lowerCaseAddr, mixedCaseAddr} + return params + }, + errorMsg: "enabled precompiles are not unique", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + err := tc.getParams().Validate() + + if tc.errorMsg == "" { + require.NoError(t, err, tc.name) + } else { + require.ErrorContains(t, err, tc.errorMsg, tc.name) + } + }) } } @@ -106,24 +279,6 @@ func TestParamsValidatePriv(t *testing.T) { require.NoError(t, validateBool(true)) require.Error(t, validateEIPs("")) require.NoError(t, validateEIPs([]int64{1884})) - - require.Error(t, validateEnabledPrecompiles([]string{""})) - require.Error(t, validateEnabledPrecompiles([]string{invalidEthAddress})) - require.Error(t, validateEnabledPrecompiles([]string{validEthAddress, invalidEthAddress})) - require.NoError(t, validateEnabledPrecompiles(nil)) - require.NoError(t, validateEnabledPrecompiles([]string{})) - require.NoError(t, validateEnabledPrecompiles([]string{validEthAddress})) - - addr1 := "0x1000000000000000000000000000000000000000" - addr2 := "0x2000000000000000000000000000000000000000" - - // check if sorted - require.NoError(t, validateEnabledPrecompiles([]string{addr1, addr2})) - require.Error(t, validateEnabledPrecompiles([]string{addr2, addr1})) - - // check if unique - require.NoError(t, validateEnabledPrecompiles([]string{addr1, addr2})) - require.Error(t, validateEnabledPrecompiles([]string{addr1, addr1})) } func TestValidateChainConfig(t *testing.T) { @@ -244,91 +399,3 @@ func TestCheckIfEnabledPrecompilesAreRegistered(t *testing.T) { }) } } - -func TestCheckIfSortedInBytesRepr(t *testing.T) { - addr1 := common.HexToAddress("0x1000000000000000000000000000000000000000") - addr2 := common.HexToAddress("0x2000000000000000000000000000000000000000") - - // NOTE: we sort in bytes representation, so proper order will be []string{mixedCaseAddr, upperCaseAddr}, - // and it differs from lexicographically sorted strings - upperCaseAddr := common.HexToAddress("0xAB00000000000000000000000000000000000000") - mixedCaseAddr := common.HexToAddress("0xaA00000000000000000000000000000000000000") - - testCases := []struct { - name string - addrs []common.Address - sorted bool - }{ - { - name: "success: addresses are sorted", - addrs: []common.Address{addr1, addr2}, - sorted: true, - }, - { - name: "failure: addresses are in reverse order", - addrs: []common.Address{addr2, addr1}, - sorted: false, - }, - { - name: "success: addresses are sorted in bytes representation", - addrs: []common.Address{mixedCaseAddr, upperCaseAddr}, - sorted: true, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - err := checkIfSortedInBytesRepr(tc.addrs) - - if tc.sorted { - require.NoError(t, err, tc.name) - } else { - require.Error(t, err, tc.name) - } - }) - } -} - -func TestCheckIfUniqueInBytesRepr(t *testing.T) { - addr1 := common.HexToAddress("0x1000000000000000000000000000000000000000") - addr2 := common.HexToAddress("0x2000000000000000000000000000000000000000") - - // NOTE: we check uniqueness in bytes representation, so lowerCaseAddr and mixedCaseAddr are the same, - // despite it differs in string representation - lowerCaseAddr := common.HexToAddress("0xab00000000000000000000000000000000000000") - mixedCaseAddr := common.HexToAddress("0xAb00000000000000000000000000000000000000") - - testCases := []struct { - name string - addrs []common.Address - unique bool - }{ - { - name: "success: addresses are unique", - addrs: []common.Address{addr1, addr2}, - unique: true, - }, - { - name: "failure: addresses are not unique", - addrs: []common.Address{addr1, addr1}, - unique: false, - }, - { - name: "failure: addresses are not unique in bytes representation", - addrs: []common.Address{lowerCaseAddr, mixedCaseAddr}, - unique: false, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - err := checkIfUniqueInBytesRepr(tc.addrs) - - if tc.unique { - require.NoError(t, err, tc.name) - } else { - require.Error(t, err, tc.name) - } - }) - } -} From c2e188f64f76a433679d10b59e47131ef62ce35d Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Thu, 2 May 2024 23:05:50 -0400 Subject: [PATCH 10/12] CR's fixes: rename function --- x/evm/genesis.go | 2 +- x/evm/types/params.go | 3 ++- x/evm/types/params_test.go | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/x/evm/genesis.go b/x/evm/genesis.go index 67ef6c33cc..992d53c9fd 100644 --- a/x/evm/genesis.go +++ b/x/evm/genesis.go @@ -40,7 +40,7 @@ func InitGenesis( ) []abci.ValidatorUpdate { k.WithChainID(ctx) - err := types.CheckIfEnabledPrecompilesAreRegistered( + err := types.ValidatePrecompileRegistration( registeredModules, data.Params.GetEnabledPrecompiles(), ) diff --git a/x/evm/types/params.go b/x/evm/types/params.go index f8091ca179..fcd45d8a73 100644 --- a/x/evm/types/params.go +++ b/x/evm/types/params.go @@ -253,7 +253,8 @@ func IsLondon(ethConfig *params.ChainConfig, height int64) bool { return ethConfig.IsLondon(big.NewInt(height)) } -func CheckIfEnabledPrecompilesAreRegistered(registeredModules []precompile_modules.Module, enabledPrecompiles []string) error { +// ValidatePrecompileRegistration checks that all enabled precompiles are registered. +func ValidatePrecompileRegistration(registeredModules []precompile_modules.Module, enabledPrecompiles []string) error { registeredAddrs := make(map[string]struct{}, len(registeredModules)) for _, module := range registeredModules { diff --git a/x/evm/types/params_test.go b/x/evm/types/params_test.go index 2b913af6a5..15a48686c2 100644 --- a/x/evm/types/params_test.go +++ b/x/evm/types/params_test.go @@ -338,7 +338,7 @@ func TestIsLondon(t *testing.T) { } } -func TestCheckIfEnabledPrecompilesAreRegistered(t *testing.T) { +func TestValidatePrecompileRegistration(t *testing.T) { m := func(addr string) precompile_modules.Module { return precompile_modules.Module{ Address: common.HexToAddress(addr), @@ -388,7 +388,7 @@ func TestCheckIfEnabledPrecompilesAreRegistered(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - err := CheckIfEnabledPrecompilesAreRegistered(tc.registeredModules, tc.enabledPrecompiles) + err := ValidatePrecompileRegistration(tc.registeredModules, tc.enabledPrecompiles) if tc.errorMsg != "" { require.Error(t, err, tc.name) From 27126aac5cd4e43252f2baa8ce9e8b198ba990a2 Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Fri, 3 May 2024 08:31:25 -0400 Subject: [PATCH 11/12] CR's fixes: rename functions --- x/evm/types/params.go | 10 ++++++---- x/evm/types/params_test.go | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/x/evm/types/params.go b/x/evm/types/params.go index fcd45d8a73..0ddb10242e 100644 --- a/x/evm/types/params.go +++ b/x/evm/types/params.go @@ -209,18 +209,19 @@ func validateEnabledPrecompiles(enabledPrecompiles []string) error { addrs[i] = common.HexToAddress(precompile) } - if err := checkIfSortedInBytesRepr(addrs); err != nil { + if err := validateSortingInBytesRepr(addrs); err != nil { return fmt.Errorf("enabled precompiles are not sorted: %v", err) } - if err := checkIfUniqueInBytesRepr(addrs); err != nil { + if err := validateUniquenessInBytesRepr(addrs); err != nil { return fmt.Errorf("enabled precompiles are not unique: %v", err) } return nil } -func checkIfSortedInBytesRepr(addrs []common.Address) error { +// validateSortingInBytesRepr checks if bytes representation of addresses are sorted in ascending order +func validateSortingInBytesRepr(addrs []common.Address) error { n := len(addrs) for i := 0; i < n-1; i++ { @@ -233,7 +234,8 @@ func checkIfSortedInBytesRepr(addrs []common.Address) error { return nil } -func checkIfUniqueInBytesRepr(addrs []common.Address) error { +// validateUniquenessInBytesRepr checks if bytes representation of addresses are unique +func validateUniquenessInBytesRepr(addrs []common.Address) error { n := len(addrs) exists := make(map[common.Address]struct{}, n) diff --git a/x/evm/types/params_test.go b/x/evm/types/params_test.go index 15a48686c2..24b52e1ab0 100644 --- a/x/evm/types/params_test.go +++ b/x/evm/types/params_test.go @@ -148,7 +148,7 @@ func TestEnabledPrecompilesAddressCorrectness(t *testing.T) { } } -func TestEnabledPrecompilesOrderInBytesRepr(t *testing.T) { +func TestEnabledPrecompilesSortingInBytesRepr(t *testing.T) { const ( addr1 = "0x1000000000000000000000000000000000000000" addr2 = "0x2000000000000000000000000000000000000000" From d6a06d7d70a65e20ff1d251fd5ae45376398788b Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Fri, 3 May 2024 08:43:57 -0400 Subject: [PATCH 12/12] Improve doc comments --- proto/ethermint/evm/v1/evm.proto | 2 ++ x/evm/types/evm.pb.go | 16 ++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/proto/ethermint/evm/v1/evm.proto b/proto/ethermint/evm/v1/evm.proto index be36686576..43b3e7a5f2 100644 --- a/proto/ethermint/evm/v1/evm.proto +++ b/proto/ethermint/evm/v1/evm.proto @@ -26,6 +26,8 @@ message Params { 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. + // enabled_precompiles should be sorted in ascending order and unique. + // sorting and uniqueness are checked against bytes representation of addresses repeated string enabled_precompiles = 8; } diff --git a/x/evm/types/evm.pb.go b/x/evm/types/evm.pb.go index ee4b4be350..9b89c17420 100644 --- a/x/evm/types/evm.pb.go +++ b/x/evm/types/evm.pb.go @@ -37,13 +37,15 @@ type Params struct { ExtraEIPs []int64 `protobuf:"varint,4,rep,packed,name=extra_eips,json=extraEips,proto3" json:"extra_eips,omitempty" yaml:"extra_eips"` // chain_config defines the EVM chain configuration parameters ChainConfig ChainConfig `protobuf:"bytes,5,opt,name=chain_config,json=chainConfig,proto3" json:"chain_config" yaml:"chain_config"` - // list of allowed eip712 msgs and their types + // eip712_allowed_msgs contains list of allowed eip712 msgs and their types EIP712AllowedMsgs []EIP712AllowedMsg `protobuf:"bytes,6,rep,name=eip712_allowed_msgs,json=eip712AllowedMsgs,proto3" json:"eip712_allowed_msgs"` // allow_unprotected_txs defines if replay-protected (i.e non EIP155 // signed) transactions can be executed on the state machine. AllowUnprotectedTxs bool `protobuf:"varint,7,opt,name=allow_unprotected_txs,json=allowUnprotectedTxs,proto3" json:"allow_unprotected_txs,omitempty"` // enabled_precompiles contains list of hex-encoded evm addresses of enabled precompiled contracts. // Precompile must be registered before it can be enabled. + // enabled_precompiles should be sorted in ascending order and unique. + // sorting and uniqueness are checked against bytes representation of addresses EnabledPrecompiles []string `protobuf:"bytes,8,rep,name=enabled_precompiles,json=enabledPrecompiles,proto3" json:"enabled_precompiles,omitempty"` } @@ -696,13 +698,13 @@ func (m *TraceConfig) GetTracerJsonConfig() string { // EIP712AllowedMsg stores an allowed legacy msg and its eip712 type. type EIP712AllowedMsg struct { - // 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" MsgTypeUrl string `protobuf:"bytes,1,opt,name=msg_type_url,json=msgTypeUrl,proto3" json:"msg_type_url,omitempty"` - // name of the eip712 value type. ie "MsgValueSend" + // msg_value_type_name is a name of the eip712 value type. ie "MsgValueSend" MsgValueTypeName string `protobuf:"bytes,2,opt,name=msg_value_type_name,json=msgValueTypeName,proto3" json:"msg_value_type_name,omitempty"` - // types of the msg value + // value_types is a list of msg value types ValueTypes []EIP712MsgAttrType `protobuf:"bytes,3,rep,name=value_types,json=valueTypes,proto3" json:"value_types"` - // nested types of the msg value + // nested_types is a list of msg value nested types NestedTypes []EIP712NestedMsgType `protobuf:"bytes,4,rep,name=nested_types,json=nestedTypes,proto3" json:"nested_types"` } @@ -767,7 +769,7 @@ func (m *EIP712AllowedMsg) GetNestedTypes() []EIP712NestedMsgType { return nil } -// EIP712MsgType is the eip712 type of a single message. +// EIP712NestedMsgType is the eip712 type of a single message. type EIP712NestedMsgType struct { // name of the nested type. ie "Fee", "Coin" Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` @@ -824,7 +826,9 @@ func (m *EIP712NestedMsgType) GetAttrs() []EIP712MsgAttrType { // EIP712MsgAttrType is the eip712 type of a single message attribute. type EIP712MsgAttrType struct { + // name Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // type Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` }