Incorrect emit due to wrong ordering of wethbalancebefore calculation
In the strategy's deallocation function, the WETH balance before withdrawal is read after the withdrawal call, so the redeemed amount always computes to zero. This causes a false loss event to be emitted even when no loss occurred.
- Disclosed after under an hour
58322 sc low incorrect emit due to wrong ordering of wethbalancebefore calculation
Submitted on Nov 1st 2025 at 09:08:33 UTC by @SOPROBRO for Audit Comp | Alchemix V3
- Report ID: #58322
- Report Type: Smart Contract
- Report severity: Low
- Target: https://github.com/alchemix-finance/v3-poc/blob/immunefi\\_audit/src/strategies/mainnet/MorphoYearnOGWETH.sol
- Impacts:
- Contract fails to deliver promised returns, but doesn't lose value
Description
Brief/Intro
In MorphoYearnOGWETH::_deallocate, the function incorrectly calculates wethBalanceBefore after performing the vault.withdraw call. This causes wethRedeemed to always evaluate to 0, resulting in an incorrect emission of a StrategyDeallocationLoss event even when there is no actual loss.
Vulnerability Details
vault.withdraw(amount, address(this), address(this));
// @audit `wethBalanceBefore` is calculated after withdrawal
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);
}
The issue is that wethBalanceBefore should represent the contract’s WETH balance before the withdrawal is executed.
However, since it is calculated after the vault.withdraw call, both wethBalanceBefore and wethBalanceAfter are the same, leading to:
wethRedeemed = wethBalanceAfter - wethBalanceBefore = 0
This triggers a false StrategyDeallocationLoss event regardless of whether the strategy incurred a real loss.
Impact Details
The StrategyDeallocationLoss event will always be emitted, even when there are no losses, which may result in false alerts
References
(Code Location) https://github.com/alchemix-finance/v3-poc/blob/a192ab313c81ba3ab621d9ca1ee000110fbdd1e9/src/strategies/mainnet/MorphoYearnOGWETH.sol#L50-L56
Proof of Concept
Proof Of Concept
Add the following test to MorphoYearnOGWETHStrategy.t.sol and run in the console forge test --mt test_strat_always_emits_strat_loss -vv, and see that the following event will be emitted emit StrategyDeallocationLoss("Strategy deallocation loss.", 5e18, 0);
event StrategyDeallocationLoss(string message, uint256 amountRequested, uint256 actualAmountSent);
function test_strat_always_emits_strat_loss() public {
uint256 amountToAllocate = 10e18;
uint256 amountToDeallocate = amountToAllocate / 2;
vm.startPrank(vault);
deal(testConfig.vaultAsset, strategy, amountToAllocate);
bytes memory prevAllocationAmount = abi.encode(0);
IMYTStrategy(strategy).allocate(prevAllocationAmount, amountToAllocate, "", address(vault));
bytes memory prevAllocationAmount2 = abi.encode(amountToAllocate);
vm.expectEmit();
emit StrategyDeallocationLoss("Strategy deallocation loss.", 5e18, 0);
IMYTStrategy(strategy).deallocate(prevAllocationAmount2, amountToDeallocate, "", address(vault));
}
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 intended to represent the pre-withdrawal state is taken after the withdrawal, so the before and after values are identical.
Impact
The strategy always emits a loss event even when there is no real loss, which could trigger false alerts.
What the attacker needed
Strategy has allocated funds; deallocation is called
The fix
The balance before withdrawal should be recorded before calling vault.withdraw.
How it was found
- Deploy or set up the strategy with a vault and allocate funds.
- Call deallocate for half the allocated amount.
- Observe that a 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.
A smart contract strategy moves money in and out of a vault. When taking money out, it tries to check how much actually came back by comparing the balance before and after. But it reads the 'before' balance too late, so both readings are the same and the difference is always zero, making it look like a loss happened.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.