Core Contracts

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

`balanceIncrease` in Debt Token contract is wrongly computed, leading to incorrect `Mint` event emission.

Summary

balanceIncrease in Debt Token contract is computed as follows:

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

This is incorrect because scaledBalance is calculated like so:

uint256 scaledBalance = balanceOf(onBehalfOf);

with balanceOf returning the the debt balance in underlying assets unit:

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

This means that when computing balanceIncrease with:

balanceIncrease = scaledBalance.rayMul(index) - scaledBalance.rayMul(_userState[onBehalfOf].index);

We actually apply a multiplication scaling by the index for the second time, given that scaledBalance is already in underlying assets unit.

Vulnerability Details

Because balanceIncrease is incorrect and greater than it should, Mint event will be emitted with wrong values:

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

Impact

The impact of this issue is medium as it leads to event emission with incorrect data, leading to important front-end integration issues.

Tools Used

Manual review

Recommendations

Make sure to correctly compute the balanceIncrease, using underlying assets unit:

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

This solution uses super.balanceOf to retrieve the balance in debt token unit. We can then multiply by the index and the last index of the user to get the correct balance increase in underlying assets unit.

Updates

Lead Judging Commences

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