<!-- canonical: https://0xsimao.com/findings/ostium-watch-list-complexity-reduced -->

# OstiumLinkUpKeep:removeFromWatchList() complexity could be reduced

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

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

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

---

### Description

[OstiumLinkUpKeep:removeFromWatchList()](https://github.com/0xOstium/smart-contracts-threeSigma/blob/dev/src/OstiumLinkUpKeep.sol#L163) currently iterates over the full
s_registryWatchLists to find the keeperIds and delete them if equal. This has O(n^2)
complexity, which could cost a significant amount of gas.

### Recommendation

One way to tackle this problem is tweaking the isInWatchList mapping to store the index
of the array instead of a bool, adding 1 to each index so that 0 is not a valid index and can be
used to check for abcense. This way, when removing, the index can be fetchd from the
corresponding mapping.

### Status

Acknowledged
