But in the moment of execution position size can be greater (or smaller) because of adjustment hence incorrect fee are applied.
User can open position with minimal amount, announce limit and adjust position to desirable size. When limit order executed, he will pay minimal fee for arbitrary large position close.
0xLogos
medium
Close position trader fee can be bypassing
Summary
User can pay less fee for position close using limit order.
Vulnerability Detail
Limit order close fee calculated using current position size when order announced in
announceLimitOrder
When executing in
_closePosition
function previously calculated fee are usedBut in the moment of execution position size can be greater (or smaller) because of adjustment hence incorrect fee are applied.
User can open position with minimal amount, announce limit and adjust position to desirable size. When limit order executed, he will pay minimal fee for arbitrary large position close.
Impact
Loss of revenue for LP
Code Snippet
https://github.com/sherlock-audit/2023-12-flatmoney/blob/bba4f077a64f43fbd565f8983388d0e985cb85db/flatcoin-v1/src/LimitOrder.sol#L62-L64
Tool used
Manual Review
Recommendation
Calculate trader fee when executing limit order in
_closePosition
function.Duplicate of #212