diff --git a/CHANGELOG.md b/CHANGELOG.md index 9de82073f2..7da4899977 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features * (rpc) [#1682](https://github.com/evmos/ethermint/pull/1682) Add config for maximum number of bytes returned from eth_call. +* (ante) [#310](https://github.com/crypto-org-chain/ethermint/pull/310) Support blocking list of addresses in mempool. ### State Machine Breaking @@ -57,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - (rpc) [#1720](https://github.com/evmos/ethermint/pull/1720) Fix next block fee for historical block and calculate base fee by params. - (rpc) [#1685](https://github.com/evmos/ethermint/pull/1685) Fix parse for websocket connID. - (rpc) [#1773](https://github.com/evmos/ethermint/pull/1773) Avoid channel get changed when concurrent subscribe happens. +* (mempool) [#310](https://github.com/crypto-org-chain/ethermint/pull/310) disable vesting messages in check tx mode. ### Improvements diff --git a/app/ante/ante.go b/app/ante/ante.go index f5c47d7e1a..eba724e72a 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -28,6 +28,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx/signing" authante "github.com/cosmos/cosmos-sdk/x/auth/ante" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" "github.com/evmos/ethermint/crypto/ethsecp256k1" ) @@ -45,6 +46,17 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { return nil, err } + blacklist := make(map[string]struct{}, len(options.Blacklist)) + for _, str := range options.Blacklist { + addr, err := sdk.AccAddressFromBech32(str) + if err != nil { + return nil, fmt.Errorf("invalid bech32 address: %s, err: %w", str, err) + } + + blacklist[string(addr)] = struct{}{} + } + blockAddressDecorator := NewBlockAddressesDecorator(blacklist) + return func( ctx sdk.Context, tx sdk.Tx, sim bool, ) (newCtx sdk.Context, err error) { @@ -52,6 +64,19 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { defer Recover(ctx.Logger(), &err) + // disable vesting message types + for _, msg := range tx.GetMsgs() { + switch msg.(type) { + case *vestingtypes.MsgCreateVestingAccount, + *vestingtypes.MsgCreatePeriodicVestingAccount, + *vestingtypes.MsgCreatePermanentLockedAccount: + return ctx, errorsmod.Wrapf( + errortypes.ErrInvalidRequest, + "vesting messages are not supported", + ) + } + } + txWithExtensions, ok := tx.(authante.HasExtensionOptionsTx) if ok { opts := txWithExtensions.GetExtensionOptions() @@ -59,13 +84,13 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { switch typeURL := opts[0].GetTypeUrl(); typeURL { case "/ethermint.evm.v1.ExtensionOptionsEthereumTx": // handle as *evmtypes.MsgEthereumTx - anteHandler = newEthAnteHandler(options) + anteHandler = newEthAnteHandler(options, blockAddressDecorator) case "/ethermint.types.v1.ExtensionOptionsWeb3Tx": // Deprecated: Handle as normal Cosmos SDK tx, except signature is checked for Legacy EIP712 representation - anteHandler = NewLegacyCosmosAnteHandlerEip712(options) + anteHandler = NewLegacyCosmosAnteHandlerEip712(options, blockAddressDecorator) case "/ethermint.types.v1.ExtensionOptionDynamicFeeTx": // cosmos-sdk tx with dynamic fee extension - anteHandler = newCosmosAnteHandler(options) + anteHandler = newCosmosAnteHandler(options, blockAddressDecorator) default: return ctx, errorsmod.Wrapf( errortypes.ErrUnknownExtensionOptions, @@ -80,7 +105,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { // handle as totally normal Cosmos SDK tx switch tx.(type) { case sdk.Tx: - anteHandler = newCosmosAnteHandler(options) + anteHandler = newCosmosAnteHandler(options, blockAddressDecorator) default: return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid transaction type: %T", tx) } diff --git a/app/ante/block_address.go b/app/ante/block_address.go new file mode 100644 index 0000000000..b703d4c649 --- /dev/null +++ b/app/ante/block_address.go @@ -0,0 +1,31 @@ +package ante + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// BlockAddressesDecorator block addresses from sending transactions +type BlockAddressesDecorator struct { + blacklist map[string]struct{} +} + +func NewBlockAddressesDecorator(blacklist map[string]struct{}) BlockAddressesDecorator { + return BlockAddressesDecorator{ + blacklist: 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.blacklist[string(signer)]; ok { + return ctx, fmt.Errorf("signer is blocked: %s", signer.String()) + } + } + } + } + return next(ctx, tx, simulate) +} diff --git a/app/ante/eip712.go b/app/ante/eip712.go index 92d767ecb8..4abe939ffb 100644 --- a/app/ante/eip712.go +++ b/app/ante/eip712.go @@ -50,13 +50,14 @@ func init() { // Deprecated: NewLegacyCosmosAnteHandlerEip712 creates an AnteHandler to process legacy EIP-712 // transactions, as defined by the presence of an ExtensionOptionsWeb3Tx extension. -func NewLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler { +func NewLegacyCosmosAnteHandlerEip712(options HandlerOptions, extra sdk.AnteDecorator) sdk.AnteHandler { return sdk.ChainAnteDecorators( RejectMessagesDecorator{}, // reject MsgEthereumTxs // disable the Msg types that cannot be included on an authz.MsgExec msgs field NewAuthzLimiterDecorator(options.DisabledAuthzMsgs), authante.NewSetUpContextDecorator(), authante.NewValidateBasicDecorator(), + extra, authante.NewTxTimeoutHeightDecorator(), NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper), authante.NewValidateMemoDecorator(options.AccountKeeper), diff --git a/app/ante/handler_options.go b/app/ante/handler_options.go index 14d97e5e7d..27fc59635a 100644 --- a/app/ante/handler_options.go +++ b/app/ante/handler_options.go @@ -45,6 +45,7 @@ type HandlerOptions struct { ExtensionOptionChecker ante.ExtensionOptionChecker TxFeeChecker ante.TxFeeChecker DisabledAuthzMsgs []string + Blacklist []string } func (options HandlerOptions) validate() error { @@ -66,12 +67,13 @@ func (options HandlerOptions) validate() error { return nil } -func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler { +func newEthAnteHandler(options HandlerOptions, extra sdk.AnteDecorator) sdk.AnteHandler { return sdk.ChainAnteDecorators( NewEthSetUpContextDecorator(options.EvmKeeper), // outermost AnteDecorator. SetUpContext must be called first NewEthMempoolFeeDecorator(options.EvmKeeper), // Check eth effective gas price against minimal-gas-prices NewEthMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper), // Check eth effective gas price against the global MinGasPrice NewEthValidateBasicDecorator(options.EvmKeeper), + extra, NewEthSigVerificationDecorator(options.EvmKeeper), NewEthAccountVerificationDecorator(options.AccountKeeper, options.EvmKeeper), NewCanTransferDecorator(options.EvmKeeper), @@ -82,7 +84,7 @@ func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler { ) } -func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler { +func newCosmosAnteHandler(options HandlerOptions, extra sdk.AnteDecorator) sdk.AnteHandler { return sdk.ChainAnteDecorators( RejectMessagesDecorator{}, // reject MsgEthereumTxs // disable the Msg types that cannot be included on an authz.MsgExec msgs field @@ -90,6 +92,7 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler { ante.NewSetUpContextDecorator(), ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker), ante.NewValidateBasicDecorator(), + extra, ante.NewTxTimeoutHeightDecorator(), NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper), ante.NewValidateMemoDecorator(options.AccountKeeper),