loanLiquidation() calculation of interest is not accurate
The loan liquidation function incorrectly treats the entire received amount as principal when calculating fees, ignoring that the received amount may exceed the principal. This leads to incorrect fee calculation when the received amount is greater than the principal.
Submitted by bin2chen
loanLiquidation(): The calculated interest codes are as follows:
function loanLiquidation(
uint256 _loanId,
uint256 _principalAmount,
uint256 _apr,
uint256,
uint256 _protocolFee,
uint256 _received,
uint256 _startTime
) external override onlyAcceptedCallers {
uint256 netApr = _netApr(_apr, _protocolFee);
uint256 interestEarned = _principalAmount.getInterest(netApr, block.timestamp - _startTime);
@> uint256 fees = IFeeManager(getFeeManager).processFees(_received, 0);
getCollectedFees += fees;
_loanTermination(msg.sender, _loanId, _principalAmount, netApr, interestEarned, _received - fees);
}
...
contract FeeManager is IFeeManager, TwoStepOwned {
...
function processFees(uint256 _principal, uint256 _interest) external view returns (uint256) {
/// @dev cached
Fees memory __fees = _fees;
return _principal.mulDivDown(__fees.managementFee, PRECISION)
+ _interest.mulDivDown(__fees.performanceFee, PRECISION);
}
The above code takes all of _received as the principal and gives it to IFeeManager to calculate. But the amount received from the bidding is not always less than the principal, it may be more than the principal, and this part should be calculated as interest.
Impact
When received is greater than the principal, fees is not correct.
Recommended Mitigation
function loanLiquidation(
uint256 _loanId,
uint256 _principalAmount,
uint256 _apr,
uint256,
uint256 _protocolFee,
uint256 _received,
uint256 _startTime
) external override onlyAcceptedCallers {
uint256 netApr = _netApr(_apr, _protocolFee);
uint256 interestEarned = _principalAmount.getInterest(netApr, block.timestamp - _startTime);
- uint256 fees = IFeeManager(getFeeManager).processFees(_received, 0);
+ uint256 fees;
+ if (_received > _principalAmount) {
+ fees = IFeeManager(getFeeManager).processFees(_principalAmount, _received - _principalAmount);
+ }else {
+ fees = IFeeManager(getFeeManager).processFees(_received, 0);
+ }
getCollectedFees += fees;
_loanTermination(msg.sender, _loanId, _principalAmount, netApr, interestEarned, _received - fees);
}
Assessed type
Context
Corrected calculation of fees as suggested.
Status: Mitigation confirmed. Full details in reports from oakcobalt, minhquanym and bin2chen.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the fee calculation logic assumes the received amount is always less than or equal to the principal, so it passes the entire received amount as principal to the fee manager without separating the interest portion.
Impact
When the received amount exceeds the principal, the fees are calculated incorrectly, potentially undercharging or overcharging fees.
What the attacker needed
Received amount > principal
The fix
The fee calculation should be corrected to treat any amount above the principal as interest, as suggested in the mitigation.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In a lending system, when a loan is liquidated, the amount received from selling collateral is used to calculate fees. The code mistakenly treats the entire received amount as the original loan amount (principal), but if the received amount is higher than the principal, the extra should be considered interest. This mistake causes fees to be calculated incorrectly.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.