Core Contracts

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

The amountToMint calculation in the DebtToken contract is wrong

Summary

In the mint function in the DebtToken contract, there was a logic error that caused the scaled amount to be incorrectly used when calculating the number of tokens that should be minted. This resulted in an inaccurate number of tokens minted.

Vulnerability Details

uint256 amountScaled = amount.rayDiv(index);
if (amountScaled == 0) revert InvalidAmount();
uint256 scaledBalance = balanceOf(onBehalfOf);
bool isFirstMint = scaledBalance == 0;
uint256 balanceIncrease = 0;
if (_userState[onBehalfOf].index != 0 && _userState[onBehalfOf].index < index) {
balanceIncrease = scaledBalance.rayMul(index) - scaledBalance.rayMul(_userState[onBehalfOf].index);
}
_userState[onBehalfOf].index = index.toUint128();
uint256 amountToMint = amount + balanceIncrease;
_mint(onBehalfOf, amountToMint.toUint128());

In the mint function, amount is used to calculate the final number of tokens to be minted without being properly scaled by index. The function calculates a scaled amount amountScaled = amount.rayDiv(index) but does not use that scaled amount in the final calculation of the number of coins to be minted. Instead, the function uses the original amount for the calculation, ignoring the effect of the scaling factor.

The amount represents the number of underlying tokens, and amountScaled is calculated based on the index. For example:

Assuming the amount is 100e18 and the index is 1.2e27, the amountScaled is 83,33333333333334e+18.

Impact

The original amount is used directly without being scaled by the index, resulting in an inaccurate amount. The relationship between amount and index is ignored, meaning you may mint too many or too few tokens.

Tools Used

Manual review

Recommendations

The final amountToMint should be calculated using amountScaled instead of the original amount. Therefore, the correct calculation should be:

uint256 amountToMint = amountScaled + balanceIncrease;
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!