DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: low
Invalid

Incorrect Open Interest Calculations

Summary

The function willPositionCollateralBeInsufficient checks open interest but does not verify if sizeDeltaUsd exceeds current position size:

if sizeDeltaUsd > positionInfo.position.numbers.sizeInUsd, calculations become invalid.

Vulnerability Details

function willPositionCollateralBeInsufficient(
MarketPrices memory prices,
bytes32 positionKey,
address market,
bool isLong,
uint256 sizeDeltaUsd,
uint256 collateralDeltaAmount
) external view returns (bool) {
if (getPositionSizeInUsd(positionKey) == 0) return true;
PositionInfo memory positionInfo = gmxReader.getPositionInfo(
address(dataStore),
referralStorage,
positionKey,
prices,
uint256(0),
address(0),
true
);
int256 realizedPnlUsd;
if (positionInfo.basePnlUsd > 0) {
@>> realizedPnlUsd = (uint256(positionInfo.basePnlUsd) * sizeDeltaUsd / positionInfo.position.numbers.sizeInUsd).toInt256();
} else {
@>> realizedPnlUsd = -(uint256(-positionInfo.basePnlUsd) * uint256(sizeDeltaUsd) / uint256(positionInfo.position.numbers.sizeInUsd)).toInt256();
}
MarketUtils.WillPositionCollateralBeSufficientValues memory values = MarketUtils.WillPositionCollateralBeSufficientValues({
positionSizeInUsd: positionInfo.position.numbers.sizeInUsd - sizeDeltaUsd,
positionCollateralAmount: positionInfo.position.numbers.collateralAmount - collateralDeltaAmount,
realizedPnlUsd: realizedPnlUsd,
openInterestDelta: -int256(sizeDeltaUsd)
});
MarketProps memory marketInfo = getMarket(market);
(bool willBeSufficient, ) = MarketUtils.willPositionCollateralBeSufficient(
dataStore,
marketInfo,
prices,
isLong,
values
);
return !willBeSufficient;return !willBeSufficient;

Impact

Attackers could force the contract to return incorrect insufficiency results, affecting liquidations and collateral calculations.

Positions might become impossible to close properly.

Tools Used

Recommendations

require(sizeDeltaUsd <= positionInfo.position.numbers.sizeInUsd, "sizeDeltaUsd exceeds position size");

Updates

Lead Judging Commences

n0kto Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Suppositions

There is no real proof, concrete root cause, specific impact, or enough details in those submissions. Examples include: "It could happen" without specifying when, "If this impossible case happens," "Unexpected behavior," etc. Make a Proof of Concept (PoC) using external functions and realistic parameters. Do not test only the internal function where you think you found something.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.