From 9dd8b94679c76aa5b6f7f07f74a5ed0f48ea3e96 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 19 Mar 2026 09:55:22 +0800 Subject: [PATCH 1/4] feat: enable incarnation cache for verify result --- ante/evm/05_signature_verification.go | 20 ++++++++++++++++++-- ante/evm/mono_decorator.go | 14 ++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/ante/evm/05_signature_verification.go b/ante/evm/05_signature_verification.go index e24aee83c..12c2258ad 100644 --- a/ante/evm/05_signature_verification.go +++ b/ante/evm/05_signature_verification.go @@ -14,6 +14,8 @@ import ( errortypes "github.com/cosmos/cosmos-sdk/types/errors" ) +const EthSigVerificationResultCacheKey = "ante:EthSigVerificationResult" + // EthSigVerificationDecorator validates an ethereum signatures type EthSigVerificationDecorator struct { evmKeeper anteinterfaces.EVMKeeper @@ -32,6 +34,15 @@ 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) { + if v, ok := ctx.GetIncarnationCache(EthSigVerificationResultCacheKey); ok { + if v != nil { + if cachedErr, ok := v.(error); ok { + return ctx, cachedErr + } + } + return next(ctx, tx, simulate) + } + ethCfg := evmtypes.GetEthChainConfig() blockNum := big.NewInt(ctx.BlockHeight()) signer := ethtypes.MakeSigner(ethCfg, blockNum, uint64(ctx.BlockTime().Unix())) //#nosec G115 -- int overflow is not a concern here @@ -44,15 +55,20 @@ func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s for _, msg := range msgs { msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx) if !ok { - return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) + err = errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) + ctx.SetIncarnationCache(EthSigVerificationResultCacheKey, err) + return ctx, err } - err := SignatureVerification(msgEthTx, msgEthTx.AsTransaction(), signer) + err = SignatureVerification(msgEthTx, msgEthTx.AsTransaction(), signer) if err != nil { + ctx.SetIncarnationCache(EthSigVerificationResultCacheKey, err) return ctx, err } } + ctx.SetIncarnationCache(EthSigVerificationResultCacheKey, nil) + return next(ctx, tx, simulate) } diff --git a/ante/evm/mono_decorator.go b/ante/evm/mono_decorator.go index 9cccf8a79..1188f73ab 100644 --- a/ante/evm/mono_decorator.go +++ b/ante/evm/mono_decorator.go @@ -159,8 +159,18 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne } // 5. signature verification - if err := SignatureVerification(ethMsg, ethTx, decUtils.Signer); err != nil { - return ctx, err + if v, ok := ctx.GetIncarnationCache(EthSigVerificationResultCacheKey); ok { + if v != nil { + if cachedErr, ok := v.(error); ok { + return ctx, cachedErr + } + } + } else { + err = SignatureVerification(ethMsg, ethTx, decUtils.Signer) + ctx.SetIncarnationCache(EthSigVerificationResultCacheKey, err) + if err != nil { + return ctx, err + } } from := ethMsg.GetFrom() From 79a6b7af8d30ca859fb980eac583d257d9296470 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 23 Mar 2026 09:12:54 +0800 Subject: [PATCH 2/4] doc --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06a5b4824..2c316d31a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - [\#589](https://github.com/cosmos/evm/pull/589) Remove parallelization blockers via migration from transient to object store, refactoring of gas, indexing, and bloom utilities. - [\#768](https://github.com/cosmos/evm/pull/768) Added ICS-02 Client Router precompile - [\#815](https://github.com/cosmos/evm/pull/815) Support for multi gRPC query clients serve with old binary. +- [\#1082](https://github.com/cosmos/evm/pull/1082) Enable incarnation cache for verify result. ### BUG FIXES From 9aef3ff5a26995bf12f539968a6cf6f03ea9906e Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 23 Mar 2026 09:13:38 +0800 Subject: [PATCH 3/4] config pre-estimate --- evmd/app.go | 3 ++- server/config/config.go | 6 ++++++ server/config/toml.go | 3 +++ server/flags/flags.go | 1 + server/start.go | 3 ++- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/evmd/app.go b/evmd/app.go index be32fb902..5ebd8c9ff 100644 --- a/evmd/app.go +++ b/evmd/app.go @@ -253,13 +253,14 @@ func NewExampleApp( for _, k := range oKeys { nonTransientKeys = append(nonTransientKeys, k) } + preEstimate := cast.ToBool(appOpts.Get(srvflags.EVMBlockSTMPreEstimate)) // enable block stm for parallel execution bApp.SetBlockSTMTxRunner(txnrunner.NewSTMRunner( encodingConfig.TxConfig.TxDecoder(), nonTransientKeys, min(goruntime.GOMAXPROCS(0), goruntime.NumCPU()), - true, + preEstimate, func(ms storetypes.MultiStore) string { return sdk.DefaultBondDenom }, )) diff --git a/server/config/config.go b/server/config/config.go index cffb9f6b4..8c79c3121 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -58,6 +58,9 @@ const ( // DefaultEnablePreimageRecording is the default value for EnablePreimageRecording DefaultEnablePreimageRecording = false + // DefaultEVMBlockSTMPreEstimate controls whether block-stm disables pre-estimation by default. + DefaultEVMBlockSTMPreEstimate = false + // DefaultMaxTxGasWanted is the default gas wanted for each eth tx returned in ante handler in check tx mode DefaultMaxTxGasWanted = 0 @@ -145,6 +148,8 @@ type EVMConfig struct { MaxTxGasWanted uint64 `mapstructure:"max-tx-gas-wanted"` // Enables tracking of SHA3 preimages in the VM EnablePreimageRecording bool `mapstructure:"cache-preimage"` + // BlockSTMPreEstimate enables pre-estimation for block-stm execution. + BlockSTMPreEstimate bool `mapstructure:"block-stm-pre-estimate"` // EVMChainID defines the EIP-155 replay-protection chain ID. EVMChainID uint64 `mapstructure:"evm-chain-id"` // MinTip defines the minimum priority fee for the mempool @@ -295,6 +300,7 @@ func DefaultEVMConfig() *EVMConfig { MaxTxGasWanted: DefaultMaxTxGasWanted, EVMChainID: DefaultEVMChainID, EnablePreimageRecording: DefaultEnablePreimageRecording, + BlockSTMPreEstimate: DefaultEVMBlockSTMPreEstimate, MinTip: DefaultEVMMinTip, GethMetricsAddress: DefaultGethMetricsAddress, Mempool: DefaultMempoolConfig(), diff --git a/server/config/toml.go b/server/config/toml.go index 5e32ef9f9..40fe82e83 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -19,6 +19,9 @@ max-tx-gas-wanted = {{ .EVM.MaxTxGasWanted }} # EnablePreimageRecording enables tracking of SHA3 preimages in the VM cache-preimage = {{ .EVM.EnablePreimageRecording }} +# BlockSTMPreEstimate is the flag to enable pre-estimation for block-stm execution. +block-stm-pre-estimate = {{ .EVM.BlockSTMPreEstimate }} + # EVMChainID is the EIP-155 compatible replay protection chain ID. This is separate from the Cosmos chain ID. evm-chain-id = {{ .EVM.EVMChainID }} diff --git a/server/flags/flags.go b/server/flags/flags.go index 2eead2c22..419fb854f 100644 --- a/server/flags/flags.go +++ b/server/flags/flags.go @@ -67,6 +67,7 @@ const ( const ( EVMTracer = "evm.tracer" EVMMaxTxGasWanted = "evm.max-tx-gas-wanted" + EVMBlockSTMPreEstimate = "evm.block-stm-pre-estimate" EVMEnablePreimageRecording = "evm.cache-preimage" EVMChainID = "evm.evm-chain-id" EVMMinTip = "evm.min-tip" diff --git a/server/start.go b/server/start.go index cfbd5354b..5d3b4a054 100644 --- a/server/start.go +++ b/server/start.go @@ -219,7 +219,8 @@ which accepts a path for the resulting pprof file. cmd.Flags().String(srvflags.EVMTracer, cosmosevmserverconfig.DefaultEVMTracer, "the EVM tracer type to collect execution traces from the EVM transaction execution (json|struct|access_list|markdown)") //nolint:lll cmd.Flags().Uint64(srvflags.EVMMaxTxGasWanted, cosmosevmserverconfig.DefaultMaxTxGasWanted, "the gas wanted for each eth tx returned in ante handler in check tx mode") //nolint:lll - cmd.Flags().Bool(srvflags.EVMEnablePreimageRecording, cosmosevmserverconfig.DefaultEnablePreimageRecording, "Enables tracking of SHA3 preimages in the EVM (not implemented yet)") //nolint:lll + cmd.Flags().Bool(srvflags.EVMBlockSTMPreEstimate, cosmosevmserverconfig.DefaultEVMBlockSTMPreEstimate, "enable pre-estimation for block-stm execution") + cmd.Flags().Bool(srvflags.EVMEnablePreimageRecording, cosmosevmserverconfig.DefaultEnablePreimageRecording, "Enables tracking of SHA3 preimages in the EVM (not implemented yet)") //nolint:lll cmd.Flags().Uint64(srvflags.EVMChainID, cosmosevmserverconfig.DefaultEVMChainID, "the EIP-155 compatible replay protection chain ID") cmd.Flags().Uint64(srvflags.EVMMinTip, cosmosevmserverconfig.DefaultEVMMinTip, "the minimum priority fee for the mempool") cmd.Flags().String(srvflags.EvmGethMetricsAddress, cosmosevmserverconfig.DefaultGethMetricsAddress, "the address to bind the geth metrics server to") From df698874646cd32d71125f55481eef5f3087f2c7 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 23 Mar 2026 09:15:14 +0800 Subject: [PATCH 4/4] Revert "config pre-estimate" This reverts commit 9aef3ff5a26995bf12f539968a6cf6f03ea9906e. --- evmd/app.go | 3 +-- server/config/config.go | 6 ------ server/config/toml.go | 3 --- server/flags/flags.go | 1 - server/start.go | 3 +-- 5 files changed, 2 insertions(+), 14 deletions(-) diff --git a/evmd/app.go b/evmd/app.go index 5ebd8c9ff..be32fb902 100644 --- a/evmd/app.go +++ b/evmd/app.go @@ -253,14 +253,13 @@ func NewExampleApp( for _, k := range oKeys { nonTransientKeys = append(nonTransientKeys, k) } - preEstimate := cast.ToBool(appOpts.Get(srvflags.EVMBlockSTMPreEstimate)) // enable block stm for parallel execution bApp.SetBlockSTMTxRunner(txnrunner.NewSTMRunner( encodingConfig.TxConfig.TxDecoder(), nonTransientKeys, min(goruntime.GOMAXPROCS(0), goruntime.NumCPU()), - preEstimate, + true, func(ms storetypes.MultiStore) string { return sdk.DefaultBondDenom }, )) diff --git a/server/config/config.go b/server/config/config.go index 8c79c3121..cffb9f6b4 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -58,9 +58,6 @@ const ( // DefaultEnablePreimageRecording is the default value for EnablePreimageRecording DefaultEnablePreimageRecording = false - // DefaultEVMBlockSTMPreEstimate controls whether block-stm disables pre-estimation by default. - DefaultEVMBlockSTMPreEstimate = false - // DefaultMaxTxGasWanted is the default gas wanted for each eth tx returned in ante handler in check tx mode DefaultMaxTxGasWanted = 0 @@ -148,8 +145,6 @@ type EVMConfig struct { MaxTxGasWanted uint64 `mapstructure:"max-tx-gas-wanted"` // Enables tracking of SHA3 preimages in the VM EnablePreimageRecording bool `mapstructure:"cache-preimage"` - // BlockSTMPreEstimate enables pre-estimation for block-stm execution. - BlockSTMPreEstimate bool `mapstructure:"block-stm-pre-estimate"` // EVMChainID defines the EIP-155 replay-protection chain ID. EVMChainID uint64 `mapstructure:"evm-chain-id"` // MinTip defines the minimum priority fee for the mempool @@ -300,7 +295,6 @@ func DefaultEVMConfig() *EVMConfig { MaxTxGasWanted: DefaultMaxTxGasWanted, EVMChainID: DefaultEVMChainID, EnablePreimageRecording: DefaultEnablePreimageRecording, - BlockSTMPreEstimate: DefaultEVMBlockSTMPreEstimate, MinTip: DefaultEVMMinTip, GethMetricsAddress: DefaultGethMetricsAddress, Mempool: DefaultMempoolConfig(), diff --git a/server/config/toml.go b/server/config/toml.go index 40fe82e83..5e32ef9f9 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -19,9 +19,6 @@ max-tx-gas-wanted = {{ .EVM.MaxTxGasWanted }} # EnablePreimageRecording enables tracking of SHA3 preimages in the VM cache-preimage = {{ .EVM.EnablePreimageRecording }} -# BlockSTMPreEstimate is the flag to enable pre-estimation for block-stm execution. -block-stm-pre-estimate = {{ .EVM.BlockSTMPreEstimate }} - # EVMChainID is the EIP-155 compatible replay protection chain ID. This is separate from the Cosmos chain ID. evm-chain-id = {{ .EVM.EVMChainID }} diff --git a/server/flags/flags.go b/server/flags/flags.go index 419fb854f..2eead2c22 100644 --- a/server/flags/flags.go +++ b/server/flags/flags.go @@ -67,7 +67,6 @@ const ( const ( EVMTracer = "evm.tracer" EVMMaxTxGasWanted = "evm.max-tx-gas-wanted" - EVMBlockSTMPreEstimate = "evm.block-stm-pre-estimate" EVMEnablePreimageRecording = "evm.cache-preimage" EVMChainID = "evm.evm-chain-id" EVMMinTip = "evm.min-tip" diff --git a/server/start.go b/server/start.go index 5d3b4a054..cfbd5354b 100644 --- a/server/start.go +++ b/server/start.go @@ -219,8 +219,7 @@ which accepts a path for the resulting pprof file. cmd.Flags().String(srvflags.EVMTracer, cosmosevmserverconfig.DefaultEVMTracer, "the EVM tracer type to collect execution traces from the EVM transaction execution (json|struct|access_list|markdown)") //nolint:lll cmd.Flags().Uint64(srvflags.EVMMaxTxGasWanted, cosmosevmserverconfig.DefaultMaxTxGasWanted, "the gas wanted for each eth tx returned in ante handler in check tx mode") //nolint:lll - cmd.Flags().Bool(srvflags.EVMBlockSTMPreEstimate, cosmosevmserverconfig.DefaultEVMBlockSTMPreEstimate, "enable pre-estimation for block-stm execution") - cmd.Flags().Bool(srvflags.EVMEnablePreimageRecording, cosmosevmserverconfig.DefaultEnablePreimageRecording, "Enables tracking of SHA3 preimages in the EVM (not implemented yet)") //nolint:lll + cmd.Flags().Bool(srvflags.EVMEnablePreimageRecording, cosmosevmserverconfig.DefaultEnablePreimageRecording, "Enables tracking of SHA3 preimages in the EVM (not implemented yet)") //nolint:lll cmd.Flags().Uint64(srvflags.EVMChainID, cosmosevmserverconfig.DefaultEVMChainID, "the EIP-155 compatible replay protection chain ID") cmd.Flags().Uint64(srvflags.EVMMinTip, cosmosevmserverconfig.DefaultEVMMinTip, "the minimum priority fee for the mempool") cmd.Flags().String(srvflags.EvmGethMetricsAddress, cosmosevmserverconfig.DefaultGethMetricsAddress, "the address to bind the geth metrics server to")