Skip to content
Business logic Audit finding Intermediate

Incorrect collateral and fee Check in _doLiquidation Allows Liquidator to loose fee.

In the liquidation routine, the contract deducts the liquidation amount (which already includes the liquidator fee) from the user's collateral, then checks whether the remaining collateral still covers the fee before paying it out. When the remaining balance is smaller than the fee, the fee is never transferred to the liquidator even though it was already taken from the user.

Bizarro Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

58061 sc high incorrect collateral and fee check in doliquidation allows liquidator to loose fee

Submitted on Oct 30th 2025 at 11:40:35 UTC by @Bizarro for Audit Comp | Alchemix V3

Description

Brief/Intro

In _doLiquidation function where the contract checks that collateralBalance >= fee before transferring the fee to the liquidator(msg.sender). This is incorrect because, in calculateLiquidation, the fee is already included in the liquidationAmount returned and is removed from the user's collateral.

Vulnerability Details

The function double-counts the fee in the collateral balance check. The fee is included in the liquidationAmount(already removed from the user's balance), but the contract still checks if the remaining balance is sufficient to pay the fee again.

Path:

  1. User position: collateralBalance = 109, liquidationAmount = 100, fee = 10
  2. _doLiquidation removes 100 from collateralBalance, leaving 9.
  3. The fee check collateralBalance >= fee fails (9<10).
  4. Fee transfer to the liquidator does not occur, even though tokens are already removed from the user.
Solidity
    function _doLiquidation(uint256 accountId, uint256 collateralInUnderlying, uint256 repaidAmountInYield)
        internal
        returns (uint256 amountLiquidated, uint256 feeInYield, uint256 feeInUnderlying)
    {
        Account storage account = _accounts[accountId];

        (uint256 liquidationAmount, uint256 debtToBurn, uint256 baseFee, uint256 outsourcedFee) = calculateLiquidation(
            collateralInUnderlying,
            account.debt,
            minimumCollateralization,
            normalizeUnderlyingTokensToDebt(_getTotalUnderlyingValue()) * FIXED_POINT_SCALAR / totalDebt,
            globalMinimumCollateralization,
            liquidatorFee
        );

        amountLiquidated = convertDebtTokensToYield(liquidationAmount);
        feeInYield = convertDebtTokensToYield(baseFee);

        // update user balance and debt
@1>         account.collateralBalance = account.collateralBalance > amountLiquidated ? account.collateralBalance - amountLiquidated : 0;
        _subDebt(accountId, debtToBurn);

        // send liquidation amount - fee to transmuter
        TokenUtils.safeTransfer(myt, transmuter, amountLiquidated - feeInYield);

        // send base fee to liquidator if available
@2>        if (feeInYield > 0 && account.collateralBalance >= feeInYield) {
            TokenUtils.safeTransfer(myt, msg.sender, feeInYield);
        }

        // Handle outsourced fee from vault
        if (outsourcedFee > 0) {
            uint256 vaultBalance = IFeeVault(alchemistFeeVault).totalDeposits();
            if (vaultBalance > 0) {
                uint256 feeBonus = normalizeDebtTokensToUnderlying(outsourcedFee);
                feeInUnderlying = vaultBalance > feeBonus ? feeBonus : vaultBalance;
                IFeeVault(alchemistFeeVault).withdraw(msg.sender, feeInUnderlying);
            }
        }

        emit Liquidated(accountId, msg.sender, amountLiquidated + repaidAmountInYield, feeInYield, feeInUnderlying);
        return (amountLiquidated + repaidAmountInYield, feeInYield, feeInUnderlying);
    }

    function calculateLiquidation(
        uint256 collateral,
        uint256 debt,
        uint256 targetCollateralization,
        uint256 alchemistCurrentCollateralization,
        uint256 alchemistMinimumCollateralization,
        uint256 feeBps
    ) public pure returns (uint256 grossCollateralToSeize, uint256 debtToBurn, uint256 fee, uint256 outsourcedFee) {


        ---


        // gross collateral seize = net + fee
@>3        grossCollateralToSeize = debtToBurn + fee;
    }
  • @3 = calculateLiquidation is returning (debtToBurn + fee, , fee,);
  • @1 = collateral is reduced by amountLiquidated (debtToBurn + fee converted to yield token)
  • @2 = after removing the fee from the collateral, collateralBalance >= feeInYield is required to transfer fee to the liquidator

Impact Details

If users' collateralBalance is just above the liquidationAmount then removing liquidationAmount leaves only 9 tokens, the subsequent check (collateralBalance >= fee) fails (9 < 10), so the fee transfer to the liquidator does not occur and the funds are stuck in the protocol, even though the fee was already deducted. This means:

  • The fee is reduced from the user's collateral but is never transferred to the liquidator.
  • Liquidator funds are stuck in the contract.

References

https://github.com/alchemix-finance/v3-poc/blob/a192ab313c81ba3ab621d9ca1ee000110fbdd1e9/src/AlchemistV3.sol#L1244

https://github.com/alchemix-finance/v3-poc/blob/a192ab313c81ba3ab621d9ca1ee000110fbdd1e9/src/AlchemistV3.sol#L852

Proof of Concept

Proof of Concept

Paste this test in test/AlchemistV3.t.sol and run forge test --mt testLiquidate_no_fee -vvv

Solidity
function testLiquidate_no_fee() external {
        vm.startPrank(alchemist.admin());
        alchemist.setLiquidatorFee(9500);
        vm.stopPrank();

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

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

        vm.startPrank(address(0xbeef));
        SafeERC20.safeApprove(address(vault), address(alchemist), depositAmount + 100e18);
        alchemist.deposit(depositAmount, address(0xbeef), 0);
        // a single position nft would have been minted to 0xbeef
        uint256 tokenIdFor0xBeef = AlchemistNFTHelper.getFirstTokenId(address(0xbeef), address(alchemistNFT));
        alchemist.mint(tokenIdFor0xBeef, alchemist.totalValue(tokenIdFor0xBeef) * FIXED_POINT_SCALAR / alchemist.minimumCollateralization(), address(0xbeef));
        vm.stopPrank();

        uint256 transmuterPreviousBalance = IERC20(address(vault)).balanceOf(address(transmuterLogic));

        uint256 initialVaultSupply = IERC20(address(mockStrategyYieldToken)).totalSupply();
        IMockYieldToken(mockStrategyYieldToken).updateMockTokenSupply(initialVaultSupply);
        // increasing yeild token suppy by 900 bps or 9%  while keeping the unederlying supply unchanged
        uint256 modifiedVaultSupply = (initialVaultSupply * 900 / 10_000) + initialVaultSupply;
        IMockYieldToken(mockStrategyYieldToken).updateMockTokenSupply(modifiedVaultSupply);

        uint256 liquidatorBalanceBefore =  IERC20(address(vault)).balanceOf(address(externalUser));
        vm.startPrank(externalUser);
        (uint256 assets, uint256 feeInYield, uint256 feeInUnderlying) = alchemist.liquidate(tokenIdFor0xBeef);
        vm.stopPrank(); 
        uint256 liquidatorBalanceAfter = IERC20(address(vault)).balanceOf(address(externalUser));

        assertEq(liquidatorBalanceAfter - liquidatorBalanceBefore, 0);
    }

The test will pass showing that the liquidator will not receive any fee.

The original report as published on Immunefi, by Bizarro. 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 code double-counts the fee: it is already included in the seized amount removed from the user's collateral, yet a further check requires the remaining collateral to cover the fee again.

Impact

The liquidator fee is deducted from the user's collateral but never paid out, so those funds remain stuck in the contract and liquidators may be discouraged from liquidating.

What the attacker needed

A liquidatable position; collateral only slightly above liquidation amount; a liquidator calls liquidate

The fix

The fee should be paid from the amount already seized rather than re-checked against the remaining collateral balance.

How it was found

  1. Set a high liquidator fee and create a position whose collateral is only slightly above the liquidation amount.
  2. Increase the yield token supply so the position becomes liquidatable.
  3. Call liquidate on the position as an external liquidator.
  4. Observe that the liquidator's balance does not increase, so no fee was paid.

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 position is liquidated, the protocol takes some of the user's collateral and is meant to give part of it to the person who triggered the liquidation as a reward. Here the reward is subtracted from the user first, but a second check looks at what is left and refuses to pay the reward if that leftover is too small. So the reward stays stuck in the contract instead of reaching the liquidator.

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 Bizarro

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.