Submitted by sinarette, also found by adriro and Jigsaw.
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/poolsUtility/Position.sol#L280-L302 https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/poolsUtility/Position.sol#L210-L223
Opening a leveraged position goes through some cycles of supplying collateral and borrowing. Since the leverage is larger than 1, the borrowed amount is usually larger than the liquid asset. So in most cases, you would need to repeat the loop backwards (repay, redeem, swap). However, closePosition tries to repay the whole borrowed amount at once, which would revert. As a result, the user would fail to close a position if he has no extra liquid assets.
closePosition first repays the borrowed asset, then redeems the collateral and closes the position:
_repay would always try to repay the whole borrowed quote tokens, so first it would sell the asset tokens for quote tokens. However, since this is a leveraged position, there wont be enough asset tokens to sell here:
It would try to replenish the asset tokens from the owner, which would fail if theres not enough balance:
The below test shows that the position closing would revert if theres not enough assets:
Hardhat
Add a repay loop (repay - redeem - swap), or enable partially closing positions.
daoio (Rubicon) disagreed with severity, disputed and commented:
HickupHH3 (judge) decreased severity to Medium and commented:
