Skip to content
Request an audit

‹ All findings

Misleading error name

Low/InfoNftperp Matching Engine·Three Sigma · NFT perpetuals · 29th January, 20243S-NFTPerp-N09

Function closePosition() 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