currentPosition is the sum of: the current position size of Liquidity Pool in Synthetix and the delta size of the current delayed order which was submitted into Synthetix perp market.
However, currentPosition missed the variable queuedPerpSize, is the total amount of pending size delta (waiting to be submitted).
Then _placeDelayedOrder will be called with the wrong newPosition, leads to the position size of pool can get a large deviation. The hedging will not be safe anymore.
Lines of code
https://github.com/code-423n4/2023-03-polynomial/blob/main/src/LiquidityPool.sol#L568-L587
Vulnerability details
Impact
Function
hedgePositions
is incorrect, leads to the hedging will not work as expected, and LiquidityPool can lose funds without expectation.Proof of concept
Let's see function
hedgePositions
in LiquidtyPool contract:currentPosition
is the sum of: the current position size of Liquidity Pool in Synthetix and the delta size of the current delayed order which was submitted into Synthetix perp market.However,
currentPosition
missed the variablequeuedPerpSize
, is the total amount of pending size delta (waiting to be submitted). Then_placeDelayedOrder
will be called with the wrongnewPosition
, leads to the position size of pool can get a large deviation. The hedging will not be safe anymore.Scenerio:
_getTotalPerpPosition
= 0,requiredPosition
= 1000,queuedPerpSize
= 1000newPosition
is calculated incorrectly to be 1000 (since it missedqueuedPerpSize
)_placeDelayedOrder(1000, false)
, thenqueuedPerpSize
increase to be 2000newPosition
should be -1000 in this caseTool used
Manual Review
Recommended Mitigation Steps
currentPosition
should be_getTotalPerpPosition()
+queuedPerpSize
in functionhedgePositions