Logic error in fee subtraction
The fee calculation in LibBalances.applyTrade() incorrectly adds the fee to the long position instead of subtracting it from both positions. This causes the contract to believe it can withdraw collected fees, leaving users with an incorrect amount of quote tokens.
Submitted by 0xsanson
In LibBalances.applyTrade(), we need to collect a fee from the trade. However, the current code subtracts a fee from the short position and adds it to the long. The correct implementation is to subtract a fee to both (see TracerPerpetualSwaps.sol L272). This issue causes withdrawals problems, since Tracer thinks it can withdraw the collect fees, leaving the users with an incorrect amount of quote tokens.
Recommend changing +fee to -fee in the highlighted line.
Valid issue 👍
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 a sign error in the fee adjustment: the code used addition instead of subtraction for the long position's fee.
Impact
The contract may allow withdrawals of fees that were never actually collected, reducing users' quote token balances incorrectly.
What the attacker needed
None
The fix
The fee should be subtracted from both the long and short positions, as done in TracerPerpetualSwaps.sol.
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 a trading system, fees should be taken from both the buyer and the seller. Here, the code accidentally gave the fee to one side instead of taking it from both, so the system thought it had extra money to withdraw, which would leave users short.
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.