Skip to content

Commit

Permalink
fix: Check blocked addresses before sending tokenize shares rewards (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
stana-miric authored Dec 4, 2024
1 parent 61dbfc5 commit d08a2ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions x/distribution/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ 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())
}

valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(record.Validator)
if err != nil {
return err
Expand Down Expand Up @@ -293,6 +298,11 @@ 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)
}

if record.Owner != ownerAddr.String() {
return nil, types.ErrNotTokenizeShareRecordOwner
}
Expand Down Expand Up @@ -340,6 +350,11 @@ 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)
}

totalRewards := sdk.Coins{}

records := k.stakingKeeper.GetTokenizeShareRecordsByOwner(ctx, ownerAddr)
Expand Down
2 changes: 2 additions & 0 deletions x/distribution/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func (k msgServer) WithdrawTokenizeShareRecordReward(goCtx context.Context, msg
if err != nil {
return nil, err
}

amount, err := k.Keeper.WithdrawTokenizeShareRecordReward(ctx, ownerAddr, msg.RecordId)
if err != nil {
return nil, err
Expand Down Expand Up @@ -271,6 +272,7 @@ func (k msgServer) WithdrawAllTokenizeShareRecordReward(goCtx context.Context, m
if err != nil {
return nil, err
}

amount, err := k.Keeper.WithdrawAllTokenizeShareRecordReward(ctx, ownerAddr)
if err != nil {
return nil, err
Expand Down

0 comments on commit d08a2ed

Please sign in to comment.