@@ -47,16 +47,13 @@ func VerifyEthAccount(
4747 return nil
4848 }
4949
50- for i , msg := range tx .GetMsgs () {
50+ for _ , msg := range tx .GetMsgs () {
5151 msgEthTx , ok := msg .(* evmtypes.MsgEthereumTx )
5252 if ! ok {
5353 return errorsmod .Wrapf (errortypes .ErrUnknownRequest , "invalid message type %T, expected %T" , msg , (* evmtypes .MsgEthereumTx )(nil ))
5454 }
5555
56- txData , err := evmtypes .UnpackTxData (msgEthTx .Data )
57- if err != nil {
58- return errorsmod .Wrapf (err , "failed to unpack tx data any for tx %d" , i )
59- }
56+ ethTx := msgEthTx .AsTransaction ()
6057
6158 // sender address should be in the tx cache from the previous AnteHandle call
6259 from := msgEthTx .GetFrom ()
@@ -76,8 +73,8 @@ func VerifyEthAccount(
7673 "the sender is not EOA: address %s, codeHash <%s>" , fromAddr , acct .CodeHash )
7774 }
7875
79- balance := evmKeeper .GetBalance (ctx , sdk . AccAddress ( fromAddr . Bytes ()) , evmDenom )
80- if err := keeper .CheckSenderBalance (sdkmath .NewIntFromBigInt (balance ), txData ); err != nil {
76+ balance := evmKeeper .GetBalance (ctx , from , evmDenom )
77+ if err := keeper .CheckSenderBalance (sdkmath .NewIntFromBigIntMut (balance ), ethTx ); err != nil {
8178 return errorsmod .Wrap (err , "failed to check sender balance" )
8279 }
8380 }
@@ -119,26 +116,22 @@ func CheckEthGasConsume(
119116 return ctx , errorsmod .Wrapf (errortypes .ErrUnknownRequest , "invalid message type %T, expected %T" , msg , (* evmtypes .MsgEthereumTx )(nil ))
120117 }
121118
122- txData , err := evmtypes .UnpackTxData (msgEthTx .Data )
123- if err != nil {
124- return ctx , errorsmod .Wrap (err , "failed to unpack tx data" )
125- }
126-
127- priority := evmtypes .GetTxPriority (txData , baseFee )
119+ priority := evmtypes .GetTxPriority (msgEthTx , baseFee )
128120
129121 if priority < minPriority {
130122 minPriority = priority
131123 }
132124
125+ gasLimit := msgEthTx .GetGas ()
133126 if ctx .IsCheckTx () && maxGasWanted != 0 {
134127 // We can't trust the tx gas limit, because we'll refund the unused gas.
135- if txData . GetGas () > maxGasWanted {
128+ if gasLimit > maxGasWanted {
136129 gasWanted += maxGasWanted
137130 } else {
138- gasWanted += txData . GetGas ()
131+ gasWanted += gasLimit
139132 }
140133 } else {
141- gasWanted += txData . GetGas ()
134+ gasWanted += gasLimit
142135 }
143136
144137 // user balance is already checked during CheckTx so there's no need to
@@ -147,7 +140,7 @@ func CheckEthGasConsume(
147140 continue
148141 }
149142
150- fees , err := keeper .VerifyFee (txData , evmDenom , baseFee , rules .IsHomestead , rules .IsIstanbul , rules .IsShanghai , ctx .IsCheckTx ())
143+ fees , err := keeper .VerifyFee (msgEthTx , evmDenom , baseFee , rules .IsHomestead , rules .IsIstanbul , rules .IsShanghai , ctx .IsCheckTx ())
151144 if err != nil {
152145 return ctx , errorsmod .Wrapf (err , "failed to verify the fees" )
153146 }
@@ -212,38 +205,32 @@ func CheckEthCanTransfer(
212205 return errorsmod .Wrapf (errortypes .ErrUnknownRequest , "invalid message type %T, expected %T" , msg , (* evmtypes .MsgEthereumTx )(nil ))
213206 }
214207
215- coreMsg , err := msgEthTx .AsMessage (baseFee )
216- if err != nil {
217- return errorsmod .Wrapf (
218- err ,
219- "failed to create an ethereum core.Message" ,
220- )
221- }
222-
208+ tx := msgEthTx .AsTransaction ()
223209 if rules .IsLondon {
224210 if baseFee == nil {
225211 return errorsmod .Wrap (
226212 evmtypes .ErrInvalidBaseFee ,
227213 "base fee is supported but evm block context value is nil" ,
228214 )
229215 }
230- if coreMsg .GasFeeCap .Cmp (baseFee ) < 0 {
216+ if tx .GasFeeCap () .Cmp (baseFee ) < 0 {
231217 return errorsmod .Wrapf (
232218 errortypes .ErrInsufficientFee ,
233219 "max fee per gas less than block base fee (%s < %s)" ,
234- coreMsg .GasFeeCap , baseFee ,
220+ tx .GasFeeCap () , baseFee ,
235221 )
236222 }
237223 }
238224
225+ from := common .BytesToAddress (msgEthTx .From )
239226 // check that caller has enough balance to cover asset transfer for **topmost** call
240227 // NOTE: here the gas consumed is from the context with the infinite gas meter
241- if coreMsg .Value .Sign () > 0 && ! canTransfer (ctx , evmKeeper , evmParams .EvmDenom , coreMsg . From , coreMsg .Value ) {
228+ if tx .Value () .Sign () > 0 && ! canTransfer (ctx , evmKeeper , evmParams .EvmDenom , from , tx .Value () ) {
242229 return errorsmod .Wrapf (
243230 errortypes .ErrInsufficientFunds ,
244231 "failed to transfer %s from address %s using the EVM block context transfer function" ,
245- coreMsg .Value ,
246- coreMsg . From ,
232+ tx .Value () ,
233+ from ,
247234 )
248235 }
249236 }
@@ -269,10 +256,7 @@ func CheckEthSenderNonce(
269256 return errorsmod .Wrapf (errortypes .ErrUnknownRequest , "invalid message type %T, expected %T" , msg , (* evmtypes .MsgEthereumTx )(nil ))
270257 }
271258
272- txData , err := evmtypes .UnpackTxData (msgEthTx .Data )
273- if err != nil {
274- return errorsmod .Wrap (err , "failed to unpack tx data" )
275- }
259+ tx := msgEthTx .AsTransaction ()
276260
277261 // increase sequence of sender
278262 acc := ak .GetAccount (ctx , msgEthTx .GetFrom ())
@@ -286,10 +270,10 @@ func CheckEthSenderNonce(
286270
287271 // we merged the nonce verification to nonce increment, so when tx includes multiple messages
288272 // with same sender, they'll be accepted.
289- if txData . GetNonce () != nonce {
273+ if tx . Nonce () != nonce {
290274 return errorsmod .Wrapf (
291275 errortypes .ErrInvalidSequence ,
292- "invalid nonce; got %d, expected %d" , txData . GetNonce (), nonce ,
276+ "invalid nonce; got %d, expected %d" , tx . Nonce (), nonce ,
293277 )
294278 }
295279
0 commit comments