Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StakingRewards: recoverERC20 should be able to withdraw excess stakingTokens #55

Closed
code423n4 opened this issue Sep 16, 2022 · 2 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working invalid This doesn't seem right sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-09-y2k-finance/blob/ac3e86f07bc2f1f51148d2265cc897e8b494adf7/src/rewards/StakingRewards.sol#L213-L223

Vulnerability details

Impact

The recoverERC20 function of the StakingRewards contract cannot withdraw stakingTokens, however, since the stakingTokens deposited by the user are already recorded using the _totalSupply variable, the recoverERC20 function should be able to withdraw stakingTokens exceeding _totalSupply if the user mistakenly transfers stakingTokens to the contract or the reward includes stakingToken.

Proof of Concept

https://github.com/code-423n4/2022-09-y2k-finance/blob/ac3e86f07bc2f1f51148d2265cc897e8b494adf7/src/rewards/StakingRewards.sol#L213-L223

Tools Used

None

Recommended Mitigation Steps

Change to

    function recoverERC20(address tokenAddress, uint256 tokenAmount)
        external
        onlyOwner
    {
        ERC20(tokenAddress).safeTransfer(owner, tokenAmount);
        require(ERC20(tokenAddress).balanceOf(this) >= _totalSupply);
        emit Recovered(tokenAddress, tokenAmount);
    }
@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Sep 16, 2022
code423n4 added a commit that referenced this issue Sep 16, 2022
@MiguelBits MiguelBits added the invalid This doesn't seem right label Sep 30, 2022
@liveactionllama liveactionllama added sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue and removed invalid This doesn't seem right labels Oct 3, 2022
@HickupHH3
Copy link
Collaborator

Worthwhile consideration, but disagree with severity. Funds directly transferred should be considered to be lost; it's not the protocol's responsibility to have recovery methods.

Part of #51

@HickupHH3 HickupHH3 added QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax duplicate This issue or pull request already exists and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Oct 31, 2022
@HickupHH3
Copy link
Collaborator

I forgot that stakingToken is ERC1155, issue is therefore invalid.

@HickupHH3 HickupHH3 added unsatisfactory does not satisfy C4 submission criteria; not eligible for awards 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value and removed duplicate This issue or pull request already exists QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax labels Oct 31, 2022
@JeeberC4 JeeberC4 added the invalid This doesn't seem right label Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working invalid This doesn't seem right sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

5 participants