Skip to content
Business logic Audit finding Intermediate

Protocol could atleast be taking a part of the protocol fee

In the `_forceRepay` function, when an account's remaining collateral is not greater than the total protocol fee, the fee is skipped entirely rather than partially collected. This means the protocol forgoes fee revenue it could otherwise have taken from the account's remaining collateral.

PotEater Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

57511 sc medium protocol could atleast be taking a part of the protocol fee

Submitted on Oct 26th 2025 at 20:43:31 UTC by @PotEater for Audit Comp | Alchemix V3

Description

Brief/Intro

The function _forceRepay is designed in a way where if the collateralBalance is smaller than the protocolFeeTotal, the account doesn't pay for the fee. This design makes the protocol lose on potential fees. The code could be changed in a way that if the account doesn't have enough, the code will attempt to decrease the fee to the account collateral, so at least a part of it is paid, making the most out of it.

Vulnerability Details

If the account doesn't have enough to pay for the fee, the fee is not deducted from account's collateral.

This behavior could be changed so the fee is then decreased at least to the colalteral balance so at least a part of the fee is taken.

Code snippet:

Solidity
        if (account.collateralBalance > protocolFeeTotal) {
            account.collateralBalance -= protocolFeeTotal;
            // Transfer the protocol fee to the protocol fee receiver
            TokenUtils.safeTransfer(myt, protocolFeeReceiver, protocolFeeTotal);
        }

This code could be changed into clamping the fee if its larger so at least minimum is taken. This could be the change:

Solidity
        if (account.collateralBalance > protocolFeeTotal) {
            account.collateralBalance -= protocolFeeTotal;
            // Transfer the protocol fee to the protocol fee receiver
            TokenUtils.safeTransfer(myt, protocolFeeReceiver, protocolFeeTotal);
        } else {
            protocolFeeTotal = account.collateralBalance;
            account.collateralBalance -= protocolFeeTotal;
            TokenUtils.safeTransfer(myt, protocolFeeReceiver, protocolFeeTotal);
        }

Impact Details

The impact is that the protocol is losing on a potential profits that could be made if the account still has some collateral.

The protocol could take at least a part of the fee, if not the full amount.

References

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

Proof of Concept

Proof of Concept

Add this function in the AlchemistV3.t.sol test file:

This PoC demonstrates how the function doesn't deduct any fee when the account doesn't have enough to cover the fee.

Meaning it doesn't take at least a part of it.

Solidity
        function test_legendary_poc() external {
        vm.startPrank(someWhale);
        IMockYieldToken(mockStrategyYieldToken).mint(whaleSupply, someWhale);
        vm.stopPrank();
        // just ensureing global alchemist collateralization stays above the minimum required for regular
        // no need to mint anything
        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 / minimumCollateralization, address(0xbeef));

        vm.stopPrank();
        // modify yield token price via modifying underlying token supply
        (, uint256 prevDebt,) = alchemist.getCDP(tokenIdFor0xBeef);
        // ensure initial debt is correct
        vm.assertApproxEqAbs(prevDebt, 180_000_000_000_000_000_018_000, minimumDepositOrWithdrawalLoss);
        // create a redemption to start earmarking debt
        vm.startPrank(address(0xdad));
        SafeERC20.safeApprove(address(alToken), address(transmuterLogic), 50e18);
        transmuterLogic.createRedemption(50e18);
        vm.stopPrank();
        uint256 initialVaultSupply = IERC20(address(mockStrategyYieldToken)).totalSupply();
        IMockYieldToken(mockStrategyYieldToken).updateMockTokenSupply(initialVaultSupply);
        // increasing yeild token suppy by 1200 bps or 12% while keeping the unederlying supply unchanged
        uint256 modifiedVaultSupply = (initialVaultSupply * 1200 / 10_000) + initialVaultSupply;
        IMockYieldToken(mockStrategyYieldToken).updateMockTokenSupply(modifiedVaultSupply);
        vm.roll(block.number + 5_256_000);
        // let another user liquidate the previous user position
        vm.startPrank(externalUser);
        alchemist.liquidate(tokenIdFor0xBeef);
    }

To exactly demonstrate the issue I slightly edited the implementation:

Solidity
event NoFeeTaken();

    function _forceRepay(uint256 accountId, uint256 amount) internal returns (uint256) {
        if (amount == 0) {
            return 0;
        }
        _checkForValidAccountId(accountId);
        Account storage account = _accounts[accountId];

        // Query transmuter and earmark global debt
        _earmark();

        // Sync current user debt before deciding how much is available to be repaid
        _sync(accountId);

        uint256 debt;

        // Burning yieldTokens will pay off all types of debt
        _checkState((debt = account.debt) > 0);

        uint256 credit = amount > debt ? debt : amount;
        uint256 creditToYield = convertDebtTokensToYield(credit);
        _subDebt(accountId, credit);

        // Repay debt from earmarked amount of debt first
        uint256 earmarkToRemove = credit > account.earmarked ? account.earmarked : credit;
        account.earmarked -= earmarkToRemove;

        creditToYield = creditToYield > account.collateralBalance ? account.collateralBalance : creditToYield;
        account.collateralBalance -= creditToYield;

        uint256 protocolFeeTotal = creditToYield * protocolFee / BPS;

        emit ForceRepay(accountId, amount, creditToYield, protocolFeeTotal);
 
        protocolFeeTotal = 199943999999999999999992;
        protocolFeeTotal = 200000000000000000000000;

        if (account.collateralBalance > protocolFeeTotal) {
            account.collateralBalance -= protocolFeeTotal;
            
            // Transfer the protocol fee to the protocol fee receiver
            TokenUtils.safeTransfer(myt, protocolFeeReceiver, protocolFeeTotal);
        } else {
            emit NoFeeTaken();
        }

        if (creditToYield > 0) {
            // Transfer the repaid tokens from the account to the transmuter.
            TokenUtils.safeTransfer(myt, address(transmuter), creditToYield);
        }
        return creditToYield;
    }

Result:

Solidity
 │   │   │   │   └─ ← [Return] 18
    │   │   │   │   └─ ← [Return] 892857142857142857000000 [8.928e23]
    │   │   │   └─ ← [Return] 201600000000000000052415 [2.016e23]
    │   │   ├─ emit ForceRepay(accountId: 2, amount: 50000000000000000000 [5e19], creditToYield: 56000000000000000008 [5.6e19], protocolFeeTotal: 0)
    │   │   ├─ emit NoFeeTaken()
    │   │   ├─ [26990] MockMYTVault::transfer(Transmuter: [0x2387b3383E89c164781d173B7Aa14d9c46eD2642], 56000000000000000008 [5.6e19])
    │   │   │   ├─ emit Transfer(from: TransparentUpgradeableProxy: [0x48c33395391C097df9c9aA887a40f1b47948D393], to: Transmuter: [0x2387b3383E89c164781d173B7Aa14d9c46eD2642], value: 56000000000000000008 [5.6e19])

Result shows that no fee was taken, not even a part of it.

The original report as published on Immunefi, by PotEater. 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

Likely the fee deduction is guarded by a strict greater-than check with no fallback branch, so the fee is silently skipped whenever collateral does not exceed the fee.

Impact

The protocol loses potential fee revenue, since at least part of the fee could have been collected from the remaining collateral.

What the attacker needed

A liquidatable position; yield token price shift

The fix

The fee should be clamped to the available collateral so that a partial fee is still transferred when the balance is insufficient.

How it was found

  1. Set up an account with a position and debt, then trigger a redemption to earmark debt.
  2. Increase the yield token supply to shift the price and make the position liquidatable.
  3. Advance the block number and have another user liquidate the position.
  4. Observe that the protocol fee is not deducted because collateral is below the 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 loan is repaid, the protocol normally takes a small fee out of the borrower's leftover collateral. Here, if that leftover collateral is smaller than the fee, the code simply skips taking any fee at all instead of taking whatever is left. The result is lost income for the protocol, not a way for an attacker to steal funds.

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 PotEater

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.