PartyBFacetImpl.chargeFundingRate should check whether quoteIds is empty array to prevent partyANonces from being increased, causing some operations of partyA to fail
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-08-symmetrical-judging/issues/41
Found by
nobody2018
[PartyBFacetImpl.chargeFundingRate](https://github.com/sherlock-audit/2023-08-symmetrical/blob/main/symmio-core/contracts/facets/PartyB/PartyBFacetImpl.sol#L310-L315) can increase partyANonces[partyA] by 1 with the quoteIds empty array. Some functions that partyA can call will use partyANonces[partyA] to verify the signature. This opens up the opportunity for partyB to DOS partyA until PartyB makes a profit or reduces its losses.
Vulnerability Detail
File: symmio-core\contracts\facets\PartyB\PartyBFacetImpl.sol
310: function chargeFundingRate(
311: address partyA,
312: uint256[] memory quoteIds,
313: int256[] memory rates,
314: PairUpnlSig memory upnlSig
315: ) internal {
316: LibMuon.verifyPairUpnl(upnlSig, msg.sender, partyA);
317: require(quoteIds.length == rates.length, "PartyBFacet: Length not match");
318: int256 partyBAvailableBalance = LibAccount.partyBAvailableBalanceForLiquidation(
319: upnlSig.upnlPartyB,
320: msg.sender,
321: partyA
322: );
323: int256 partyAAvailableBalance = LibAccount.partyAAvailableBalanceForLiquidation(
324: upnlSig.upnlPartyA,
325: partyA
326: );
327: uint256 epochDuration;
328: uint256 windowTime;
329: for (uint256 i = 0; i < quoteIds.length; i++) {
......//quoteIds is empty array, so code is never executed.
390: }
391: require(partyAAvailableBalance >= 0, "PartyBFacet: PartyA will be insolvent");
392: require(partyBAvailableBalance >= 0, "PartyBFacet: PartyB will be insolvent");
393: AccountStorage.layout().partyBNonces[msg.sender][partyA] += 1;
394:-> AccountStorage.layout().partyANonces[partyA] += 1;
395: }
As long as partyBAvailableBalance(L318) and partyAAvailableBalance(L323) are greater than or equal to 0, that is to say, PartyA and PartyB are solvent. Then, partyB can add 1 to partyANonces[partyA] at little cost which is the gas of tx.
An example is given to illustrate how to cause losses for partyA. Assume that partyA requests to close a quote via [PartyAFacetImpl.requestToClosePosition](https://github.com/sherlock-audit/2023-08-symmetrical/blob/main/symmio-core/contracts/facets/PartyA/PartyAFacetImpl.sol#L150). PartyB ignored it. partyA can only wait for maLayout.forceCloseCooldown seconds, and then call [PartyAFacetImpl.forceClosePosition](https://github.com/sherlock-audit/2023-08-symmetrical/blob/main/symmio-core/contracts/facets/PartyA/PartyAFacetImpl.sol#L239) to forcefully close the quote.
File: symmio-core\contracts\facets\PartyA\PartyAFacetImpl.sol
239: function forceClosePosition(uint256 quoteId, PairUpnlAndPriceSig memory upnlSig) internal {
240: AccountStorage.Layout storage accountLayout = AccountStorage.layout();
241: MAStorage.Layout storage maLayout = MAStorage.layout();
242: Quote storage quote = QuoteStorage.layout().quotes[quoteId];
......//assume codes here are executed
273:-> LibMuon.verifyPairUpnlAndPrice(upnlSig, quote.partyB, quote.partyA, quote.symbolId);
......
283: }
L273, [LibMuon.verifyPairUpnlAndPrice](https://github.com/sherlock-audit/2023-08-symmetrical/blob/main/symmio-core/contracts/libraries/LibMuon.sol#L181-L182) is used to verify signatures, where partyBNonces[partyB][partyA] and partyANonces[partyA] are used internally.
If the current price goes against partyB, then partyB can front-run forceClosePosition and call chargeFundingRate to increase the nonces of both parties by 1. In this way, partyA's forceClosePosition will inevitably revert because the nonces are incorrect.
Similarly, if partyA wants to deallocate funds via [AccountFacetImpl.deallocate](https://github.com/sherlock-audit/2023-08-symmetrical/blob/main/symmio-core/contracts/facets/Account/AccountFacetImpl.sol#L53), partyB can also prevent this operation via chargeFundingRate.
Impact
Due to this issue, partyB can increase nonces of any partyA with little cost, causing some operations of partyA to fail (refer to the Vulnerability Detail section). This opens up the opportunity for partyB to turn the table.
Code Snippet
Tool used
Manual Review
Recommendation
File: symmio-core\contracts\facets\PartyB\PartyBFacetImpl.sol
310: function chargeFundingRate(
311: address partyA,
312: uint256[] memory quoteIds,
313: int256[] memory rates,
314: PairUpnlSig memory upnlSig
315: ) internal {
316: LibMuon.verifyPairUpnl(upnlSig, msg.sender, partyA);
317:- require(quoteIds.length == rates.length, "PartyBFacet: Length not match");
317:+ require(quoteIds.length > 0 && quoteIds.length == rates.length, "PartyBFacet: Length is 0 or Length not match");
Discussion
sherlock-admin
1 comment(s) were left on this issue during the judging contest.
panprog commented:
valid medium
securitygrid
Escalate
This is not a dup of #31. Please review it.
This issue describes how PartyB uses chargeFundingRate to cause PartyA to suffer losses.
All PartyB can easily take advantage of it against PartyA, making themselves always profitable.
Consider the following two situations here:
- If the current price goes for PartyB, then the quote is closed and PartyB makes a profit.
- If the current price goes against PartyB, then PartyB can use this issue to prevent PartyA from forcibly closing the quote until the price goes for PartyB.
sherlock-admin2
Escalate This is not a dup of #31. Please review it. This issue describes how PartyB uses
chargeFundingRateto cause PartyA to suffer losses. All PartyB can easily take advantage of it against PartyA, making themselves always profitable. Consider the following two situations here:
- If the current price goes for PartyB, then the quote is closed and PartyB makes a profit.
- If the current price goes against PartyB, then PartyB can use this issue to prevent PartyA from forcibly closing the quote until the price goes for PartyB.
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.
nevillehuang
Escalate This is not a dup of #31. Please review it. This issue describes how PartyB uses
chargeFundingRateto cause PartyA to suffer losses. All PartyB can easily take advantage of it against PartyA, making themselves always profitable. Consider the following two situations here:
- If the current price goes for PartyB, then the quote is closed and PartyB makes a profit.
- If the current price goes against PartyB, then PartyB can use this issue to prevent PartyA from forcibly closing the quote until the price goes for PartyB.
So this issue can be H.
Agreed, although both stems from the same root case of abusing chargeFundingRate to increment nonce, it is not a duplicate of #31 given that issue is invalid. This is talking about partyB potentially causing losses to partyA not about preventing its own liquidation process.
@MoonKnightDev want to hear ur thoughts on this, given protocol determines party B is a trusted role.
panprog
Escalate
I believe this is a valid medium. It is similar to #31 in that it uses nonce increase to block certain functionality, however #31 only lists liquidation as impact (which is invalid), while this issue shows valid impact for partyB to be able to avoid forceClosePosition. I think function from #31 (deallocate) and also transferAllocation can also be used for the same (increase partyB nonce to prevent forceClosePosition).
So from my view:
- core reason: the same as #31 (which also mentions
chargeFundingRate, without details though) - impact: this issue - valid medium. #31 - invalid.
If identifiying core reason is enough to make issue valid, then #31 should also be a (valid) dup of this. But I personally think that lack of correct impact should keep it invalid.
As to why it's medium - it requires partyB to be malicious, and since partyB is semi-trusted role - as established in previous contest, all issues caused by malicious partyB should be treated as medium.
Based on all of this I think this should be a valid medium while #31 should remain invalid.
sherlock-admin2
Escalate
I believe this is a valid medium. It is similar to #31 in that it uses nonce increase to block certain functionality, however #31 only lists liquidation as impact (which is invalid), while this issue shows valid impact for partyB to be able to avoid
forceClosePosition. I think function from #31 (deallocate) and alsotransferAllocationcan also be used for the same (increase partyB nonce to preventforceClosePosition).So from my view:
- core reason: the same as #31 (which also mentions
chargeFundingRate, without details though)- impact: this issue - valid medium. #31 - invalid.
If identifiying core reason is enough to make issue valid, then #31 should also be a (valid) dup of this. But I personally think that lack of correct impact should keep it invalid.
As to why it's medium - it requires partyB to be malicious, and since partyB is semi-trusted role - as established in previous contest, all issues caused by malicious partyB should be treated as medium.
Based on all of this I think this should be a valid medium while #31 should remain invalid.
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.
nevillehuang
Escalate
I believe this is a valid medium. It is similar to #31 in that it uses nonce increase to block certain functionality, however #31 only lists liquidation as impact (which is invalid), while this issue shows valid impact for partyB to be able to avoid
forceClosePosition. I think function from #31 (deallocate) and alsotransferAllocationcan also be used for the same (increase partyB nonce to preventforceClosePosition).So from my view:
- core reason: the same as xiaoming90 - PartyB can block liquidation by incrementing the nonce #31 (which also mentions
chargeFundingRate, without details though)- impact: this issue - valid medium. xiaoming90 - PartyB can block liquidation by incrementing the nonce #31 - invalid.
If identifiying core reason is enough to make issue valid, then #31 should also be a (valid) dup of this. But I personally think that lack of correct impact should keep it invalid.
As to why it's medium - it requires partyB to be malicious, and since partyB is semi-trusted role - as established in previous contest, all issues caused by malicious partyB should be treated as medium.
Based on all of this I think this should be a valid medium while #31 should remain invalid.
Agree with this escalation. Unless there is a sufficient penalty mechanism in place for partyB to avoid abusing this vulnerability, this submission should be a valid medium. And given #31 wrongly identifies the attack path from the root cause, it is a valid low based on sherlocks rule here and thus is invalid:
- In addition to this, there is a submission D which identifies the core issue but does not clearly describe the impact or an attack path. Then D is considered low.
securitygrid
Agree that this is M since some issues about malicious partyB were M in previous contest.
hrishibhat
Result: Medium Unique Considering this a valid issue on its own based on the above comments
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- securitygrid: accepted
- panprog: accepted
MoonKnightDev
Fixed Code PR: https://github.com/SYMM-IO/symmio-core/pull/37/commits/80eb930a4c8ba8f4a89f17ad085412f9a41a11cd
xiaoming9090
Verified. Fixed in https://github.com/SYMM-IO/symmio-core/commit/80eb930a4c8ba8f4a89f17ad085412f9a41a11cd.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity doS bug in Symmetrical Update. Sherlock made it public on 19 September 2023. Found in the 108 audit contest (finding M-5).
About DoS
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.