The calculateDeCRVUSDAmount and calculateRcrvUSDAmount functions in the StabilityPool contract use inconsistent scaling logic:
calculateDeCRVUSDAmount divides by the exchange rate.
calculateRcrvUSDAmount divides by the scaling factor.
While this inconsistency does not currently cause issues because the exchange rate is hardcoded to 1e18, it introduces a potential vulnerability if the exchange rate ever becomes dynamic. The impact of this issue includes:
Incorrect token conversions if the exchange rate changes.
Potential loss of funds or unfair advantages for users.
Assume:
rTokenDecimals = 18
deTokenDecimals = 18
getExchangeRate() = 2e18 (1 rToken = 2 deToken)
User deposits 100 rToken.
calculateDeCRVUSDAmount:The user receives only 50 deToken instead of the expected 200 deToken.
calculateRcrvUSDAmount:If the user withdraws 50 deToken:
The user receives 100 rToken, which is correct, but the initial deposit calculation was incorrect.
To prevent future issues, update the functions to use consistent scaling logic, even if the exchange rate is currently 1e18. For example:
calculateDeCRVUSDAmount:
calculateRcrvUSDAmount:
This ensures that the calculations remain correct even if the exchange rate changes in the future.
Both tokens have 18 decimals. Info
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.