When unwinding a leveraged position, the protocol calculates how much collateral can be withdrawn after repaying debt. The calculation should use the LTV (Loan-to-Value) ratio, which represents the maximum borrowing power of collateral. However, the code incorrectly uses liquidationThreshold, which is a higher threshold used for liquidation risk assessment. The liquidation threshold is typically 5-10% higher than LTV (e.g., LTV = 80%, liquidation threshold = 85%), meaning the formula extracts less collateral than it should. Additionally, the code comments explicitly state that LTV should be used, creating a discrepancy between documentation and implementation.
Likelihood:
This calculation runs on every unwindPosition call where the protocol calculates collateral withdrawal internally.
The code comments explicitly state LTV should be used, indicating this was the intended design, making the use of liquidation threshold a clear implementation error.
Impact:
Reduced Withdrawal Amount: Users receive less collateral than they should when unwinding positions. For example, if LTV = 80% and liquidation threshold = 85%, repaying $1000 debt would allow withdrawal of $1250 collateral (using LTV) but only $1176.47 collateral (using liquidation threshold), a difference of $73.53 per $1000 debt.
Code Documentation Mismatch: The discrepancy between comments and implementation creates confusion and makes the code harder to maintain and audit.
Fix the code to use LTV as indicated by the comments:
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.
The contest is complete and the rewards are being distributed.