The lack of Time-Weighted reward calculation in StabilityPool.sol
allows malicious users to continuously drain the majority of rewards, resulting in an unfair reward distribution compared to long-time staking users.
StabilityPool::calculateRaacRewards
:
As you can clearly see in above calculation, any consideration for the time a user has staked is missing, the only thing on which the calculation is based is the deposit amount at the time of withdraw. Therefor a user can potentially use flashloans or other high liquidity, provide it for the transaction and immediately withdraw it afterwards, harming a fair reward distribution and taking away the incentives for users to stake at all.
Since the PoC is a foundry test I have added a Makefile at the end of this report to simplify installation for your convenience. Otherwise if console commands would be prefered:
First run: npm install --save-dev @nomicfoundation/hardhat-foundry
Second add: require("@nomicfoundation/hardhat-foundry");
on top of the Hardhat.Config
file in the projects root directory.
Third run: npx hardhat init-foundry
And lastly, you will encounter one of the mock contracts throwing an error during compilation, this error can be circumvented by commenting out the code in entirety (ReserveLibraryMocks.sol
).
And the test should be good to go:
After following above steps copy & paste the following code into ./test/invariant/PoC.t.sol
and run forge test --mt test_PocFrontrunRewardDistro -vv
Running above code produces the following console log:
As you can clearly see in the log, even User 1 and User 2 were staking 20k rTokens for roughly 1 year (estimated via the 7200 blocks per day proposed within the protocol), but user3 who frontran their withdraws took most of the rewards staking for only 1 transaction, leaving the long-term stakers with crumbs.
Staking Rewards within RAACs contract system are supposed to attract liquidity, which is needed to liquidate potential users, since liquidation in the protocol is strictly INTERNAL.
With the rewards being front-runnable within a single transaction Users lose the incentive to stake their tokens, leaving the protocol with insufficient liquidity for liquidations, directly affecting the health of the protocol, therefore, even though reward MEVs are usually considered a medium, I will rate this as a High, because of above mentioned liquidity issues for internal liquidations.
Likelihood: High
Impact: High
Severity: High
Foundry & Manual Review
Consider using a Time-Weighted-Average calculation for rewards distribution.
Copy the following import into your Hardhat.Config
file in the projects root dir:
require("@nomicfoundation/hardhat-foundry");
Paste the following into a new file "Makefile" into the projects root directory:
And run make all
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.