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

recoverERC20 can be used by the owner as a backdoor to retrieve the rewardsToken #40

Closed
code423n4 opened this issue Oct 28, 2022 · 7 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 duplicate-68 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-10-paladin/blob/d6d0c0e57ad80f15e9691086c9c7270d4ccfe0e6/contracts/WardenPledge.sol#L653-L662

Vulnerability details

Impact

The recoverERC20 () function is used to recover tokens sent to the contract by mistake. The contract requires one parameter token and can only be called by the owner. However, from the function code, the contract owner can use this function to recover any token including the rewardsToken used in the contract as there is no check to prevent this from happening from the code snippet shown below:

    function recoverERC20(address token) external onlyOwner returns(bool) {
        if(minAmountRewardToken[token] != 0) revert Errors.CannotRecoverToken();

        uint256 amount = IERC20(token).balanceOf(address(this));
        if(amount == 0) revert Errors.NullValue();
        IERC20(token).safeTransfer(owner(), amount);

        return true;
    }

As a result, users can lose all their rewards to a malicious or compromised owner.

Proof of Concept

https://github.com/code-423n4/2022-10-paladin/blob/d6d0c0e57ad80f15e9691086c9c7270d4ccfe0e6/contracts/WardenPledge.sol#L653-L662

Tools Used

Recommended Mitigation Steps

Consider implementing this function as follows:

    function recoverERC20(address token) external onlyOwner returns(bool) {
        require(token != rewardToken;

        if(minAmountRewardToken[token] != 0) revert Errors.CannotRecoverToken();

        uint256 amount = IERC20(token).balanceOf(address(this));
        if(amount == 0) revert Errors.NullValue();
        IERC20(token).safeTransfer(owner(), amount);

        return true;
    }

References

  1. [WP-H29] StakingRewards.sol recoverERC20() can be used as a backdoor by the owner to retrieve rewardsToken 2022-02-concur-findings#210
  2. StakingRewards.recoverERC20 allows owner to rug the rewardsToken 2022-02-concur-findings#69
@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 Oct 28, 2022
code423n4 added a commit that referenced this issue Oct 28, 2022
@Kogaroshi
Copy link

Duplicate of #17

@Kogaroshi Kogaroshi marked this as a duplicate of #17 Oct 30, 2022
@Kogaroshi Kogaroshi added the duplicate This issue or pull request already exists label Oct 30, 2022
@c4-judge
Copy link
Contributor

kirk-baird marked the issue as not a duplicate

@c4-judge c4-judge removed the duplicate This issue or pull request already exists label Nov 10, 2022
@c4-judge
Copy link
Contributor

kirk-baird marked the issue as duplicate

@c4-judge
Copy link
Contributor

kirk-baird marked the issue as satisfactory

@c4-judge c4-judge reopened this Nov 10, 2022
@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Nov 10, 2022
@c4-judge
Copy link
Contributor

kirk-baird marked the issue as not a duplicate

@c4-judge
Copy link
Contributor

kirk-baird marked the issue as duplicate of #17

@c4-judge
Copy link
Contributor

c4-judge commented Dec 6, 2022

Simon-Busch marked the issue as duplicate of #68

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 duplicate-68 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

3 participants