sherlock-audit / 2023-05-perennial-judging

12 stars 9 forks source link

mstpr-brainbot - Potential Vault Rebalancing Failure due to Zero Target Collateral #206

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

mstpr-brainbot

high

Potential Vault Rebalancing Failure due to Zero Target Collateral

Summary

The rebalancing process of a vault can fail if the target collateral is computed as "0". This typically happens when the collateral balance falls below the controller's minimum collateral balance. In such a situation, for the vault to fully remove the collateral, it should first close its position. If not handled properly, this could lead to a failure in the vault's rebalancing operation.

Vulnerability Detail

A vault could potentially fail to rebalance if the calculated target collateral is "0". This situation can occur if the collateral balance is less than the minimum collateral balance as specified by the controller. In its normal operation, the vault first attempts to remove collateral before updating its position. However, if there is some position open, fully removing the collateral would require the vault to close its position prior to the collateral removal. If this isn't managed appropriately, the vault's rebalancing process could fail.

Impact

Code Snippet

https://github.com/sherlock-audit/2023-05-perennial/blob/main/perennial-mono/packages/perennial-vaults/contracts/balanced/BalancedVault.sol#L440-L533

Tool used

Manual Review

Recommendation

First remove the position then the collateral

Duplicate of #66