Core Contracts

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

Unnecessary scaling of debt

Summary

In LendingPool contract there is unnecessary scaling of the user debt. It also they are maked some math operations that they are not used.

Vulnerability Details

In Lending Pool contract in _repay function

// Calculate the user's debt (for the onBehalfOf address)
uint256 userDebt = IDebtToken(reserve.reserveDebtTokenAddress).balanceOf(onBehalfOf);
uint256 userScaledDebt = userDebt.rayDiv(reserve.usageIndex);
// If amount is greater than userDebt, cap it at userDebt
uint256 actualRepayAmount = amount > userScaledDebt ? userScaledDebt : amount;
uint256 scaledAmount = actualRepayAmount.rayDiv(reserve.usageIndex);

variable userDebt is already scaled, because of calling the function balanceOf() from DebtToken contract. If the amount comes greater than userScaledDebt, actualRepayAmount will be scaled twice, because of userScaledDebt.
scaledAmount is scaling againg the actualRepayAmount. I see that these variables are not used but it will cost more gas.

Impact

Gas efficiency

Recommendations

If you want to use this functionallity for future you can comment out this part of code to save some gas. And also to fix it you should remove userScaledDebt variable and rename userDebt like this:

// Calculate the user's debt (for the onBehalfOf address)
uint256 userScaledDebt = IDebtToken(reserve.reserveDebtTokenAddress).balanceOf(onBehalfOf);
Updates

Lead Judging Commences

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

LendingPool::_repay compares scaled userScaledDebt with unscaled amount, creating unused actualRepayAmount; calculation is bypassed when burn is called with original amount

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

LendingPool::_repay compares scaled userScaledDebt with unscaled amount, creating unused actualRepayAmount; calculation is bypassed when burn is called with original amount

Support

FAQs

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