Incorrect protocol fee implementation results in outstandingValues to be mis-accounted in Pool.sol
Submitted by oakcobalt
The vulnerability is that LiquidationDistributer::_handleLoanMangerCall hardcodes 0 as protocol fee when calling LoanManager(_tranche.lender).loanLiquidation().
//src/lib/LiquidationDistributor.sol
function _handleLoanManagerCall(IMultiSourceLoan.Tranche calldata _tranche, uint256 _sent) private {
if (getLoanManagerRegistry.isLoanManager(_tranche.lender)) {
LoanManager(_tranche.lender).loanLiquidation(
_tranche.loanId,
_tranche.principalAmount,
_tranche.aprBps,
_tranche.accruedInterest,
|> 0, //@audit this should be the actual protocol fee fraction
_sent,
_tranche.startTime
);
}
}
_handleLoanManagerCall() will be called as part of the flow to distribute proceeds from a liquidation.
When protocol fee is hardcoded 0, in the Pool::loanliquidation call, netApr will not account for protocol fee fraction which will inflate the _apr used to offset _outstandingValues.sumApr, a state variable that accounts for the total annual apr of outstanding loans.
//src/lib/pools/Pool.sol
OutstandingValues memory __outstandingValues,
uint256 _principalAmount,
uint256 _apr,
uint256 _interestEarned
) private view returns (OutstandingValues memory) {
...
//@audit inflated _apr will offset __outstandingValues.sumApr to an incorrect lower value, causing accounting error
|> __outstandingValues.sumApr -= uint128(_apr * _principalAmount);
...
For comparison, when a loan is created (pool::validateOffer), the actual protocol fee (protocolFee.fraction) will be passed, and __outstandingValues.sumApr will be added with the post-fee apr value, instead of the before-fee apr.
State accounting __outstandingValues will be incorrect, all flows that consume __outstandingValues.sumApr when calculating interests will be affected.
Recommended Mitigation Steps
User _loan.protocolFeeinstead of 0.
0xend (Gondi) confirmed and commented:
Messes up with accounting, I think this is a high one.
Passing protocol fee.
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.
What is known
A high-severity business logic bug in Gondi Invitational. Code4rena made it public on 25 July 2024. Found in the 2024-04-gondi audit contest (finding H-11).
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.