Skip to content
Request an audit

‹ All findings

trimDuplicatePools() is very expensive, having O(n^2) complexity and could be simplified

Low/InfoNftperp Matching Engine·Three Sigma · NFT perpetuals · 29th January, 20243S-NFTPerp-N06

Description

ammRouter:trimDuplicatePools() eliminates duplicate pools in the input by comparing every element of the array for duplicates, which is very expensive.

Note: the function is actually useless as it is impossible to add liquidity in duplicate pools. It would revert with error "SANDWICH".

Recommendation

Force the user to input pool indexes ordered and if there are duplicates, revert. Here is an example of safe using this technique.

Status

Addressed in #8c1e930