The deposit function in the ReserveLibrary mints RTokens based on the reserve.liquidityIndex, which is not a 1:1 ratio with the underlying asset. This design flaw causes users to withdraw more or less of the underlying asset than they initially deposited, depending on the state of the liquidityIndex. This issue undermines the fairness and predictability of the protocol, potentially leading to financial losses for users.
The deposit function in the ReserveLibrary mints RTokens to users based on the reserve.liquidityIndex, which is updated over time to reflect accrued interest.
RToken contract _update function
The amountScaled (minted RTokens) is calculated using the reserve.liquidityIndex, which increases over time as interest accrues. This means that the same amount of underlying assets deposited at different times will result in different amounts of RTokens being minted. When users withdraw their funds, the amount of underlying assets they receive is determined by the current liquidityIndex, which may not match the index at the time of deposit.
This creates a discrepancy between the deposited and withdrawn amounts, leading to unfair outcomes for users. For example:
If the liquidityIndex increases significantly after a deposit, users may receive more underlying assets than they deposited, potentially at the expense of other users.
If the liquidityIndex decreases, users may receive fewer underlying assets than they deposited, resulting in financial losses.
Initial State:
reserve.liquidityIndex = 1e27 (RAY, representing 1.0)
User A deposits 100 crvUSD.
Minting RTokens:
The mint function calculates amountScaled as amount / liquidityIndex.
amountScaled = 100e18 / 1e27 = 1e11 RTokens are minted to User A.
Interest Accrual:
Over time, the liquidityIndex increases to 1.1e27 due to accrued interest.
User A Withdraws:
User A attempts to withdraw their 1e11 RTokens.
The burn function calculates the underlying amount as amountScaled * liquidityIndex.
amountUnderlying = 1e11 * 1.1e27 = 110e18 crvUSD.
Result:
User A deposited 100 crvUSD but withdrew 110 crvUSD, receiving 10% more than they deposited. This excess comes from the protocol's reserves, potentially disadvantaging other users.
Users may receive fewer underlying assets than they deposited if the liquidityIndex decreases.
Users may receive more underlying assets than they deposited if the liquidityIndex increases, potentially at the expense of other users.
Manual Review
Modify the mint and burn functions to ensure a 1:1 ratio between deposited underlying assets and minted RTokens.
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.