<!-- canonical: https://0xsimao.com/findings/nftperp-ii-mark-price-whenever-changed -->

# Call _updateMarkPrice() whenever markPrice is changed

Medium · Three Sigma · NFT perpetuals · 29th January, 2024

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

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

---

### Description

Functions [addLiquidity()](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/8ea05fc0ecf299ca8374b571486846652c8725f8/src/AMMRouter.sol#L291) and [removeLiquidity()](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/8ea05fc0ecf299ca8374b571486846652c8725f8/src/AMMRouter.sol#L350) change mark price but don't call
_updateMarkPrice(). Since these functions are meant to add/remove liquidity, the price
isn't expected to fluctuate drastically, but numerical approximations and the use of virtual
reserves can lead to some price fluctuation. Calling _updateMarkPrice() would take a new
snapshot of the price ensuring consistency between the markPrice variable and the
snapshots on storage, as well as protect users in case of price fluctuation.

### Recommendation

Call _updateMarkPrice() to update the markPrice instead of changing this variable
directly

### Status

Addressed in [#1423a79](https://github.com/nftperp/NFTPerp-V2-Contracts/commit/1423a790f8be9a80ed0492d3ab704ae3cf93a57e)

---

Related findings:

- [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
- [Unused UPDATE_SL OstiumPriceUpKeep::OrderType](https://0xsimao.com/findings/ostium-unused-price-keep-type): Ostium
