Core Contracts

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

The computation of `balanceIncrease` in `mint()` is incorrect

Summary

In the mint() function, the scaledBalance variable fetched from balanceOf() is an UNSCALED balance. However, we assume that it is SCALED, this leads to computation of a wrong balanceIncrease which results in minting WRONG number of tokens.

Vulnerability Details

Function mint() computes the amount of debt tokens to be minted to the user. In case the User is making borrow for the second time, we compute the balanceIncrease to account for interest accumulated between previous borrow and current borrow. i.e. mint()

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

However, the usage of scaledBalance variable for the computation of balanceIncrease is wrong.
Reason being, the call to balanceOf returns an unscaled balance instead of a scaled one. i.e. balanceOf

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

This scaledBalance is multiplied by the latest usage index which results in an unscaled amount, hence it defeats the purpose of calculating the balanceIncrease as the same value is later multiplied with usage index.

The issue occurs due to wrong call to balanceOf, instead it should have called scaledBalanceOf() function for fetching the correct scaledBalance.

Impact

Wrong amount of tokens will be minted to the user

Tools Used

Manual

Recommendations

Consider replacing the function call with this one

uint256 userBalance = scaledBalanceOf(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!