The StabilityPool contract contains conversion functions that do not correctly handle tokens with differing decimal places. This can lead to inaccurate calculations when converting between rToken and deToken, potentially resulting in incorrect token amounts being returned or redeemed.
The functions calculateDeCRVUSDAmount and calculateRcrvUSDAmount are responsible for converting amounts between rToken and deToken. These functions use a scalingFactor to adjust for differences in token decimals.
The scaling factor is calculated as 10**(18 + deTokenDecimals - rTokenDecimals) in calculateDeCRVUSDAmount and 10**(18 + rTokenDecimals - deTokenDecimals) in calculateRcrvUSDAmount. However, this approach can lead to incorrect conversions if the token decimals differ significantly.
Example
rToken has 6 decimals.
deToken has 18 decimals.
getExchangeRate() returns 1e18.
For calculateDeCRVUSDAmount:
scalingFactor = 10``(18 + 18 - 6) = 10e30
If rcrvUSDAmount =1e6 , the function returns (1e6 * 10**30) / 1e18 = 10**18.
For calculateRcrvUSDAmount:
scalingFactor = 10**(18 + 6 - 18) = 10**6
If deCRVUSDAmount = 1e18, the function returns (1e18 * 1e18) / 10**6 = 10**30.
same deCRVUSDAmountis not correctly converted to initial amount
Withdraw would fail since it would try to send much more rTokens than user balance
Manual
To fix the inconsistency, update the calculateRcrvUSDAmount function so that it uses the same scaling factor as calculateDeCRVUSDAmount
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.