Hedgers are not incentivized to respond to user's closing requests
Hedgers can ignore users' close requests, forcing users to call forceClosePosition and pay a spread, which benefits hedgers. This results in users closing at a worse price and losing profit.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-06-symmetrical-judging/issues/239
Found by
xiaoming90
Summary
Hedgers could intentionally force the users to close the positions themselves via the forceClosePosition and charge a spread to earn more, which results in the users closing at a worse price, leading to a loss of profit for them.
Vulnerability Detail
How fillCloseRequest function works?
For a Long position, when PartyB (Hedger) calls the fillCloseRequest function to fill a close position under normal circumstances, the hedger cannot charge a spread because the hedger has to close at the user's requested close price (quote.requestedClosePrice),
If the hedger decides to close at a higher price, it is permissible by the function, but the hedger will lose more, and the users will gain more because the users' profit is computed based on long profit = closing price - opening price.
Under normal circumstances, most users will set the requested close price (quote.requestedClosePrice) close to the market price most of the time.
In short, the fillCloseRequest function requires the hedger to match or exceed the user' requested price. The hedger cannot close at a price below the user's requested price in order to charge a spread.
function fillCloseRequest(
..SNIP..
if (quote.positionType == PositionType.LONG) {
require(
closedPrice >= quote.requestedClosePrice,
"PartyBFacet: Closed price isn't valid"
)
How forceClosePosition function works?
For a Long position, the forceCloseGapRatio will allow the hedger to charge a spread from the user's requested price (quote.requestedClosePrice) when the user (PartyA) attempts to force close the position.
The upnlSig.price is the market price and quote.requestedClosePrice is the price users ask to close at. By having the forceCloseGapRatio, assuming that forceCloseGapRatio is 5%, this will create a spread between the two prices (upnlSig.price and quote.requestedClosePrice) that represent a cost that the users (PartyA) need to "pay" in order to force close a position.
function forceClosePosition(uint256 quoteId, PairUpnlAndPriceSig memory upnlSig) internal {
..SNIP..
if (quote.positionType == PositionType.LONG) {
require(
upnlSig.price >=
quote.requestedClosePrice +
(quote.requestedClosePrice * maLayout.forceCloseGapRatio) /
1e18,
"PartyAFacet: Requested close price not reached"
);
..SNIP..
LibQuote.closeQuote(quote, filledAmount, quote.requestedClosePrice);
Issue with current design
Assume a hedger ignores the user's close request. In this case, the users (PartyA) have to call the forceClosePosition function by themselves to close the position and pay a spread.
The hedgers can abuse this mechanic to their benefit. Assuming the users (PartyA) ask to close a LONG position at a fair value, and the hedgers respond by calling the fillCloseRequest to close it. In this case, the hedgers won't be able to charge a spread because the hedgers are forced to close at a price equal to or higher than the user's asking closing price (quote.requestedClosePrice).
However, if the hedger chooses to ignore the user's close request, this will force the user to call the forceClosePosition, and the user will have to pay a spread to the hedgers due to the gap ratio. In this case, the hedgers will benefit more due to the spread.
In the long run, the hedgers will be incentivized to ignore users' close requests.
Impact
The hedgers will be incentivized to ignore users' close requests, resulting in the users having to wait for the cooldown before being able to force close a position themselves. The time spent waiting could potentially lead to a loss of opportunity cost for the users.
In addition, hedgers could intentionally force the users to close the positions themselves via the forceClosePosition and charge a spread to earn more, which results in the users closing at a worse price, leading to a loss of profit for them.
Code Snippet
Tool used
Manual Review
Recommendation
Hedgers should not be entitled to charge a spread within the forceClosePosition function because some hedgers might intentionally choose not to respond to user requests in order to force the users to close the position themselves. In addition, hedgers are incentivized to force users to close the position themselves as the forceClosePosition function allows them the charge a spread.
Within the forceClosePosition function, consider removing the gap ratio to remove the spread and fill the position at the market price (upnlSig.price).
function forceClosePosition(uint256 quoteId, PairUpnlAndPriceSig memory upnlSig) internal {
..SNIP..
if (quote.positionType == PositionType.LONG) {
require(
upnlSig.price >=
+ quote.requestedClosePrice,
- quote.requestedClosePrice +
- (quote.requestedClosePrice * maLayout.forceCloseGapRatio) /
- 1e18,
"PartyAFacet: Requested close price not reached"
);
} else {
require(
upnlSig.price <=
+ quote.requestedClosePrice,
- quote.requestedClosePrice -
- (quote.requestedClosePrice * maLayout.forceCloseGapRatio) /
- 1e18,
"PartyAFacet: Requested close price not reached"
);
}
..SNIP..
- LibQuote.closeQuote(quote, filledAmount, quote.requestedClosePrice);
+ LibQuote.closeQuote(quote, filledAmount, upnlSig.price);
}
For long-term improvement to the protocol, assuming that the user's requested price is of fair value:
- Hedger should be penalized for not responding to the user's closing request in a timely manner; OR
- Hegder should be incentivized to respond to the user's closing request. For instance, they are entitled to charge a spread if they respond to user closing requests.
Discussion
mstpr
Escalate
Hedgers are not incentivized to hold the position because
1- price can move, it is not a safe bet to keep the position for couple more days always. When hedgers take the risk of not closing a position they also take the risk of price movements against their position.
2- Hedgers are not taking any spread. Quote is closed at the requested close price. https://github.com/sherlock-audit/2023-06-symmetrical/blob/6d2b64b6732fcfbd07c8217897dd233dbb6cd1f5/symmio-core/contracts/facets/PartyA/PartyAFacetImpl.sol#L296
Both partyA and partyB shouldn't be penalized for these actions. Recommendation says that the hedger (partyB) should be penalized if things go to forcing. However, this can also be easily abusable by partyA, partyA can create close requests near the market price and continuously cash out the profits knowing that partyB will forced to close the request rather than keep it waiting.
If the market price is used for force close as stated in recommendation it is even worse. Now, the partyB has a chance, will he keep the trade and wish for the price to move to its favor or just take the trade. Now, partyB is actually kind of incentivized to hold the position. Current design ensures that the request is closed as the requested price. There is a small buffer to keep partyA not abusing this which makes sense. I don't think anything is wrong here and everything is design choice.
sherlock-admin2
Escalate
Hedgers are not incentivized to hold the position because
1- price can move, it is not a safe bet to keep the position for couple more days always. When hedgers take the risk of not closing a position they also take the risk of price movements against their position.
2- Hedgers are not taking any spread. Quote is closed at the requested close price. https://github.com/sherlock-audit/2023-06-symmetrical/blob/6d2b64b6732fcfbd07c8217897dd233dbb6cd1f5/symmio-core/contracts/facets/PartyA/PartyAFacetImpl.sol#L296
Both partyA and partyB shouldn't be penalized for these actions. Recommendation says that the hedger (partyB) should be penalized if things go to forcing. However, this can also be easily abusable by partyA, partyA can create close requests near the market price and continuously cash out the profits knowing that partyB will forced to close the request rather than keep it waiting.
If the market price is used for force close as stated in recommendation it is even worse. Now, the partyB has a chance, will he keep the trade and wish for the price to move to its favor or just take the trade. Now, partyB is actually kind of incentivized to hold the position. Current design ensures that the request is closed as the requested price. There is a small buffer to keep partyA not abusing this which makes sense. I don't think anything is wrong here and everything is design choice.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
imherefortech
Escalate
To add some arguments, if hedgers do not respond to the requests in time, users will move to other hedgers. Remember, that users provide a whitelist of hedgers that can respond to their quotes. Hedgers are pretty clearly incentivized this way.
sherlock-admin2
Escalate
To add some arguments, if hedgers do not respond to the requests in time, users will move to other hedgers. Remember, that users provide a whitelist of hedgers that can respond to their quotes. Hedgers are pretty clearly incentivized this way.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
xiaoming9090
Escalate
Hedgers are not incentivized to hold the position because
1- price can move, it is not a safe bet to keep the position for couple more days always. When hedgers take the risk of not closing a position they also take the risk of price movements against their position.
2- Hedgers are not taking any spread. Quote is closed at the requested close price. https://github.com/sherlock-audit/2023-06-symmetrical/blob/6d2b64b6732fcfbd07c8217897dd233dbb6cd1f5/symmio-core/contracts/facets/PartyA/PartyAFacetImpl.sol#L296
Both partyA and partyB shouldn't be penalized for these actions. Recommendation says that the hedger (partyB) should be penalized if things go to forcing. However, this can also be easily abusable by partyA, partyA can create close requests near the market price and continuously cash out the profits knowing that partyB will forced to close the request rather than keep it waiting.
If the market price is used for force close as stated in recommendation it is even worse. Now, the partyB has a chance, will he keep the trade and wish for the price to move to its favor or just take the trade. Now, partyB is actually kind of incentivized to hold the position. Current design ensures that the request is closed as the requested price. There is a small buffer to keep partyA not abusing this which makes sense. I don't think anything is wrong here and everything is design choice.
Point 1 is irrelevant. If the PartyB (Hedger) choose not to close the position, obviously they have evaluated and chosen to accept the risk of price movements.
Point 2 is incorrect. The require statement and the forceCloseGapRatio here ensure that there is spread.
There is a misunderstanding. The report is not saying that PartyA and/or PartyB (Hedger) should be penalized. Instead, the report is saying that PartyB (Hedger) should not be rewarded with a spread if it does not do its job by responding to user's close position request.
xiaoming9090
Escalate
To add some arguments, if hedgers do not respond to the requests in time, users will move to other hedgers. Remember, that users provide a whitelist of hedgers that can respond to their quotes. Hedgers are pretty clearly incentivized this way.
If such a measure did not exist in the first place, the issue would have been graded as 'High' since there would be less deterrence to ensure that PartyB (Hedger) behaves appropriately. However, in this case, it has been downgraded to Medium taking into consideration of other factors. Also, the main goal (root problem) of this report is to highlight the fact that Hedgers are still being rewarded with the spread even though they do not do their job by responding to users' close position requests.
In addition, it does not make sense for a user who has to manually force close their position because the Hedger refuses to do its job, and yet the user has to pay a spread and reward it to the Hedger for not doing its job.
mstpr
"However, if the hedger chooses to ignore the user's close request, this will force the user to call the forceClosePosition, and the user will have to pay a spread to the hedgers due to the gap ratio. In this case, the hedgers will benefit more due to the spread."
the position is closed at the requested close price not at the requested close price + buffer. There is only a buffer for partyA to not abuse the system which make sense. If hedger does not want to close the position at the requested price of partyA, which is totally understandable and fine, then the hedger is not necessarily safe or incentivized. It means that the hedger is still exposed to the price movements during the time.
Both partyA and partyB are counterparties of a trade. PartyB does not have to follow the rules of partyA.
I would kindly ask for you to provide a scenario where its "always" in benefit of partyB to stall the close request. I think your recommended fix is an another medium finding for Sherlock.
MoonKnightDev
Fixed code PR link: https://github.com/SYMM-IO/symmio-core/pull/17
hrishibhat
Result: Medium Unique After considering the above discussion considering this issue a valid medium. Agree with the comments here There is a spread in addition to the requested close price. Additionally, the fix also acknowledges the problem Some comments from the Sponsor on the function:
Hedgers have the option to close their positions on the broker side, adding a spread on top of it. However, when it comes to filling the contract side, it is preferable for them to match or exceed the user's requested price. Regarding the force close mechanism, the gap ratio allows hedgers to charge a spread on the broker side. Additionally, during a force close, the position should be filled at the market price rather than the user's requested price.
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- mstpr: rejected
- imherefortech: rejected
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The forceClosePosition function charges a spread (via forceCloseGapRatio) that benefits the hedger, while fillCloseRequest does not allow the hedger to charge a spread, creating an incentive to ignore close requests.
Impact
Hedgers may ignore close requests, forcing users to wait for a cooldown and then force-close at a worse price, causing a loss of profit.
What the attacker needed
User has an open position; hedger ignores close request; user calls forceClosePosition
The fix
The report recommends removing the gap ratio in forceClosePosition so no spread is charged, and filling at the market price; the project later fixed it.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this trading system, users ask hedgers to close their positions at a chosen price. If the hedger ignores the request, the user can force-close but must pay an extra fee called a spread. The report says hedgers are rewarded for ignoring requests, which hurts users.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.