<!-- canonical: https://0xsimao.com/findings/nftperp-i-price-below-bounds-underflows -->

# Swapping amounts that would send the price below/above the bounds of the amm underflows without a reason

Low/Info · Three Sigma · NFT perpetuals · 2nd January, 2024

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

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

---

### Description

For example, [_getBaseValue()](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/1c16f2010a851ac23aec73822d55388901bbe5e7/src/AMM.sol#L1348) calculates the base amount according to the k using the
virtual reserves; however, some amounts will return a base amount bigger than the real
reserves, silently underflowing when updating the reserves in [swapOpen()](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/1c16f2010a851ac23aec73822d55388901bbe5e7/src/AMM.sol#L344).

### Recommendation

Add a revert message if the base/quote amount calculated is bigger than the real
base/quote reserves.

### Status

Addressed in the AMMRouter

---

Related findings:

- [`LenderCommitmentGroup_Smart` picks the wrong Uniswap price, allowing borrowing at a discount by swapping before withdrawing](https://0xsimao.com/findings/teller-finance-picks-uniswap-price-allowing): Teller Finance
