Skip to content

Commit 06c667d

Browse files
committed
fix evm test cases
1 parent a8e0046 commit 06c667d

File tree

2 files changed

+94
-200
lines changed

2 files changed

+94
-200
lines changed

x/vm/types/msg.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/cosmos/cosmos-sdk/x/auth/ante"
2626
"github.com/cosmos/cosmos-sdk/x/auth/signing"
2727
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
28+
"github.com/ethereum/go-ethereum/core/txpool"
2829
)
2930

3031
var (
@@ -88,6 +89,42 @@ func (msg MsgEthereumTx) ValidateBasic() error {
8889
return errorsmod.Wrapf(errortypes.ErrInvalidRequest, "raw transaction is required")
8990
}
9091

92+
tx := msg.Raw.Transaction
93+
94+
// validate the transaction
95+
// Transactions can't be negative. This may never happen using RLP decoded
96+
// transactions but may occur for transactions created using the RPC.
97+
if tx.Value().Sign() < 0 {
98+
return txpool.ErrNegativeValue
99+
}
100+
// Sanity check for extremely large numbers (supported by RLP or RPC)
101+
if tx.GasFeeCap().BitLen() > 256 {
102+
return core.ErrFeeCapVeryHigh
103+
}
104+
if tx.GasTipCap().BitLen() > 256 {
105+
return core.ErrTipVeryHigh
106+
}
107+
if tx.GasTipCap().Sign() < 0 {
108+
return fmt.Errorf("%w: gas tip cap %v, minimum needed 0", txpool.ErrTxGasPriceTooLow, tx.GasTipCap())
109+
}
110+
// Ensure gasFeeCap is greater than or equal to gasTipCap
111+
if tx.GasFeeCapIntCmp(tx.GasTipCap()) < 0 {
112+
return core.ErrTipAboveFeeCap
113+
}
114+
115+
intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), tx.To() == nil, true, true, true)
116+
if err != nil {
117+
return err
118+
}
119+
if tx.Gas() < intrGas {
120+
return fmt.Errorf("%w: gas %v, minimum needed %v", core.ErrIntrinsicGas, tx.Gas(), intrGas)
121+
}
122+
123+
if tx.Type() == ethtypes.SetCodeTxType {
124+
if len(tx.SetCodeAuthorizations()) == 0 {
125+
return fmt.Errorf("set code tx must have at least one authorization tuple")
126+
}
127+
}
91128
return nil
92129
}
93130

@@ -151,7 +188,9 @@ func (msg MsgEthereumTx) GetFee() *big.Int {
151188

152189
// GetEffectiveFee returns the fee for dynamic fee tx
153190
func (msg MsgEthereumTx) GetEffectiveFee(baseFee *big.Int) *big.Int {
154-
return new(big.Int).Add(msg.Raw.EffectiveGasTipValue(baseFee), baseFee)
191+
i := new(big.Int).SetUint64(msg.Raw.Gas())
192+
effectiveGasPrice := new(big.Int).Add(msg.Raw.EffectiveGasTipValue(baseFee), baseFee)
193+
return i.Mul(i, effectiveGasPrice)
155194
}
156195

157196
// GetFrom loads the ethereum sender address from the sigcache and returns an

0 commit comments

Comments
 (0)