Core Contracts

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

Incorrect Dust Calculation and calculateDustAmount function will always return 0

Summary :

The calculateDustAmount function in the Rtoken contract incorrectly uses rayDiv and rayMul to calculate the dust amount, leading to meaningless results.the function scales the contract balance down by 27 decimals and scales the total supply up by 27 decimals, resulting in a huge disparity between the two values. As a result, the function always returns 0 or a very small value, which does not accurately represent the dust generated by the protocol.

Vulnerability Details :

The issue exists in the calculateDustAmount function, which is intended to calculate the excess balance of the underlying asset that is not tied to the rToken supply. The function performs the following steps:

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. Scales Down Contract Balance:

    • The contract balance is divided by the normalized income using rayDiv, which scales it down by 27 decimals.

    • Example: If the contract balance is 100e18 and the normalized income is 1.1e27, the result is 90.90e-9.

  2. Scales Up Total Supply:

    • The total supply of rTokens is multiplied by the normalized income using rayMul, which scales it up by 27 decimals.

    • Example: If the total supply is 90.90e18 and the normalized income is 1.1e27, the result is 99.99e45.

  3. Compares and Subtracts:

    • The scaled-down contract balance is compared to the scaled-up total real balance.

    • Due to the scaling, the contract balance will always be much smaller than the total real balance, causing the function to always return 0.

Impact :

  • The function always returns 0 which does not accurately represent the dust generated by the protocol. So If the dust amount is used for donations or protocol fees, the incorrect calculation indeed could lead to

    Loss of funds (if dust is underestimated).

Tools Used :

Manuel review

Updates

Lead Judging Commences

inallhonesty Lead Judge 4 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.