Core Contracts

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

Debt Inflation Due to Double Scaling in `DebtToken.mint()` Function

Summary

A critical issue in the mint() function of DebtToken.sol causes users to be minted more debt tokens than they should owe, leading to unintended debt inflation. The issue arises from double scaling when computing balanceIncrease, making users liable for higher debt than they actually borrowed. This leads to excessive debt accumulation, unfair borrowing conditions, and potential financial loss. The protocol must urgently address this to prevent users from being overburdened with unintended debt liabilities.

Vulnerability Details

The mint() function first retrieves the user’s debt balance via:

DebtToken.sol#L150

uint256 scaledBalance = balanceOf(onBehalfOf);

However, balanceOf() already applies rayMul() to scale up the balance:

DebtToken.sol#L223-L226

function balanceOf(address account) public view override(ERC20, IERC20) returns (uint256) {
uint256 scaledBalance = super.balanceOf(account);
return scaledBalance.rayMul(ILendingPool(_reservePool).getNormalizedDebt());
}

Later in mint(), scaledBalance is scaled again when computing balanceIncrease if tis isn't the first mint:

DebtToken.sol#L154-L156

if (_userState[onBehalfOf].index != 0 && _userState[onBehalfOf].index < index) {
balanceIncrease = scaledBalance.rayMul(index) - scaledBalance.rayMul(_userState[onBehalfOf].index);
}

This results in double scaling, making balanceIncrease larger than it should be.

Consequently, the incorrectly computed balanceIncrease is added to the original borrow amount:

uint256 amountToMint = amount + balanceIncrease;

It then mints an inflated number of debt tokens for the user:

_mint(onBehalfOf, amountToMint.toUint128());

This means the user's debt balance incorrectly increases every time they borrow after the first mint.

Such inflated amount is also propagated via the Mint event:

DebtToken.sol#L165

emit Mint(user, onBehalfOf, amountToMint, balanceIncrease, index);

Impact

  • Users are unfairly charged more debt than they actually borrowed from the second borrow onwards.

  • Compounded interest is applied on an inflated debt principal, making the issue exponentially worse over time.

  • Borrowers may face liquidation sooner than expected, even if they initially borrowed responsibly.

  • Protocol fairness and stability are at risk, as some users may unknowingly become significantly over-leveraged.

  • Potential reputational damage to the lending protocol, as users experience unexpected losses.

Tools Used

Manual

Recommendations

Consider making the following code refactoring:

DebtToken.sol#L150

- uint256 scaledBalance = balanceOf(onBehalfOf);
+ uint256 scaledBalance = super.balanceOf(onBehalfOf);
Updates

Lead Judging Commences

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

DebtToken::mint miscalculates debt by applying interest twice, inflating borrow amounts and risking premature liquidations

Support

FAQs

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

Give us feedback!