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

Variable `sizeInTokens` is Actually Storing the Position Size in USD

RootCause & Where It Happens

In the very beginning of getPositionInfo(...):

function getPositionInfo(
bytes32 key,
MarketPrices memory prices
) external view returns (PositionData memory) {
// Name is 'sizeInTokens', but we call getPositionSizeInUsd(key)
uint256 sizeInTokens = getPositionSizeInUsd(key);
if (sizeInTokens == 0) {
// ...
}
// ...
}

Notice:

  1. The code calls getPositionSizeInUsd(key), which returns the position’s size in USD.

  2. It stores this USD value in a local variable incorrectly named sizeInTokens.

  3. It then performs if (sizeInTokens == 0) { ... }, which actually checks if sizeInUsd == 0, not if sizeInTokens == 0.

Later, the function references the real positionInfo.position.numbers.sizeInTokens from the GMX reader, which is the actual token-based size. This mismatch in variable naming is more than a simple naming error; it can lead to subtle logic or debugging errors if a developer assumes that sizeInTokens indeed holds a token-based size.

Impact

  • Confusion and Potential Logic Mistakes: Another developer reading or modifying the contract might assume sizeInTokens is measured in tokens, but it is actually measured in USD. This can cause them to write incorrect conditionals or calculations.

  • Inconsistent Data Checks: The code’s early check if (sizeInTokens == 0) is a check on “sizeInUsd,” contradicting the variable name. If, for instance, a future extension references this local variable for token logic, it will behave incorrectly.

Recommended Remediation

  1. Rename the Local Variable from sizeInTokens to sizeInUsd (or similar), making it consistent with the actual data from getPositionSizeInUsd(key).

  2. Ensure that calls or conditionals referencing sizeInTokens do not incorrectly treat it as tokens.

  3. Add Comments clarifying that the function is skipping the entire read logic if the position’s USD size is zero, not if its token-based size is zero.

Updates

Lead Judging Commences

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

invalid_getPosition_sizeInTokens_value_in_USD

Only check if there are no tokens. Checking if USD is 0 is equivalent. There is no problem here, even if the variable has an incorrect name: Informational.

Support

FAQs

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