When the bid amount is not enough, the lender will be repaid in order of tranche[].
In order to minimize the risk, the user can specify maxSeniorRepayment to avoid the risk to some extent, and put himself in a position of higher repayment priority.
At the same time emitLoan() checks maxSeniorRepayment for the emitLoan()
Because bidding takes a certain amount of time (3~7days), using block.timestamp - thisTranche.startTime will be larger than expected!
Correctly should use: (loan.startTime + loan.duration - thisTranche.startTime) to calculate the interest.
This leads to the problem that if there is not enough funds, the front lender will get a larger repayment than expected, breaking the back lender's initial expectation of `maxSeniorRepayment
Impact
If there are not enough funds, the initial expectation of maxSeniorRepayment may be broken
Lines of code
https://github.com/code-423n4/2024-04-gondi/blob/b9863d73c08fcdd2337dc80a8b5e0917e18b036c/src/lib/LiquidationDistributor.sol#L39
Vulnerability details
Vulnerability details
When the bid amount is not enough, the
lender
will be repaid in order oftranche[]
. In order to minimize the risk, the user can specifymaxSeniorRepayment
to avoid the risk to some extent, and put himself in a position of higher repayment priority. At the same timeemitLoan()
checksmaxSeniorRepayment
for theemitLoan()
emitLoan()
->_processOffersFromExecutionData()
->_checkOffer()
Note:
totalAmountWithMaxInterest
is computed usingloan._duration
But when the bidding ends and the distribution is done
LiquidationDistributor.distribute()
the current time is used to calculateInterest
.Because bidding takes a certain amount of time (3~7days), using
block.timestamp - thisTranche.startTime
will be larger than expected! Correctly should use: (loan.startTime + loan.duration
-thisTranche.startTime
) to calculate theinterest
.This leads to the problem that if there is not enough funds, the front
lender
will get a larger repayment than expected, breaking the backlender
's initial expectation of `maxSeniorRepaymentImpact
If there are not enough funds, the initial expectation of
maxSeniorRepayment
may be brokenRecommended Mitigation
Assessed type
Context