<!-- canonical: https://0xsimao.com/findings/nftperp-ii-index-underflow-impact-registered -->

# Index underflow is not protected against, although it has no impact as the pool with index type(uint256).max should not be registered

Low/Info · Three Sigma · NFT perpetuals · 29th January, 2024

Finding 3S-NFTPerp-N04 of the Nftperp Matching Engine security review.

- Report: /reports/nftperp-ii
- Source: https://cdn.sanity.io/files/qoqld077/production/87f617e82d5468500e950a669f30607376b37c32.pdf

---

### Description

The following places do an unchecked increment/decrement, but the index could underflow
and become type(uint256).max. This has no consequences with the code as is, but it's
better to revert for underflows.
https://github.com/nftperp/NFTPerp-V2-Contracts/blob/8ea05fc0ecf299ca8374b571486846652c8725f8/src/AMMRouter.sol#L667
https://github.com/nftperp/NFTPerp-V2-Contracts/blob/8ea05fc0ecf299ca8374b571486846652c8725f8/src/AMMRouter.sol#L1087-L1092
https://github.com/nftperp/NFTPerp-V2-Contracts/blob/8ea05fc0ecf299ca8374b571486846652c8725f8/src/ClearingHouseBase.sol#L477

### Status

Acknowledged

---

Related findings:

- [ClampLib::mulDivDownInverse reverts on `target == type(uint256).max` before the overflow guard runs](https://0xsimao.com/findings/tenor-markets-reverts-overflow-guard-runs): Tenor Morpho Migrations
- [DOS on liquidation type 1 due to underflow in cds profits computation](https://0xsimao.com/findings/autonomint-dos-liquidation-underflow-computation): Autonomint
- [OstiumTrading::topUpCollateral() is missing pairsStored.groupMaxCollateral(pairIndex) check](https://0xsimao.com/findings/ostium-collateral-pairs-stored-index): Ostium
- [Partially removing liquidity may underflow if the price of the pool has changed significantly](https://0xsimao.com/findings/nftperp-i-partially-underflow-price-significantly): Nftperp Exchange
