This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
xiaoming90 - Incorrect price used when updating the global position data #188
Labels
Has Duplicates
A valid issue with 1+ other issues describing the same vulnerability
High
A valid High severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
xiaoming90
high
Incorrect price used when updating the global position data
Summary
Incorrect price used when updating the global position data leading to a loss of assets for LPs.
Vulnerability Detail
Near the end of the liquidation process, the
updateGlobalPositionData
function at Line 159 will be executed to update the global position data. However, when executing theupdateGlobalPositionData
function, the code sets the price at Line 160 below to the position's last price (position.lastPrice
), which is incorrect. The price should be set to the current price instead, and not the position's last price.https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/LiquidationModule.sol#L160
The reason why the
updateGlobalPositionData
function expects a current price to be passed in is that within thePerpMath._profitLossTotal
function, it will compute the price shift between the current price and the last price to obtain the PnL of all the open positions. Also, per the comment at Line 170 below, it expects the current price of the collateral to be passed in.Thus, it is incorrect to pass in the individual position's last/entry price, which is usually the price of the collateral when the position was first opened or adjusted some time ago.
Thus, if the last/entry price of the liquidated position is higher than the current price of collateral, the PnL will be inflated, indicating more gain for the long traders. Since this is a zero-sum game, this also means that the LP loses more assets than expected due to the inflated gain of the long traders.
https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/FlatcoinVault.sol#L173
Impact
Loss of assets for the LP as mentioned in the above section.
Code Snippet
https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/LiquidationModule.sol#L160
Tool used
Manual Review
Recommendation
Use the current price instead of liquidated position's last price when update the global position data
The text was updated successfully, but these errors were encountered: