<!-- canonical: https://0xsimao.com/findings/nftperp-i-funding-period-calling-settle -->

# setFundingPeriod() can be DoSed due to calling settleFunding()

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

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

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

---

### Description

[setFundingPeriod()](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/1c16f2010a851ac23aec73822d55388901bbe5e7/src/AMM.sol#L856) calls [settleFunding()](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/1c16f2010a851ac23aec73822d55388901bbe5e7/src/ClearingHouse.sol#L523) in the ClearingHouse. It may be the case that
someone frontruns setFundingPeriod() with a call to settleFunding(), making the
setFundingPeriod() transaction revert.

### Recommendation

Make the funding payments pro-rata to time instead of in fixed intervals. This would also
solve the fact that settleFunding() calls can be frontrunned to avoid payments.

### Status

Addressed in [#d75fc8c](https://github.com/nftperp/NFTPerp-V2-Contracts/commit/d75fc8c2b0b96d19ed58d8c9dbd974f1e9b7bd50)

---

Related findings:

- [`Voter::finalize()` incorrect rewards distribution due to transfering WETH before calling `distributor::setTokensPerInterval()`](https://0xsimao.com/findings/bmx-voter-rewards-transfering-weth): BMX
