The StabilityPool contract contains a critical vulnerability that allows a malicious actor to drain all rewards by repeatedly depositing and withdrawing funds by calling StabilityPool::withdraw. The root cause lies in the 1:1 minting ratio of deToken to rToken and the lack of proper accounting for user deposits over time. This enables new users to claim the same rewards as long-standing users, leading to unfair reward distribution and potential fund drainage.
Root Cause:
The deToken is minted at a 1:1 ratio to the rToken deposited into the pool. This design flaw allows users to manipulate the system by repeatedly depositing and withdrawing funds to claim rewards disproportionately.
The reward calculation does not account for the duration of a user's deposit. New users can deposit and withdraw immediately, claiming the same rewards as users who have been staking for a longer period.
Impact:
A malicious actor can drain all rewards from the pool by repeatedly depositing and withdrawing funds.
The system unfairly distributes rewards, as new users can claim the same rewards as long-standing users.
Proof of Concept
Two users (user1 and user2) deposit the same amount of rToken into the StabilityPool.
Time passes, and rewards are accumulated in the pool.
user1 repeatedly deposits and withdraws funds to claim rewards disproportionately.
user1 drains all rewards from the pool, leaving user2 with no reward to claim.
The vulnerability is demonstrated in the following Foundry test suite. Convert to foundry project using the steps highlighted here. Then in the test/ folder create a Test file named StabilityPoolTest .t.sol and paste the test into it. Make sure the imports path are correct and run the test using forge test --mt testDrainRAACRewards :
The test shows that user1 can drain RAAC tokens from the pool by repeatedly depositing and withdrawing funds, even though he started with same balance as user2. Just 1 wei is left in the pool.
Implement ERC4626 Vault System:
Replace the current reward distribution mechanism with an ERC4626-compliant vault system. ERC4626 provides a standardized way to handle shares and rewards, ensuring fair distribution.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.