Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: insufficient invalid value check in eth transaction #497

Merged
merged 1 commit into from
Jul 12, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (deps) [#489](https://github.com/crypto-org-chain/ethermint/pull/489) Update cosmos-sdk to `v0.50.7`.
* (rpc) [#491](https://github.com/crypto-org-chain/ethermint/pull/491) Avoid unnecessary tx decode in tx listener.
* [#496](https://github.com/crypto-org-chain/cronos/pull/496) Set mempool MaxTx from config.
* (ante) [#497](https://github.com/crypto-org-chain/ethermint/pull/497) Enforce positive value check in eth transaction.

## v0.21.x-cronos

Expand Down
10 changes: 7 additions & 3 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package ante

import (
"fmt"
"math"
"math/big"

Expand Down Expand Up @@ -216,15 +217,18 @@ func CheckEthCanTransfer(
)
}
}

value := tx.Value()
if value == nil || value.Sign() == -1 {
return fmt.Errorf("value (%s) must be positive", value)
}
from := common.BytesToAddress(msgEthTx.From)
// check that caller has enough balance to cover asset transfer for **topmost** call
// NOTE: here the gas consumed is from the context with the infinite gas meter
if tx.Value().Sign() > 0 && !canTransfer(ctx, evmKeeper, evmParams.EvmDenom, from, tx.Value()) {
if value.Sign() > 0 && !canTransfer(ctx, evmKeeper, evmParams.EvmDenom, from, value) {
return errorsmod.Wrapf(
errortypes.ErrInsufficientFunds,
"failed to transfer %s from address %s using the EVM block context transfer function",
tx.Value(),
value,
from,
)
}
Expand Down
20 changes: 17 additions & 3 deletions app/ante/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,24 @@ func (suite *AnteTestSuite) TestCanTransferDecorator() {
nil,
&ethtypes.AccessList{},
)
tx3 := evmtypes.NewTxContract(
suite.app.EvmKeeper.ChainID(),
1,
big.NewInt(-10),
1000,
big.NewInt(150),
big.NewInt(200),
nil,
nil,
&ethtypes.AccessList{},
)

tx.From = addr.Bytes()
for _, tx := range []*evmtypes.MsgEthereumTx{tx, tx3} {
tx.From = addr.Bytes()

err := tx.Sign(suite.ethSigner, tests.NewSigner(privKey))
suite.Require().NoError(err)
err := tx.Sign(suite.ethSigner, tests.NewSigner(privKey))
suite.Require().NoError(err)
}

var vmdb *statedb.StateDB

Expand All @@ -369,6 +382,7 @@ func (suite *AnteTestSuite) TestCanTransferDecorator() {
}{
{"invalid transaction type", &invalidTx{}, func() {}, false},
{"AsMessage failed", tx2, func() {}, false},
{"negative value", tx3, func() {}, false},
{
"evm CanTransfer failed",
tx,
Expand Down
Loading