<!-- canonical: https://0xsimao.com/findings/nftperp-ii-misleading-error-name -->

# Misleading error name

Low/Info · Three Sigma · NFT perpetuals · 29th January, 2024

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

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

---

Function [closePosition()](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/8ea05fc0ecf299ca8374b571486846652c8725f8/src/ClearingHouse.sol#L218) of the ClearingHouse contract checks if the size sent as an
argument to this function is smaller than the size of the position to close. If the size to close
is greater than the position size, the execution reverts with error INSUFFICIENT_SIZE. This
error name is misleading and could lead a user into thinking they called the function with
insufficient size, and call the same function again with a greater size, which would lead to
another revert. For clarification, take a look at a simplified code segment illustrating this
issue

```solidity
function closePosition(IRouter amm, uint256 size, uint256 quoteLimit)
external {
    int256 oldSize = _assertOpenPosition(amm, msg.sender);
    uint256 oldSizeAbs = oldSize.abs();
    if (size > oldSizeAbs) revert INSUFFICIENT_SIZE();
    (...)
}
```

### Status

Acknowledged
