Skip to content
Business logic Audit finding Intermediate

Fee collector can grief the protocol by withdrawing trading fees that could still need to be returned to Party A

The fee collector can withdraw all trading fees, leaving insufficient balance to refund fees to Party A when a quote is cancelled or expires, causing an underflow that blocks several functions. This griefs the protocol by temporarily denying service until the fee collector's balance is replenished.

AkshaySrivastav Follow with Ch_301, Lilyjjo and 5 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-06-symmetrical-judging/issues/299

Found by

AkshaySrivastav, Ch_301, Lilyjjo, Ruhum, berndartmueller, bitsurfer, libratus, simon135

Summary

The fee collector can grief the SYMM protocol by withdrawing the collected trading fees, resulting in an underflow error when attempting to return trading fees to Party A due to the lack of available funds.

Vulnerability Detail

Trading fees are collected whenever Party A creates a new quote via the sendQuote function in the PartyAFacetImpl library. The accumulated fees are accounted for in the accountLayout.balances[GlobalAppStorage.layout().feeCollector] storage variable, the same balances mapping that is also used to account for the balances for Party A and Party B. The fee collector can withdraw the received trading fees at any time with the deposit function in the AccountFacet contract.

However, as trading fees are potentially returned to Party A, for example, when a quote gets canceled or expires, deducting the returned trading fees from the fee collector's balance can potentially revert with an underflow error if the balance is insufficient.

Impact

If insufficient funds are available in the fee collector's balance (accountLayout.balances[GlobalAppStorage.layout().feeCollector]), attempting to return trading fees to Party A will revert with an underflow error. This will grief and DoS the following functions until the fee collector's balance is sufficiently replenished:

  • PartyAFacetImpl.requestToCancelQuote in line 136
  • PartyAFacetImpl.forceCancelQuote in line 227
  • PartyBFacetImpl.acceptCancelRequest in line 70
  • PartyBFacetImpl.openPosition in line 231
  • LibQuote.expireQuote in line 241

Code Snippet

contracts/libraries/LibQuote.sol#L139

Solidity
135: function returnTradingFee(uint256 quoteId) internal {
136:     AccountStorage.Layout storage accountLayout = AccountStorage.layout();
137:     uint256 tradingFee = LibQuote.getTradingFee(quoteId);
138:     accountLayout.allocatedBalances[QuoteStorage.layout().quotes[quoteId].partyA] += tradingFee;
139:     accountLayout.balances[GlobalAppStorage.layout().feeCollector] -= tradingFee; // @audit-issue potentially reverts with an underflow error
140: }

Tool used

Manual Review

Recommendation

Consider accounting the received trading fees in separate variables and keep track of the fees which can still be returned to Party A and only allow withdrawing the received fees that are non-returnable.

Discussion

securitygrid

Escalate for 10 usdc This is not valid M. This is not permanent, only temporary. Insufficient funds are available in the fee collector's balance, which occurs when the collector withdraws most of the balance. fee collector should be from protocol. so this is an administrator error.

sherlock-admin2

Escalate for 10 usdc This is not valid M. This is not permanent, only temporary. Insufficient funds are available in the fee collector's balance, which occurs when the collector withdraws most of the balance. fee collector should be from protocol. so this is an administrator error.

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.

CodingNameKiki

Should be invalid, admins are trusted authors.

berndartmueller

The fee collector (feeCollector) is not necessarily the admin of the protocol (i.e., the fee collector address is not controlled by the admin). Thus the medium severity.

mstpr

Escalate

fee collector address is set by the admin role which admin is trusted hence the fee collector should also be trusted.

https://github.com/sherlock-audit/2023-06-symmetrical/blob/6d2b64b6732fcfbd07c8217897dd233dbb6cd1f5/symmio-core/contracts/facets/control/ControlFacet.sol#L235-L240

sherlock-admin2

Escalate

fee collector address is set by the admin role which admin is trusted hence the fee collector should also be trusted.

https://github.com/sherlock-audit/2023-06-symmetrical/blob/6d2b64b6732fcfbd07c8217897dd233dbb6cd1f5/symmio-core/contracts/facets/control/ControlFacet.sol#L235-L240

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.

JeffCX

Escalate

fee collector address is set by the admin role which admin is trusted hence the fee collector should also be trusted.

https://github.com/sherlock-audit/2023-06-symmetrical/blob/6d2b64b6732fcfbd07c8217897dd233dbb6cd1f5/symmio-core/contracts/facets/control/ControlFacet.sol#L235-L240

Agree with this escalation

Solidity
    function setFeeCollector(
        address feeCollector
    ) external onlyRole(LibAccessibility.DEFAULT_ADMIN_ROLE) {
        emit SetFeeCollector(GlobalAppStorage.layout().feeCollector, feeCollector);
        GlobalAppStorage.layout().feeCollector = feeCollector;
    }

MoonKnightDev

Fixed code PR link: https://github.com/SYMM-IO/symmio-core/pull/8

hrishibhat

Result: Medium Has duplicates After further review and internal discussion, the ownership of the fee collector is not relevant in the context of this report. The reason is that there is a logic error in the code, and it must be fixed. So when the users request to open a position, their trading fee is temporarily locked/escrowed in the contract under the fee collector account. If the users decide to cancel their pending position later, the trading fee will be refunded to the users. The main bug is that if the fee collector collects all the fees, there won't be any locked funds left in the fee collector account to refund the users if they cancel the position. The fees collected must be regularly distributed to the stakers. The issue here is all the fees pending/settled is together under once account. So although the fee collector can be considered TRUSTED, the fee collector can still make the protocol malfunction by behaving in a trusted way, by claiming the fees. Considering this a valid medium.

sherlock-admin2

Escalations have been resolved successfully!

Escalation status:

The original report as published on Sherlock, by AkshaySrivastav. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

Likely, the contract uses a single balance for both withdrawable fees and fees that may need to be refunded, so withdrawing all fees leaves insufficient balance for refunds.

Impact

If the fee collector withdraws fees, returning trading fees to Party A can revert with an underflow, temporarily blocking functions such as requestToCancelQuote, forceCancelQuote, acceptCancelRequest, openPosition, and expireQuote until the balance is replenished.

What the attacker needed

Fee collector withdraws fees; Party A cancels or quote expires

The fix

The fees that may need to be returned should be accounted for separately, and only non-returnable fees should be withdrawable.

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 smart contract, trading fees are held in a special account for the fee collector. If the fee collector takes out all the fees, there is no money left to give back to users when they cancel a trade. This causes the contract to fail when it tries to return the fee, blocking several actions until more fees are collected.

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.

More by AkshaySrivastav

View all

16 more disclosed reports, best first.

More from Symmetrical Update

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.