Skip to content
Business logic Audit finding Beginner

Incorrect balance snapshot in strategy deallocation causes false loss events and masks real shortfalls

The strategy's deallocation function samples the WETH balance both before and after the vault withdrawal, so the redeemed amount is always computed as zero. This causes a false loss event to be emitted on every deallocation and prevents accurate measurement of redeemed funds.

ihtishamsudo Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

56909 sc low incorrect balance snapshot in strategy deallocation causes false loss events and masks real shortfalls

Submitted on Oct 21st 2025 at 17:15:26 UTC by @ihtishamsudo for Audit Comp | Alchemix V3

Description

Brief/Intro

The deallocation logic in MorphoYearnOGWETHStrategy measures “before” and “after” balances after the withdrawal operation, causing the strategy to compute zero redeemed assets on every deallocation.

Vulnerability Details

Both wethBalanceBefore and wethBalanceAfter are sampled after vault.withdraw. Therefore, wethRedeemed is computed as 0 every time, regardless of what the vault actually returned.

Solidity
function _deallocate(uint256 amount) internal override returns (uint256) {
        vault.withdraw(amount, address(this), address(this)); //@audit incorrect order
        uint256 wethBalanceBefore = TokenUtils.safeBalanceOf(address(weth), address(this));
        uint256 wethBalanceAfter = TokenUtils.safeBalanceOf(address(weth), address(this));
        uint256 wethRedeemed = wethBalanceAfter - wethBalanceBefore;
        if (wethRedeemed < amount) {
            emit StrategyDeallocationLoss("Strategy deallocation loss.", amount, wethRedeemed);
        }
        require(wethRedeemed + wethBalanceBefore >= amount, "Strategy balance is less than the amount needed");
        require(TokenUtils.safeBalanceOf(address(weth), address(this)) >= amount, "Strategy balance is less than the amount needed");
        TokenUtils.safeApprove(address(weth), msg.sender, amount);
        return amount;
    }

Impact Details

StrategyDeallocationLoss is emitted on every deallocation with misleading data (looks like total loss: actualAmountSent=0) and actual redeemed funds are never measured correctly.

References

https://github.com/alchemix-finance/v3-poc/blob/b2e2aba046c36ff5e1db6f40f399e93cd2bdaad0/src/strategies/mainnet/MorphoYearnOGWETH.sol#L49

Proof of Concept

Proof of Concept

Add following in MorphoYearnOGWETHStrategy.t.sol and execute test with forge test --mt test_bug_emits_false_loss_event -vvv

Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import "../libraries/BaseStrategyTest.sol";
import "forge-std/Test.sol";
import {MorphoYearnOGWETHStrategy} from "../../strategies/mainnet/MorphoYearnOGWETH.sol";

// Minimal ERC20 mock for testing
import {ERC20} from "../../../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

contract ERC20Mock is ERC20 {
    constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) {}
    function mint(address to, uint256 amount) external {
        _mint(to, amount);
    }
}

// Minimal ERC4626-like mock implementing only what the strategy uses
contract ERC4626Mock {
    ERC20 public immutable assetToken;
    mapping(address => uint256) internal _shares;

    constructor(address asset_) {
        assetToken = ERC20(asset_);
    }

    function asset() external view returns (address) {
        return address(assetToken);
    }

    function deposit(uint256 assets, address receiver) external returns (uint256 shares) {
        // pull assets from msg.sender (strategy must have approved this contract)
        require(assetToken.transferFrom(msg.sender, address(this), assets), "transferFrom failed");
        shares = assets;
        _shares[receiver] += shares;
    }

    function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares) {
        // burn shares from owner and send assets to receiver
        shares = assets;
        require(_shares[owner] >= shares, "insufficient shares");
        _shares[owner] -= shares;
        require(assetToken.transfer(receiver, assets), "transfer failed");
    }

    function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assetsOut) {
        assetsOut = shares;
        require(_shares[owner] >= shares, "insufficient shares");
        _shares[owner] -= shares;
        require(assetToken.transfer(receiver, assetsOut), "transfer failed");
    }

    function convertToAssets(uint256 shares) external pure returns (uint256 assets) {
        return shares;
    }

    function convertToShares(uint256 assets) external pure returns (uint256 shares) {
        return assets;
    }

    function balanceOf(address account) external view returns (uint256) {
        return _shares[account];
    }

    function previewWithdraw(uint256 assets) external pure returns (uint256 shares) {
        return assets;
    }
}

contract MockMorphoYearnOGWETHStrategy is MorphoYearnOGWETHStrategy {
    constructor(address _myt, StrategyParams memory _params, address _vault, address _weth, address _permit2Address)
        MorphoYearnOGWETHStrategy(_myt, _params, _vault, _weth, _permit2Address)
    {}
}

contract MorphoYearnOGWETHStrategyTest is BaseStrategyTest {
    address public constant MORPHO_YEARN_OG_VAULT = 0xE89371eAaAC6D46d4C3ED23453241987916224FC;
    address public constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
    address public constant MAINNET_PERMIT2 = 0x000000000022d473030f1dF7Fa9381e04776c7c5;

    function getStrategyConfig() internal pure override returns (IMYTStrategy.StrategyParams memory) {
        return IMYTStrategy.StrategyParams({
            owner: address(1),
            name: "MorphoYearnOGETH",
            protocol: "MorphoYearnOGETH",
            riskClass: IMYTStrategy.RiskClass.LOW,
            cap: 10_000e18,
            globalCap: 1e18,
            estimatedYield: 100e18,
            additionalIncentives: false,
            slippageBPS: 1
        });
    }

    function getTestConfig() internal pure override returns (TestConfig memory) {
        return TestConfig({vaultAsset: WETH, vaultInitialDeposit: 1000e18, absoluteCap: 10_000e18, relativeCap: 1e18, decimals: 18});
    }

    function getForkBlockNumber() internal pure override returns (uint256) {
        return 23_298_447;
    }

    function getRpcUrl() internal view override returns (string memory) {
        return vm.envString("MAINNET_RPC_URL");
    }

    function createStrategy(address vault, IMYTStrategy.StrategyParams memory params) internal override returns (address) {
        return address(new MockMorphoYearnOGWETHStrategy(vault, params, MORPHO_YEARN_OG_VAULT, WETH, MAINNET_PERMIT2));
    }

    function test_strategy_deallocate_reverts_due_to_slippage(uint256 amountToAllocate, uint256 amountToDeallocate) public {
        amountToAllocate = bound(amountToAllocate, 1e18, testConfig.vaultInitialDeposit);
        amountToDeallocate = amountToAllocate;
        vm.startPrank(vault);
        deal(WETH, strategy, amountToAllocate);
        bytes memory prevAllocationAmount = abi.encode(0);
        IMYTStrategy(strategy).allocate(prevAllocationAmount, amountToAllocate, "", address(vault));
        uint256 initialRealAssets = IMYTStrategy(strategy).realAssets();
        require(initialRealAssets > 0, "Initial real assets is 0");
        bytes memory prevAllocationAmount2 = abi.encode(amountToAllocate);
        vm.expectRevert();
        IMYTStrategy(strategy).deallocate(prevAllocationAmount2, amountToDeallocate, "", address(vault));
        vm.stopPrank();
    }

    /*     

    function test_allocated_position_generated_yield() public {
            vm.startPrank(address(vault));
            uint256 amount = 100 ether;
            deal(WETH, address(mytStrategy), amount);
            bytes memory prevAllocationAmount = abi.encode(0);
            mytStrategy.allocate(prevAllocationAmount, amount, "", address(vault));
            uint256 initialRealAssets = mytStrategy.realAssets();
            emit MorphoYearnOGWETHStrategyTestLog("initialRealAssets", initialRealAssets);
            assertApproxEqAbs(initialRealAssets, amount, 1e18);
            vm.warp(block.timestamp + 180 days);
            uint256 realAssets = mytStrategy.realAssets();
            emit MorphoYearnOGWETHStrategyTestLog("realAssets", realAssets);
            assertGt(realAssets, initialRealAssets);
            vm.stopPrank();
        }
    */
}

contract MorphoYearnOGWETHStrategyBugDemoTest is Test {
    // mirror the event signature from MYTStrategy to assert on it
    event StrategyDeallocationLoss(string message, uint256 amountRequested, uint256 actualAmountSent);

    function test_bug_emits_false_loss_event() public {
        // Arrange: set up mock WETH, mock 4626 vault, and strategy
        address myt = address(0xBEEF);
        ERC20Mock weth = new ERC20Mock("WETH", "WETH");
        ERC4626Mock vault = new ERC4626Mock(address(weth));

        // Build minimal params
        IMYTStrategy.StrategyParams memory params = IMYTStrategy.StrategyParams({
            owner: address(this),
            name: "MorphoYearnOGETH",
            protocol: "MorphoYearnOGETH",
            riskClass: IMYTStrategy.RiskClass.LOW,
            cap: 10_000e18,
            globalCap: 1e18,
            estimatedYield: 100e18,
            additionalIncentives: false,
            slippageBPS: 1
        });

        MorphoYearnOGWETHStrategy strat = new MockMorphoYearnOGWETHStrategy(
            myt, params, address(vault), address(weth), address(0x01)
        );

        // Fund the strategy so it can deposit
        uint256 amount = 10 ether;
        weth.mint(address(strat), amount);

        // Act: allocate and then deallocate as the MYT (vault)
        // Expectation: due to the bug, deallocate emits a false loss with actualAmountSent == 0
        vm.startPrank(myt);
        IMYTStrategy(address(strat)).allocate(abi.encode(0), amount, "", myt);

        vm.expectEmit(false, false, false, true);
        emit StrategyDeallocationLoss("Strategy deallocation loss.", amount, 0);
        IMYTStrategy(address(strat)).deallocate(abi.encode(amount), amount, "", myt);
        vm.stopPrank();
    }
}
  • Test logs
Bash
forge test --mt test_bug_emits_false_loss_event -vvv
[⠒] Compiling...
No files changed, compilation skipped

Ran 1 test for src/test/strategies/MorphoYearnOGWETHStrategy.t.sol:MorphoYearnOGWETHStrategyBugDemoTest
[PASS] test_bug_emits_false_loss_event() (gas: 3303480)
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 4.85ms (2.86ms CPU time)

Ran 1 test suite in 16.82ms (4.85ms 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

The balance snapshot is taken after the withdrawal instead of before, so the redeemed amount is always zero.

Impact

The strategy emits a misleading loss event on every deallocation and never measures redeemed funds correctly, which could mask real shortfalls.

What the attacker needed

Strategy has funds allocated; deallocation is called

The fix

The balance before the withdrawal should be recorded before calling vault.withdraw, so the redeemed amount is calculated correctly.

How it was found

  1. Deploy the strategy with a mock vault and mock WETH.
  2. Fund the strategy with WETH and call allocate.
  3. Call deallocate and observe the false loss event with actualAmountSent equal to zero.

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 the strategy takes money out of a vault, it tries to check how much actually came back by comparing the balance before and after. But it records both balances after the withdrawal has already happened, so the difference is always zero. This makes the strategy think it lost money every time, even when it did not.

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.