Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

reject tx if address in blacklist #754

Closed
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 @@ -62,6 +62,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (api) [\#687](https://github.com/cosmos/ethermint/issues/687) Returns error for a transaction with an incorrect nonce.
* (evm) [\#674](https://github.com/cosmos/ethermint/issues/674) Reset all cache after account data has been committed in `EndBlock` to make sure every node state consistent.
* (evm) [\#672](https://github.com/cosmos/ethermint/issues/672) Fix panic of `wrong Block.Header.AppHash` when restart a node with snapshot.
* (evm) [\#753](https://github.com/cosmos/ethermint/issues/753) Using evm tx to transfer token to the module account causes the module account balance to be tainted.

### Features
* (api) [\#821](https://github.com/cosmos/ethermint/pull/821) Individually enable the api modules. Will be implemented in the latest version of ethermint with the upcoming stargate upgrade.
Expand Down
2 changes: 1 addition & 1 deletion app/ethermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func NewEthermintApp(
)
app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], app.cdc)
app.EvmKeeper = evm.NewKeeper(
app.cdc, keys[evm.StoreKey], app.subspaces[evm.ModuleName], app.AccountKeeper,
app.cdc, keys[evm.StoreKey], app.subspaces[evm.ModuleName], app.AccountKeeper, app.BankKeeper,
)

// create evidence keeper with router
Expand Down
10 changes: 4 additions & 6 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import (
"fmt"
"math/big"

"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/params"

"github.com/cosmos/ethermint/x/evm/types"

"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/tendermint/tendermint/libs/log"
)

// Keeper wraps the CommitStateDB, allowing us to pass in SDK context while adhering
Expand Down Expand Up @@ -43,7 +41,7 @@ type Keeper struct {

// NewKeeper generates new evm module keeper
func NewKeeper(
cdc *codec.Codec, storeKey sdk.StoreKey, paramSpace params.Subspace, ak types.AccountKeeper,
cdc *codec.Codec, storeKey sdk.StoreKey, paramSpace params.Subspace, ak types.AccountKeeper, bk bank.Keeper,
) *Keeper {
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
Expand All @@ -55,7 +53,7 @@ func NewKeeper(
cdc: cdc,
storeKey: storeKey,
accountKeeper: ak,
CommitStateDB: types.NewCommitStateDB(sdk.Context{}, storeKey, paramSpace, ak),
CommitStateDB: types.NewCommitStateDB(sdk.Context{}, storeKey, paramSpace, ak, bk),
TxCount: 0,
Bloom: big.NewInt(0),
}
Expand Down
12 changes: 9 additions & 3 deletions x/evm/types/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/params"

ethermint "github.com/cosmos/ethermint/types"

ethcmn "github.com/ethereum/go-ethereum/common"
ethstate "github.com/ethereum/go-ethereum/core/state"
ethtypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -45,6 +44,7 @@ type CommitStateDB struct {
storeKey sdk.StoreKey
paramSpace params.Subspace
accountKeeper AccountKeeper
bankKeeper bank.Keeper

// array that hold 'live' objects, which will get modified while processing a
// state transition
Expand Down Expand Up @@ -90,13 +90,14 @@ type CommitStateDB struct {
// CONTRACT: Stores used for state must be cache-wrapped as the ordering of the
// key/value space matters in determining the merkle root.
func NewCommitStateDB(
ctx sdk.Context, storeKey sdk.StoreKey, paramSpace params.Subspace, ak AccountKeeper,
ctx sdk.Context, storeKey sdk.StoreKey, paramSpace params.Subspace, ak AccountKeeper, bk bank.Keeper,
) *CommitStateDB {
return &CommitStateDB{
ctx: ctx,
storeKey: storeKey,
paramSpace: paramSpace,
accountKeeper: ak,
bankKeeper: bk,
stateObjects: []stateEntry{},
addressToObjectIndex: make(map[ethcmn.Address]int),
stateObjectsDirty: make(map[ethcmn.Address]struct{}),
Expand Down Expand Up @@ -568,6 +569,11 @@ func (csdb *CommitStateDB) updateStateObject(so *stateObject) error {
return fmt.Errorf("invalid balance %s", newBalance)
}

//checking and reject tx if address in blacklist
if csdb.bankKeeper.BlacklistedAddr(so.account.GetAddress()) {
return fmt.Errorf("address <%s> in blacklist is not allowed", so.account.GetAddress().String())
}

coins := so.account.GetCoins()
balance := coins.AmountOf(newBalance.Denom)
if balance.IsZero() || !balance.Equal(newBalance.Amount) {
Expand Down