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