Skip to content
Business logic Audit finding Intermediate

Protocol wrongly withdraws before checking balance of withdraw

The _deallocate function in the MorphoYearnOGWETHStrategy contract measures the WETH balance before and after the vault withdrawal, but both measurements are taken after the withdrawal has already occurred. As a result, the calculated redeemed amount is always zero, causing a loss event to be emitted on every deallocation even when no loss happened.

securehash1 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

57599 sc low protocol wrongly withdraws before checking balance of withdraw

Submitted on Oct 27th 2025 at 12:17:17 UTC by @securehash1 for Audit Comp | Alchemix V3

Description

Brief/Intro

The _deallocate function in the MorphoYearnOGWETHStrategy contract contains a logical flaw that results in incorrect accounting during the deallocation process. It wrongly makes withdrawal before checking balanceBefore.

Vulnerability Details

When deallocating funds, the function attempts to measure the amount of WETH received from the Yearn vault by comparing the WETH balance before and after the withdrawal. However, due to a logical error, both balance accounting (wethBalanceBefore and wethBalanceAfter) are taken after the vault.withdraw() call has completed.

Solidity
function _deallocate(uint256 amount) internal override returns (uint256) {
    vault.withdraw(amount, address(this), address(this));
    // BUG: Both balance checks happen AFTER the withdrawal.
    uint256 wethBalanceBefore = TokenUtils.safeBalanceOf(address(weth), address(this));
    uint256 wethBalanceAfter = TokenUtils.safeBalanceOf(address(weth), address(this));
    // `wethRedeemed` will always be 0 as `wethBalanceAfter` equals `wethBalanceBefore`.
    uint256 wethRedeemed = wethBalanceAfter - wethBalanceBefore;
    if (wethRedeemed < amount) {
        emit StrategyDeallocationLoss("Strategy deallocation loss.", amount, wethRedeemed);
    }
    // This check becomes `require(wethBalanceAfterWithdrawal >= amount)`
    require(wethRedeemed + wethBalanceBefore >= amount, "Strategy balance is less than the amount needed");

}

As a result, wethRedeemed is always calculated as 0. This incorrectly triggers the StrategyDeallocationLoss event on every deallocation (since amount will be > 0), even when no loss has occurred.

Impact Details

Contract would fail to deliver promised return

References

https://github.com/alchemix-finance/v3-poc/blob/immunefi\\_audit/src/strategies/mainnet/MorphoYearnOGWETH.sol?utm\\_source=immunefi

Proof of Concept

Proof of Concept

Copy and paste to MorphoYearnOGWETHStrategy.t.sol

Solidity
    function test_strategy_deallocate_succeeds(uint256 amountToAllocate) public {
        amountToAllocate = bound(amountToAllocate, 1e18, testConfig.vaultInitialDeposit);
        uint256 amountToDeallocate = IMYTStrategy(strategy).previewAdjustedWithdraw(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);
        uint256 vaultBalanceBefore = IERC20(WETH).balanceOf(vault);
        IMYTStrategy(strategy).deallocate(prevAllocationAmount2, amountToDeallocate, "", vault);
        uint256 vaultBalanceAfter = IERC20(WETH).balanceOf(vault);
        assertApproxEqAbs(vaultBalanceAfter - vaultBalanceBefore, amountToDeallocate, 1e18);
        vm.stopPrank();
    }

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

}

The original report as published on Immunefi, by securehash1. 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 balance snapshot for 'before' is taken after the withdrawal call instead of before it, so the difference is always zero.

Impact

The contract would fail to deliver promised returns by incorrectly emitting a loss event on every deallocation, though no actual value is lost.

What the attacker needed

None

The fix

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

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.

This is a smart contract bug where the code tries to check how much money came back from a withdrawal, but it checks the account balance after the money has already arrived, so it sees no change. That makes the contract think it lost money every time, even though 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 securehash1

View all

1 more disclosed report, 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.