Core Contracts

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

`StabilityPool::calculateRaacRewards()` does not take into account dynamic `deToken` and `rToken` decimals

Summary

The StabilityPool allows for dynamic decimal settings on the rToken and deToken tokens, and incorporates functions to calculate what X amount of token will equal for the other token when depositing and withdrawing. However, these calculations are not carried out when RAAC rewards are being calculated in calculateRaacRewards(...).

Vulnerability Details

Let's look at the StabilityPool storage variables:

https://github.com/Cyfrin/2025-02-raac/blob/main/contracts/core/pools/StabilityPool/StabilityPool.sol#L54-L56

// Allow to make rToken / deToken decimals flexible
uint8 public rTokenDecimals;
uint8 public deTokenDecimals;

From the above, we can confirm that the protocol plans to use different variables for their deToken and rToken implementations. This is further confirmed by the way deposits and withdraws are being made. However, the calculateRaacRewards(...) function does not carry out the same conversions and assumes that deToken and rToken wil always have the same decimals, leading to issues in the cases when they are not:

https://github.com/Cyfrin/2025-02-raac/blob/main/contracts/core/pools/StabilityPool/StabilityPool.sol#L251-L259

function calculateRaacRewards(address user) public view returns (uint256) {
uint256 userDeposit = userDeposits[user];
uint256 totalDeposits = deToken.totalSupply();
uint256 totalRewards = raacToken.balanceOf(address(this));
if (totalDeposits < 1e6) return 0;
return (totalRewards * userDeposit) / totalDeposits;
}

If for example rToken is with 18 decimals and deToken is with 6 decimals, we will have (Xe18 * Ye18) / Ze6 = ((X*Y) / Z)e30 -> overinflation as rewards must be in RAACTokens, which is with 18 decimals. If we have the other way areound (Xe18 * Ye6) / Ze18 = ((X*Y) / Z)e6 -> dust amount of RAACToken rewards

Impact

Incorrect reward calculations.

Tools Used

Manual review.

Recommendations

Carefully align deToken and rToken decimals when calculating RAACToken rewards`

Updates

Lead Judging Commences

inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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