From 4c76868b5204d7d30449b823dfdfe6d8636b2efe Mon Sep 17 00:00:00 2001 From: stana-ethernal Date: Mon, 2 Dec 2024 15:35:05 +0100 Subject: [PATCH 1/4] check blocked addresses before sending tokenize shares rewards --- x/distribution/keeper/keeper.go | 5 +++++ x/distribution/keeper/msg_server.go | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index f7b68fd59cc5..70006494c251 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -7,6 +7,7 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/store" + "cosmossdk.io/errors" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" @@ -231,6 +232,10 @@ func (k Keeper) WithdrawSingleShareRecordReward(ctx context.Context, recordID ui } owner := sdk.AccAddress(ownerAddr) + if k.bankKeeper.BlockedAddr(owner) { + return errors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", owner.String()) + } + valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(record.Validator) if err != nil { return err diff --git a/x/distribution/keeper/msg_server.go b/x/distribution/keeper/msg_server.go index 7004316e565e..0367c050659c 100644 --- a/x/distribution/keeper/msg_server.go +++ b/x/distribution/keeper/msg_server.go @@ -243,6 +243,11 @@ func (k msgServer) WithdrawTokenizeShareRecordReward(goCtx context.Context, msg if err != nil { return nil, err } + + if k.bankKeeper.BlockedAddr(ownerAddr) { + return nil, errors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", ownerAddr) + } + amount, err := k.Keeper.WithdrawTokenizeShareRecordReward(ctx, ownerAddr, msg.RecordId) if err != nil { return nil, err @@ -271,6 +276,11 @@ func (k msgServer) WithdrawAllTokenizeShareRecordReward(goCtx context.Context, m if err != nil { return nil, err } + + if k.bankKeeper.BlockedAddr(ownerAddr) { + return nil, errors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", ownerAddr) + } + amount, err := k.Keeper.WithdrawAllTokenizeShareRecordReward(ctx, ownerAddr) if err != nil { return nil, err From 844a4656b2c7d5f927153c9827766e9ecb69c63a Mon Sep 17 00:00:00 2001 From: stana-ethernal Date: Tue, 3 Dec 2024 11:56:20 +0100 Subject: [PATCH 2/4] remove duplicated import --- x/distribution/keeper/keeper.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index 70006494c251..e914f5e33679 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -7,7 +7,6 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/store" - "cosmossdk.io/errors" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" @@ -233,7 +232,7 @@ func (k Keeper) WithdrawSingleShareRecordReward(ctx context.Context, recordID ui owner := sdk.AccAddress(ownerAddr) if k.bankKeeper.BlockedAddr(owner) { - return errors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", owner.String()) + return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", owner.String()) } valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(record.Validator) From 47b290d9d88ff68e38ea202f855cd9283bcfb3d7 Mon Sep 17 00:00:00 2001 From: stana-ethernal Date: Tue, 3 Dec 2024 16:17:31 +0100 Subject: [PATCH 3/4] move checks from msg_server to keeper --- x/distribution/keeper/keeper.go | 8 ++++++++ x/distribution/keeper/msg_server.go | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index e914f5e33679..b49ea28cab2d 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -297,6 +297,10 @@ func (k Keeper) WithdrawTokenizeShareRecordReward(ctx sdk.Context, ownerAddr sdk return nil, err } + if k.bankKeeper.BlockedAddr(ownerAddr) { + return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", ownerAddr) + } + if record.Owner != ownerAddr.String() { return nil, types.ErrNotTokenizeShareRecordOwner } @@ -344,6 +348,10 @@ func (k Keeper) WithdrawTokenizeShareRecordReward(ctx sdk.Context, ownerAddr sdk // withdraw reward for all owning TokenizeShareRecord func (k Keeper) WithdrawAllTokenizeShareRecordReward(ctx sdk.Context, ownerAddr sdk.AccAddress) (sdk.Coins, error) { + if k.bankKeeper.BlockedAddr(ownerAddr) { + return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", ownerAddr) + } + totalRewards := sdk.Coins{} records := k.stakingKeeper.GetTokenizeShareRecordsByOwner(ctx, ownerAddr) diff --git a/x/distribution/keeper/msg_server.go b/x/distribution/keeper/msg_server.go index 0367c050659c..a48be11e6330 100644 --- a/x/distribution/keeper/msg_server.go +++ b/x/distribution/keeper/msg_server.go @@ -244,10 +244,6 @@ func (k msgServer) WithdrawTokenizeShareRecordReward(goCtx context.Context, msg return nil, err } - if k.bankKeeper.BlockedAddr(ownerAddr) { - return nil, errors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", ownerAddr) - } - amount, err := k.Keeper.WithdrawTokenizeShareRecordReward(ctx, ownerAddr, msg.RecordId) if err != nil { return nil, err @@ -277,10 +273,6 @@ func (k msgServer) WithdrawAllTokenizeShareRecordReward(goCtx context.Context, m return nil, err } - if k.bankKeeper.BlockedAddr(ownerAddr) { - return nil, errors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", ownerAddr) - } - amount, err := k.Keeper.WithdrawAllTokenizeShareRecordReward(ctx, ownerAddr) if err != nil { return nil, err From f5eb1d3e7c30986c3c892ff7419b690ac7b8534b Mon Sep 17 00:00:00 2001 From: stana-ethernal Date: Wed, 4 Dec 2024 12:45:22 +0100 Subject: [PATCH 4/4] added comments --- x/distribution/keeper/keeper.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index b49ea28cab2d..1b21dbb163b3 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -231,6 +231,7 @@ func (k Keeper) WithdrawSingleShareRecordReward(ctx context.Context, recordID ui } owner := sdk.AccAddress(ownerAddr) + // This check is necessary to prevent sending rewards to a blacklisted address if k.bankKeeper.BlockedAddr(owner) { return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", owner.String()) } @@ -297,6 +298,7 @@ func (k Keeper) WithdrawTokenizeShareRecordReward(ctx sdk.Context, ownerAddr sdk return nil, err } + // This check is necessary to prevent sending rewards to a blacklisted address if k.bankKeeper.BlockedAddr(ownerAddr) { return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", ownerAddr) } @@ -348,6 +350,7 @@ func (k Keeper) WithdrawTokenizeShareRecordReward(ctx sdk.Context, ownerAddr sdk // withdraw reward for all owning TokenizeShareRecord func (k Keeper) WithdrawAllTokenizeShareRecordReward(ctx sdk.Context, ownerAddr sdk.AccAddress) (sdk.Coins, error) { + // This check is necessary to prevent sending rewards to a blacklisted address if k.bankKeeper.BlockedAddr(ownerAddr) { return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", ownerAddr) }