when withdrawing margin the validateMarginRequirement check is bypassed when requiredInitialMarginUsdX18 and marginBalanceUsdX18 are equal which means the function may allow users to withdraw funds down to the maintenance margin, increasing the risk of liquidation.
here is the check which is supposed to prevent user from withdrawing to the maintainance margin.
check against initial margin requirement as initial margin > maintanance margin
hence prevent the user from withdrawing all the way to the maintenance margin
so that they couldn't be liquidated very soon afterwards if their position
goes against them even a little bit
in , validateMarginRequirement
it uses gt which becomes true when both values are equal.
high risk of user being liquidated.
manual review
use gte() instead of gt().
liquidation fee is not added when calculating LiquidationBranch:isLiquidatable
The LiquidationBranch:isLiquidatable function does not include the liquidation fee when determining if an account is liquidatable. The function only compares the required maintenance margin to the margin balance, which is inconsistent with the documented formula.
The current implementation of the LiquidationBranch:isLiquidatable function does not match with the documentation. This function only computes the required maintenance margin to the margin balance, excluding the liquidation fee.
formula for calculating isLiquidatable in the documentation
$ isLiquidatable={ requiredMM+ liquidationFeeUsd ≥ marginBalanceUsd }$.
The function behavior does not match the documented formula.
manual review
add liquidationFeeUsdX18
to calculate isLiquidatable
branches could be upgraded to empty addresses
Branches might be upgraded to empty addresses if the length of initializables and initializePayloads does not match the length of branchUpgrades.
there is no check for the length sizes for initializables and initilaizePayloads.
if these two parameters are not equal to branchUpgrades the slots which are empty will initialize the empty addresses.
The contract might initialize branches incorrectly,which leads to incomplete upgrades.
manual review
add a validation step at the beginning of the upgrade function to ensure that all arrays have the same length.
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.