Missing _mytSharesDeposited Decrements in Token Transfers
The contract's tracked MYT share deposit total is not reduced when tokens leave during liquidations and force repayments, so the reported total value locked stays higher than the real balance. An attacker could exploit this inflated figure to distort collateralisation checks and deposit caps, potentially pushing the protocol toward insolvency.
- Disclosed after under an hour
56791 sc high missing mytsharesdeposited decrements in token transfers
Submitted on Oct 20th 2025 at 17:47:43 UTC by @teoslaf1 for Audit Comp | Alchemix V3
- Report ID: #56791
- Report Type: Smart Contract
- Report severity: High
- Target: https://github.com/alchemix-finance/v3-poc/blob/immunefi\\_audit/src/AlchemistV3.sol
- Impacts:
- Protocol insolvency
Description
Summary
The _mytSharesDeposited state variable is not decremented when MYT tokens are transferred out of the AlchemistV3 contract during liquidations and force repayments. This causes the Total Value Locked (TVL) to be artificially inflated, leading to incorrect collateralization calculations, deposit cap issues, and bad debt ratio miscalculations.
Vulnerability Details
Root Cause
_mytSharesDeposited tracks the total MYT shares deposited in the contract and is used to calculate TVL:
// Line 1244 in AlchemistV3.sol
function _getTotalUnderlyingValue() internal view returns (uint256 totalUnderlyingValue) {
uint256 yieldTokenTVLInUnderlying = convertYieldTokensToUnderlying(_mytSharesDeposited);
totalUnderlyingValue = yieldTokenTVLInUnderlying;
}
However, when tokens are transferred out during liquidations and force repayments, _mytSharesDeposited is not decremented, causing it to diverge from the actual token balance.
Missing Decrements
1. In _doLiquidation() (Lines 880 & 884)
// Line 880 - Transfer to transmuter
TokenUtils.safeTransfer(myt, transmuter, amountLiquidated - feeInYield);
// missing -> _mytSharesDeposited -= (amountLiquidated - feeInYield);
// Line 884 - Transfer fee to liquidator
if (feeInYield > 0 && account.collateralBalance >= feeInYield) {
TokenUtils.safeTransfer(myt, msg.sender, feeInYield);
// missing -> _mytSharesDeposited -= feeInYield;
}
2. In _forceRepay() (Lines 779 & 785)
// Line 779 - Protocol fee transfer
if (account.collateralBalance > protocolFeeTotal) {
account.collateralBalance -= protocolFeeTotal;
TokenUtils.safeTransfer(myt, protocolFeeReceiver, protocolFeeTotal);
// missing -> _mytSharesDeposited -= protocolFeeTotal;
}
// Line 785 - Transmuter transfer
if (creditToYield > 0) {
TokenUtils.safeTransfer(myt, address(transmuter), creditToYield);
// missing -> _mytSharesDeposited -= creditToYield;
}
Impact
Inflated TVL Calculations
getTotalUnderlyingValue()returns inflated values- Affects all collateralization ratio calculations throughout the protocol
- System appears healthier than reality
Recommended Mitigation
Add _mytSharesDeposited decrements after each token transfer:
Fix for _doLiquidation()
function _doLiquidation(uint256 accountId, uint256 collateralInUnderlying, uint256 repaidAmountInYield)
internal
returns (uint256 amountLiquidated, uint256 feeInYield, uint256 feeInUnderlying)
{
// ... existing code ...
// send liquidation amount - fee to transmuter
TokenUtils.safeTransfer(myt, transmuter, amountLiquidated - feeInYield);
+ _mytSharesDeposited -= (amountLiquidated - feeInYield);
// send base fee to liquidator if available
if (feeInYield > 0 && account.collateralBalance >= feeInYield) {
TokenUtils.safeTransfer(myt, msg.sender, feeInYield);
+ _mytSharesDeposited -= feeInYield;
}
// ... rest of function ...
}
Fix for _forceRepay()
function _forceRepay(uint256 accountId, uint256 credit) internal returns (uint256 creditToYield) {
// ... existing code ...
if (account.collateralBalance > protocolFeeTotal) {
account.collateralBalance -= protocolFeeTotal;
// Transfer the protocol fee to the protocol fee receiver
TokenUtils.safeTransfer(myt, protocolFeeReceiver, protocolFeeTotal);
+ _mytSharesDeposited -= protocolFeeTotal;
}
if (creditToYield > 0) {
// Transfer the repaid tokens from the account to the transmuter.
TokenUtils.safeTransfer(myt, address(transmuter), creditToYield);
+ _mytSharesDeposited -= creditToYield;
}
return creditToYield;
}
Proof of Concept
Add this to AlchemistV3.t.sol
function testPOC_MytSharesDeposited_Not_Decremented_On_Liquidate() external {
vm.startPrank(someWhale);
IMockYieldToken(mockStrategyYieldToken).mint(whaleSupply, someWhale);
vm.stopPrank();
uint256 depositAmt = 200_000e18;
// Create healthy position for global collateralization
vm.startPrank(yetAnotherExternalUser);
SafeERC20.safeApprove(address(vault), address(alchemist), depositAmt * 2);
alchemist.deposit(depositAmt, yetAnotherExternalUser, 0);
vm.stopPrank();
// Create position to be liquidated
vm.startPrank(address(0xbeef));
SafeERC20.safeApprove(address(vault), address(alchemist), depositAmt);
alchemist.deposit(depositAmt, address(0xbeef), 0);
uint256 tokenId = AlchemistNFTHelper.getFirstTokenId(address(0xbeef), address(alchemistNFT));
alchemist.mint(tokenId, alchemist.totalValue(tokenId) * FIXED_POINT_SCALAR / minimumCollateralization, address(0xbeef));
vm.stopPrank();
// Crash collateral value
uint256 initialVaultSupply = IERC20(address(mockStrategyYieldToken)).totalSupply();
IMockYieldToken(mockStrategyYieldToken).updateMockTokenSupply(initialVaultSupply);
uint256 modifiedVaultSupply = (initialVaultSupply * 590 / 10_000) + initialVaultSupply;
IMockYieldToken(mockStrategyYieldToken).updateMockTokenSupply(modifiedVaultSupply);
// State before liquidation
uint256 actualBalanceBefore = vault.balanceOf(address(alchemist));
uint256 transmuterBalanceBefore = vault.balanceOf(address(transmuterLogic));
// Liquidate
vm.prank(externalUser);
alchemist.liquidate(tokenId);
// State after liquidation
uint256 tvlAfter = alchemist.getTotalUnderlyingValue();
uint256 actualBalanceAfter = vault.balanceOf(address(alchemist));
uint256 tokensToTransmuter = vault.balanceOf(address(transmuterLogic)) - transmuterBalanceBefore;
uint256 tokensTransferredOut = actualBalanceBefore - actualBalanceAfter;
assertGt(tokensTransferredOut, 0, "Tokens transferred out");
assertGt(tokensToTransmuter, 0, "Tokens sent to transmuter");
assertGt(tvlAfter, actualBalanceAfter, "BUG: TVL inflated vs actual balance");
console.log("TVL:", tvlAfter);
console.log("Actual Balance:", actualBalanceAfter);
console.log("Inflation:", tvlAfter - actualBalanceAfter);
}
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 state variable tracking deposited MYT shares is not decremented after tokens are transferred out in liquidation and force-repay paths.
Impact
The inflated total value locked could distort collateralisation ratios and deposit caps, making the system appear healthier than reality and potentially leading to protocol insolvency.
What the attacker needed
A position eligible for liquidation; a position eligible for force repayment
The fix
The report recommends decrementing the tracked share total after each token transfer in the liquidation and force-repay functions.
How it was found
- Create a healthy position to keep global collateralisation high.
- Create a second position that will be liquidated.
- Crash the collateral value by changing the mock token supply.
- Liquidate the second position.
- Observe that the reported total value locked is greater than the actual token balance.
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 a running tally of how many tokens it holds, and uses that tally to decide how much the whole system is worth. When tokens are sent out during a liquidation, the tally is not reduced, so the system thinks it still has tokens it no longer holds. That wrong number can make the protocol look safer than it is and let bad debt build up.
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.