Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: medium
Invalid

token conversions are incorrect in Stability Pool

Summary

Incorrect conversion of rToken to deToken.

Vulnerability Details

its should be returnd same R token deposited after burning de token. But here its not returned same R token after burning de token due to incorrect conversion.

This function returns minting amount of de token for a given R token.

function calculateDeCRVUSDAmount(uint256 rcrvUSDAmount) public view returns (uint256) {
uint256 scalingFactor = 10**(18 + deTokenDecimals - rTokenDecimals);
return (rcrvUSDAmount * scalingFactor) / getExchangeRate();
}

This returns , receiving R token amount due to burn de token.

function calculateRcrvUSDAmount(uint256 deCRVUSDAmount) public view returns (uint256) {
uint256 scalingFactor = 10**(18 + rTokenDecimals - deTokenDecimals);
return (deCRVUSDAmount * getExchangeRate()) / scalingFactor;
}

Consider deTokenDecimals and rTokenDecimals are different 6 and 18 respectivly.

Consider user stake 1e18 R token , its minting,

scalingFactor = 10**(18 + 6 - 18) = 10^6

deToken(mint) = 1e18 * 10^6 / 1e18 = 10^6

If user burn same deToken(10^6) amount user should be recived initial deposit amount(1e18).

When burning 10^6 deToken ,

scalingFactor = 10**(18 + 18 - 6) = 10^30

Rtoken(mint) = 10^6 * 1e18/10^30 = 10^24/10^30 which round off to zero . But it should be returned 1e18 R token.

This meaning token conversion is not properly done. Reason for this is , used different scalingFactor for two token conversion. Use same scalingFactor comparing with higher decimal and lower decimals , since its needed to prevent negative power in scalingFactor.

Impact

Token conversion is incorrect.

Tools Used

Manual Review

Recommendations

Use same scalingFactor comparing for both cases.

Updates

Lead Judging Commences

inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Incorrect scaling factor formula in StabilityPool::calculateRcrvUSDAmount function

Both tokens have 18 decimals. Info

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!