Skip to content
Business logic Audit finding Beginner

Wrong order of balance checks in morphoyearnogwethstrategy

The _deallocate function records the 'before' balance after the withdrawal, so the redeemed amount is always zero and a false loss event is emitted on every withdrawal. This floods monitoring systems with false positives, making real losses indistinguishable.

Pro_King Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

57057 sc low wrong order of balance checks in morphoyearnogwethstrategy

Submitted on Oct 23rd 2025 at 05:55:54 UTC by @Pro_King for Audit Comp | Alchemix V3

Description

Brief/Intro

The MorphoYearnOGWETHStrategy contract contains a logic error in the _deallocate function where before and after balance checks are performed after withdrawal, causing every withdrawal to falsely report losses and incorrect financial reporting in production.

Vulnerability Details

The vulnerability exists in the _deallocate function of the MorphoYearnOGWETHStrategy contract, where the balance checks are performed in the incorrect order:

Solidity
function _deallocate(uint256 amount) internal override returns (uint256) {
    vault.withdraw(amount, address(this), address(this));  // Withdrawal happens FIRST
--->    uint256 wethBalanceBefore = TokenUtils.safeBalanceOf(address(weth), address(this));  // "Before" balance recorded AFTER withdrawal
--->    uint256 wethBalanceAfter = TokenUtils.safeBalanceOf(address(weth), address(this));   // "After" balance recorded AFTER withdrawal
    uint256 wethRedeemed = wethBalanceAfter - wethBalanceBefore;  // Always equals 0
    if (wethRedeemed < amount) {  // Always true (0 < amount)
        emit StrategyDeallocationLoss("Strategy deallocation loss.", amount, wethRedeemed);  // Always emitted
    }
    // ... rest of function
}

The issue is that the "before" balance is recorded AFTER the withdrawal has already occurred, making both balance checks identical. This results in wethRedeemed always being 0, which is always less than the requested amount, causing the function to always emit a false loss event.

The correct implementation should record the "before" balance first, then perform the withdrawal, and finally record the "after" balance:

Impact Details

This vulnerability has several impacts:

  1. Alert System Failure: Every withdrawal triggers a false loss event, flooding monitoring systems with false positives. This renders loss detection systems useless, as real losses become indistinguishable from normal operations.
  2. Undetected Theft: If a real loss occurs, it will be buried among numerous false alerts, allowing attackers to steal funds without triggering unique alerts.
  3. Risk Management Breakdown: The strategy appears to be constantly losing money, making accurate risk assessment impossible. This could lead to incorrect allocation decisions, premature strategy replacement, or failure to replace a genuinely underperforming strategy.
  4. Financial Misreporting: The false loss events could lead to incorrect financial reporting, potentially affecting user confidence and protocol valuation. The system would report losses of 100% on every withdrawal (showing 0 WETH received for X WETH requested).

References

Proof of Concept

Proof of Concept

Place this below test at v3-poc/src/test/strategies/MorphoYearnOGWETHStrategy.t.sol file and run this command forge test --mt "test_bug_false_loss_event_always_emitted" -vv

Solidity
function test_bug_false_loss_event_always_emitted() public {
        uint256 amountToAllocate = 10e18; 
        uint256 amountToDeallocate = 5e18; 
        
        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");
        
        vm.expectEmit(true, true, true, true);
        emit MYTStrategy.StrategyDeallocationLoss("Strategy deallocation loss.", amountToDeallocate, 0);
        
        bytes memory prevAllocationAmount2 = abi.encode(amountToAllocate);
        IMYTStrategy(strategy).deallocate(prevAllocationAmount2, amountToDeallocate, "", address(vault));

        vm.stopPrank();
    }

Output of test:

JavaScript
Ran 1 test for src/test/strategies/MorphoYearnOGWETHStrategy.t.sol:MorphoYearnOGWETHStrategyTest
[PASS] test_bug_false_loss_event_always_emitted() (gas: 1172420)
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 39.07s (2.37s CPU time)

The original report as published on Immunefi, by Pro_King. 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 'before' balance is recorded after the withdrawal has already occurred, so both balance checks are identical and the calculated redeemed amount is always zero.

Impact

Every withdrawal triggers a false loss event, which could flood monitoring systems and make real losses indistinguishable, potentially allowing theft to go unnoticed.

What the attacker needed

None

The fix

The 'before' balance should be recorded before the withdrawal, and the 'after' balance after the withdrawal.

How it was found

  1. Deploy the strategy and allocate funds.
  2. Call deallocate with a specified amount.
  3. Observe that a StrategyDeallocationLoss event is emitted with zero redeemed amount.

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 function is supposed to check how much money was received after a withdrawal. It mistakenly measures the balance after the withdrawal for both the 'before' and 'after' values, so the difference is always zero. This makes the contract think it lost money every time, which could hide real theft.

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 Pro_King

View all

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