`emergencyClosePosition` can be blocked
The emergencyClosePosition function only works when a position's status is OPENED, but PartyA can change the status to CLOSE_PENDING by requesting to close a tiny amount, causing emergency closes to revert. This could block PartyB from urgently closing positions during emergency mode, potentially leading to losses.
Yuki Follow with nobody2018 and xiaoming90
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-06-symmetrical-judging/issues/236
Found by
Yuki, nobody2018, xiaoming90
Summary
The emergencyClosePosition function can be blocked as PartyA can change the position's status, which causes the transaction to revert when executed.
Vulnerability Detail
Activating the emergency mode can be done either for a specific PartyB or for the entire system. Once activated, PartyB gains the ability to swiftly close positions without requiring users' requests. This functionality is specifically designed to cater to urgent situations where PartyBs must promptly close their positions.
Based on the PartyBFacetImpl.emergencyClosePosition function, a position can only be "emergency" close if its status is QuoteStatus.OPENED.
File: PartyBFacetImpl.sol
309: function emergencyClosePosition(uint256 quoteId, PairUpnlAndPriceSig memory upnlSig) internal {
310: AccountStorage.Layout storage accountLayout = AccountStorage.layout();
311: Quote storage quote = QuoteStorage.layout().quotes[quoteId];
312: require(quote.quoteStatus == QuoteStatus.OPENED, "PartyBFacet: Invalid state");
..SNIP..
As a result, if PartyA knows that emergency mode has been activated, PartyA could pre-emptively call the PartyAFacetImpl.requestToClosePosition with minimum possible quantityToClose (e.g. 1 wei) against their positions to change the state to QuoteStatus.CLOSE_PENDING so that the PartyBFacetImpl.emergencyClosePosition function will always revert when triggered by PartyB. This effectively blocks PartyB from "emergency" close the positions in urgent situations.
PartyA could also block PartyB "emergency" close on-demand by front-running PartyB's PartyBFacetImpl.emergencyClosePosition transaction with the PartyAFacetImpl.requestToClosePosition with minimum possible quantityToClose (e.g. 1 wei) when detected.
PartyB could accept the close position request of 1 wei to revert the quote's status back to QuoteStatus.OPENED and try to perform an "emergency" close again. However, a sophisticated malicious user could front-run PartyA to revert the quote's status back to QuoteStatus.CLOSE_PENDING again to block the "emergency" close for a second time.
Impact
During urgent situations where emergency mode is activated, the positions need to be promptly closed to avoid negative events that could potentially lead to serious loss of funds (e.g. the protocol is compromised, and the attacker is planning to or has started draining funds from the protocols). However, if the emergency closure of positions is blocked or delayed, it might lead to unrecoverable losses.
Code Snippet
Tool used
Manual Review
Recommendation
Update the emergencyClosePosition so that the "emergency" close can still proceed even if the position's status is QuoteStatus.CLOSE_PENDING.
function emergencyClosePosition(uint256 quoteId, PairUpnlAndPriceSig memory upnlSig) internal {
AccountStorage.Layout storage accountLayout = AccountStorage.layout();
Quote storage quote = QuoteStorage.layout().quotes[quoteId];
- require(quote.quoteStatus == QuoteStatus.OPENED, "PartyBFacet: Invalid state");
+ require(quote.quoteStatus == QuoteStatus.OPENED || quote.quoteStatus == QuoteStatus.CLOSE_PENDING, "PartyBFacet: Invalid state");
..SNIP..
Discussion
MoonKnightDev
Indeed, when Party B fulfills the close request, both Party A and Party B are required to obtain a new signature from Muon - Party A for the request to close and Party B for the emergency close. Party B is more likely to be successful. Moreover, Party A cannot front-run due to the distinct signatures. so we don't consider it as "High"
MoonKnightDev
Fixed code PR link: https://github.com/SYMM-IO/symmio-core/pull/16
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 emergency close function requires the position status to be exactly OPENED, but PartyA can change it to CLOSE_PENDING with a minimal close request, blocking the emergency close.
Impact
If emergency closure is blocked or delayed, it might lead to unrecoverable losses during urgent situations.
What the attacker needed
Emergency mode activated; PartyA can submit transactions
The fix
The emergencyClosePosition function was updated to also allow closing when the position status is CLOSE_PENDING.
How it was found
- PartyA calls requestToClosePosition with a very small quantityToClose (e.g., 1 wei) to change the position status to CLOSE_PENDING.
- PartyB attempts to call emergencyClosePosition, but it reverts because the status is not OPENED.
- PartyB could accept the close request to revert status to OPENED, but PartyA can front-run again to set it back to CLOSE_PENDING.
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 system, PartyA and PartyB have a financial agreement. In an emergency, PartyB is supposed to be able to close the agreement quickly. But PartyA can make a tiny change to the agreement's status that stops PartyB from closing it, which could be dangerous if funds are at risk.
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.