Submitted by shaflow2
https://github.com/code-423n4/2024-12-bakerfi/blob/3873b82ae8b321473f3afaf08727e97be0635be9/contracts/core/strategies/StrategySupplyMorpho.sol#L78
In the _undeploy function, assetsMax is incorrectly calculated because the contract directly retrieves totalSupplyAssets and totalSupplyShares from _morpho storage without accounting for the accrued interest over time. This leads to an underestimation of assetsMax, which may allow users to withdraw more assets than they should, causing losses to other users.
In the StrategySupplyMorpho contract, when retrieving assets, the expectedSupplyAssets function is used, which considers accrued interest and fees from the elapsed time since the last update. This ensures that the withdraw and redeem functions calculate assets, including unaccounted interest.
However, in the _undeploy function, the calculation of assetsMax does not account for the accrued interest and fees over time. This may result in assetsMax being underestimated compared to its actual value. On the other hand, the amount parameter includes accrued interest and fees, which can lead to the function entering the wrong branch.
If the function mistakenly enters the second branch, it may incorrectly convert all _morpho shares in the strategy to assets and send them to the withdrawer. In this case, the strategys assets will be 0, but the vault shares will still remain in the vault.
The remaining shareholders in the vault will not be able to normally claim assets.
Example:  
When calculating assetsMax, consider the accrued interest and fees that have not been updated.
chefkenji (BakerFi) confirmed
BakerFi mitigated:
Status: Mitigation confirmed. Full details in reports from 0xlemon and shaflow2.
