Skip to content

Commit

Permalink
Merge branch 'develop' into incarnation-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Jul 15, 2024
2 parents 9c0b3a5 + 45ac081 commit 5625144
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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

0 comments on commit 5625144

Please sign in to comment.