calculateRcrvUSDAmount() calculates & applies scalingFactor
incorrectly. It should be:
Imagine:
deTokenDecimals = 20 and rTokenDecimals = 12
rTokenAmount = 100 * 1e12 ⬅️
Converted to deTokenAmount as per calculateDeCRVUSDAmount()
:
scalingFactor = 10**(18 + 20 - 12) = 10**26
deTokenAmount = (100e12 * 1e26) / 1e18 = 100e20
Let's convert back via calculateRcrvUSDAmount()
:
scalingFactor = 10**(18 + 12 - 20) = 10**10
rTokenAmount = (100e20 * 1e18) / 1e10 = 100e28 ❌
Depending on the difference between decimals of the two tokens, the value returned could be highly inflated or deflated. This will heavily effect deposit()
and withdraw()
functions and can cause protocol loss as they mint and burn disproportionate amount of funds.
As shown in the diff, use:
scalingFactor = 10**(18 + 20 - 12) = 10**26
rTokenAmount = (100e20 * 1e18) / 1e26 = 100e12 ✔️
We are assuming of course that getExchangeRate()
will always be 1e18
.
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.