Skip to content
Business logic Audit finding Beginner

Incorrect wethbalancebefore read causes broken loss detection in deallocation

In the strategy's deallocation function, the WETH balance snapshot is taken after the vault withdrawal, so the before and after readings are identical and the computed redeemed amount is always zero. This breaks loss detection: the loss event fires on every deallocation with a zero redeemed figure, and real shortfalls within the require tolerance go unnoticed.

Khay3 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

58648 sc low incorrect wethbalancebefore read causes broken loss detection in deallocation

Submitted on Nov 3rd 2025 at 19:35:04 UTC by @Khay3 for Audit Comp | Alchemix V3

Description

Summary

A balance snapshot is taken after withdrawal in MorphoYearnOGWETHStrategy::_deallocate, making wethRedeemed always zero and breaking loss detection.

Vulnerability details

MorphoYearnOGWETHStrategy::\_deallocate reads wethBalanceBefore after the withdrawal. Since both “before” and “after” balances are read post-withdrawal, their difference is always zero, masking any loss and causing misleading events.

MorphoYearnOGWETHStrategy::_deallocate():

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));  // Read AFTER
    uint256 wethBalanceAfter = TokenUtils.safeBalanceOf(address(weth), address(this));   // Same value
    uint256 wethRedeemed = wethBalanceAfter - wethBalanceBefore;  // Always 0
    if (wethRedeemed < amount) {
        emit StrategyDeallocationLoss("Strategy deallocation loss.", amount, wethRedeemed);
    }
    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;
}

In comparison with other strategies, they implemented this correct (Read balance before wtihdrawal)

Example scenario

Morpho vault experiences issues and return only 95TH when 100 ETH was requested. Strategy cannot deter the 5ETH loss(wethRedeemd shows 0 instead of 95). The loss event incorrectly shows StrategyDeallocationLoss("...", 100, 0) instead of StrategyDeallocationLoss("...", 100, 95). If the loss is within the require tolerance, it goes completely unnoticed

Impact

This lead to the system not being able to detect actual losses from vault withdrawals. The StrategyDeallocationLoss event will always fire, since 0 < amount is always true, even when there's no loss

Likelihood

This will occur on every deallocation but mitigated with the require statement

Solidity
require(TokenUtils.safeBalanceOf(address(weth), address(this)) >= amount, 
        "Strategy balance is less than the amount needed");

Recommendation

Read the WETH balance before the withdrawal, then withdraw, then read after, and compute the delta from those two readings.

Solidity
function _deallocate(uint256 amount) internal override returns (uint256) {
    // Read balance BEFORE withdrawal
    uint256 wethBalanceBefore = TokenUtils.safeBalanceOf(address(weth), address(this));
    
    // Perform withdrawal
    vault.withdraw(amount, address(this), address(this));
    
    //Read balance AFTER withdrawal
    uint256 wethBalanceAfter = TokenUtils.safeBalanceOf(address(weth), address(this));
    uint256 wethRedeemed = wethBalanceAfter - wethBalanceBefore;

Proof of Concept

paste in src/test/strategies/MorphoYearnOGWETHStrategy.t.sol and run with forge test --match-test test_strategy_deallocate_wrong_balance_calculation -vvv

Solidity
function test_strategy_deallocate_wrong_balance_calculation() public {
    // This test directly shows the bug by examining the code flow
    vm.startPrank(vault);
    uint256 amount = 0.01e18;  // Very small amount

    // Fund strategy with WETH and allocate
    deal(WETH, strategy, amount);
    bytes memory prevAllocation = abi.encode(0);
    IMYTStrategy(strategy).allocate(prevAllocation, amount, "", address(vault));
    
    // Deallocate a tiny bit less than current assets to avoid revert
    uint256 real = IMYTStrategy(strategy).realAssets();
    require(real > 1, "no assets after allocation");
    uint256 dealloc = real - 1;
    bytes memory prevAllocation2 = abi.encode(dealloc);
    IMYTStrategy(strategy).deallocate(prevAllocation2, dealloc, "", address(vault));
    
    // (Balance delta omitted here to avoid dependency import; event-based PoC below)
    
    vm.stopPrank();
    }

The original report as published on Immunefi, by Khay3. 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 labelled 'before' is read after the withdrawal call, so the before and after values are the same and the delta is always zero.

Impact

Real losses from vault withdrawals cannot be detected, and the loss event always fires with a zero redeemed amount; the final require statement limits the damage but does not fix the broken accounting.

What the attacker needed

Vault returns less than requested

The fix

The balance should be read before the withdrawal, then after, and the delta computed from those two readings.

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 money is pulled out of a vault, the code tries to check how much actually came back by comparing the balance before and after. Here both readings are taken after the money has already arrived, so the difference is always zero. That means the alarm that should flag a shortfall never shows the real numbers, and small losses can slip past the final safety check.

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 Khay3

View all

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