<!-- canonical: https://0xsimao.com/findings/ostium-redundant-calculations-trading-trade -->

# Redundant Calculations in OstiumTrading::openTrade()

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

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

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

---

### Description

When opening a LIMIT or STOP order, the first empty index is calculated using
OstiumTradingStorage::firstEmptyOpenLimitIndex() on [L209](https://github.com/0xOstium/smart-contracts-threeSigma/blob/1b70cffbac621d39e321c159e45c048b703add92/src/OstiumTrading.sol#L209). However, the same
function is executed again in OstiumTradingStorage::storeOpenLimitOrder() on [L233](https://github.com/0xOstium/smart-contracts-threeSigma/blob/1b70cffbac621d39e321c159e45c048b703add92/src/OstiumTradingStorage.sol#L233),
which results in the index property being overridden with the same value. Similarly, the
current block number is retrieved on [L211](https://github.com/0xOstium/smart-contracts-threeSigma/blob/1b70cffbac621d39e321c159e45c048b703add92/src/OstiumTrading.sol#L211) in OstiumTrading, and then on [L231](https://github.com/0xOstium/smart-contracts-threeSigma/blob/1b70cffbac621d39e321c159e45c048b703add92/src/OstiumTradingStorage.sol#L231) in
OstiumTradingStorage.

### Recommendation

Remove the redundant overriding of these variables from
OstiumTradingStorage::storeOpenLimitOrder().

### Status

Addressed in [#3d116cd](https://github.com/0xOstium/smart-contracts-threeSigma/pull/58/commits/3d116cd22fbfdaeda8fafbc84176095708316641).
