Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 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
10 changes: 6 additions & 4 deletions ante/evm/fee_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,16 @@ func TestSDKTxFeeChecker(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cfg := evmtypes.GetEthChainConfig()
chainCfg := evmtypes.GetChainConfig()
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)
}
evmKeeper := NewExtendedEVMKeeper()
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
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 {

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

View workflow job for this annotation

GitHub Actions / Run golangci-lint

type chainConfigProvider is unused (unused)
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
10 changes: 8 additions & 2 deletions mempool/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ func NewBlockchain(ctx func(height int64, prove bool) (sdk.Context, error), logg
// Config returns the Ethereum chain configuration. It should only be called after the chain is initialized.
// This provides the necessary parameters for EVM execution and transaction validation.
func (b *Blockchain) Config() *params.ChainConfig {
return evmtypes.GetEthChainConfig()
if cfg := b.vmKeeper.EthChainConfig(); cfg != nil {
return cfg
}
if chainCfg := b.vmKeeper.ChainConfig(); chainCfg != nil {
return chainCfg.EthereumConfig(nil)
}
return evmtypes.DefaultChainConfig(0).EthereumConfig(nil)
}

// CurrentBlock returns the current block header for the app.
Expand Down Expand Up @@ -109,7 +115,7 @@ func (b *Blockchain) CurrentBlock() *types.Header {
Difficulty: big.NewInt(0), // 0 difficulty on PoS
}

chainConfig := evmtypes.GetEthChainConfig()
chainConfig := b.Config()
if chainConfig.IsLondon(header.Number) {
baseFee := b.vmKeeper.GetBaseFee(ctx)
if baseFee != nil {
Expand Down
2 changes: 2 additions & 0 deletions mempool/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func TestBlockchainRaceCondition(t *testing.T) {
mockVMKeeper.On("GetBaseFee", mock.Anything).Return(big.NewInt(1000000000)).Maybe() // 1 gwei
mockFeeMarketKeeper.On("GetBlockGasWanted", mock.Anything).Return(uint64(10000000)).Maybe() // 10M gas
mockVMKeeper.On("GetParams", mock.Anything).Return(vmtypes.DefaultParams()).Maybe()
mockVMKeeper.On("ChainConfig").Return(ethCfg).Maybe()
mockVMKeeper.On("EthChainConfig").Return(ethCfg.EthereumConfig(nil)).Maybe()
mockVMKeeper.On("GetAccount", mock.Anything, common.Address{}).Return(&statedb.Account{}).Maybe()
mockVMKeeper.On("GetState", mock.Anything, common.Address{}, common.Hash{}).Return(common.Hash{}).Maybe()
mockVMKeeper.On("GetCode", mock.Anything, common.Hash{}).Return([]byte{}).Maybe()
Expand Down
3 changes: 3 additions & 0 deletions mempool/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
gethparams "github.com/ethereum/go-ethereum/params"

"github.com/cosmos/evm/x/vm/statedb"
vmtypes "github.com/cosmos/evm/x/vm/types"
Expand All @@ -17,6 +18,8 @@ type VMKeeperI interface {
GetBaseFee(ctx sdk.Context) *big.Int
GetParams(ctx sdk.Context) (params vmtypes.Params)
GetEvmCoinInfo(ctx sdk.Context) (coinInfo vmtypes.EvmCoinInfo)
ChainConfig() *vmtypes.ChainConfig
EthChainConfig() *gethparams.ChainConfig
GetAccount(ctx sdk.Context, addr common.Address) *statedb.Account
GetState(ctx sdk.Context, addr common.Address, key common.Hash) common.Hash
GetCode(ctx sdk.Context, codeHash common.Hash) []byte
Expand Down
41 changes: 41 additions & 0 deletions mempool/mocks/VMKeeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading