diff --git a/app/app.go b/app/app.go index 946ea821dd..b1264420b8 100644 --- a/app/app.go +++ b/app/app.go @@ -1106,7 +1106,7 @@ func (app *App) setAnteHandler(txConfig client.TxConfig, maxGasWanted uint64, bl blockedMap[addr.String()] = struct{}{} } - blockAddressDecorator := NewBlockAddressesDecorator(blockedMap) + blockAddressDecorator := NewBlockAddressesDecorator(blockedMap, app.CronosKeeper.GetParams) options := evmante.HandlerOptions{ AccountKeeper: app.AccountKeeper, BankKeeper: app.BankKeeper, diff --git a/app/block_address.go b/app/block_address.go index 4fc3e4cfd1..76e41ce8d8 100644 --- a/app/block_address.go +++ b/app/block_address.go @@ -3,18 +3,26 @@ package app import ( "fmt" + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/signing" + "github.com/crypto-org-chain/cronos/v2/x/cronos/types" ) // BlockAddressesDecorator block addresses from sending transactions type BlockAddressesDecorator struct { blockedMap map[string]struct{} + getParams func(ctx sdk.Context) types.Params } -func NewBlockAddressesDecorator(blacklist map[string]struct{}) BlockAddressesDecorator { +func NewBlockAddressesDecorator( + blacklist map[string]struct{}, + getParams func(ctx sdk.Context) types.Params, +) BlockAddressesDecorator { return BlockAddressesDecorator{ blockedMap: blacklist, + getParams: getParams, } } @@ -31,6 +39,14 @@ func (bad BlockAddressesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula } } } + admin := bad.getParams(ctx).CronosAdmin + for _, msg := range tx.GetMsgs() { + if blocklistMsg, ok := msg.(*types.MsgStoreBlockList); ok { + if admin != blocklistMsg.From { + return ctx, errors.Wrap(sdkerrors.ErrUnauthorized, "msg sender is not authorized") + } + } + } } return next(ctx, tx, simulate) } diff --git a/x/cronos/types/messages.go b/x/cronos/types/messages.go index aa78cc110a..5b342e4070 100644 --- a/x/cronos/types/messages.go +++ b/x/cronos/types/messages.go @@ -191,8 +191,6 @@ func NewMsgStoreBlockList(from string, blob []byte) *MsgStoreBlockList { var errDummyIdentity = stderrors.New("dummy") -const MaximumBlobLength = 20480 - type dummyIdentity struct{} func (i *dummyIdentity) Unwrap(stanzas []*age.Stanza) ([]byte, error) { @@ -200,10 +198,6 @@ func (i *dummyIdentity) Unwrap(stanzas []*age.Stanza) ([]byte, error) { } func (msg *MsgStoreBlockList) ValidateBasic() error { - length := len(msg.Blob) - if length > MaximumBlobLength { - return errors.Wrapf(sdkerrors.ErrInvalidRequest, "block length %d must not exceed %d", length, MaximumBlobLength) - } _, err := sdk.AccAddressFromBech32(msg.From) if err != nil { return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) diff --git a/x/cronos/types/messages_test.go b/x/cronos/types/messages_test.go index 93a06cdd60..ac2265daa1 100644 --- a/x/cronos/types/messages_test.go +++ b/x/cronos/types/messages_test.go @@ -84,16 +84,6 @@ func TestValidateMsgStoreBlockList(t *testing.T) { false, "", }, - { - "blob exceeds maximum length", - types.NewMsgStoreBlockList( - from, - make([]byte, types.MaximumBlobLength+1), - ), - false, - true, - fmt.Sprintf("must not exceed %d", types.MaximumBlobLength), - }, { "invalid sender address", types.NewMsgStoreBlockList("invalid", blob),