57926 sc low the conditional strategydeallocationloss event in morphoyearnogwethstrategy deallocate gets logged all the time due a misplacement in variable declaration
Contract fails to deliver promised returns, but doesn't lose value
Description
Brief/Intro
A misplacement in syntax makes a conditional event trigger all the time, which could lead to issues in on-chain/off-chain mechanisms listening to it
Vulnerability Details
In the MorphoYearnOGWETHStrategy contract, StrategyDeallocationLoss event is logged all the time due to wethBalanceBefore and wethBalanceAfter being the same value. This happened cause wethBalanceBefore is declared after the withdrawal is triggered rather than before. This means wethBalanceBefore and wethBalanceAfter are the same value hence, wethRedeemed, a variable which depends on the difference of both always returns 0. This in turn makes StrategyDeallocationLoss, which depends on wethRedeemed, always return true. Hence the event always triggers leaving any onchain/offchain variables listening to it susceptible to error.
Impact Details
The function executes properly regardless, and no immediate funds are at risk; however, other mechanisms that listen to the StrategyDeallocationLoss may be at risk as the third parameter, wethRedeemed would always return 0.
References
Proof of Concept
Proof of Concept
Place the following into MorphoYearnOGWETHStrategyTest.t.sol
Place this in MorphoYearnOGWETHStrategyTest contract
This will result in an error due to Foundry's vm.expectEmit, which struggles to compare dynamic types like strings and bytes (when comparing the actual emitted string and the expected emitted string). But from the stack trace, we can see that an event was truly logged at that point. This occurs for every possible value of amount