Skip to content
Business logic Audit finding Beginner

Incorrect Balance Measurement in _deallocate function of MorphoYearnOGWETHStrategy

The _deallocate function in MorphoYearnOGWETHStrategy reads the WETH balance twice after withdrawing, so the measured redeemed amount is always zero. This causes a loss event to be emitted on every deallocation and can allow silent under-deallocation if the post-withdrawal balance is sufficient.

Razkky Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

57665 sc low incorrect balance measurement in deallocate function of morphoyearnogwethstrategy

Submitted on Oct 28th 2025 at 00:16:43 UTC by @Razkky for Audit Comp | Alchemix V3

Description

Summary

A critical bug exists in the _deallocate function of the MorphoYearnOGWETHStrategy contract. The function incorrectly measures the WETH before and after balance after making withdrawal, resulting in wethRedeemed always being zero since the wethBalanceBefore and wethBalanceAfter are thesame. This causes the StrategyDeallocationLoss event to be emitted every time, regardless of actual loss, and breaks the intended event-based monitoring for deallocation shortfall.

Relevant code

Solidity
function _deallocate(uint256 amount) internal override returns (uint256) {
    vault.withdraw(amount, address(this), address(this));
    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;
}

Issue Explanation

  • The MorphoYearnOGWETHStrategy::_deallocate function calls vault.withdraw and then reads both wethBalanceBefore and wethBalanceAfter, so both reflect the post-withdrawal balance.
  • As a result, wethRedeemed is always zero (wethBalanceAfter - wethBalanceBefore).
  • The event StrategyDeallocationLoss is emitted every time, with wethRedeemed as zero, even if the withdrawal was successful and no loss occurred.
  • The require statement is logically correct, but because wethBalanceBefore is measured after withdrawal, it does not serve its intended purpose in this context
  • If the vault returns less than the requested amount, but the post-withdrawal balance is high enough (e.g., due to a prior deposit or unrelated transfer), the function will not revert, and the strategy will silently deallocate less than intended.

Impact

  • False Event Emission: The StrategyDeallocationLoss event is always emitted, making it impossible to distinguish real losses from normal operations.
  • Silent Under-Deallocation: The function may not revert even if less than the requested amount is actually withdrawn, as long as the post-withdrawal balance is sufficient. This can lead to accounting errors and potential loss of funds for users relying on accurate deallocation.
  • Monitoring and Alerting Failure: Automated systems or users monitoring for real deallocation losses will receive false positives, reducing trust in the event system.

Likelihood

High.

This bug will occur every time _deallocate on MorphoYearnOGWETHStrategy is called, regardless of the actual outcome of the withdrawal. The event will always be emitted, and the function may silently under-deallocate if the post-withdrawal balance is sufficient. This makes the issue highly likely to impact all users and monitoring systems relying on the event or on correct deallocation behavior.

Proof of Concept

Proof of Concept

A test that allocates and then deallocates the same amount will always emit the StrategyDeallocationLoss event with the wethRedeemed as 0, even when no loss occurs. This demonstrates the bug:

The below test case should be aded to MorphoYearnOGWETHStrategyTest Run the command to execute the test after setting up your env variable forge test --mt test_buggy_deallocate_always_emits_loss_event

Solidity
    function test_buggy_deallocate_always_emits_loss_event(uint256 amountToAllocate) public {
        amountToAllocate = bound(amountToAllocate, 1e18, testConfig.vaultInitialDeposit);
        uint256 amountToDeallocate = amountToAllocate - 0.5e18; // Deallocate slightly less to avoid revert
        vm.startPrank(vault);
        deal(WETH, strategy, amountToAllocate);
        bytes memory prevAllocationAmount = abi.encode(0);
        IMYTStrategy(strategy).allocate(prevAllocationAmount, amountToAllocate, "", address(vault));
        // Allocate full amount
        uint256 initialRealAssets = IMYTStrategy(strategy).realAssets();
        require(initialRealAssets > 0, "Initial real assets is 0");
        bytes memory prevAllocationAmount2 = abi.encode(amountToAllocate);
        // The bug: event is always emitted with wethRedeemed as 0 , despite wethRedeemed should equal actual redeemed amount
        vm.expectEmit(); // Expect event emission (should not happen in correct logic)
        emit MYTStrategy.StrategyDeallocationLoss("Strategy deallocation loss.", amountToDeallocate, 0); // Always emitted due to bug
        IMYTStrategy(strategy).deallocate(prevAllocationAmount2, amountToDeallocate, "", address(vault)); // Triggers buggy event
        vm.stopPrank();
    }

The original report as published on Immunefi, by Razkky. 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 before withdrawal is read after the withdrawal call, so the before and after values are identical and the redeemed amount is always zero.

Impact

The loss event is always emitted, making real losses indistinguishable from normal operation, and the function may silently deallocate less than requested if the post-withdrawal balance is high enough.

What the attacker needed

Strategy has allocated funds; deallocate is called

The fix

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

How it was found

  1. Allocate a chosen amount to the strategy.
  2. Deallocate slightly less than the allocated amount.
  3. Observe that the StrategyDeallocationLoss event is emitted with a redeemed amount of 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.

This contract is supposed to withdraw a certain amount of a token and check whether it actually received that much. But it checks the balance only after the withdrawal, so the 'before' and 'after' numbers are the same. That makes the contract think it always received zero, so it raises a false alarm every time and may not notice when it really receives too little.

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 Razkky

View all

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