Skip to content
Access control Audit finding Beginner

StakingRewards: recoverERC20() can be used as a backdoor by the owner to retrieve rewardsToken

The recoverERC20 function only prevents the owner from withdrawing the staking token, but not the rewards token. A malicious owner could therefore sweep all reward tokens, depriving depositors of their rewards.

cccz Follow

Originally disclosed on Code4rena

Submitted by cccz, also found by csanuragjain, fatherOfBlocks, pashov, Respx, Saintcode_, and unforgiven

Similar to https://github.com/code-423n4/2022-02-concur-findings/issues/210 StakingRewards.recoverERC20 rightfully checks against the stakingToken being sweeped away. However, there’s no check against the rewardsToken. This is the case of an admin privilege, which allows the owner to sweep the rewards tokens, perhaps as a way to rug depositors.

    function recoverERC20(address tokenAddress, uint256 tokenAmount)
        external
        onlyOwner
    {
        require(
            tokenAddress != address(stakingToken),
            "Cannot withdraw the staking token"
        );
        ERC20(tokenAddress).safeTransfer(owner, tokenAmount);
        emit Recovered(tokenAddress, tokenAmount);
    }

Proof of Concept

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

Recommended Mitigation Steps

Add an additional check

        require(
            tokenAddress != address(rewardsToken),
            "Cannot withdraw the rewards token"
        );

scaraven (warden) commented:

I’m curious what others think about this issue, if users do not receive any reward tokens is that really a problem? Users are still able to withdraw their ERC1155 tokens at any time, and vaults still work as expected. If the admin is malicious, users will miss out on tokens which will be worthless after a rugpull anyway.

MiguelBits (Y2K Finance) disputed and commented:

This is how synthetix rewards work, I forked their smart contracts.

HickupHH3 commented:

Including this issue, issues #50, #51 and #52 can be considered to be admin privilege findings. There’s active discussion revolving how findings of this category should be handled / standardized.

For now, I’m keeping the medium severity due to historical context (past contest references). l also reproduce the classification rationale that I gave for a previous contest below:

Classification and thought process

The issues raised about rugpull vulnerabilities via centralisation risks can be broadly classified into 2 categories:

  1. Those that can be mitigated with contract modifications. Examples include:
  2. ensuring upper / lower proper bounds on key variables (fees not exceeding max threshold, for instance)
  3. adding safeguards and conditional checks (require statements)
  4. Those that can’t be strictly enforced
  5. Use multisig, put admin under timelock

Category 1 can be separated into the various attack vectors and actors (admin / strategist), as the mitigation is more tangible in nature. This way, the recommended fixes can also be easily identified and adopted. A warden that grouped multiple attack vectors together will have their issue made the primary issue; the rest will be marked as duplicates of it.

Regarding category 2, for issues that are generic “put admin under timelock” without explaining how and why a compromised owner / strategist can rug, as per the rulebook and judges’ general consensus, I will downgrade their severity to QA. Those that explained the impact and vulnerability in detail will be grouped together with medium severity because there isn’t much that can be done about it.


The original report as published on Code4rena, by cccz. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The recoverERC20 function lacks a check to prevent the owner from withdrawing the rewards token.

Impact

A malicious owner could rug depositors by sweeping all reward tokens, though users can still withdraw their staked tokens and the vaults continue to function.

What the attacker needed

Owner is malicious; contract holds reward tokens

The fix

Add a require statement that tokenAddress is not the rewardsToken, similar to the existing check for the staking token.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

In a staking contract, users lock tokens and earn rewards. The contract owner has a special function to recover other tokens accidentally sent in, but it only blocks recovering the staking token. Because it does not block the reward token, the owner can take all the rewards for themselves, leaving users with nothing.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by cccz

View all

104 more disclosed reports, best first.

More from Y2k Finance contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.