Skip to content
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ante/cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func newCosmosAnteHandler(ctx sdk.Context, options HandlerOptions) sdk.AnteHandl
feemarketParams := options.FeeMarketKeeper.GetParams(ctx)
var txFeeChecker ante.TxFeeChecker
if options.DynamicFeeChecker {
txFeeChecker = evmante.NewDynamicFeeChecker(&feemarketParams)
txFeeChecker = evmante.NewDynamicFeeChecker(options.EvmKeeper, &feemarketParams)
}

return sdk.ChainAnteDecorators(
Expand All @@ -30,7 +30,7 @@ func newCosmosAnteHandler(ctx sdk.Context, options HandlerOptions) sdk.AnteHandl
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
cosmosante.NewMinGasPriceDecorator(&feemarketParams),
cosmosante.NewMinGasPriceDecorator(&feemarketParams, options.EvmKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, txFeeChecker),
// SetPubKeyDecorator must be called before all signature verification decorators
Expand Down
12 changes: 8 additions & 4 deletions ante/cosmos/min_gas_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"math/big"
"slices"

anteinterfaces "github.com/cosmos/evm/ante/interfaces"
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"
evmtypes "github.com/cosmos/evm/x/vm/types"

errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
Expand All @@ -22,12 +22,16 @@ import (
// CONTRACT: Tx must implement FeeTx to use MinGasPriceDecorator
type MinGasPriceDecorator struct {
feemarketParams *feemarkettypes.Params
evmKeeper anteinterfaces.EVMKeeper
}

// NewMinGasPriceDecorator creates a new MinGasPriceDecorator instance used only for
// Cosmos transactions.
func NewMinGasPriceDecorator(feemarketParams *feemarkettypes.Params) MinGasPriceDecorator {
return MinGasPriceDecorator{feemarketParams}
func NewMinGasPriceDecorator(feemarketParams *feemarkettypes.Params, evmKeeper anteinterfaces.EVMKeeper) MinGasPriceDecorator {
return MinGasPriceDecorator{
feemarketParams: feemarketParams,
evmKeeper: evmKeeper,
}
}

func (mpd MinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
Expand All @@ -39,7 +43,7 @@ func (mpd MinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
minGasPrice := mpd.feemarketParams.MinGasPrice

feeCoins := feeTx.GetFee()
evmDenom := evmtypes.GetEVMCoinDenom()
evmDenom := mpd.evmKeeper.EvmCoinInfo().Denom

// only allow user to pass in aatom and stake native token as transaction fees
// allow use stake native tokens for fees is just for unit tests to pass
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 @@ -32,7 +32,7 @@ func NewEthSigVerificationDecorator(ek anteinterfaces.EVMKeeper) EthSigVerificat
// Failure in RecheckTx will prevent tx to be included into block, especially when CheckTx succeed, in which case user
// won't see the error message.
func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
ethCfg := evmtypes.GetEthChainConfig()
ethCfg := esvd.evmKeeper.EthChainConfig()
blockNum := big.NewInt(ctx.BlockHeight())
signer := ethtypes.MakeSigner(ethCfg, blockNum, uint64(ctx.BlockTime().Unix())) //#nosec G115 -- int overflow is not a concern here

Expand Down
3 changes: 1 addition & 2 deletions ante/evm/10_gas_wanted.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
anteinterfaces "github.com/cosmos/evm/ante/interfaces"
"github.com/cosmos/evm/ante/types"
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"
evmtypes "github.com/cosmos/evm/x/vm/types"

errorsmod "cosmossdk.io/errors"

Expand Down Expand Up @@ -37,7 +36,7 @@ func NewGasWantedDecorator(
}

func (gwd GasWantedDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
ethCfg := evmtypes.GetEthChainConfig()
ethCfg := gwd.evmKeeper.EthChainConfig()

blockHeight := big.NewInt(ctx.BlockHeight())
isLondon := ethCfg.IsLondon(blockHeight)
Expand Down
16 changes: 10 additions & 6 deletions ante/evm/fee_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import (
"math"

Check failure on line 5 in ante/evm/fee_checker.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not properly formatted (gci)
"github.com/ethereum/go-ethereum/params"

anteinterfaces "github.com/cosmos/evm/ante/interfaces"
cosmosevmtypes "github.com/cosmos/evm/ante/types"
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"
evmtypes "github.com/cosmos/evm/x/vm/types"
Expand All @@ -15,6 +14,7 @@
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
gethparams "github.com/ethereum/go-ethereum/params"
)

// NewDynamicFeeChecker returns a `TxFeeChecker` that applies a dynamic fee to
Expand All @@ -25,7 +25,7 @@
// - when `ExtensionOptionDynamicFeeTx` is omitted, `tipFeeCap` defaults to `MaxInt64`.
// - when london hardfork is not enabled, it falls back to SDK default behavior (validator min-gas-prices).
// - Tx priority is set to `effectiveGasPrice / DefaultPriorityReduction`.
func NewDynamicFeeChecker(feemarketParams *feemarkettypes.Params) authante.TxFeeChecker {
func NewDynamicFeeChecker(evmKeeper anteinterfaces.EVMKeeper, feemarketParams *feemarkettypes.Params) authante.TxFeeChecker {
return func(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, int64, error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
Expand All @@ -37,8 +37,12 @@
// genesis transactions: fallback to min-gas-price logic
return checkTxFeeWithValidatorMinGasPrices(ctx, feeTx)
}
denom := evmtypes.GetEVMCoinDenom()
ethCfg := evmtypes.GetEthChainConfig()
ethCfg := evmKeeper.EthChainConfig()
coinInfo := evmKeeper.EvmCoinInfo()
denom := coinInfo.Denom
if denom == "" {
denom = evmtypes.DefaultEVMDenom
}

return FeeChecker(ctx, feemarketParams, denom, ethCfg, feeTx)
}
Expand All @@ -49,7 +53,7 @@
ctx sdk.Context,
feemarketParams *feemarkettypes.Params,
denom string,
ethConfig *params.ChainConfig,
ethConfig *gethparams.ChainConfig,
feeTx sdk.FeeTx,
) (sdk.Coins, int64, error) {
if !evmtypes.IsLondon(ethConfig, ctx.BlockHeight()) {
Expand Down
28 changes: 7 additions & 21 deletions ante/evm/fee_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,8 @@
// without extension option
// london hardfork enableness
chainID := uint64(testconstants.EighteenDecimalsChainID)
encodingConfig := encoding.MakeConfig(chainID) //nolint:staticcheck // this is used

Check failure on line 37 in ante/evm/fee_checker_test.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

directive `//nolint:staticcheck // this is used` is unused for linter "staticcheck" (nolintlint)

configurator := evmtypes.NewEVMConfigurator()
configurator.ResetTestConfig()
// set global chain config
ethCfg := evmtypes.DefaultChainConfig(chainID)
if err := evmtypes.SetChainConfig(ethCfg); err != nil {
panic(err)
}
err := configurator.
WithExtendedEips(evmtypes.DefaultCosmosEVMActivators).
// NOTE: we're using the 18 decimals default for the example chain
WithEVMCoinInfo(testconstants.ChainsCoinInfo[chainID]).
Configure()
require.NoError(t, err)
if err != nil {
panic(err)
}

evmDenom := evmtypes.GetEVMCoinDenom()
minGasPrices := sdk.NewDecCoins(sdk.NewDecCoin(evmDenom, math.NewInt(10)))

Expand Down Expand Up @@ -251,14 +234,17 @@

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cfg := evmtypes.GetEthChainConfig()
evmKeeper := NewExtendedEVMKeeper()
chainCfg := evmKeeper.ChainConfig()
ethCfg := chainCfg.EthereumConfig(nil)
if !tc.londonEnabled {
cfg.LondonBlock = big.NewInt(10000)
ethCfg.LondonBlock = big.NewInt(10000)
} else {
cfg.LondonBlock = big.NewInt(0)
ethCfg.LondonBlock = big.NewInt(0)
}

feemarketParams := tc.feemarketParamsFn()
fees, priority, err := evm.NewDynamicFeeChecker(&feemarketParams)(tc.ctx, tc.buildTx())
fees, priority, err := evm.NewDynamicFeeChecker(evmKeeper, &feemarketParams)(tc.ctx, tc.buildTx())
if tc.expSuccess {
require.Equal(t, tc.expFees, fees.String())
require.Equal(t, tc.expPriority, priority)
Expand Down
7 changes: 5 additions & 2 deletions ante/evm/mono_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
}
}

evmDenom := evmtypes.GetEVMCoinDenom()
evmDenom := md.evmKeeper.EvmCoinInfo().Denom
if evmDenom == "" {
evmDenom = evmtypes.DefaultEVMDenom
}

// 1. setup ctx
ctx, err = SetupContextAndResetTransientGas(ctx, tx, md.evmKeeper)
Expand Down Expand Up @@ -112,7 +115,7 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
Difficulty: big.NewInt(0),
}

chainConfig := evmtypes.GetEthChainConfig()
chainConfig := md.evmKeeper.EthChainConfig()

if err := txpool.ValidateTransaction(ethTx, &header, decUtils.Signer, &txpool.ValidationOptions{
Config: chainConfig,
Expand Down
23 changes: 4 additions & 19 deletions ante/evm/mono_decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@
msg := evmsdktypes.NewTx(args)
fromAddr := common.BytesToAddress(privKey.PubKey().Address().Bytes())
msg.From = fromAddr.Bytes()
ethSigner := ethtypes.LatestSignerForChainID(evmsdktypes.GetEthChainConfig().ChainID)
chainID := evmsdktypes.DefaultEVMChainID
ethSigner := ethtypes.LatestSignerForChainID(big.NewInt(int64(chainID)))

Check failure on line 125 in ante/evm/mono_decorator_test.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

G115: integer overflow conversion uint64 -> int64 (gosec)
require.NoError(t, msg.Sign(ethSigner, utiltx.NewSigner(privKey)))
return msg
}
Expand Down Expand Up @@ -196,23 +197,6 @@

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
configurator := evmsdktypes.NewEVMConfigurator()
configurator.ResetTestConfig()
chainConfig := evmsdktypes.DefaultChainConfig(evmsdktypes.DefaultEVMChainID)
err := evmsdktypes.SetChainConfig(chainConfig)
require.NoError(t, err)
coinInfo := evmsdktypes.EvmCoinInfo{
Denom: evmsdktypes.DefaultEVMExtendedDenom,
ExtendedDenom: evmsdktypes.DefaultEVMExtendedDenom,
DisplayDenom: evmsdktypes.DefaultEVMDisplayDenom,
Decimals: 18,
}
err = configurator.
WithExtendedEips(evmsdktypes.DefaultCosmosEVMActivators).
// NOTE: we're using the 18 decimals default for the example chain
WithEVMCoinInfo(coinInfo).
Configure()
require.NoError(t, err)
privKey, _ := ethsecp256k1.GenerateKey()
keeper, cosmosAddr := setupFundedKeeper(t, privKey)
accountKeeper := MockAccountKeeper{FundedAddr: cosmosAddr}
Expand All @@ -223,8 +207,9 @@
ctx := sdk.NewContext(nil, tmproto.Header{}, false, log.NewNopLogger())
ctx = ctx.WithBlockGasMeter(storetypes.NewGasMeter(1e19))

evmChainID := big.NewInt(int64(evmsdktypes.DefaultEVMChainID))

Check failure on line 210 in ante/evm/mono_decorator_test.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

G115: integer overflow conversion uint64 -> int64 (gosec)
msgs := tc.buildMsgs(privKey)
tx, err := utiltx.PrepareEthTx(cfg.TxConfig, nil, toMsgSlice(msgs)...)
tx, err := utiltx.PrepareEthTx(cfg.TxConfig, nil, evmChainID, toMsgSlice(msgs)...)
require.NoError(t, err)

newCtx, err := monoDec.AnteHandle(ctx, tx, tc.simulate, func(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) { return ctx, nil })
Expand Down
11 changes: 9 additions & 2 deletions ante/evm/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"math/big"

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

Check failure on line 8 in ante/evm/utils.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

ST1019: package "github.com/ethereum/go-ethereum/params" is being imported more than once (staticcheck)
gethparams "github.com/ethereum/go-ethereum/params"

Check failure on line 9 in ante/evm/utils.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

ST1019(related information): other import of "github.com/ethereum/go-ethereum/params" (staticcheck)

anteinterfaces "github.com/cosmos/evm/ante/interfaces"
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"
Expand Down Expand Up @@ -33,6 +34,11 @@
TxFee *big.Int
}

type chainConfigProvider interface {
EthChainConfig() *gethparams.ChainConfig
ChainConfig() *evmtypes.ChainConfig
}

// NewMonoDecoratorUtils returns a new DecoratorUtils instance.
//
// These utilities are extracted once at the beginning of the ante handle process,
Expand All @@ -47,8 +53,9 @@
evmParams *evmtypes.Params,
feemarketParams *feemarkettypes.Params,
) (*DecoratorUtils, error) {
ethCfg := evmtypes.GetEthChainConfig()
evmDenom := evmtypes.GetEVMCoinDenom()
ethCfg := ek.EthChainConfig()
evmDenom := ek.EvmCoinInfo().Denom

blockHeight := big.NewInt(ctx.BlockHeight())
rules := ethCfg.Rules(blockHeight, true, uint64(ctx.BlockTime().Unix())) //#nosec G115 -- int overflow is not a concern here
baseFee := evmtypes.GetBaseFee(ctx.BlockHeight(), ethCfg, feemarketParams)
Expand Down
4 changes: 4 additions & 0 deletions ante/interfaces/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/vm"
gethparams "github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"

feemarkettypes "github.com/cosmos/evm/x/feemarket/types"
Expand All @@ -26,6 +27,9 @@ type EVMKeeper interface {
ResetTransientGasUsed(ctx sdk.Context)
GetTxIndexTransient(ctx sdk.Context) uint64
GetParams(ctx sdk.Context) evmtypes.Params
ChainConfig() *evmtypes.ChainConfig
EthChainConfig() *gethparams.ChainConfig
EvmCoinInfo() evmtypes.EvmCoinInfo
}

// FeeMarketKeeper exposes the required feemarket keeper interface required for ante handlers
Expand Down
5 changes: 4 additions & 1 deletion evmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"os"


"github.com/spf13/cast"

// Force-load the tracer engines to trigger registration due to Go-Ethereum v1.10.15 changes
Expand Down Expand Up @@ -803,6 +802,10 @@ func (app *EVMD) RegisterPendingTxListener(listener func(common.Hash)) {
app.pendingTxListeners = append(app.pendingTxListeners, listener)
}

func (app *EVMD) RuntimeConfig() *evmtypes.RuntimeConfig {
return app.EVMKeeper.RuntimeConfig()
}

func (app *EVMD) setPostHandler() {
postHandler, err := posthandler.NewPostHandler(
posthandler.HandlerOptions{},
Expand Down
4 changes: 2 additions & 2 deletions evmd/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package evmd

import (
"fmt"

"github.com/cosmos/evm/server"

"cosmossdk.io/log"
Expand All @@ -11,12 +12,11 @@ import (
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"

evmmempool "github.com/cosmos/evm/mempool"
evmtypes "github.com/cosmos/evm/x/vm/types"
)

// configureEVMMempool sets up the EVM mempool and related handlers using viper configuration.
func (app *EVMD) configureEVMMempool(appOpts servertypes.AppOptions, logger log.Logger) error {
if evmtypes.GetChainConfig() == nil {
if app.EVMKeeper.ChainConfig() == nil {
logger.Debug("evm chain config is not set, skipping mempool configuration")
return nil
}
Expand Down
22 changes: 0 additions & 22 deletions evmd/tests/integration/x_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,6 @@ func BenchmarkGasEstimation(b *testing.B) {
// gh := grpc.NewIntegrationHandler(nw)
// tf := factory.New(nw, gh)

chainConfig := types.DefaultChainConfig(nw.GetEIP155ChainID().Uint64())
// get the denom and decimals set on chain initialization
// because we'll need to set them again when resetting the chain config
denom := types.GetEVMCoinDenom()
extendedDenom := types.GetEVMCoinExtendedDenom()
displayDenom := types.GetEVMCoinDisplayDenom()
decimals := types.GetEVMCoinDecimals()

configurator := types.NewEVMConfigurator()
configurator.ResetTestConfig()
err := types.SetChainConfig(chainConfig)
require.NoError(b, err)
err = configurator.
WithEVMCoinInfo(types.EvmCoinInfo{
Denom: denom,
ExtendedDenom: extendedDenom,
DisplayDenom: displayDenom,
Decimals: decimals.Uint32(),
}).
Configure()
require.NoError(b, err)

// Use simple transaction args for consistent benchmarking
args := types.TransactionArgs{
To: &common.Address{},
Expand Down
9 changes: 6 additions & 3 deletions evmd/testutil/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ func DeliverEthTx(
msgs ...sdk.Msg,
) (abci.ExecTxResult, error) {
txConfig := exampleApp.GetTxConfig()
evmChainID := exampleApp.GetEVMKeeper().EvmChainID()

tx, err := tx.PrepareEthTx(txConfig, priv, msgs...)
tx, err := tx.PrepareEthTx(txConfig, priv, evmChainID, msgs...)
if err != nil {
return abci.ExecTxResult{}, err
}
Expand All @@ -121,8 +122,9 @@ func DeliverEthTxWithoutCheck(
msgs ...sdk.Msg,
) (abci.ExecTxResult, error) {
txConfig := exampleApp.GetTxConfig()
evmChainID := exampleApp.GetEVMKeeper().EvmChainID()

tx, err := tx.PrepareEthTx(txConfig, priv, msgs...)
tx, err := tx.PrepareEthTx(txConfig, priv, evmChainID, msgs...)
if err != nil {
return abci.ExecTxResult{}, err
}
Expand Down Expand Up @@ -170,8 +172,9 @@ func CheckEthTx(
msgs ...sdk.Msg,
) (abci.ResponseCheckTx, error) {
txConfig := exampleApp.GetTxConfig()
evmChainID := exampleApp.GetEVMKeeper().EvmChainID()

tx, err := tx.PrepareEthTx(txConfig, priv, msgs...)
tx, err := tx.PrepareEthTx(txConfig, priv, evmChainID, msgs...)
if err != nil {
return abci.ResponseCheckTx{}, err
}
Expand Down
Loading
Loading