StakingRewards.recoverERC20 allows owner to rug the rewardsToken
The StakingRewards contract's recoverERC20 function allows the owner to withdraw the rewards token, which is meant to be distributed to stakers. A malicious owner could sweep all rewards tokens, effectively rugging depositors.
Originally disclosed on Code4rena
Submitted by Alex the Entreprenerd, also found by pauliax
StakingRewards.recoverERC20 rightfully checks against the stakingToken being sweeped away.
However, there’s no check against the rewardsToken which over time will sit in this contract.
This is the case of an admin privilege, which allows the owner to sweep the rewards tokens, perhaps as a way to rug depositors.
Proof of Concept
Calling StakingRewards.recoverERC20(rewardsToken, rewardsToken.balanceOf(this)) enables the owner to sweep the token.
Recommended Mitigation Steps
Add an additional check
require(
tokenAddress != address(rewardsToken),
"Cannot withdraw the rewards token"
);
Alex the Entreprenerd (judge) commented:
Because I’m judging the contest, I am forfeiting any warden winnings.
The sponsor confirms and I believe this to be medium severity as it is contingent on a malicious owner. Adding the extra check removes the rug vector.
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 checks that the staking token cannot be withdrawn but fails to check the rewards token, allowing the owner to withdraw it.
What the attacker needed
Malicious owner
The fix
Add a check in recoverERC20 to prevent withdrawal of the rewards token.
How it was found
- Call StakingRewards.recoverERC20 with the rewards token address and the contract's balance of that 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 their tokens and earn rewards paid in another token. The contract has a function for the owner to recover tokens accidentally sent in, but it doesn't prevent the owner from taking the reward tokens themselves. So a dishonest owner could steal all the rewards.
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.