The StabilityPool contract allows users to deposit rToken and receive deToken in return, while also distributing RAAC rewards based on the proportion of a user's stake relative to the total stake. However, the current implementation of the reward calculation (calculateRaacRewards) is vulnerable to Flash Loan attacks, where a user can temporarily stake a large amount of tokens and immediately withdraw them to claim a disproportionate share of the rewards. This issue arises because rewards are distributed solely based on the staking proportion, without considering the staking duration.
The calculateRaacRewards function computes a user's RAAC rewards using the formula:
This means that simply having a large temporary deposit allows the attacker to claim rewards in the proportional manner calculated.
By utilizing a Flash Loan, an attacker can borrow a significant amount of crvUSD and deposit to LendingPool to receive rToken, immediately stake them in the StabilityPool, and when the rewards are calculated, they would receive rewards corresponding to their temporarily inflated stake. Following this, the attacker can withdraw their rToken in StabilityPool and then burn rToken to receive crvUSD in LendingPool , at last, he can pay back the Flash Loan, pocketing a significant portion of the rewards that were accrued based on their short-time stakes.
Attack Scenario
A user borrows a large amount of crvUSD via a Flash Loan.
The user calls the deposit function in LendingPool to receive rToken.
The user calls the deposit function in StabilityPool to stake the rToken.
The user calls the withdraw function in StabilityPool to unstake the rToken and claim rewards.
the user calls the withdraw function in LendingPool to burn rToken and get back the crvUSD.
The user repays the crvUSD Flash Loan within the same transaction.
Since the reward calculation does not consider the staking duration, the user can claim a significant portion of the rewards despite staking the tokens for only a brief moment.
All rewards can be stolen. The impact is High, the likelihood is High, so the severity is High.
Manual Review
To address this issue, rewards should be calculated based on both the amount and duration of the stake. Consider adopting a reward distribution mechanism inspired by SushiSwap's MasterChef.
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.