<!-- canonical: https://0xsimao.com/findings/ostium-callback-executes-worse-price -->

# executeAutomationOpenOrderCallback Executes STOP Orders at a Worse Price

Low/Info · Three Sigma · RWA perpetuals DEX · 19th February, 2024

Finding 3S-OS-L03 of the Ostium security review.

- Protocol: https://www.ostium.com/
- Report: /reports/ostium
- Source: https://cdn.sanity.io/files/qoqld077/production/a95b9c69e0f65d1d6b0e649f0d62a362358ca8ce.pdf

---

### Description

The condition executed when the OpenOrderType is of type STOP, as seen [here](https://github.com/0xOstium/smart-contracts-threeSigma/blob/1b70cffbac621d39e321c159e45c048b703add92/src/OstiumTradingCallbacks.sol#L274), triggers
when the current price is greater than or equal to the target price. This approach results in
traders potentially receiving a worse price compared to using price after impact >=
target price. This is because when buying, the price typically rises, meaning that the
target price may be reached sooner than when using the current market price.

### Recommendation

Use:
cancelReason = ( o.orderType == IOstiumTradingStorage.OpenOrderType.LIMIT
? (o.buy ? priceAfterImpact > o.targetPrice : priceAfterImpact <
o.targetPrice)
- : (o.buy ? uint192(a.price) < o.targetPrice : uint192(a.price) >
o.targetPrice) +
: (o.buy ? priceAfterImpact < o.targetPrice : priceAfterImpact >
o.targetPrice) )

### Status

Acknowledged

---

Related findings:

- [Major insolvency risk in LiquidationLogic::executeCrossLiquidateERC721() due to not setting a maximum liquidation price](https://0xsimao.com/findings/benddao-insolvency-liquidation-liquidate-erc721): BendDAO
