<!-- canonical: https://0xsimao.com/findings/nftperp-i-partially-underflow-price-significantly -->

# Partially removing liquidity may underflow if the price of the pool has changed significantly

Medium · Three Sigma · NFT perpetuals · 2nd January, 2024

Finding 3S-NFTPerp-L04 of the Nftperp Exchange security review.

- Report: /reports/nftperp-i
- Source: https://cdn.sanity.io/files/qoqld077/production/c19530de75e234ad15694b4563edb1fc9d2a3fd8.pdf

---

### Description

[removeLiquidity()](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/1c16f2010a851ac23aec73822d55388901bbe5e7/src/AMM.sol#L654-L655) updates the position quote and base amount based on the removed
quote and base amounts. However, if the proportions changed since the position was
opened, it may underflow.

### Recommendation

Reduce the quote and base amounts of the position pro-rata to the removed shares.

### Status

Addressed in the AMMRouter

---

Related findings:

- [Call _updateMarkPrice() whenever markPrice is changed](https://0xsimao.com/findings/nftperp-ii-mark-price-whenever-changed): Nftperp Matching Engine
- [Index underflow is not protected against, although it has no impact as the pool with index type(uint256).max should not be registered](https://0xsimao.com/findings/nftperp-ii-index-underflow-impact-registered): Nftperp Matching Engine
- [Unconditional lastUpdated advance in RangePool.sync leads to loss of streamed BMX when pool liquidity == 0](https://0xsimao.com/findings/bmx-unconditional-range-streamed-bmx): BMX
- [Add a 0 address check on the pool when adding liquidity for greater verbosity](https://0xsimao.com/findings/nftperp-ii-add-adding-greater-verbosity): Nftperp Matching Engine
