Closed sherlock-admin2 closed 8 months ago
1 comment(s) were left on this issue during the judging contest.
takarez commented:
valid: the fee should correspond to the size; high(11)
The protocol team fixed this issue in PR/commit https://github.com/dhedge/flatcoin-v1/pull/274.
LTDingZhen
high
Trade fee is miscalculated in
LimitOrder
Summary
When the user chooses to close the position using
announceLeverageClose
, trade fee is calculated from the price at which the user closes the position. But in 'announceLimitOrder', trade fee is calculated from the price at which the user set the limit order, whichTrade fee in
LimitOrder
should be determined by the position size at the take-profit and stop-loss prices, but it is actually miscalculated by user's position size when he callsannounceLimitOrder
.Vulnerability Detail
In
DelayedOrder
, trade fee is calculated based on the the size of the position of the user's announce operation:But, as price changes affect users' position size, when a Take Profit order is triggered, less trade fee is charged and when a Stop Loss order is triggered, more trade fee is charged. (compare with
announceLeverageClose
)Impact
The trade fee of every limit order is miscalculated, putting the protocol or all users at a significant loss in a one-sided market.
Code Snippet
Trade fee is correctly calculated in
announceLeverageClose
: https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/DelayedOrder.sol#L331Trade fee is miscalculated in
announceLimitOrder
: https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/LimitOrder.sol#L62-L64Tool used
Manual Review
Recommendation
Trade fee in
LimitOrder
should be determined by the position size at the take-profit and stop-loss prices.Duplicate of #212