When unwinding a leveraged position, the protocol should withdraw enough collateral to repay the debt plus the user's remaining equity (margin/profit). The unwindPosition function accepts a collateralToWithdraw parameter that allows users to specify how much collateral they want to withdraw. However, the _executeUnwindOperation function completely ignores this user-provided parameter and instead calculates the withdrawal amount based on the Aave liquidation threshold. This formula calculates the minimum collateral required to back the debt (Debt / LiquidationThreshold), not the total collateral associated with the position. Any collateral exceeding this threshold (the user's equity/profit) is left inside the Aave protocol. Since there are no other functions to withdraw collateral, these funds are permanently locked or only accessible by the owner via recoverTokens.
Likelihood:
This calculation runs on every unwindPosition call. Unless a user's position is exactly at the liquidation threshold (about to be liquidated), they will always have excess collateral (equity).
Impact:
Loss of Funds: Users lose 100% of their equity (margin) when closing a position. For example, if a user deposits $2000 to borrow $1000, and later unwinds, the contract might only withdraw $1250 (to cover the $1000 debt + buffer), leaving $750 of the user's money locked in Aave.
Permanent Lock: Since all positions are stored under the contract address (address(this)) and there is no user-level position tracking, the locked collateral cannot be attributed to specific users or withdrawn individually.
No Recovery Mechanism: The only way to recover these funds is through the recoverTokens function, which requires owner privileges and can only recover tokens in the contract balance, not from Aave positions.
Use the user-provided collateralToWithdraw parameter and add validation to ensure it covers the debt repayment:
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.