Skip to content
Business logic Audit finding Intermediate

Quote helper mutates persistent close-factor state

The public quote function calculate_liquidation mutates a persistent temporary-storage counter (USER_LIQUIDATED_THIS_TX) that execute_liquidation later treats as authoritative. An attacker can call the quote function for arbitrary users to consume the close-factor budget, causing engine-mediated liquidations to be reduced, blocked, or recorded with false metadata.

v12 Follow

Originally disclosed on Code4rena

Submitted by v12

Found by V12

  • contracts/liquidation-engine/src/calculation.rs #L7
  • contracts/liquidation-engine/src/contract.rs #L49
  • contracts/liquidation-engine/src/storage.rs #L266

Targets

  • LiquidationEngineContract::calculate_liquidation
  • LiquidationEngineContract::execute_liquidation
  • LiquidationEngineContract::adduserliquidatedthistx

Affected Locations

  • LiquidationEngineContract.calculate_liquidation: Core calculation updates USER_LIQUIDATED_THIS_TX while computing actual_debt_to_cover, making a supposed quote mutate close-factor state.
  • LiquidationEngineContract.execute_liquidation: Execution path reuses the same helper, so previously poisoned state changes the liquidation values recorded and enforced by the engine.
  • LiquidationEngineContract.adduserliquidatedthistx: Temporary-storage counter is incremented from the calculation path even when no real router liquidation has happened.

Description

calculate_liquidation is exposed as a public quote-like entry, but its underlying calculation path mutates USER_LIQUIDATED_THIS_TX by calling add_user_liquidated_this_tx whenever actual_debt_to_cover > 0. execute_liquidation then calls the same helper again, so any prior quote or probe changes remaining_liquidatable even though no router liquidation has occurred. Because this counter is kept in Soroban temporary() storage rather than true transaction-local state, the poisoning can persist beyond a single call for the entry TTL instead of naturally resetting after one transaction. The result is that the engine can reduce actual_debt_to_cover to a smaller value or 0, block its own liquidation flow, and record collateral_to_liquidate and liquidation_bonus from a state-skewed second quote. This breaks both availability of the engine path and integrity of the engine’s liquidation records, even though the router’s own liquidation logic remains separate.

Root Cause

The contract mixes quoting with accounting by letting calculate_liquidation update USER_LIQUIDATED_THIS_TX in Soroban temporary() storage, so an unauthenticated helper call mutates state that execute_liquidation later treats as authoritative.

Impact

An attacker can cheaply call calculate_liquidation for arbitrary users to consume the engine’s close-factor budget that execute_liquidation later relies on, causing engine-mediated liquidations to be reduced, blocked, or recorded as zero-value actions. They can also desynchronize the engine’s history from the router’s actual settlement, so any accounting, rewards, monitoring, or analytics that trust the engine’s records receive false liquidation metadata.

Proof of Concept

See original finding for full Proof of Concept

Remediation

Removed liquidation-engine quote-side close-factor state mutation. calculateliquidation now computes a pure single-call close-factor cap and no longer reads or writes USERLIQUIDATEDTHISTX, so unauthenticated quote/probe calls cannot poison later execute_liquidation metadata or availability. The router remains the settlement-time source of truth for close-factor enforcement.

See original finding for patch details

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

The contract mixes quoting with accounting by letting calculate_liquidation update USER_LIQUIDATED_THIS_TX in Soroban temporary() storage, so an unauthenticated helper call mutates state that execute_liquidation later treats as authoritative.

Impact

An attacker can cheaply call calculate_liquidation for arbitrary users to consume the engine's close-factor budget, causing engine-mediated liquidations to be reduced, blocked, or recorded as zero-value actions, and desynchronising the engine's history from the router's actual settlement.

What the attacker needed

No authentication needed; ability to call the public quote function

The fix

The liquidation-engine quote-side close-factor state mutation was removed; calculate_liquidation now computes a pure single-call close-factor cap and no longer reads or writes USER_LIQUIDATED_THIS_TX.

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 'quote' function is meant to just calculate and return numbers without changing anything, like a price check. Here the quote function secretly updated a shared counter that the real liquidation function later trusted, so anyone could call the quote repeatedly and distort what the real function did. The counter lived in temporary storage that lasted longer than one transaction, so the damage did not reset automatically.

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.