evm

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanTransfer

func CanTransfer(
	ctx sdk.Context,
	evmKeeper anteinterfaces.EVMKeeper,
	msg core.Message,
	baseFee *big.Int,
	ethCfg *params.ChainConfig,
	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 CheckGasWanted

func CheckGasWanted(ctx sdk.Context, feeMarketKeeper anteinterfaces.FeeMarketKeeper, tx sdk.Tx, isLondon bool) error

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, msgIndex uint64)

EmitTxHashEvent emits the Ethereum tx

FIXME: This is Technical debt. Ideally the sdk.Tx hash should be the Ethereum tx hash (msg.Hash) instead of using events for indexing Eth txs. TxIndex should be included in the header vote extension as part of ABCI++

func FeeChecker

func FeeChecker(
	ctx sdk.Context,
	k anteinterfaces.FeeMarketKeeper,
	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(
	txData evmtypes.TxData,
	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(k anteinterfaces.FeeMarketKeeper) 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, evmKeeper anteinterfaces.EVMKeeper) (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,
	signer ethtypes.Signer,
	allowUnprotectedTxs bool,
) 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,
	txData evmtypes.TxData,
	from sdktypes.AccAddress,
) error

ValidateMsg validates an Ethereum specific message type and returns an error if invalid. It checks the following requirements: - nil MUST be passed as the from address - 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,
	accountKeeper anteinterfaces.AccountKeeper,
	account *statedb.Account,
	from common.Address,
	txData evmtypes.TxData,
) 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
	BlockTxIndex       uint64
	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,
) (*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 EthEmitEventDecorator

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

EthEmitEventDecorator emit events in ante handler in case of tx execution failed (out of block gas limit).

func NewEthEmitEventDecorator

func NewEthEmitEventDecorator(evmKeeper anteinterfaces.EVMKeeper) EthEmitEventDecorator

NewEthEmitEventDecorator creates a new EthEmitEventDecorator

func (EthEmitEventDecorator) AnteHandle

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

AnteHandle emits some basic events for the eth messages

type EthSetupContextDecorator

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

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

func NewEthSetUpContextDecorator

func NewEthSetUpContextDecorator(evmKeeper anteinterfaces.EVMKeeper) EthSetupContextDecorator

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 GasWantedDecorator

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

GasWantedDecorator keeps track of the gasWanted amount on the current block in transient store for BaseFee calculation. NOTE: This decorator does not perform any validation

func NewGasWantedDecorator

func NewGasWantedDecorator(
	evmKeeper anteinterfaces.EVMKeeper,
	feeMarketKeeper anteinterfaces.FeeMarketKeeper,
) GasWantedDecorator

NewGasWantedDecorator creates a new NewGasWantedDecorator

func (GasWantedDecorator) AnteHandle

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

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,
) 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