Skip to content
This repository has been archived by the owner on Jan 12, 2025. It is now read-only.

pinalikefruit - Unclaimed Extra Rewards Stuck in Contract After setExtraRewarder Update #559

Closed
sherlock-admin2 opened this issue Jul 15, 2024 · 1 comment
Labels
Non-Reward This issue will not receive a payout

Comments

@sherlock-admin2
Copy link

sherlock-admin2 commented Jul 15, 2024

pinalikefruit

High

Unclaimed Extra Rewards Stuck in Contract After setExtraRewarder Update

Summary

The MasterChef contract includes an extraRewarder token to incentivize users. However, if the extraRewarder address is updated, any unclaimed rewards from the previous extraRewarder cannot be claimed or retrieved, resulting in these tokens being stuck in the contract.

Vulnerability Detail

When users make a deposit or withdraw, they receive extra rewards directly. If the MasterChefV2::setExtraRewarder function updates the extraRewarder to a new address, users will start receiving rewards from the new extraRewarder. However, any unclaimed rewards from the old extraRewarder cannot be claimed because the only function to receive the claim, onModify, can only be executed when in the Linked status:

    function onModify(address account, uint256 pid, uint256 oldBalance, uint256 newBalance, uint256 oldTotalSupply)
        public
        override(BaseRewarder, IBaseRewarder)
        returns (uint256 reward)
    {
@>      if (_status != Status.Linked) revert MasterChefRewarder__NotLinked();

        reward = BaseRewarder.onModify(account, pid, oldBalance, newBalance, oldTotalSupply);

        _claim(account, reward);
    }

Additionally, the function available to the owner for handling reward tokens, sweep, does not allow for the retrieval of unclaimed rewards:

    function sweep(IERC20 token, address account) public virtual override onlyOwner {
        uint256 balance = _balanceOfThis(token);

        if (token == _token()) {
            if (_isStopped) {
@>              if (_getTotalSupply() > 0) balance -= _totalUnclaimedRewards;
            } else {
                balance -= _reserve;
            }
        }
        if (balance == 0) revert BaseRewarder__ZeroAmount();

        _safeTransferTo(token, account, balance);

        emit Swept(token, account, balance);
    }

As a result, unclaimed tokens from the old extraRewarder remain stuck in the contract indefinitely.

Impact

Unclaimed extra reward tokens are stuck in the contract forever, effectively lost to users or owner.

Code Snippet

https://github.com/sherlock-audit/2024-06-magicsea/blob/7fd1a65b76d50f1bf2555c699ef06cde2b646674/magicsea-staking/src/rewarders/MasterChefRewarder.sol#L68-L78

Tool used

Manual Review

Recommendation

Add a function that allows users or the owner to withdraw unclaimed tokens when the contract is unlinked. This ensures that users can retrieve any rewards owed to them even after an extraRewarder update.

@github-actions github-actions bot added duplicate Medium A Medium severity issue. labels Jul 21, 2024
@sherlock-admin4 sherlock-admin4 added the Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label label Jul 22, 2024
@sherlock-admin4 sherlock-admin4 changed the title Fluffy Arctic Hippo - Unclaimed Extra Rewards Stuck in Contract After setExtraRewarder Update pinalikefruit - Unclaimed Extra Rewards Stuck in Contract After setExtraRewarder Update Jul 29, 2024
@sherlock-admin4 sherlock-admin4 added the Reward A payout will be made for this issue label Jul 29, 2024
@WangSecurity WangSecurity removed Medium A Medium severity issue. Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Aug 20, 2024
@sherlock-admin2 sherlock-admin2 added Non-Reward This issue will not receive a payout and removed Reward A payout will be made for this issue labels Aug 20, 2024
@WangSecurity
Copy link

Invalid based on the discussion under #460

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Non-Reward This issue will not receive a payout
Projects
None yet
Development

No branches or pull requests

3 participants