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: don't support blocking addresses in mempool #1179

Merged
merged 9 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -78,6 +78,7 @@
- [#1151](https:/crypto-org-chain/cronos/pull/1151) memiavl `CacheMultiStoreWithVersion` supports `io.Closer`.
- [#1154](https:/crypto-org-chain/cronos/pull/1154) Remove dependency on cosmos-sdk.
- [#1171](https:/crypto-org-chain/cronos/pull/1171) Add memiavl background snapshot writing concurrency limit.
- [#]() Support blocking addresses in mempool.
yihuang marked this conversation as resolved.
Show resolved Hide resolved
yihuang marked this conversation as resolved.
Show resolved Hide resolved

*April 13, 2023*

Expand Down
23 changes: 20 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
//
// NOTE: In the SDK, the default value is 255.
AddrLen = 20

FlagBlockedAddresses = "blocked-addresses"
)

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down Expand Up @@ -862,7 +864,10 @@
app.SetPreBlocker(app.PreBlocker)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
app.setAnteHandler(encodingConfig.TxConfig, cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted)))
app.setAnteHandler(encodingConfig.TxConfig,
cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted)),
cast.ToStringSlice(appOpts.Get(FlagBlockedAddresses)),
)
Fixed Show fixed Hide fixed
// In v0.46, the SDK introduces _postHandlers_. PostHandlers are like
// antehandlers, but are run _after_ the `runMsgs` execution. They are also
// defined as a chain, and have the same signature as antehandlers.
Expand Down Expand Up @@ -902,7 +907,17 @@
}

// use Ethermint's custom AnteHandler
func (app *App) setAnteHandler(txConfig client.TxConfig, maxGasWanted uint64) {
func (app *App) setAnteHandler(txConfig client.TxConfig, maxGasWanted uint64, blacklist []string) error {
blockedMap := make(map[string]struct{}, len(blacklist))
for _, str := range blacklist {
addr, err := sdk.AccAddressFromBech32(str)
if err != nil {
return fmt.Errorf("invalid bech32 address: %s, err: %w", str, err)
}

blockedMap[string(addr)] = struct{}{}
}
blockAddressDecorator := NewBlockAddressesDecorator(blockedMap)
evmOptions := evmante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
Expand All @@ -919,6 +934,7 @@
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreateVestingAccount{}),
},
ExtraDecorators: []sdk.AnteDecorator{blockAddressDecorator},
}
options := ante.HandlerOptions{
EvmOptions: evmOptions,
Expand All @@ -927,10 +943,11 @@

anteHandler, err := ante.NewAnteHandler(options)
if err != nil {
panic(err)
return err
}

app.SetAnteHandler(anteHandler)
return nil
}

func (app *App) setPostHandler() {
Expand Down
31 changes: 31 additions & 0 deletions app/block_address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package app

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// BlockAddressesDecorator block addresses from sending transactions
type BlockAddressesDecorator struct {
blockedMap map[string]struct{}
}

func NewBlockAddressesDecorator(blacklist map[string]struct{}) BlockAddressesDecorator {
return BlockAddressesDecorator{
blockedMap: blacklist,
}
}

func (bad BlockAddressesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
if ctx.IsCheckTx() {
for _, msg := range tx.GetMsgs() {
for _, signer := range msg.GetSigners() {
if _, ok := bad.blockedMap[string(signer)]; ok {
return ctx, fmt.Errorf("signer is blocked: %s", signer.String())
}
}
}
}
return next(ctx, tx, simulate)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ replace (
// TODO: remove it: https:/cosmos/cosmos-sdk/issues/13134
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc1
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20230914072023-bdeaf36d31ea
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20230920075522-5db4c7d5e2db
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
// TODO Remove it: https:/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ github.com/crypto-org-chain/cometbft-db v0.0.0-20230412133340-ac70df4b45f6 h1:d4
github.com/crypto-org-chain/cometbft-db v0.0.0-20230412133340-ac70df4b45f6/go.mod h1:hF5aclS++7WrW8USOA3zPeKI0CuzwUD2TPYug25ANlQ=
github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20230905040840-b3af5590283b h1:d2GOFR3i3BjDlPsmJkp8Gsrt9LK2nq2IVEnE/rMv1Fo=
github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20230905040840-b3af5590283b/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c=
github.com/crypto-org-chain/ethermint v0.6.1-0.20230914072023-bdeaf36d31ea h1:dBmeOxXiJThF169i02lreJbtVG89QUaXIlc2e+x3wnU=
github.com/crypto-org-chain/ethermint v0.6.1-0.20230914072023-bdeaf36d31ea/go.mod h1:OtQsOW22hho1CzpMTzF3+dE9a42e0KhLYXqkNzX40ls=
github.com/crypto-org-chain/ethermint v0.6.1-0.20230920075522-5db4c7d5e2db h1:l1bIe1SeCUHyK/Q255QbuErXVR1yXcqHdd4k4x7JwTQ=
github.com/crypto-org-chain/ethermint v0.6.1-0.20230920075522-5db4c7d5e2db/go.mod h1:OtQsOW22hho1CzpMTzF3+dE9a42e0KhLYXqkNzX40ls=
github.com/crypto-org-chain/gravity-bridge/module/v2 v2.0.1-0.20230825054824-75403cd90c6e h1:rSTc35OBjjCBx47rHPWBCIHNGPbMnEj8f7fNcK2TjVI=
github.com/crypto-org-chain/gravity-bridge/module/v2 v2.0.1-0.20230825054824-75403cd90c6e/go.mod h1:HBaDqlFjlaXJwVQtA7jHejyaA7xwjXI2o6pU/ccP3tE=
github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ schema = 3
hash = "sha256-GgcReGsIIuBE2TabDYqDO9sBGogdVr9RSh4arQzdPnE="
replaced = "github.com/evmos/go-ethereum"
[mod."github.com/evmos/ethermint"]
version = "v0.6.1-0.20230914072023-bdeaf36d31ea"
hash = "sha256-Kx/4tTotsbKR17tVukNcd3XcRPwIrso+eTImXISuuPA="
version = "v0.6.1-0.20230920075522-5db4c7d5e2db"
hash = "sha256-yTULFChBu+/CHo0spMXxVnzdD5iHoTI/+aEbf/3tGAw="
replaced = "github.com/crypto-org-chain/ethermint"
[mod."github.com/felixge/httpsnoop"]
version = "v1.0.2"
Expand Down
3 changes: 3 additions & 0 deletions integration_tests/configs/long_timeout_commit.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ default {
timeout_commit: '15s',
},
},
'app-config'+: {
'blocked-addresses': ['crc16z0herz998946wr659lr84c8c556da55dc34hh'],
},
},
}
11 changes: 10 additions & 1 deletion integration_tests/test_mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def test_mempool(cronos_mempool):

to = ADDRS["community"]
params = {"gasPrice": w3.eth.gas_price}
block_num_0, sended_hash_set = send_txs(w3, cli, to, KEYS.values(), params)
block_num_0, sended_hash_set = send_txs(
w3, cli, to, [v for k, v in KEYS.items() if k != "signer1"], params
)
print(f"all send tx hash: {sended_hash_set} at {block_num_0}")

all_pending = w3.eth.get_filter_changes(filter.filter_id)
Expand All @@ -72,3 +74,10 @@ def test_mempool(cronos_mempool):
break
wait_for_new_blocks(cli, 1, sleep=0.1)
assert len(sended_hash_set) == 0


def test_blocked_address(cronos_mempool):
cli = cronos_mempool.cosmos_cli(0)
rsp = cli.transfer("signer1", cli.address("validator"), "1basecro")
assert rsp["code"] != 0
assert "signer is blocked" in rsp["raw_log"]
3 changes: 2 additions & 1 deletion integration_tests/test_vesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ def test_create_account(cronos):
end_time = int(time.time()) + 3000
fees = f"{fee}{denom}"
res = cli.create_vesting_account(addr, amt, end_time, from_="validator", fees=fees)
assert res["code"] == 18, res["raw_log"]
assert res["code"] != 0
assert "vesting messages are not supported" in res["raw_log"]
Loading