Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (indexer) [#96](https://github.com/EscanBE/evermint/pull/96) Make EVMTxIndexer mandatory service, starts before Json-RPC
- (test) [#100](https://github.com/EscanBE/evermint/pull/100) Add some edge test cases + benchmark tests
- (evm) [#103](https://github.com/EscanBE/evermint/pull/103) General use zero gas config for EVM exec
- (ante) [#110](https://github.com/EscanBE/evermint/pull/110) Reject EVM txs which having negative value
- (ante) [#112](https://github.com/EscanBE/evermint/pull/112) Add some validation relates to number range for EVM txs

### Bug Fixes

Expand All @@ -69,7 +71,6 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (rename-chain) [#80](https://github.com/EscanBE/evermint/pull/80) Handle new cases of rename-chain with recent changes
- (rpc) [#85](https://github.com/EscanBE/evermint/pull/85) Compute and return correct `transactionsRoot` and `receiptsRoot` hashes
- (rename-chain) [#108](https://github.com/EscanBE/evermint/pull/108) Resolve compile error `*_test.go` after run rename chain
- (ante) [#110](https://github.com/EscanBE/evermint/pull/110) Reject EVM txs which having negative value

### Client Breaking

Expand Down
38 changes: 36 additions & 2 deletions app/ante/evm/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,43 @@ func (bvd EthBasicValidationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, si
}

value := txData.GetValue()
if value != nil {
if value.Sign() < 0 {
return ctx, errorsmod.Wrap(evmtypes.ErrInvalidAmount, "tx value cannot be negative")
} else if value.BitLen() > 256 {
return ctx, errorsmod.Wrap(evmtypes.ErrInvalidAmount, "tx value excess 256 bits")
}
}

gasPrice := txData.GetGasPrice()
if gasPrice != nil {
if gasPrice.Sign() < 0 {
return ctx, errorsmod.Wrap(evmtypes.ErrInvalidGasPrice, "gas price cannot be negative")
} else if gasPrice.BitLen() > 256 {
return ctx, errorsmod.Wrap(evmtypes.ErrInvalidGasPrice, "gas price excess 256 bits")
} else if new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(txData.GetGas())).BitLen() > 256 {
return ctx, errorsmod.Wrap(evmtypes.ErrInvalidGasPrice, "gas * gas price exceeds 256 bits")
}
}

if value != nil && value.Sign() < 0 {
return ctx, errorsmod.Wrap(evmtypes.ErrInvalidAmount, "tx value cannot be negative")
gasFeeCap := txData.GetGasFeeCap()
if gasFeeCap != nil {
if gasFeeCap.Sign() < 0 {
return ctx, errorsmod.Wrap(evmtypes.ErrInvalidGasFee, "gas fee cap cannot be negative")
} else if gasFeeCap.BitLen() > 256 {
return ctx, errorsmod.Wrap(evmtypes.ErrInvalidGasFee, "gas fee cap excess 256 bits")
} else if new(big.Int).Mul(gasFeeCap, new(big.Int).SetUint64(txData.GetGas())).BitLen() > 256 {
return ctx, errorsmod.Wrap(evmtypes.ErrInvalidGasFee, "gas * gas fee cap exceeds 256 bits")
}
}

gasTipCap := txData.GetGasTipCap()
if gasTipCap != nil {
if gasTipCap.Sign() < 0 {
return ctx, errorsmod.Wrap(evmtypes.ErrInvalidGasFee, "gas tip cap cannot be negative")
} else if gasTipCap.BitLen() > 256 {
return ctx, errorsmod.Wrap(evmtypes.ErrInvalidGasFee, "gas tip cap excess 256 bits")
}
}
}

Expand Down
228 changes: 210 additions & 18 deletions app/ante/evm/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,48 +720,240 @@ func (suite *AnteTestSuite) TestValidateBasicDecorator() {
}

testCases := []struct {
name string
tx sdk.Tx
expPass bool
name string
tx func() sdk.Tx
expPass bool
expPanic bool
}{
{
name: "invalid transaction type",
tx: &testutiltx.InvalidTx{},
name: "invalid transaction type",
tx: func() sdk.Tx {
return &testutiltx.InvalidTx{}
},
expPass: false,
},
{
name: "accept positive value",
tx: getTx(func(args *evmtypes.EvmTxArgs) {
args.Amount = big.NewInt(10)
}),
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.Amount = big.NewInt(10)
})
},
expPass: true,
},
{
name: "accept zero value",
tx: getTx(func(args *evmtypes.EvmTxArgs) {
args.Amount = big.NewInt(0)
}),
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.Amount = big.NewInt(0)
})
},
expPass: true,
},
{
name: "accept nil value",
tx: getTx(func(args *evmtypes.EvmTxArgs) {
args.Amount = nil
}),
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.Amount = nil
})
},
expPass: true,
},
{
name: "reject negative value",
tx: getTx(func(args *evmtypes.EvmTxArgs) {
args.Amount = big.NewInt(-10)
}),
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.Amount = big.NewInt(-10)
})
},
expPass: false,
},
{
name: "reject value which more than 256 bits",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
bz := make([]byte, 257)
bz[0] = 0xFF
args.Amount = new(big.Int).SetBytes(bz)
})
},
expPanic: true,
},
{
name: "accept positive gas price",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = big.NewInt(10)
})
},
expPass: true,
},
{
name: "not reject zero gas price",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = big.NewInt(0)
})
},
expPass: true,
},
{
name: "not reject nil gas price",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = nil
})
},
expPass: true,
},
{
name: "reject negative gas price",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = big.NewInt(-10)
args.GasFeeCap = nil
args.GasTipCap = nil
})
},
expPass: false,
},
{
name: "reject gas price which more than 256 bits",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
bz := make([]byte, 257)
bz[0] = 0xFF
args.GasPrice = new(big.Int).SetBytes(bz)
})
},
expPanic: true,
},
{
name: "accept positive gas fee cap",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = nil

args.GasFeeCap = big.NewInt(10)
})
},
expPass: true,
},
{
name: "not reject zero gas fee cap",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = nil

args.GasFeeCap = big.NewInt(0)
})
},
expPass: true,
},
{
name: "not reject nil gas fee cap",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = nil

args.GasFeeCap = nil
})
},
expPass: true,
},
{
name: "reject negative gas fee cap",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = nil

args.GasFeeCap = big.NewInt(-10)
})
},
expPass: false,
},
{
name: "reject gas fee cap which more than 256 bits",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = nil

bz := make([]byte, 257)
bz[0] = 0xFF
args.GasFeeCap = new(big.Int).SetBytes(bz)
})
},
expPanic: true,
},
{
name: "accept positive gas tip cap",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = nil

args.GasTipCap = big.NewInt(10)
})
},
expPass: true,
},
{
name: "not reject zero gas tip cap",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = nil

args.GasTipCap = big.NewInt(0)
})
},
expPass: true,
},
{
name: "not reject nil gas tip cap",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = nil

args.GasTipCap = nil
})
},
expPass: true,
},
{
name: "reject negative gas tip cap",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = nil

args.GasTipCap = big.NewInt(-10)
})
},
expPass: false,
},
{
name: "reject gas tip cap which more than 256 bits",
tx: func() sdk.Tx {
return getTx(func(args *evmtypes.EvmTxArgs) {
args.GasPrice = nil

bz := make([]byte, 257)
bz[0] = 0xFF
args.GasTipCap = new(big.Int).SetBytes(bz)
})
},
expPanic: true,
},
}

for _, tc := range testCases {
suite.Run(tc.name, func() {
_, err := dec.AnteHandle(suite.ctx, tc.tx, false, testutil.NextFn)
if tc.expPanic {
suite.Require().Panics(func() {
_, _ = dec.AnteHandle(suite.ctx, tc.tx(), false, testutil.NextFn)
})
return
}

_, err := dec.AnteHandle(suite.ctx, tc.tx(), false, testutil.NextFn)

if tc.expPass {
suite.Require().NoError(err)
Expand Down