From 5c6aa7148ac9c4ac77bbdb7e1a9d581738dec965 Mon Sep 17 00:00:00 2001 From: javiersuweijie Date: Wed, 31 Jul 2024 15:31:20 +0800 Subject: [PATCH] feat: blacklist ante --- app/ante/ante.go | 2 ++ app/ante/blacklist/blacklist.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 app/ante/blacklist/blacklist.go diff --git a/app/ante/ante.go b/app/ante/ante.go index 9f9ab1c3..aa495aad 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -3,6 +3,7 @@ package ante import ( ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante" ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + "github.com/terra-money/core/v2/app/ante/blacklist" feesharekeeper "github.com/terra-money/core/v2/x/feeshare/keeper" "github.com/cosmos/cosmos-sdk/client" @@ -54,6 +55,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), wasmkeeper.NewCountTXDecorator(options.TxCounterStoreKey), + blacklist.NewBlacklistDecorator(), ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker), ante.NewValidateBasicDecorator(), ante.NewTxTimeoutHeightDecorator(), diff --git a/app/ante/blacklist/blacklist.go b/app/ante/blacklist/blacklist.go new file mode 100644 index 00000000..51b1fcaf --- /dev/null +++ b/app/ante/blacklist/blacklist.go @@ -0,0 +1,31 @@ +package blacklist + +import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" +) + +var Blacklist = map[string]bool{ + // IBC exploiter + "terra1wrve5z5vsmrgy6ldcveq93aldr6wk3qmxavs4j": true, +} + +type BlacklistAnteHandler struct { +} + +func NewBlacklistDecorator() BlacklistAnteHandler { + return BlacklistAnteHandler{} +} + +func (b BlacklistAnteHandler) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { + sigTx, ok := tx.(authsigning.SigVerifiableTx) + if ok { + for _, sig := range sigTx.GetSigners() { + if Blacklist[sig.String()] { + return ctx, fmt.Errorf("signer %s is blacklisted", sig.String()) + } + } + } + return next(ctx, tx, simulate) +}