Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp(all): Add EVM, ERC-20, feemarket and precompiles from Evmos #37

Merged
merged 32 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
408300c
import evm feemarket and precompiles
Aug 13, 2024
d1bfb7c
add changelog entry
Aug 13, 2024
00b2252
more wip
Aug 13, 2024
2d1515c
add erc20 module and IBC middleware
Aug 13, 2024
56efcc9
regenerate protos
Aug 13, 2024
dc2e88f
untangle
Aug 13, 2024
b966b96
run go mod tidy
Aug 13, 2024
305393e
more wip
Aug 13, 2024
1b21e5b
Merge branch 'main' into add-modules
Aug 14, 2024
2faaaa1
wip
Aug 15, 2024
413d96c
fix all this s
Aug 16, 2024
ac682fd
address linters
Aug 16, 2024
79ac817
move some chain native stuff to testutils
Aug 16, 2024
b731356
fix extension options type url
Aug 16, 2024
81d3ef4
use empty default extensions as params
Aug 16, 2024
08b54b5
run go work sync
Aug 19, 2024
11aad01
rework default EVM genesis after removing default EVM params to be pa…
Aug 19, 2024
5e95113
fix error message and tests
Aug 19, 2024
013edbf
fix ante tests
Aug 19, 2024
774ac37
commit wip fixing tests
Aug 19, 2024
bd25c16
linters
Aug 19, 2024
ca5e49a
more evm tests fixed
Aug 20, 2024
196313c
add ibc module to example app
Aug 20, 2024
d8eafcf
use all available precompiles in example app
Aug 20, 2024
b99dfdc
fix more tests and add initial token pair to example application
Aug 20, 2024
50f5a5f
refactors to align genesis states with example chain and tests
Aug 20, 2024
7642c13
add default power reduction for 18 decimals and fixes / linters
Aug 21, 2024
c167e7e
fix tests
Aug 21, 2024
03c017d
avoid using hardcoded bech32 prefix in distribution precompile
Aug 21, 2024
6b6710e
address G115 int overflow linters
Aug 21, 2024
175c482
rename example app import alias
Aug 23, 2024
a3c4f48
add missing linters
Aug 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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"
example_app "github.com/evmos/os/example_chain"
MalteHerrmann marked this conversation as resolved.
Show resolved Hide resolved
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 *example_app.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 *example_app.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 = example_app.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(example_app.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
Loading