Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
5 changes: 0 additions & 5 deletions ante/cosmos/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ import (
)

func TestAuthzLimiterDecorator(t *testing.T) {
evmConfigurator := evmtypes.NewEVMConfigurator().
WithEVMCoinInfo(constants.ExampleChainCoinInfo[constants.ExampleChainID])
err := evmConfigurator.Configure()
require.NoError(t, err)

encodingCfg := encoding.MakeConfig(constants.ExampleChainID.EVMChainID)
txCfg := encodingCfg.TxConfig
testPrivKeys, testAddresses, err := testutil.GeneratePrivKeyAddressPairs(5)
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 @@ -3,8 +3,7 @@ package evm
import (
"math"

"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 @@ import (
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 @@ import (
// - 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 @@ func NewDynamicFeeChecker(feemarketParams *feemarkettypes.Params) authante.TxFee
// 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 @@ func FeeChecker(
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 @@ -36,23 +36,6 @@ func TestSDKTxFeeChecker(t *testing.T) {
chainID := uint64(testconstants.EighteenDecimalsChainID)
encodingConfig := encoding.MakeConfig(chainID) //nolint:staticcheck // this is used

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 @@ func TestSDKTxFeeChecker(t *testing.T) {

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 @@ func signMsgEthereumTx(t *testing.T, privKey *ethsecp256k1.PrivKey, args *evmsdk
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)))
require.NoError(t, msg.Sign(ethSigner, utiltx.NewSigner(privKey)))
return msg
}
Expand Down Expand Up @@ -196,23 +197,6 @@ func TestMonoDecorator(t *testing.T) {

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 @@ func TestMonoDecorator(t *testing.T) {
ctx := sdk.NewContext(nil, tmproto.Header{}, false, log.NewNopLogger())
ctx = ctx.WithBlockGasMeter(storetypes.NewGasMeter(1e19))

evmChainID := big.NewInt(int64(evmsdktypes.DefaultEVMChainID))
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 @@ -6,6 +6,7 @@ import (

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

anteinterfaces "github.com/cosmos/evm/ante/interfaces"
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"
Expand Down Expand Up @@ -33,6 +34,11 @@ type DecoratorUtils struct {
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 @@ func NewMonoDecoratorUtils(
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
4 changes: 0 additions & 4 deletions ethereum/eip712/preprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ type TestCaseStruct struct {
func TestLedgerPreprocessing(t *testing.T) {
// Update bech32 prefix
sdk.GetConfig().SetBech32PrefixForAccount(constants.ExampleBech32Prefix, "")
evmConfigurator := evmtypes.NewEVMConfigurator().
WithEVMCoinInfo(constants.ExampleChainCoinInfo[constants.ExampleChainID])
err := evmConfigurator.Configure()
require.NoError(t, err)

testCases := []TestCaseStruct{
createBasicTestCase(t),
Expand Down
7 changes: 6 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 @@ -470,6 +469,8 @@ func NewExampleApp(
),
)

app.PreciseBankKeeper.SetCoinInfo(app.EVMKeeper.EvmCoinInfo())

app.Erc20Keeper = erc20keeper.NewKeeper(
keys[erc20types.StoreKey],
appCodec,
Expand Down Expand Up @@ -803,6 +804,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
Loading