The LiquidationBranch contract in Zaros' perpetual trading system is responsible for managing liquidations of trading accounts. A critical issue has been identified in the liquidateAccounts function where the deductAccountMargin function is called with an incorrect parameter. Specifically, the pnlUsdX18 parameter is incorrectly set to the value of requiredMaintenanceMarginUsdX18 instead of the actual unrealized profit and loss (accountTotalUnrealizedPnlUsdX18). This discrepancy could lead to inaccuracies in margin deductions and liquidation processes.
Parameter Mismatch:
In the LiquidationBranch::liquidateAccounts() function, the deductAccountMargin function is invoked with the pnlUsdX18 parameter set to requiredMaintenanceMarginUsdX18, which is not appropriate.
LiquidationBranch.sol#L152-L161
Intended Usage:
The pnlUsdX18 parameter should reflect the account's actual unrealized profit and loss (accountTotalUnrealizedPnlUsdX18), not the required maintenance margin (requiredMaintenanceMarginUsdX18).
Using requiredMaintenanceMarginUsdX18 instead of accountTotalUnrealizedPnlUsdX18 for pnlUsdX18 will lead to incorrect margin deductions. This can cause either excessive or insufficient deductions, potentially resulting in erroneous liquidations and financial instability for traders.
Manual code review
Parameter Correction: modify the call to deductAccountMargin to use the correct parameter for unrealized PnL. Replace requiredMaintenanceMarginUsdX18 with accountTotalUnrealizedPnlUsdX18 in the pnlUsdX18 parameter.
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.