From 8920dc3a82b6004a30f460f1bb57c895bb0db636 Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 15 Jul 2025 12:17:11 +0800 Subject: [PATCH 1/7] feat: re-use tx validation rules from go-ethereum --- ante/evm/05_signature_verification.go | 4 ++-- ante/evm/mono_decorator.go | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ante/evm/05_signature_verification.go b/ante/evm/05_signature_verification.go index 674a3540b..8b33d5235 100644 --- a/ante/evm/05_signature_verification.go +++ b/ante/evm/05_signature_verification.go @@ -49,7 +49,7 @@ func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) } - err := SignatureVerification(msgEthTx, signer, allowUnprotectedTxs) + err := SignatureVerification(msgEthTx, msgEthTx.AsTransaction(), signer, allowUnprotectedTxs) if err != nil { return ctx, err } @@ -64,10 +64,10 @@ func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s // computed from the signature of the Ethereum transaction. func SignatureVerification( msg *evmtypes.MsgEthereumTx, + ethTx *ethtypes.Transaction, signer ethtypes.Signer, allowUnprotectedTxs bool, ) error { - ethTx := msg.AsTransaction() ethCfg := evmtypes.GetEthChainConfig() if !allowUnprotectedTxs { diff --git a/ante/evm/mono_decorator.go b/ante/evm/mono_decorator.go index 0a9b82f98..b9ad5172c 100644 --- a/ante/evm/mono_decorator.go +++ b/ante/evm/mono_decorator.go @@ -1,9 +1,11 @@ package evm import ( + "math" "math/big" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/txpool" ethtypes "github.com/ethereum/go-ethereum/core/types" anteinterfaces "github.com/cosmos/evm/ante/interfaces" @@ -18,6 +20,12 @@ import ( txtypes "github.com/cosmos/cosmos-sdk/types/tx" ) +const ACCEPTED_TX_TYPE = 0 | + 1< Date: Fri, 18 Jul 2025 09:31:28 +0800 Subject: [PATCH 2/7] fix format --- ante/evm/mono_decorator.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ante/evm/mono_decorator.go b/ante/evm/mono_decorator.go index a604fa3ca..463255f66 100644 --- a/ante/evm/mono_decorator.go +++ b/ante/evm/mono_decorator.go @@ -96,9 +96,9 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne return ctx, err } - ethTx := ethMsg.AsTransaction() + ethTx := ethMsg.AsTransaction() - // call go-ethereum transaction validation + // call go-ethereum transaction validation header := ethtypes.Header{ GasLimit: ctx.BlockGasMeter().Limit(), BaseFee: decUtils.BaseFee, @@ -113,7 +113,7 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne }); err != nil { return ctx, err } - + feeAmt := txData.Fee() gas := txData.GetGas() fee := sdkmath.LegacyNewDecFromBigInt(feeAmt) @@ -157,7 +157,7 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne // 5. signature verification if err := SignatureVerification( ethMsg, - ethTx, + ethTx, decUtils.Signer, decUtils.EvmParams.AllowUnprotectedTxs, ); err != nil { From 9ea97b5ca540c3088a1823e394cad93662809d03 Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 12 Aug 2025 13:49:43 +0800 Subject: [PATCH 3/7] fix lint --- ante/evm/mono_decorator.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ante/evm/mono_decorator.go b/ante/evm/mono_decorator.go index c1757545c..30f2f4af6 100644 --- a/ante/evm/mono_decorator.go +++ b/ante/evm/mono_decorator.go @@ -20,7 +20,7 @@ import ( txtypes "github.com/cosmos/cosmos-sdk/types/tx" ) -const ACCEPTED_TX_TYPE = 0 | +const AcceptedTxType = 0 | 1< Date: Tue, 12 Aug 2025 14:18:43 +0800 Subject: [PATCH 4/7] add missing gas rules --- x/vm/keeper/grpc_query.go | 2 +- x/vm/keeper/state_transition.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/x/vm/keeper/grpc_query.go b/x/vm/keeper/grpc_query.go index 3c8f787ef..ddbeef402 100644 --- a/x/vm/keeper/grpc_query.go +++ b/x/vm/keeper/grpc_query.go @@ -392,7 +392,7 @@ func (k Keeper) EstimateGasInternal(c context.Context, req *types.EthCallRequest // pass false to not commit StateDB rsp, err = k.ApplyMessageWithConfig(tmpCtx, msg, nil, false, cfg, txConfig, false) if err != nil { - if errors.Is(err, core.ErrIntrinsicGas) { + if errors.Is(err, core.ErrIntrinsicGas) || errors.Is(err, core.ErrFloorDataGas) { return true, nil, nil // Special case, raise gas limit } return true, nil, err // Bail out diff --git a/x/vm/keeper/state_transition.go b/x/vm/keeper/state_transition.go index 2c518878d..74d4b3e8d 100644 --- a/x/vm/keeper/state_transition.go +++ b/x/vm/keeper/state_transition.go @@ -1,6 +1,7 @@ package keeper import ( + "fmt" "math/big" "github.com/ethereum/go-ethereum/common" @@ -377,11 +378,21 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context, msg core.Message, trace // eth_estimateGas will check for this exact error return nil, errorsmod.Wrap(core.ErrIntrinsicGas, "apply message") } + // Gas limit suffices for the floor data cost (EIP-7623) + rules := ethCfg.Rules(big.NewInt(ctx.BlockHeight()), true, uint64(ctx.BlockTime().Unix())) //#nosec G115 -- int overflow is not a concern here + if rules.IsPrague { + floorDataGas, err := core.FloorDataGas(msg.Data) + if err != nil { + return nil, err + } + if msg.GasLimit < floorDataGas { + return nil, fmt.Errorf("%w: have %d, want %d", core.ErrFloorDataGas, msg.GasLimit, floorDataGas) + } + } leftoverGas -= intrinsicGas // access list preparation is moved from ante handler to here, because it's needed when `ApplyMessage` is called // under contexts where ante handlers are not run, for example `eth_call` and `eth_estimateGas`. - rules := ethCfg.Rules(big.NewInt(ctx.BlockHeight()), true, uint64(ctx.BlockTime().Unix())) //#nosec G115 -- int overflow is not a concern here stateDB.Prepare(rules, msg.From, common.Address{}, msg.To, evm.ActivePrecompiles(), msg.AccessList) convertedValue, err := utils.Uint256FromBigInt(msg.Value) From 98b225bab236d072e8fbdf7bebad0d040582c15b Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 12 Aug 2025 15:52:59 +0800 Subject: [PATCH 5/7] fix test --- tests/integration/precompiles/gov/test_integration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/precompiles/gov/test_integration.go b/tests/integration/precompiles/gov/test_integration.go index 0eda32bea..1c6a49706 100644 --- a/tests/integration/precompiles/gov/test_integration.go +++ b/tests/integration/precompiles/gov/test_integration.go @@ -108,7 +108,7 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp BeforeEach(func() { callArgs.MethodName = method }) It("fails with low gas", func() { - txArgs.GasLimit = 30_000 + txArgs.GasLimit = 37_790 // meed the requirement of floor data gas cost jsonBlob := minimalBankSendProposalJSON(proposerAccAddr, s.network.GetBaseDenom(), "50") callArgs.Args = []interface{}{proposerAddr, jsonBlob, minimalDeposit(s.network.GetBaseDenom(), big.NewInt(1))} From dc23ff301dd4a5258597b48a95b4ab62bc3b9143 Mon Sep 17 00:00:00 2001 From: yihuang Date: Thu, 14 Aug 2025 23:56:26 +0800 Subject: [PATCH 6/7] fix build --- ante/evm/mono_decorator.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/ante/evm/mono_decorator.go b/ante/evm/mono_decorator.go index ec8ab4f23..33a5f2466 100644 --- a/ante/evm/mono_decorator.go +++ b/ante/evm/mono_decorator.go @@ -96,8 +96,6 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne return ctx, err } - ethTx := ethMsg.AsTransaction() - // call go-ethereum transaction validation header := ethtypes.Header{ GasLimit: ctx.BlockGasMeter().Limit(), From 6f0737c8057eec9bce3d8408f94e5b68e2ccdc50 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 15 Aug 2025 11:07:45 +0800 Subject: [PATCH 7/7] don't check tx gas --- ante/evm/mono_decorator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ante/evm/mono_decorator.go b/ante/evm/mono_decorator.go index 33a5f2466..3277fbc76 100644 --- a/ante/evm/mono_decorator.go +++ b/ante/evm/mono_decorator.go @@ -98,7 +98,7 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne // call go-ethereum transaction validation header := ethtypes.Header{ - GasLimit: ctx.BlockGasMeter().Limit(), + GasLimit: ethTx.Gas(), BaseFee: decUtils.BaseFee, Number: big.NewInt(ctx.BlockHeight()), Time: uint64(ctx.BlockTime().Unix()), //nolint:gosec