The deposit()
function in StabilityPool.sol
incorrectly descales the deposit amount twice, leading to undercharging users for their deposits while overminting DETokens
. The issue arises because the function calls safeTransferFrom()
, which internally descales the amount by _liquidityIndex
in transferFrom()
.
This results in significantly fewer RTokens being transferred from the user than intended, while minting DETokens
as if the full amount was deposited.
The amount parameter in StabilityPool#deposit
is the RToken amount a user wishes to deposit. The function deposit()
calls safeTransferFrom(user, StabilityPool, amount)
as we can see below.
safeTransferFrom()
calls transferFrom
function in RToken
which is declared as:
We can see that the amount parameter is specified to be in underlying asset units. Then amount is descaled by _liquidityIndex
and super.transferFrom
is called.
Example:
User wants to deposit 100 RTokens
. Calls deposit(100)
.
In the safeTransferFrom
call the amount is divided by _liquidityIndex
which is meant to represent the liquidity index of the reserve.
Liquidity index = 4 (example value)
100 / 4 = 25 RTokens
The actual amount that is taken from the user is 25 RTokens
but 100 DETokens
are minted to him which is incorrect. The minting of DETokens
assumes the contract has received the amount
provided to the function.
The issue is that a user wants to withdraw the contract will send him 100 RTokens
(because DETokens
are converted 1:1 with RTokens
). Essentially the user is stealing from other users even though it can be unintentional.
An attacker can drain all RToken
deposits from the StabilityPool
essentially stealing the lenders' deposits in the LendingPool
.
manual review
Remove the logic for descaling the provided amount from the overridden transferFrom()
function in RToken.sol
. Make it behave like a regular ERC20 function.
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.