Core Contracts

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

Incorrect Return Value of `totalSupply` in `DebtToken` Contract

Summary

There's a critical inconsistency in the totalSupply() calculation compared with balanceOf(). The issue stems from using different operations (rayDiv vs rayMul) for scaling.

Vulnerability Details

Lines:

https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/tokens/DebtToken.sol#L234

function totalSupply() public view override(ERC20, IERC20) returns (uint256) {
uint256 scaledSupply = super.totalSupply();
return scaledSupply.rayDiv(ILendingPool(_reservePool).getNormalizedDebt()); // Problematic line
}

The totalSupply function uses rayDiv to scale the scaledSupply by the normalized debt obtained from the lending pool. This is inconsistent with how balances are calculated in the balanceOf function, which uses rayMul to scale the user's balance by the same normalized debt.

Impact

Using rayDiv in totalSupply implies that the total supply decreases as the normalized debt increases, which is counterintuitive. The total supply should reflect the total amount of tokens in circulation, not decrease based on the debt index.

Tools Used

Manual Review

Recommendations

To correct this issue, the totalSupply function should use rayMul instead of rayDiv to ensure that the total supply reflects the correct scaling based on the normalized debt:

function totalSupply() public view override(ERC20, IERC20) returns (uint256) {
uint256 scaledSupply = super.totalSupply();
return scaledSupply.rayMul(ILendingPool(_reservePool).getNormalizedDebt()); // Corrected line
}
Updates

Lead Judging Commences

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

DebtToken::totalSupply incorrectly uses rayDiv instead of rayMul, severely under-reporting total debt and causing lending protocol accounting errors

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

DebtToken::totalSupply incorrectly uses rayDiv instead of rayMul, severely under-reporting total debt and causing lending protocol accounting errors

Support

FAQs

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