Skip to content
Business logic Audit finding Intermediate

Zero-scaled repay clears debt

A repayment smaller than the borrow index divided by RAY floors to zero scaled debt, and the debt token's dust-cleanup branch then wipes the entire remaining debt. A borrower can repay a tiny amount and clear more debt than they actually paid, leaving the reserve short.

v12 Follow with 0xanmol, 0xBookerH and 23 others

Originally disclosed on Code4rena

Submitted by v12, also found by 0xanmol, 0xBookerH, Agontuk, bunnyhunter, coinsspor, DemoreX, dorkerdevil, Ezrel, hezze, indieshipx247, K42, kind0dev, legat, maigadoh, mfosec, nairobi7, odeili, oziajibogu, qed, rsquared, samuraii77, toski04, tradingview, wuji, and y4y

Found by V12

  • contracts/shared/src/utils.rs #L79

Description

ray_div_down floor-divides amount * RAY / index, so any positive repayment smaller than index / RAY produces 0. DebtToken::burn_scaled uses that value as amount_scaled and never rejects the zero case. When the borrower’s remaining scaled debt is 1, the later dust-cleanup branch if new_scaled_debt <= 1 overwrites amount_scaled with the full current_scaled_debt and deletes the debt entirely, even though the caller only paid the tiny underlying amount that floored to zero. KineticRouter::repay transfers only amount_to_repay to the pool before calling burn_scaled and ignores the tuple returned by the burn, so the underpayment is not detected. A borrower can intentionally repay down to 1 scaled unit and then clear the entire remainder with a smaller-than-owed payment once the borrow index has grown enough that one scaled unit represents more than the minimal repayment.

Root Cause

ray_div_down legitimately truncates small repayments to zero, but DebtToken::burn_scaled allows that zero-scaled result to enter its new_scaled_debt <= 1 dust-cleanup path and convert it into a full debt wipe. KineticRouter::repay compounds the issue by assuming the requested underlying amount was actually burned instead of validating the effective burn result returned by the debt token.

Impact

A borrower can extinguish more debt than they actually repay, leaving the reserve short and pushing the loss onto suppliers. On reserves with coarse decimals or sufficiently grown borrow indices, the forgiven remainder can exceed a full underlying unit per position, and a motivated attacker can repeat the pattern across many accounts or reserves they control.

Proof of Concept

See this gist for full Proof of Concept


The original report as published on Code4rena, by v12. 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 debt token's dust-cleanup branch treats a zero scaled repayment as a full debt wipe, and the router does not check the actual burn result.

Impact

A borrower can extinguish more debt than they repay, leaving the reserve short and pushing the loss onto suppliers; the forgiven amount can exceed a full underlying unit on coarse-decimal reserves or with grown indices.

What the attacker needed

A borrower position with debt; borrow index grown enough; ability to make a tiny repayment

The fix

The debt token should reject zero scaled repayments or not treat them as dust cleanup, and the router should validate the burn result.

How it was found

  1. Repay down to one scaled unit of debt.
  2. Wait until the borrow index has grown enough that one scaled unit is worth more than the minimal repayment.
  3. Make a repayment smaller than index divided by RAY, which floors to zero scaled units.
  4. The dust-cleanup branch deletes the entire remaining debt.

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 lending pools, debt is tracked in 'scaled' units that grow with interest. A rounding step can turn a very small repayment into zero scaled units. The code then treats that zero as 'almost paid off' and deletes the whole remaining debt, so the borrower pays less than they owe.

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 v12

View all

37 more disclosed reports, best first.

More from K2

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.