Skip to content

Commit

Permalink
imp(all): Add EVM, ERC-20, feemarket and precompiles from Evmos (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
MalteHerrmann authored Aug 23, 2024
1 parent 532e742 commit c7da69b
Show file tree
Hide file tree
Showing 650 changed files with 132,905 additions and 1,048 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This changelog was created using the `clu` binary

### Improvements

- (all) [#37](https://github.com/evmos/os/pull/37) Add EVM, feemarket and precompiles from evmOS.
- (all) [#38](https://github.com/evmos/os/pull/38) Add readme.
- (all) [#30](https://github.com/evmos/os/pull/30) Add example chain implementation and ante handlers.
- (ci) [#35](https://github.com/evmos/os/pull/35) Disable dependabot temporarily.
Expand Down
2 changes: 1 addition & 1 deletion ante/cosmos/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewAuthzLimiterDecorator(disabledMsgTypes ...string) AuthzLimiterDecorator

func (ald AuthzLimiterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
if err := ald.checkDisabledMsgs(tx.GetMsgs(), false, 1); err != nil {
return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, err.Error())
return ctx, errorsmod.Wrap(errortypes.ErrUnauthorized, err.Error())
}
return next(ctx, tx, simulate)
}
Expand Down
34 changes: 16 additions & 18 deletions ante/cosmos/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ import (
"testing"
"time"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/stretchr/testify/require"

"cosmossdk.io/math"
abci "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
sdkvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

ethtypes "github.com/ethereum/go-ethereum/core/types"
evmtypes "github.com/evmos/evmos/v19/x/evm/types"
cosmosante "github.com/evmos/os/ante/cosmos"
"github.com/evmos/os/testutil"
utiltx "github.com/evmos/os/testutil/tx"
evmtypes "github.com/evmos/os/x/evm/types"
"github.com/stretchr/testify/require"
)

func TestAuthzLimiterDecorator(t *testing.T) {
Expand Down Expand Up @@ -54,7 +52,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[1],
sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)),
sdk.NewCoins(sdk.NewInt64Coin(testutil.ExampleAttoDenom, 100e6)),
),
},
false,
Expand Down Expand Up @@ -136,7 +134,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
[]sdk.Msg{banktypes.NewMsgSend(
testAddresses[0],
testAddresses[3],
sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)),
sdk.NewCoins(sdk.NewInt64Coin(testutil.ExampleAttoDenom, 100e6)),
)}),
},
false,
Expand Down Expand Up @@ -170,7 +168,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[3],
sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)),
sdk.NewCoins(sdk.NewInt64Coin(testutil.ExampleAttoDenom, 100e6)),
),
&evmtypes.MsgEthereumTx{},
},
Expand Down Expand Up @@ -221,7 +219,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[3],
sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)),
sdk.NewCoins(sdk.NewInt64Coin(testutil.ExampleAttoDenom, 100e6)),
),
},
),
Expand All @@ -239,7 +237,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[3],
sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)),
sdk.NewCoins(sdk.NewInt64Coin(testutil.ExampleAttoDenom, 100e6)),
),
},
),
Expand All @@ -250,7 +248,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[3],
sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)),
sdk.NewCoins(sdk.NewInt64Coin(testutil.ExampleAttoDenom, 100e6)),
),
},
),
Expand Down Expand Up @@ -339,7 +337,7 @@ func (suite *AnteTestSuite) TestRejectMsgsInAuthz() {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[3],
sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)),
sdk.NewCoins(sdk.NewInt64Coin(testutil.ExampleAttoDenom, 100e6)),
),
msgEthereumTx,
},
Expand Down Expand Up @@ -370,7 +368,7 @@ func (suite *AnteTestSuite) TestRejectMsgsInAuthz() {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[3],
sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)),
sdk.NewCoins(sdk.NewInt64Coin(testutil.ExampleAttoDenom, 100e6)),
),
},
),
Expand All @@ -387,7 +385,7 @@ func (suite *AnteTestSuite) TestRejectMsgsInAuthz() {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[3],
sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)),
sdk.NewCoins(sdk.NewInt64Coin(testutil.ExampleAttoDenom, 100e6)),
),
},
),
Expand All @@ -398,7 +396,7 @@ func (suite *AnteTestSuite) TestRejectMsgsInAuthz() {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[3],
sdk.NewCoins(sdk.NewInt64Coin(evmtypes.DefaultEVMDenom, 100e6)),
sdk.NewCoins(sdk.NewInt64Coin(testutil.ExampleAttoDenom, 100e6)),
),
},
),
Expand All @@ -416,7 +414,7 @@ func (suite *AnteTestSuite) TestRejectMsgsInAuthz() {
)

if tc.isEIP712 {
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
coinAmount := sdk.NewCoin(testutil.ExampleAttoDenom, math.NewInt(20))
fees := sdk.NewCoins(coinAmount)
cosmosTxArgs := utiltx.CosmosTxArgs{
TxCfg: suite.clientCtx.TxConfig,
Expand Down Expand Up @@ -450,14 +448,14 @@ func (suite *AnteTestSuite) TestRejectMsgsInAuthz() {
Type: abci.CheckTxType_New,
},
)
suite.Require().Equal(resCheckTx.Code, tc.expectedCode, resCheckTx.Log)
suite.Require().Equal(tc.expectedCode, resCheckTx.Code, resCheckTx.Log)

resDeliverTx := suite.app.DeliverTx(
abci.RequestDeliverTx{
Tx: bz,
},
)
suite.Require().Equal(resDeliverTx.Code, tc.expectedCode, resDeliverTx.Log)
suite.Require().Equal(tc.expectedCode, resDeliverTx.Code, resDeliverTx.Log)
})
}
}
2 changes: 1 addition & 1 deletion ante/cosmos/eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
evmtypes "github.com/evmos/evmos/v19/x/evm/types"
"github.com/evmos/os/crypto/ethsecp256k1"
"github.com/evmos/os/ethereum/eip712"
"github.com/evmos/os/types"
evmtypes "github.com/evmos/os/x/evm/types"
)

var evmosCodec codec.ProtoCodecMarshaler
Expand Down
2 changes: 1 addition & 1 deletion ante/cosmos/min_gas_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (suite *AnteTestSuite) TestMinGasPriceDecorator() {
return txBuilder.GetTx()
},
false,
fmt.Sprintf("expected only use native token %s for fee", denom),
fmt.Sprintf("expected only native token %s for fee", denom),
true,
},
}
Expand Down
2 changes: 1 addition & 1 deletion ante/cosmos/reject_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
evmtypes "github.com/evmos/evmos/v19/x/evm/types"
evmtypes "github.com/evmos/os/x/evm/types"
)

// RejectMessagesDecorator prevents invalid msg types from being executed
Expand Down
20 changes: 9 additions & 11 deletions ante/cosmos/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"testing"
"time"

"github.com/stretchr/testify/suite"

sdkmath "cosmossdk.io/math"
"cosmossdk.io/simapp"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
Expand All @@ -16,30 +14,29 @@ import (
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"

"github.com/evmos/evmos/v19/x/evm/statedb"
evmtypes "github.com/evmos/evmos/v19/x/evm/types"
feemarkettypes "github.com/evmos/evmos/v19/x/feemarket/types"
"github.com/evmos/os/ante"
evmante "github.com/evmos/os/ante/evm"
"github.com/evmos/os/crypto/ethsecp256k1"
"github.com/evmos/os/encoding"
"github.com/evmos/os/ethereum/eip712"
app "github.com/evmos/os/example_chain"
exampleapp "github.com/evmos/os/example_chain"
chainante "github.com/evmos/os/example_chain/ante"
chaintestutil "github.com/evmos/os/example_chain/testutil"
"github.com/evmos/os/testutil"
"github.com/evmos/os/types"
"github.com/evmos/os/x/evm/statedb"
evmtypes "github.com/evmos/os/x/evm/types"
feemarkettypes "github.com/evmos/os/x/feemarket/types"
"github.com/stretchr/testify/suite"
)

type AnteTestSuite struct {
suite.Suite

ctx sdk.Context
app *app.ExampleChain
app *exampleapp.ExampleChain
clientCtx client.Context
anteHandler sdk.AnteHandler
ethSigner ethtypes.Signer
Expand All @@ -63,7 +60,7 @@ func (suite *AnteTestSuite) SetupTest() {
suite.Require().NoError(err)
suite.priv = priv

suite.app = app.EthSetup(checkTx, func(app *app.ExampleChain, genesis simapp.GenesisState) simapp.GenesisState {
suite.app = chaintestutil.EthSetup(checkTx, testutil.ExampleChainID, func(app *exampleapp.ExampleChain, genesis simapp.GenesisState) simapp.GenesisState {
if suite.enableFeemarket {
// setup feemarketGenesis params
feemarketGenesis := feemarkettypes.DefaultGenesisState()
Expand All @@ -75,6 +72,7 @@ func (suite *AnteTestSuite) SetupTest() {
genesis[feemarkettypes.ModuleName] = app.AppCodec().MustMarshalJSON(feemarketGenesis)
}
evmGenesis := evmtypes.DefaultGenesisState()
evmGenesis.Params.EvmDenom = exampleapp.ExampleChainDenom // NOTE: use chain-specific denomination here for testing
evmGenesis.Params.AllowUnprotectedTxs = false
if !suite.enableLondonHF {
maxInt := sdkmath.NewInt(math.MaxInt64)
Expand Down Expand Up @@ -105,7 +103,7 @@ func (suite *AnteTestSuite) SetupTest() {
err = suite.app.AccountKeeper.SetParams(infCtx, authtypes.DefaultParams())
suite.Require().NoError(err)

encodingConfig := encoding.MakeConfig(app.ModuleBasics)
encodingConfig := encoding.MakeConfig(exampleapp.ModuleBasics)
// We're using TestMsg amino encoding in some tests, so register it here.
encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil)
eip712.SetEncodingConfig(encodingConfig)
Expand Down
2 changes: 1 addition & 1 deletion ante/evm/01_setup_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
sdktypes "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
evmante "github.com/evmos/evmos/v19/x/evm/ante"
anteinterfaces "github.com/evmos/os/ante/interfaces"
evmante "github.com/evmos/os/x/evm/ante"
)

var _ sdktypes.AnteDecorator = &EthSetupContextDecorator{}
Expand Down
2 changes: 1 addition & 1 deletion ante/evm/04_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
sdktypes "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx"
evmtypes "github.com/evmos/evmos/v19/x/evm/types"
anteinterfaces "github.com/evmos/os/ante/interfaces"
evmtypes "github.com/evmos/os/x/evm/types"
)

// ValidateMsg validates an Ethereum specific message type and returns an error if invalid
Expand Down
23 changes: 12 additions & 11 deletions ante/evm/04_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
sdktypes "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
testkeyring "github.com/evmos/evmos/v19/testutil/integration/evmos/keyring"
evmtypes "github.com/evmos/evmos/v19/x/evm/types"
"github.com/evmos/os/ante/evm"
"github.com/evmos/os/testutil"
testkeyring "github.com/evmos/os/testutil/integration/os/keyring"
evmtypes "github.com/evmos/os/x/evm/types"
)

type validateMsgParams struct {
Expand All @@ -32,7 +33,7 @@ func (suite *EvmAnteTestSuite) TestValidateMsg() {
expectedError: errortypes.ErrInvalidRequest,
getFunctionParams: func() validateMsgParams {
return validateMsgParams{
evmParams: evmtypes.DefaultParams(),
evmParams: evmtypes.DefaultParamsWithEVMDenom(testutil.ExampleAttoDenom),
txData: nil,
from: keyring.GetAccAddr(0),
}
Expand All @@ -46,7 +47,7 @@ func (suite *EvmAnteTestSuite) TestValidateMsg() {
txData, err := txArgs.ToTxData()
suite.Require().NoError(err)
return validateMsgParams{
evmParams: evmtypes.DefaultParams(),
evmParams: evmtypes.DefaultParamsWithEVMDenom(testutil.ExampleAttoDenom),
txData: txData,
from: nil,
}
Expand All @@ -60,7 +61,7 @@ func (suite *EvmAnteTestSuite) TestValidateMsg() {
txData, err := txArgs.ToTxData()
suite.Require().NoError(err)

params := evmtypes.DefaultParams()
params := evmtypes.DefaultParamsWithEVMDenom(testutil.ExampleAttoDenom)
params.AccessControl.Call.AccessType = evmtypes.AccessTypeRestricted
params.AccessControl.Create.AccessType = evmtypes.AccessTypeRestricted

Expand All @@ -79,7 +80,7 @@ func (suite *EvmAnteTestSuite) TestValidateMsg() {
txData, err := txArgs.ToTxData()
suite.Require().NoError(err)
return validateMsgParams{
evmParams: evmtypes.DefaultParams(),
evmParams: evmtypes.DefaultParamsWithEVMDenom(testutil.ExampleAttoDenom),
txData: txData,
from: nil,
}
Expand All @@ -93,7 +94,7 @@ func (suite *EvmAnteTestSuite) TestValidateMsg() {
txData, err := txArgs.ToTxData()
suite.Require().NoError(err)

params := evmtypes.DefaultParams()
params := evmtypes.DefaultParamsWithEVMDenom(testutil.ExampleAttoDenom)
params.AccessControl.Create.AccessType = evmtypes.AccessTypeRestricted

return validateMsgParams{
Expand All @@ -111,7 +112,7 @@ func (suite *EvmAnteTestSuite) TestValidateMsg() {
txData, err := txArgs.ToTxData()
suite.Require().NoError(err)

params := evmtypes.DefaultParams()
params := evmtypes.DefaultParamsWithEVMDenom(testutil.ExampleAttoDenom)
params.AccessControl.Call.AccessType = evmtypes.AccessTypeRestricted

return validateMsgParams{
Expand All @@ -129,7 +130,7 @@ func (suite *EvmAnteTestSuite) TestValidateMsg() {
txData, err := txArgs.ToTxData()
suite.Require().NoError(err)
return validateMsgParams{
evmParams: evmtypes.DefaultParams(),
evmParams: evmtypes.DefaultParamsWithEVMDenom(testutil.ExampleAttoDenom),
txData: txData,
from: nil,
}
Expand All @@ -143,7 +144,7 @@ func (suite *EvmAnteTestSuite) TestValidateMsg() {
txData, err := txArgs.ToTxData()
suite.Require().NoError(err)

params := evmtypes.DefaultParams()
params := evmtypes.DefaultParamsWithEVMDenom(testutil.ExampleAttoDenom)
params.AccessControl.Call.AccessType = evmtypes.AccessTypeRestricted

return validateMsgParams{
Expand All @@ -161,7 +162,7 @@ func (suite *EvmAnteTestSuite) TestValidateMsg() {
txData, err := txArgs.ToTxData()
suite.Require().NoError(err)

params := evmtypes.DefaultParams()
params := evmtypes.DefaultParamsWithEVMDenom(testutil.ExampleAttoDenom)
params.AccessControl.Create.AccessType = evmtypes.AccessTypeRestricted

return validateMsgParams{
Expand Down
2 changes: 1 addition & 1 deletion ante/evm/05_signature_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
ethtypes "github.com/ethereum/go-ethereum/core/types"
evmtypes "github.com/evmos/evmos/v19/x/evm/types"
anteinterfaces "github.com/evmos/os/ante/interfaces"
evmtypes "github.com/evmos/os/x/evm/types"
)

// EthSigVerificationDecorator validates an ethereum signatures
Expand Down
6 changes: 3 additions & 3 deletions ante/evm/06_account_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
"github.com/evmos/evmos/v19/x/evm/keeper"
"github.com/evmos/evmos/v19/x/evm/statedb"
evmtypes "github.com/evmos/evmos/v19/x/evm/types"
"github.com/evmos/os/x/evm/keeper"
"github.com/evmos/os/x/evm/statedb"
evmtypes "github.com/evmos/os/x/evm/types"
)

// VerifyAccountBalance checks that the account balance is greater than the total transaction cost.
Expand Down
Loading

0 comments on commit c7da69b

Please sign in to comment.