<!-- canonical: https://0xsimao.com/findings/nftperp-i-price-reverts-happen-entirely -->

# _getPriceToTick() reverts if the price is smaller than 1e10, which may happen in _search() as it assumes the final tick as going entirely to the amm

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

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

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

---

### Description

_search() calculates the final tick as if the order is completely filled on the amm. This
means that if a significant chunk of the liquidity is in the limit orders, if a user has an order
bigger than the current amm liquidity, it may return 1e7 from
[amm.getMarkPriceAfterOpen()](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/1c16f2010a851ac23aec73822d55388901bbe5e7/src/AMM.sol#L1170), which reverts in [_getPriceToTick()](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/1c16f2010a851ac23aec73822d55388901bbe5e7/src/ClearingHouseBase.sol#L490), as it divides by 1e10 and
reverts when [calculating](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/1c16f2010a851ac23aec73822d55388901bbe5e7/src/math/TickMath.sol#L63) the tick.

### Recommendation

Return 1e10 instead of 1e7 so that it does not round down to 0 in _getPriceToTick().

### Status

Addressed in the AMMRouter

---

Related findings:

- [getDepositFeeInBNB() assumes a stablecoin price of 1 USD, which may not be true if it depegs](https://0xsimao.com/findings/clip-finance-i-deposit-fee-price-depegs): Clip Finance Strategies
- [Price deviation as is can be circumvented by making smaller trades in a loop](https://0xsimao.com/findings/nftperp-ii-price-deviation-circumvented-loop): Nftperp Matching Engine
- [OstiumPriceUpKeep::performUpKeep() does not correctly handle possible reverts](https://0xsimao.com/findings/ostium-price-perform-correctly-reverts): Ostium
