evm

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 26 Imported by: 38

Documentation

Index

Constants

View Source
const EthSigVerificationResultCacheKey = "ante:EthSigVerificationResult"

EthSigVerificationResultCacheKey caches sig verification per incarnation, since the result is a pure function of the tx bytes and signer.

Variables

This section is empty.

Functions

func CanTransfer

func CanTransfer(
	ctx sdk.Context,
	evmKeeper anteinterfaces.EVMKeeper,
	msg core.Message,
	baseFee *big.Int,
	params evmtypes.Params,
	isLondon bool,
) error

CanTransfer checks if the sender is allowed to transfer funds according to the EVM block

func CheckBlockGasLimit

func CheckBlockGasLimit(ctx sdktypes.Context, gasWanted uint64, minPriority int64) (sdktypes.Context, error)

TODO: (@fedekunze) Why is this necessary? This seems to be a duplicate from the CheckGasWanted function.

func CheckGlobalFee

func CheckGlobalFee(fee, globalMinGasPrice, gasLimit math.LegacyDec) error

CheckGlobalFee validates the provided fee value against the required global fee.

For dynamic transactions, GetFee() uses the GasFeeCap value, which is the maximum gas price that the signer can pay. In practice, the signer can pay less, if the block's BaseFee is lower. So, in this case, we use the EffectiveFee. If the feemarket formula results in a BaseFee that lowers EffectivePrice until it is < MinGasPrices, the users must increase the GasTipCap (priority fee) until EffectivePrice > MinGasPrices. Transactions with MinGasPrices * gasUsed < tx fees < EffectiveFee are rejected by the feemarket AnteHandle

func CheckMempoolFee

func CheckMempoolFee(fee, mempoolMinGasPrice, gasLimit sdkmath.LegacyDec, isLondon bool) error

CheckMempoolFee checks if the provided fee is at least as large as the local validator's configured value. The fee computation assumes that both price and fee are represented in 18 decimals.

func CheckTxFee

func CheckTxFee(txFeeInfo *tx.Fee, txFee *big.Int, txGasLimit uint64) error

CheckTxFee checks if the Amount and GasLimit fields of the txFeeInfo input are equal to the txFee coins and the txGasLimit value. The function expects txFeeInfo to contains coins in the original decimal representation.

func ConsumeFeesAndEmitEvent

func ConsumeFeesAndEmitEvent(
	ctx sdktypes.Context,
	evmKeeper anteinterfaces.EVMKeeper,
	fees sdktypes.Coins,
	from sdktypes.AccAddress,
) error

ConsumeFeesAndEmitEvent deduces fees from sender and emits the event

func EmitTxHashEvent

func EmitTxHashEvent(ctx sdk.Context, msg *evmtypes.MsgEthereumTx, blockTxIndex uint64)

EmitTxHashEvent emits the ethereum_tx event with the tx hash and the cosmos-tx index from ctx.TxIndex(). Emitting from the ante handler ensures expected-failure txs still produce the event for indexer lookups.

func FeeChecker

func FeeChecker(
	ctx sdk.Context,
	feemarketParams *feemarkettypes.Params,
	denom string,
	ethConfig *params.ChainConfig,
	feeTx sdk.FeeTx,
) (sdk.Coins, int64, error)

FeeChecker returns the effective fee and priority for a given transaction.

func GetMsgPriority

func GetMsgPriority(
	ethTx *ethtypes.Transaction,
	minPriority int64,
	baseFee *big.Int,
) int64

GetMsgPriority returns the priority of an Eth Tx capped by the minimum priority

func IncrementNonce

func IncrementNonce(
	ctx sdk.Context,
	accountKeeper anteinterfaces.AccountKeeper,
	account sdk.AccountI,
	txNonce uint64,
) error

IncrementNonce increments the sequence of the account.

func NewDynamicFeeChecker

func NewDynamicFeeChecker(feemarketParams *feemarkettypes.Params) authante.TxFeeChecker

NewDynamicFeeChecker returns a `TxFeeChecker` that applies a dynamic fee to Cosmos txs using the EIP-1559 fee market logic. This can be called in both CheckTx and deliverTx modes. a) feeCap = tx.fees / tx.gas b) tipFeeCap = tx.MaxPriorityPrice (default) or MaxInt64 - 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 SetupContextAndResetTransientGas

func SetupContextAndResetTransientGas(ctx sdktypes.Context, tx sdktypes.Tx) (sdktypes.Context, error)

SetupContextAndResetTransientGas modifies the context to be used in the execution of the ante handler associated with an EVM transaction. Previous gas consumed is reset in the transient store.

func SignatureVerification

func SignatureVerification(msg *evmtypes.MsgEthereumTx, _ *ethtypes.Transaction, signer ethtypes.Signer) error

SignatureVerification checks that the registered chain id is the same as the one on the message, and that the signer address matches the one defined on the message. The function set the field from of the given message equal to the sender computed from the signature of the Ethereum transaction.

func UpdateCumulativeGasWanted

func UpdateCumulativeGasWanted(
	ctx sdktypes.Context,
	msgGasWanted uint64,
	maxTxGasWanted uint64,
	cumulativeGasWanted uint64,
) uint64

UpdateCumulativeGasWanted updates the cumulative gas wanted

func ValidateMsg

func ValidateMsg(
	evmParams evmtypes.Params,
	ethTx *ethtypes.Transaction,
) error

ValidateMsg validates an Ethereum specific message type and returns an error if invalid. It checks the following requirements: - If the transaction is a contract creation or call, the corresponding operation must be enabled in the EVM parameters

func ValidateTx

func ValidateTx(tx sdktypes.Tx) (*tx.Fee, error)

ValidateTx validates an Ethereum specific transaction type and returns an error if invalid.

FIXME: this shouldn't be required if the tx was an Ethereum transaction type.

func VerifyAccountBalance

func VerifyAccountBalance(
	ctx sdk.Context,
	evmKeeper anteinterfaces.EVMKeeper,
	accountKeeper anteinterfaces.AccountKeeper,
	account *statedb.Account,
	from common.Address,
	ethTx *ethtypes.Transaction,
) error

VerifyAccountBalance checks that the account balance is greater than the total transaction cost. The account will be set to store if it doesn't exist, i.e. cannot be found on store. This method will fail if: - from address is NOT an EOA - account balance is lower than the transaction cost

Types

type DecoratorUtils

type DecoratorUtils struct {
	EvmParams          evmtypes.Params
	Rules              params.Rules
	Signer             ethtypes.Signer
	BaseFee            *big.Int
	MempoolMinGasPrice sdkmath.LegacyDec
	GlobalMinGasPrice  sdkmath.LegacyDec
	TxGasLimit         uint64
	GasWanted          uint64
	MinPriority        int64
	TxFee              *big.Int
}

DecoratorUtils contain a bunch of relevant variables used for a variety of checks throughout the verification of an Ethereum transaction.

func NewMonoDecoratorUtils

func NewMonoDecoratorUtils(
	ctx sdk.Context,
	ek anteinterfaces.EVMKeeper,
	evmParams *evmtypes.Params,
	feemarketParams *feemarkettypes.Params,
) (*DecoratorUtils, error)

NewMonoDecoratorUtils returns a new DecoratorUtils instance.

These utilities are extracted once at the beginning of the ante handle process, and are used throughout the entire decorator chain. This avoids redundant calls to the keeper and thus improves speed of transaction processing.

All prices, fees and balances are converted into 18 decimals here to be correctly used in the EVM.

type EthSetupContextDecorator

type EthSetupContextDecorator struct{}

EthSetupContextDecorator is adapted from SetUpContextDecorator from cosmos-sdk, it ignores gas consumption by setting the gas meter to infinite

func (EthSetupContextDecorator) AnteHandle

func (esc EthSetupContextDecorator) AnteHandle(ctx sdktypes.Context, tx sdktypes.Tx, simulate bool, next sdktypes.AnteHandler) (newCtx sdktypes.Context, err error)

type EthSigVerificationDecorator

type EthSigVerificationDecorator struct {
	// contains filtered or unexported fields
}

EthSigVerificationDecorator validates an ethereum signatures

func NewEthSigVerificationDecorator

func NewEthSigVerificationDecorator(ek anteinterfaces.EVMKeeper) EthSigVerificationDecorator

NewEthSigVerificationDecorator creates a new EthSigVerificationDecorator

func (EthSigVerificationDecorator) AnteHandle

func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error)

AnteHandle validates checks that the registered chain id is the same as the one on the message, and that the signer address matches the one defined on the message. It's not skipped for RecheckTx, because it set `From` address which is critical from other ante handler to work. 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.

type MonoDecorator

type MonoDecorator struct {
	// contains filtered or unexported fields
}

MonoDecorator is a single decorator that handles all the prechecks for ethereum transactions.

func NewEVMMonoDecorator

func NewEVMMonoDecorator(
	accountKeeper anteinterfaces.AccountKeeper,
	feeMarketKeeper anteinterfaces.FeeMarketKeeper,
	evmKeeper anteinterfaces.EVMKeeper,
	maxGasWanted uint64,
	evmParams *evmtypes.Params,
	feemarketParams *feemarkettypes.Params,
) MonoDecorator

NewEVMMonoDecorator creates the 'mono' decorator, that is used to run the ante handle logic for EVM transactions on the chain.

This runs all the default checks for EVM transactions enable through Cosmos EVM. Any partner chains can use this in their ante handler logic and build additional EVM decorators using the returned DecoratorUtils

func (MonoDecorator) AnteHandle

func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error)

AnteHandle handles the entire decorator chain using a mono decorator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL