Submitted by chaduke, also found by lightoasis, jigster, and AKA8u9K111er
First of all, in CDPVault, the amount of collateral maintained in each position is scaled using tokenScale. See the code in deposit:
https://github.com/code-423n4/2024-07-loopfi/blob/57871f64bdea450c1f04c9a53dc1a78223719164/src/CDPVault.sol#L223-L233
and the function modifyCollateralAndDebt():
https://github.com/code-423n4/2024-07-loopfi/blob/57871f64bdea450c1f04c9a53dc1a78223719164/src/CDPVault.sol#L367-L460
For example, when withdrawing collateral, it will scale it with tokenScale from internal amount:
However, when sending collateral to the liquidator, it uses the internal amount without scaling by tokenScale in function liquidatePosition at L565.
As a result, when tokenScale < 10 ** 18, the above line actually send more tokens to the liquidator than it is supposed to, a loss of funds for the protocol.
In the following POC, we show:
Please run forge test --match-test testLiquidate1 -vv:
Foundry
Scale the collateral amount from internal representation to the real amount by tokenScale.
Decimal
0xtj24 (LoopFi) acknowledged
Koolex (judge) decreased severity to Medium
Note: For full discussion, see here.
