Skip to content

Commit

Permalink
check from
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Oct 7, 2024
1 parent dd51c58 commit 354d043
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 17 additions & 1 deletion app/block_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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)
}
6 changes: 0 additions & 6 deletions x/cronos/types/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,13 @@ 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) {
return nil, errDummyIdentity
}

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)
Expand Down
10 changes: 0 additions & 10 deletions x/cronos/types/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 354d043

Please sign in to comment.