Call to declareInsolvent() would revert when contract status reaches liquidation point after repayment of credit position 1
The declareInsolvent() function is guarded by a modifier that reverts when the first credit position has zero principal. After a borrower repays one credit position, the queue reordering can move a fully repaid position to the front, so the arbiter's call to declare insolvency reverts even though the contract is liquidatable.
Submitted by cryptphi, also found by adriro, Ch_301, PaludoX0, ayeslick, and perseverancesuccess
Impact
The modifier whileBorrowing() is used along in the call to LineOfCredit.declareInsolvent(). However this check reverts when count == 0 or credits[ids[0]].principal == 0 . Within the contract, any lender can add credit which adds an entry in credits array, credits[ids].
Assume, when borrower chooses lender positions including credits[ids[0]] to draw on, and repays back the loan fully for credits[ids[1]], then the call to declareInsolvent() by the arbiter would revert since it does not pass the whileBorrowing() modifier check due to the ids array index shift in the call to stepQ(), which would shift ids[1] to ids[0], thereby making the condition for credits[ids[0]].principal == 0 be true causing the revert.
Proof of Concept
- LineOfCredit contract is set up and 5 lenders have deposited into the contract.
- Alice, the borrower borrows credit from these 5 credit positions including by calling
LineOfCredit.borrow()for the position ids. - Later Alice pays back the loan for credit position id 1 just before the contract gets liquidated.
- At the point where
ids.stepQ()is called in\_repay(), position 1 is moved to ids[0] - When contract status is LIQUIDATABLE, no loan drawn on credit position 0 and arbiter calls declareInsolvent() , the call would revert since
credits[ids[0]].principal == 0
Recommended Mitigation Steps
The modifier whileBorrowing() would need to be reviewed and amended.
dmvt (judge) increased severity to High
kibagateaux (Debt DAO) confirmed
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 whileBorrowing() modifier checks only the first credit position's principal, but the ids queue can be reordered by repayment so a zero-principal position becomes first.
Impact
The arbiter cannot declare the contract insolvent, so the liquidation process is blocked for that state.
What the attacker needed
Borrower has multiple credit positions; borrower repays one position before liquidation; contract reaches liquidatable status; arbiter calls declareInsolvent()
The fix
The whileBorrowing() modifier should be reviewed and amended so it does not depend on the first credit position's principal.
How it was found
- Set up the LineOfCredit contract with five lenders depositing.
- Borrower draws credit from the five credit positions.
- Borrower repays the loan for credit position id 1 just before liquidation.
- The repayment call reorders the ids queue so position 1 moves to the front.
- When the contract is liquidatable, the arbiter calls declareInsolvent() and it reverts.
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.
A borrower can take credit from several lenders at once, and the contract keeps those credit positions in a list. The function that declares the borrower insolvent only works if the first position in that list still has money owed. Repaying one position can shuffle the list so a fully repaid position ends up first, which makes the insolvency declaration fail.
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.