The TradingAccountBranch::getAccountLeverage
function is susceptible to underflow when handling cases with disproportionately large positions relative to minimal margin balances. This can lead to incorrect leverage calculations or function reverts, potentially disrupting critical operations that rely on accurate leverage information.
A user opens a leveraged long position significantly larger than their deposited margin. If the market experiences even a slight downturn, querying the account's leverage via TradingAccountBranch::getAccountLeverage can cause the function to fail.
Copy the following test in the test suite:
Incorrect leverage calculations can lead to mispricing of positions or misrepresentation of account health to users. It can also destabilize the system if other functions depend on accurate leverage calculations.
Although this issue does not directly cause a loss of funds, it can lead to financial losses due to incorrect decision-making based on inaccurate leverage information.
Manual Testing
Implement a check to ensure the margin balance is not negative, preventing invalid leverage calculations:
Alternatively, use the absolute value of marginBalanceUsdX18
to prevent division by a negative value, which could result in erroneous calculations:
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.