RootCause & Where It Happens
In the very beginning of getPositionInfo(...)
:
Notice:
The code calls getPositionSizeInUsd(key)
, which returns the position’s size in USD.
It stores this USD value in a local variable incorrectly named sizeInTokens
.
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.
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.
Rename the Local Variable from sizeInTokens
to sizeInUsd
(or similar), making it consistent with the actual data from getPositionSizeInUsd(key)
.
Ensure that calls or conditionals referencing sizeInTokens
do not incorrectly treat it as tokens.
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.
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.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.