Skip to content
Business logic Audit finding Intermediate

Incorrect maxClose Calculation in Liquidation

The liquidation function calculates the maximum repayable amount using the historical borrow balance without accrued interest, rather than the current debt. This prevents liquidators from repaying the full allowable amount, reducing their rewards and potentially delaying debt recovery.

0xAlix2 Follow with 0xc0ffEE, Aenovir and 18 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-05-lend-audit-contest-judging/issues/1029

Found by

0xAlix2, 0xc0ffEE, Aenovir, Brene, Etherking, Hueber, PNS, Rorschach, Ruppin, Tigerfrake, coin2own, jokr, m3dython, molaratai, newspacexyz, onthehunt, oxelmiguel, patitonar, rudhra1749, ydlee, zraxx

Summary

The liquidateBorrowAllowedInternal function uses an outdated borrow balance (borrowBalance.amount) to calculate maxClose, causing the require(repayAmount <= maxClose) check to restrict liquidators from repaying the full allowable debt, reducing their liquidation rewards.

Root Cause

In Lend-V2.sol, the liquidateBorrowAllowedInternal function calculates maxClose as the product of closeFactorMantissa and borrowBalance.amount, which represents the historical borrow amount without accrued interest. However, the liquidation eligibility check (borrowedAmount > collateral) uses the current debt with interest (borrowedAmount), leading to a mismatch. The require(repayAmount <= maxClose) condition prevents liquidators from repaying amounts based on the actual debt, limiting their rewards.

Internal Pre-conditions

  1. A borrower needs to have a loan with accrued interest (e.g., 1000 USDC initial debt with borrowIndex increased by 10%, resulting in 1100 USDC current debt).
  2. The borrower's current debt (borrowedAmount) must exceed their collateral value (e.g., 1100 USDC > 1000 USDC) to allow liquidation.
  3. A liquidator needs to attempt repaying an amount (repayAmount) greater than maxClose, calculated as closeFactorMantissa * borrowBalance.amount (e.g., 50% * 1000 USDC = 500 USDC).
  4. The closeFactorMantissa (e.g., 50%) needs to limit the maximum repayable amount.

External Pre-conditions

  1. The underlying token prices (e.g., USDC) need to remain stable to ensure consistent collateral and borrow valuations.
  2. The oracle price feed for lTokens needs to be consistent to avoid unrelated reverts.

Attack Path

  1. A borrower borrows 1000 USDC on Chain A for cUSDC, recorded in borrowBalance.amount with borrowIndex = 1e18. Over time, borrowIndex increases to 1.1e18 (10% interest), making the current debt (borrowedAmount) 1100 USDC.
  2. The borrower's collateral is valued at 1000 USDC (after collateral factor), so borrowedAmount > collateral (1100 > 1000), enabling liquidation.
  3. A liquidator attempts to liquidate 550 USDC (50% of current debt) via liquidateBorrow.
  4. The function liquidateBorrowAllowedInternal calculates maxClose = 0.5 * borrowBalance.amount = 0.5 * 1000 = 500 USDC.
  5. The check require(repayAmount <= maxClose) reverts, as 550 > 500, preventing the liquidator from repaying 550 USDC.
  6. The liquidator is restricted to repaying 500 USDC, losing the opportunity to earn a liquidation reward (e.g., 8% of 50 USDC = 4 USDC) on the additional 50 USDC.

Impact

Liquidators are unfairly restricted from repaying the full allowable debt, losing potential liquidation rewards (e.g., $4 for 50 USDC at 8% incentive), exceeding $10 and 0.01% (e.g., 0.4% of a 1000 USDC debt). This reduces liquidator participation, potentially delaying debt recovery and increasing insolvency risk for the protocol. Borrowers may face prolonged debt exposure due to incomplete liquidations, accruing additional interest. The core liquidation functionality is impaired, as the protocol fails to align maxClose with actual debt, undermining liquidator incentives. The issue can affect multiple liquidations and tokens, reducing protocol efficiency.

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

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 code uses the stored borrow balance without accrued interest to compute the maximum close amount, while the eligibility check uses the current debt with interest, creating a mismatch.

Impact

Liquidators are restricted from repaying the full allowable debt, losing potential rewards, which could reduce participation and delay debt recovery, increasing insolvency risk.

What the attacker needed

Borrower has loan with accrued interest; debt exceeds collateral value; liquidator attempts repayment above maxClose

The fix

The calculation of maxClose should use the current debt including accrued interest instead of the historical borrow balance.

How it was found

  1. A borrower borrows 1000 USDC, recorded with borrowIndex = 1e18.
  2. Over time, borrowIndex increases to 1.1e18 (10% interest), making current debt 1100 USDC.
  3. The borrower's collateral is valued at 1000 USDC, so borrowedAmount > collateral, enabling liquidation.
  4. A liquidator attempts to repay 550 USDC (50% of current debt).
  5. The function calculates maxClose = 0.5 * 1000 = 500 USDC.
  6. The require check reverts because 550 > 500, restricting the liquidator to 500 USDC.

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 a lending protocol, when a borrower's debt exceeds their collateral, a liquidator can repay part of the debt and earn a reward. The code limits how much can be repaid based on the original borrowed amount, not the current amount including interest. This means liquidators cannot repay as much as they should, so they earn less and may be less willing to help.

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 0xAlix2

View all

39 more disclosed reports, best first.

More from LEND

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.