MorphoYearnOGWETH _deallocate function always emits StrategyDeallocationLoss due to flawed balance measurement
The _deallocate function in the MorphoYearnOGWETH strategy takes both the before and after balance readings after the withdrawal has already happened, so the measured redeemed amount is always zero. As a result the contract always emits a StrategyDeallocationLoss event even when no loss occurred, misleading users and monitoring systems.
- Disclosed after under an hour
56343 sc low morphoyearnogweth deallocate function always emits strategydeallocationloss due to flawed balance measurement
Submitted on Oct 14th 2025 at 18:22:27 UTC by @DashBug for Audit Comp | Alchemix V3
- Report ID: #56343
- 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
The _deallocate function in src/strategies/mainnet/MorphoYearnOGWETH.sol contains flawed balance measurement logic that causes it to always emit StrategyDeallocationLoss events, even when no actual loss occurs. This creates misleading performance signals and false negative reporting to users and monitoring systems.
Vulnerability Details
- The
_deallocatefunction measures balance before and after withdrawal incorrectly:
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;
}
- The balance measurement occurs after the withdrawal on both lines 51 and 52
- Since both measurements are taken at the same point,
wethBalanceBeforeequalswethBalanceAfter - This results in
wethRedeemed = 0always - The condition
if (wethRedeemed < amount)is always true (since 0 < amount) StrategyDeallocationLossis always emitted regardless of actual performance
Impact Details
- Misleading events: Users see loss events even when the strategy performs correctly
- False negative reporting: External monitoring systems receive incorrect loss signals
- Reputation damage: The strategy appears to always underperform
- No actual financial loss: The contract still delivers promised returns, just with incorrect reporting
- Severity: Low (logic error affecting reporting, not financial security)
References
src/strategies/mainnet/MorphoYearnOGWETH.sol:- Flawed balance measurement (both measurements after withdrawal)
uint256 wethBalanceBefore = TokenUtils.safeBalanceOf(address(weth), address(this));
uint256 wethBalanceAfter = TokenUtils.safeBalanceOf(address(weth), address(this));
- Always true condition leading to false loss emission
if (wethRedeemed < amount) {
emit StrategyDeallocationLoss("Strategy deallocation loss.", amount, wethRedeemed);
}
Recommendation
Fix the balance measurement by taking the "before" measurement before the withdrawal:
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));
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;
}
This ensures accurate loss reporting and eliminates false negative signals.
Link to Proof of Concept
https://gist.github.com/dash19991226/6766247cd19c790a47bb6240e6c1b735
Proof of Concept
Proof of Concept
Runnable PoC Test
A working Proof of Concept test is available at:
src/test/strategies/MorphoYearnOGWETH_AlwaysEmitsLoss_PoC.t.sol
To run the PoC:
forge test --match-contract MorphoYearnOGWETH_AlwaysEmitsLoss_PoC -vv
Expected output:
[PASS] test_AlwaysEmitsLoss() (gas: 17587)
Logs:
=== MorphoYearnOGWETH Always Emits Loss PoC ===
BUG DEMONSTRATION:
1. Both balance measurements happen AFTER withdrawal
2. wethRedeemed = wethBalanceAfter - wethBalanceBefore = 0
3. Since 0 < amount, StrategyDeallocationLoss is ALWAYS emitted
4. This happens even when there's no actual loss!
Simulated values:
Amount: 100000000000000000000
wethBalanceBefore: 1000000000000000000000
wethBalanceAfter: 1000000000000000000000
wethRedeemed: 0
Should emit loss event: true
PoC SUCCESS: Bug confirmed - loss event always emitted
[PASS] test_RootCauseAnalysis() (gas: 7055)
Logs:
=== Root Cause Analysis ===
Root cause: Both balance measurements occur AFTER withdrawal
Result: wethRedeemed is always 0, so loss event always emitted
Fix: Measure wethBalanceBefore BEFORE withdrawal
The PoC demonstrates that the loss event is always emitted due to the flawed balance measurement logic, confirming the bug exists in the production code.
Manual Steps to Reproduce
- Call
_deallocatefunction with any valid amount - Observe that
StrategyDeallocationLossevent is always emitted - Verify that both balance measurements occur after withdrawal
Expected vs Actual:
- Expected: Loss event only emitted when actual loss occurs
- Actual: Loss event always emitted due to flawed measurement logic
Root Cause Analysis:
- Both balance measurements taken after withdrawal
wethRedeemedalways equals 0- Condition
wethRedeemed < amountalways true - False loss reporting to users and monitoring systems
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
Likely the 'before' balance is read after the withdrawal call instead of before it, so both readings are identical and the computed redeemed amount is always zero.
Impact
The contract still delivers the promised returns, but it always emits a loss event, giving users and external monitoring systems false loss signals and making the strategy appear to underperform.
What the attacker needed
None
The fix
The 'before' balance should be measured before the withdrawal call so the redeemed amount is calculated correctly.
How it was found
- Call the _deallocate function with any valid amount
- Observe that the StrategyDeallocationLoss event is always emitted
- Verify that both balance measurements occur after the withdrawal
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 is a program that runs on a blockchain. This strategy contract withdraws funds and then tries to check how much was actually received by comparing the balance before and after. The mistake is that it reads the balance twice after the withdrawal, so the two numbers are identical and the difference is always zero, which makes the contract wrongly announce 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.