Skip to content
Business logic Audit finding Intermediate

In case if trading fee will be changed then refund will be done with wrong amount

The trading fee for a quote is calculated using the current fee rate at the time of cancellation, not the rate when the quote was created. If the fee rate changes between creation and cancellation, the refunded fee amount will be incorrect, causing a loss to either the user or the protocol.

0xcrunch Follow with Jiamin, Juntao and 7 others

Originally disclosed on Sherlock

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

Found by

0xcrunch, Jiamin, Juntao, Lilyjjo, circlelooper, libratus, mstpr-brainbot, nobody2018, rvierdiiev, xiaoming90

Summary

In case if trading fee will be changed then refund will be done with wrong amount

Vulnerability Detail

When user creates quote, then he pays trading fees. Amount that should be paid is calculated inside LibQuote.getTradingFee function.

https://github.com/sherlock-audit/2023-06-symmetrical/blob/main/symmio-core/contracts/libraries/LibQuote.sol#L122-L133

SOLDITY
    function getTradingFee(uint256 quoteId) internal view returns (uint256 fee) {
        QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
        Quote storage quote = quoteLayout.quotes[quoteId];
        Symbol storage symbol = SymbolStorage.layout().symbols[quote.symbolId];
        if (quote.orderType == OrderType.LIMIT) {
            fee =
                (LibQuote.quoteOpenAmount(quote) * quote.requestedOpenPrice * symbol.tradingFee) /
                1e36;
        } else {
            fee = (LibQuote.quoteOpenAmount(quote) * quote.marketPrice * symbol.tradingFee) / 1e36;
        }
    }

As you can see symbol.tradingFee is used to determine fee amount. This fee can be changed any time.

When order is canceled, then fee should be returned to user. This function also uses LibQuote.getTradingFee function to calculate fee to return.

So in case if order was created before fee changes, then returned amount will be not same, when it is canceled after fee changes.

Impact

User or protocol losses portion of funds.

Code Snippet

Provided above

Tool used

Manual Review

Recommendation

You can store fee paid by user inside quote struct. And when canceled return that amount.

Discussion

MoonKnightDev

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

The original report as published on Sherlock, by 0xcrunch. 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

Impact

Users or the protocol could lose a portion of funds due to incorrect refund amounts when the trading fee changes.

What the attacker needed

Trading fee rate changes between quote creation and…

The fix

The fee paid by the user should be stored in the quote struct and refunded exactly that amount upon cancellation.

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.

When you create a trade, you pay a fee based on the current fee rate. If you cancel the trade later, the system recalculates the fee using the new rate, not the rate you originally paid. This means you might get back more or less than you paid, which is unfair.

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 0xcrunch

View all

5 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.