MIMOManagedRebalance.sol#rebalance calculates managerFee incorrectly
The manager fee in MIMOManagedRebalance was calculated using the flashloan amount in the collateral asset rather than its PAR value, making the fee unpredictable as the asset's price fluctuates. This could overcharge users or under-incentivise managers, potentially leading to unexpected liquidations.
*Submitted by 0x52*
Inconsistent manager fees could lead to lack of incentivization to rebalance and unexpected liquidation.
### Proof of Concept
```
uint256 managerFee = managedVault.fixedFee + flData.amount.wadMul(managedVault.varFee);
IERC20(a.stablex()).safeTransfer(managedVault.manager, managerFee);
```
The variable portion of the fee is calculated using the amount of the flashloan but pays out in PAR. This is problematic because the value of the flashloan asset is constantly fluctuating in value against PAR. This results in an unpredictable fee for both the user and the manager. If the asset drops in price then the user will pay more than they intended. If the asset increases in price then the fee may not be enough to incentivize the manager to call them. The purpose of the managed rebalance is to limit user interaction. If the manager isn’t incentivized to call the vault then the user may be unexpectedly liquidated, resulting in loss of user funds.
### Recommended Mitigation Steps
varFee should be calculated against the PAR of the rebalance like it is in MIMOAutoRebalance.sol:
```
IPriceFeed priceFeed = a.priceFeed();
address fromCollateral = vaultsData.vaultCollateralType(rbData.vaultId);
uint256 rebalanceValue = priceFeed.convertFrom(fromCollateral, flData.amount);
uint256 managerFee = managedVault.fixedFee + rebalanceValue.wadMul(managedVault.varFee);
```
**[RayXpub (Mimo) confirmed and commented](https://github.com/code-423n4/2022-08-mimo-findings/issues/34#issuecomment-1210609570):**
> We acknowledge this issue and intend to fix it.
**horsefacts (warden) reviewed mitigation:**
> **Status:** �
Resolved
> **Finding:** A warden identified that the variable portion of manager fees in `MIMOManagedRebalance` was calculated incorrectly, based on the amount of the rebalance flash loan denominated in the collateral asset rather than the amount of the rebalance denominated in PAR.
> **What changed:** The Mimo team updated the [fee calculation](https://github.com/mimo-capital/2022-08-mimo/blob/5186ef4be23f9dda81c8474096edb1f0594d70c3/contracts/actions/managed/MIMOManagedRebalance.sol#L61) to calculate the rebalance amount in PAR using a price feed.
> **Why it works:** Since the rebalance amount is now denominated in PAR, it no longer fluctuates in terms of the collateral asset.
---Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
Users could pay more than intended if the collateral price drops, or managers may not be sufficiently incentivised if it rises, potentially leading to unexpected liquidation.
What the attacker needed
Manager calls rebalance; collateral price differs from PAR
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract pays a manager a fee for rebalancing a vault. The fee had a variable part based on the size of a temporary loan, but it was measured in a different currency (the collateral) than the one used for payment (PAR). Because the collateral's price changes, the fee could be too high or too low, which might discourage managers from doing their job and put users at risk of liquidation.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.