1616package ante
1717
1818import (
19+ "fmt"
1920 "math"
2021 "math/big"
2122
@@ -24,14 +25,14 @@ import (
2425
2526 sdk "github.com/cosmos/cosmos-sdk/types"
2627 errortypes "github.com/cosmos/cosmos-sdk/types/errors"
28+ "github.com/holiman/uint256"
2729
2830 ethermint "github.com/zeta-chain/ethermint/types"
2931 "github.com/zeta-chain/ethermint/x/evm/keeper"
3032 "github.com/zeta-chain/ethermint/x/evm/statedb"
3133 evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
3234
3335 "github.com/ethereum/go-ethereum/common"
34- ethtypes "github.com/ethereum/go-ethereum/core/types"
3536)
3637
3738// EthAccountVerificationDecorator validates an account balance checks
@@ -94,7 +95,7 @@ func (avd EthAccountVerificationDecorator) AnteHandle(
9495 "the sender is not EOA: address %s, codeHash <%s>" , fromAddr , acct .CodeHash )
9596 }
9697
97- if err := keeper .CheckSenderBalance (sdkmath .NewIntFromBigInt (acct .Balance ), txData ); err != nil {
98+ if err := keeper .CheckSenderBalance (sdkmath .NewIntFromBigInt (acct .Balance . ToBig () ), txData ); err != nil {
9899 return ctx , errorsmod .Wrap (err , "failed to check sender balance" )
99100 }
100101 }
@@ -156,6 +157,7 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
156157 blockHeight := big .NewInt (ctx .BlockHeight ())
157158 homestead := ethCfg .IsHomestead (blockHeight )
158159 istanbul := ethCfg .IsIstanbul (blockHeight )
160+ shanghai := ethCfg .IsShanghai (blockHeight , 1 )
159161 var events sdk.Events
160162
161163 // Use the lowest priority of all the messages as the final one.
@@ -186,7 +188,7 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
186188
187189 evmDenom := evmParams .GetEvmDenom ()
188190
189- fees , err := keeper .VerifyFee (txData , evmDenom , baseFee , homestead , istanbul , ctx .IsCheckTx ())
191+ fees , err := keeper .VerifyFee (txData , evmDenom , baseFee , homestead , istanbul , shanghai , ctx .IsCheckTx ())
190192 if err != nil {
191193 return ctx , errorsmod .Wrapf (err , "failed to verify the fees" )
192194 }
@@ -258,7 +260,7 @@ func NewCanTransferDecorator(evmKeeper EVMKeeper) CanTransferDecorator {
258260func (ctd CanTransferDecorator ) AnteHandle (ctx sdk.Context , tx sdk.Tx , simulate bool , next sdk.AnteHandler ) (sdk.Context , error ) {
259261 params := ctd .evmKeeper .GetParams (ctx )
260262 ethCfg := params .ChainConfig .EthereumConfig (ctd .evmKeeper .ChainID ())
261- signer := ethtypes .MakeSigner (ethCfg , big .NewInt (ctx .BlockHeight ()))
263+ signer := ethermint .MakeSigner (ethCfg , big .NewInt (ctx .BlockHeight ()))
262264
263265 for _ , msg := range tx .GetMsgs () {
264266 msgEthTx , ok := msg .(* evmtypes.MsgEthereumTx )
@@ -283,11 +285,11 @@ func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
283285 "base fee is supported but evm block context value is nil" ,
284286 )
285287 }
286- if coreMsg .GasFeeCap () .Cmp (baseFee ) < 0 {
288+ if coreMsg .GasFeeCap .Cmp (baseFee ) < 0 {
287289 return ctx , errorsmod .Wrapf (
288290 errortypes .ErrInsufficientFee ,
289291 "max fee per gas less than block base fee (%s < %s)" ,
290- coreMsg .GasFeeCap () , baseFee ,
292+ coreMsg .GasFeeCap , baseFee ,
291293 )
292294 }
293295 }
@@ -303,14 +305,19 @@ func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
303305 stateDB := statedb .New (ctx , ctd .evmKeeper , statedb .NewEmptyTxConfig (common .BytesToHash (ctx .HeaderHash ().Bytes ())))
304306 evm := ctd .evmKeeper .NewEVM (ctx , coreMsg , cfg , evmtypes .NewNoOpTracer (), stateDB )
305307
308+ valueU256 , isOverflow := uint256 .FromBig (coreMsg .Value )
309+ if isOverflow {
310+ return ctx , fmt .Errorf ("%v is not a valid uint256" , coreMsg .Value )
311+ }
312+
306313 // check that caller has enough balance to cover asset transfer for **topmost** call
307314 // NOTE: here the gas consumed is from the context with the infinite gas meter
308- if coreMsg .Value () .Sign () > 0 && ! evm .Context .CanTransfer (stateDB , coreMsg .From (), coreMsg . Value () ) {
315+ if coreMsg .Value .Sign () > 0 && ! evm .Context .CanTransfer (stateDB , coreMsg .From , valueU256 ) {
309316 return ctx , errorsmod .Wrapf (
310317 errortypes .ErrInsufficientFunds ,
311318 "failed to transfer %s from address %s using the EVM block context transfer function" ,
312- coreMsg .Value () ,
313- coreMsg .From () ,
319+ coreMsg .Value ,
320+ coreMsg .From ,
314321 )
315322 }
316323 }
0 commit comments