Skip to content
Business logic Audit finding Intermediate

Liquidation fee overdraft drains pooled collateral

The liquidation fee calculation deducts only the remaining collateral from the liquidated account but transfers the full calculated fee from the protocol's pooled collateral. An attacker can repeatedly liquidate accounts with insufficient collateral to drain the shared pool.

failsafe_intern Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

56365 sc critical liquidation fee overdraft drains pooled collateral

Submitted on Oct 15th 2025 at 06:04:30 UTC by @failsafe_intern for Audit Comp | Alchemix V3

Description

Description

The _liquidate function pays liquidators a repayment fee that exceeds what was deducted from the liquidated account, stealing the shortfall from the protocol's pooled MYT collateral shared by all users.

Vulnerability Mechanism

When an account with earmarked debt is liquidated and the debt fully clears, _resolveRepaymentFee calculates the fee but only deducts min(fee, collateralBalance) from the account:

File: v3-poc-b0505da/src/AlchemistV3.sol
Lines: 515-533

Solidity
function _resolveRepaymentFee(uint256 accountId, uint256 repaidAmountInYield) internal returns (uint256 fee) {
    Account storage account = _accounts[accountId];
    fee = repaidAmountInYield * repaymentFee / BPS;
    account.collateralBalance -= fee > account.collateralBalance ? account.collateralBalance : fee;
    return fee;  // Returns FULL fee
}

However, _liquidate unconditionally transfers the full returned fee to the liquidator from the contract's pooled MYT balance:

File: v3-poc-b0505da/src/AlchemistV3.sol
Lines: 495-499

Solidity
if (account.debt == 0) {
    feeInYield = _resolveRepaymentFee(accountId, repaidAmountInYield);
    TokenUtils.safeTransfer(myt, msg.sender, feeInYield);  // Transfers FULL fee from pool
    return (repaidAmountInYield, feeInYield, 0);
}

Root Cause

The mismatch occurs because:

  1. _forceRepay consumes most/all account collateral during earmarked debt repayment
  2. _resolveRepaymentFee can only deduct remaining collateral but returns the full calculated fee
  3. _liquidate transfers the full fee amount from _mytSharesDeposited (aggregate pool)

File: v3-poc-b0505da/src/AlchemistV3.sol
Lines: 377-415 (excerpt)

Solidity
creditToYield = creditToYield > account.collateralBalance ? account.collateralBalance : creditToYield;
account.collateralBalance -= creditToYield;  // Depletes collateral

Attack Scenario

Setup:

  • Account has 1000 MYT earmarked debt
  • Account has only 10 MYT remaining collateral
  • repaymentFee = 5% (500 BPS)

Execution:

  1. Attacker calls liquidate(accountId)
  2. _forceRepay clears the 1000 MYT earmarked debt, consuming the 10 MYT collateral
  3. Account debt reaches 0, triggering _resolveRepaymentFee
  4. Calculated fee: 1000 * 5% = 50 MYT
  5. Account deduction: min(50, 0) = 0 MYT (collateral already depleted)
  6. Liquidator receives: 50 MYT from contract's pooled balance

Result: Protocol loses 50 MYT from pooled collateral, account contributed 0 MYT

Impact

  • Direct theft of pooled user funds (_mytSharesDeposited)
  • Accounting desynchronization between tracked collateral and actual MYT balance
  • Cascading insolvency as repeated liquidations drain the pool
  • Scalable attack via batchLiquidate across multiple accounts
  • No special privileges required - any address can call liquidate()

Link to Proof of Concept

https://gist.github.com/Joshua-Medvinsky/9e997ff1c82ae9267b8442a9696b064b

Proof of Concept

Proof of Concept

Step 1: Identify Vulnerable Account

Query accounts via getCDP(accountId) to find:

  • account.earmarked > 0 (has earmarked debt)
  • account.collateralBalance < (account.earmarked * repaymentFee / BPS) (insufficient collateral for fee)
  • Account is liquidatable (collateralization <= collateralizationLowerBound)

Step 2: Execute Liquidation

Call liquidate(accountId) from any address

Step 3: Observe Overdraft

If earmarked debt clears the position (account.debt == 0):

Account Side:

  • Collateral deducted: min(calculatedFee, account.collateralBalance) (capped)

Liquidator Side:

  • Fee received: calculatedFee (uncapped, from pooled MYT)

Shortfall:

stolen = calculatedFee - min(calculatedFee, account.collateralBalance)

This amount is extracted from _mytSharesDeposited (all users' collateral)

Step 4: Repeat Attack

Target additional vulnerable accounts via batchLiquidate() to systematically drain pooled collateral

Expected Results

Single liquidation example:

  • Earmarked debt cleared: 1000 MYT
  • Repayment fee (5%): 50 MYT
  • Account collateral available: 10 MYT
  • Account deduction: 10 MYT
  • Liquidator receives: 50 MYT
  • Stolen from pool: 40 MYT

Scaled attack (100 similar accounts):

  • Total stolen: 4,000 MYT from pooled collateral
  • Protocol becomes insolvent
  • Legitimate withdrawals fail

References

Affected Functions:

  • liquidate(uint256) - Entry point at AlchemistV3.sol:417
  • _liquidate(uint256) - Transfers full fee at lines 495-499
  • _resolveRepaymentFee(uint256,uint256) - Overdraft calculation at lines 515-533
  • _forceRepay(uint256,uint256) - Depletes collateral at lines 377-415
  • batchLiquidate(uint256[]) - Enables scaled exploitation

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

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 fee deduction is capped at the account's collateral balance, but the full uncapped fee is transferred from the pooled contract balance.

Impact

An attacker could steal pooled user funds, causing accounting desynchronization and potentially cascading insolvency as repeated liquidations drain the pool.

What the attacker needed

Liquidatable account with earmarked debt; collateral less than calculated fee; any address can call liquidate

How it was found

  1. Find a liquidatable account with earmarked debt and collateral less than the calculated fee.
  2. Call liquidate(accountId) from any address.
  3. The earmarked debt is cleared, consuming the account's collateral.
  4. The full fee is transferred to the liquidator from the pooled MYT balance, creating a shortfall.
  5. Repeat with batchLiquidate to drain more pooled collateral.

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.

When a borrower is liquidated, the protocol pays the liquidator a fee. The code takes this fee from the borrower's remaining collateral, but if the borrower doesn't have enough, it still pays the full fee from a shared pool of everyone's collateral. An attacker can trigger liquidations to take more from the pool than the borrower contributed.

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 failsafe_intern

View all

4 more disclosed reports, best first.

More from Alchemix V3

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.