Submitted by pkqs90, also found by 0xAlix2, hearmen, web3km, Bigsam, lian886, Infect3d, Bauchibred, crypticdefense, Spearmint, grearlake, Ruhum, karsar, and hash
When using flashlender to create loans, there is small amount of fees. The fees are sent to PoolV3 and is spread out to the lpETH stakers.
The issue is, the current implementation uses pool.repayCreditAccount() to add the profit, by setting the profit == fees. This is incorrect, and the correct implementation should be to use pool.mintProfit() to send the fees.
Both implementation mints the extra fees as lpETH to the StakingLPEth.sol contract, which is correct. However, the current implementation does NOT update the expectedLiquidity, since it assumes the profit is a part of the interest that should be paid by debt borrowers, and is already included, which is incorrect.
We can see the mintProfit() function also adds the amount of fees to the expectedLiquidity, since this is a different kind of fees than debt interest.
The impact of this issue is that the WETH amount in PoolV3 would be larger than expectedLiquidity. Since lpETH:WETH is always 1:1, when users want to withdraw the WETH, it may revert due to underflow when updating expectedLiquidity. An example is:
Note that CDPVault also uses mintProfit() to send the extra liquidation penalty as profit to PoolV3.
https://github.com/code-423n4/2024-07-loopfi/blob/main/src/CDPVault.sol#L569
Flashlender.sol:
PoolV3.sol:
Use mintProfit() to mint flashloan fees instead.
amarcu (LoopFi) confirmed
