StopLoss/TakeProfit should be validated again for the new price in Trading.executeLimitOrder()
The executeLimitOrder function updates the trade price for stop orders but does not re-validate the stop-loss and take-profit levels against the new price. An attacker could have a limit order execute at a price that immediately triggers the take-profit, causing an unexpected loss for the user.
But it doesn’t validate sl/tp again for the new price so the order might have an invalid sl/tp.
The new price wouldn’t satisfy the sl/tp requirements when the price was changed much from the original price due to the high slippage and the order might be closed immediately by sl or tp in this case.
Originally, the protocol validates stoploss only but I say to validate both of stoploss and takeprofit. (I submitted it as another issue to validate tp as well as sl).
Recommended Mitigation Steps
Recommend validating sl/tp for the new trade.price in Trading.executeLimitOrder().
Ultimately it looks like trade.price is changed to the new price from the feed, which is a “correct” price, but may not be a price the caller was originally willing to act on (not in range with SL / TP).
The warden has shown how, due to a lack of check, limit orders that pass the logic check may be executed even though the validation for their Stop Loss / Take Profit may not be hit
Given the level of detail I believe the finding to be of Medium Severity.
Since this issue only affects TP and not SL, I only added a check for that.
The original report as published on Code4rena, by hansfriese. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the code updates trade.price for stop orders without re-checking that the stop-loss and take-profit values are still valid relative to the new price.
Impact
The executed market order might be closed immediately, causing an unexpected loss for users.
What the attacker needed
A stop order with SL/TP; price moves significantly
The fix
The issue was fixed by adding a check for take-profit only, since the problem affects TP and not SL.
How it was found
A user places a stop order with stop-loss and take-profit levels.
The order is executed via executeLimitOrder and the price is updated to the current market price.
The new price is far from the original, making the stop-loss or take-profit invalid.
The position is closed immediately, causing an unexpected loss.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
In trading, a stop-loss and take-profit are safety orders that automatically close a position at certain prices. This report says that when a special type of order (a stop order) is executed, the system updates the entry price but forgets to check that the safety orders still make sense for the new price. So the position could be closed right away at a loss.
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.