Core Contracts

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

calculateDustAmount() will always return zero due to unnecessary scaling

Summary

In RToken.sol, the calculateDustAmount()will always return 0, as the calculation of the real balance is unnecessarily multiplied by the reserve usage index, causing an over-inflated value.

Vulnerability Details

function calculateDustAmount() public view returns (uint256) {
// Calculate the actual balance of the underlying asset held by this contract
uint256 contractBalance = IERC20(_assetAddress).balanceOf(address(this)).rayDiv(ILendingPool(_reservePool).getNormalizedIncome());
// Calculate the total real obligations to the token holders
uint256 currentTotalSupply = totalSupply();
// Calculate the total real balance equivalent to the total supply
uint256 totalRealBalance = currentTotalSupply.rayMul(ILendingPool(_reservePool).getNormalizedIncome());
// All balance, that is not tied to rToken are dust (can be donated or is the rest of exponential vs linear)
return contractBalance <= totalRealBalance ? 0 : contractBalance - totalRealBalance;
}
  1. In the above function, contractBalance takes the current balance of crvUSD in RToken.sol then divide it by the liquidity index that is retrieved from getNormalizedIncome().

  2. totalSupply()will return the supply of RToken multiplied by the same liquidity index:

    function totalSupply() public view override(ERC20, IERC20) returns (uint256) {
    return super.totalSupply().rayMul(ILendingPool(_reservePool).getNormalizedIncome());
    }
  3. Now, currentTotalSupply is multiplied again by the same liquidity index as seen in line 9, to get totalRealBalance

  4. This will result in extremely high certainty that contractBalance <= totalRealBalance will be true, hence always returning 0.

Impact

Dust amount will always be 0, and cannot be rescued.

Tools Used

Manual

Recommendations

Ensure that there is no double multiplying by the liquidity index when calculating the real balance.

Updates

Lead Judging Commences

inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Validated
Assigned finding tags:

RToken::calculateDustAmount incorrectly applies liquidity index, severely under-reporting dust amounts and permanently trapping crvUSD in contract

Support

FAQs

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

Give us feedback!