Wrong order in balance querying instructions in MorphoYearnOGWETHStrategy::_deallocate function leads to always emit StrategyDeallocationLoss event
In the strategy's deallocate function, the WETH balance is read twice after the vault withdrawal instead of once before and once after, so the computed redeemed amount is always zero. As a result the contract always emits a deallocation-loss event even when the full amount was withdrawn, misleading off-chain listeners.
Originally disclosed on Immunefi
- Disclosed after under an hour
58393 sc low wrong order in balance querying instructions in morphoyearnogwethstrategy deallocate function leads to always emit strategydeallocationloss event
Submitted on Nov 1st 2025 at 21:49:35 UTC by @hunter0xweb3 for Audit Comp | Alchemix V3
- Report ID: #58393
- 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
MorphoYearnOGWETHStrategy::_deallocate(amount) function perform two weth.balanceOf(address(this)) queries to check if enough weth amount was withdrawn from a vault, and emits an event if amount withdrawn from the vault was not enough.
However, the two weth.balanceOf(address(this)) queries are performed in wrong order leading to MorphoYearnOGWETHStrategy always emit that amount withdrawn was not enough, even when enough amount was withdrawn from the vault.
Vulnerability Details
The issue occurs because the weth balanceBefore query is performed after withdrawn from the vault instead of querying balance before
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);
}
So when it compares balanceBefore and balanceAfter variables values they are the same
Because of this the value of wethRedeemed variable will always be zero, so conditional branch code will always be executed, leading _deallocate function to always emit StrategyDeallocationLoss event, even when enough weth was withdraw from the vault
Impact Details
- Wrong balance comparission before and after withdrawn from the vault
- Emit StrategyDeallocationLoss event is always emited generating incorrect emitted information for offchain listeners and integrators
- Contract fails to deliver promised returns, but doesn't lose value
References
Recommendation Perform wethBalanceBefore before call to vault withdraw
function _deallocate(uint256 amount) internal override returns (uint256) {
uint256 wethBalanceBefore = TokenUtils.safeBalanceOf(address(weth), address(this));
vault.withdraw(amount, address(this), address(this));
uint256 wethBalanceAfter = TokenUtils.safeBalanceOf(address(weth), address(this));
Proof of Concept
Proof of Concept
The following Proof of concept performs a successfull allocation and deallocation (enough weth was withdraw from vault), however _deallocate function will emit StrategyDeallocationLoss leading emitted event integrity loss
Create in src/test/strategies/MorphoYearnOGWETHStrategy.t.sol The following test case:
function test_MorphoYearnOGWETHDeallocateWrongBalanceComparission(uint256 amountToAllocate, uint256 amountToDeallocate) public {
amountToAllocate = bound(amountToAllocate, 1e18, testConfig.vaultInitialDeposit);
amountToDeallocate = amountToAllocate/2;
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");
// Records logs emitted by deallocate
vm.recordLogs();
bytes memory prevAllocationAmount2 = abi.encode(amountToAllocate);
IMYTStrategy(strategy).deallocate(prevAllocationAmount2, amountToDeallocate, "", address(vault));
// Because of wrong before/ after balance querying
// StrategyDeallocationLoss is always emitted
VmSafe.Log[] memory logs = vm.getRecordedLogs();
bytes32 eventSignature = keccak256(
"StrategyDeallocationLoss(string,uint256,uint256)"
);
uint eventCount;
for (uint256 i = 0; i < logs.length; i++) {
if(logs[i].topics[0] == eventSignature ){
eventCount+=1;
}
}
assertEq(eventCount,1);
vm.stopPrank();
}
Exec test with
forge test --mc MorphoYearnOGWETHStrategy --mt test_MorphoYearnOGWETHDeallocateWrongBalanceComparission -vv
Observe event is always emitted (even when redeemed weth is >= amount argument) due wrong balance order querying in MorphoYearnOGWETHStrategy::_deallocate function
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 reading is taken after the vault withdrawal, so both readings are identical and the redeemed amount is always zero.
Impact
The contract does not lose funds, but it always emits a false loss event, giving incorrect information to off-chain listeners and integrators.
What the attacker needed
Strategy holds allocated WETH
The fix
The balance-before reading should be taken before the vault withdrawal call.
How it was found
- Allocate WETH to the strategy through the vault.
- Record the logs emitted during the deallocation call.
- Call deallocate for half of the allocated amount.
- Count the StrategyDeallocationLoss events in the recorded logs and observe one is emitted.
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 keeps track of how much of a token it holds. To check that a withdrawal worked, it should note the balance before the withdrawal and again afterwards, then compare the two. Here both readings are taken after the withdrawal, so the difference is always zero and the contract wrongly reports a loss every time.
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.