Skip to content
Business logic Audit finding Intermediate

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.

cryptphi Follow with adriro, Ch_301 and 3 others

Originally disclosed on Code4rena

Submitted by cryptphi, also found by adriro, Ch_301, PaludoX0, ayeslick, and perseverancesuccess

https://github.com/debtdao/Line-of-Credit/blob/audit/code4rena-2022-11-03/contracts/modules/credit/LineOfCredit.sol#L143

https://github.com/debtdao/Line-of-Credit/blob/audit/code4rena-2022-11-03/contracts/modules/credit/LineOfCredit.sol#L83-L86

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

  1. LineOfCredit contract is set up and 5 lenders have deposited into the contract.
  2. Alice, the borrower borrows credit from these 5 credit positions including by calling LineOfCredit.borrow() for the position ids.
  3. Later Alice pays back the loan for credit position id 1 just before the contract gets liquidated.
  4. At the point where ids.stepQ() is called in \_repay(), position 1 is moved to ids[0]
  5. 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


The original report as published on Code4rena, by cryptphi. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Set up the LineOfCredit contract with five lenders depositing.
  2. Borrower draws credit from the five credit positions.
  3. Borrower repays the loan for credit position id 1 just before liquidation.
  4. The repayment call reorders the ids queue so position 1 moves to the front.
  5. 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.

More by cryptphi

View all

7 more disclosed reports, best first.

More from Debt DAO contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.