# Vault rebalancing can be exploited if two vaults rebalance into the same vault

Reentrancy via malicious ERC20 in Mimo auto-rebalance lets attacker reenter a second vault's rebalance, double-counting shared vault value to siphon funds.

- Payout: Contest reward
- Severity: medium
- Program: Mimo DeFi
- Credited: 0x52
- Disclosed: 2022-10-17
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2022-08-mimo-findings/issues/39
- Library page: https://bugbountylibrary.com/r/c4%3A2022-08-mimo%3AM-01
- Tags: domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:chained vuln:accounting-error vuln:reentrancy

**Target:** MIMOAutoRebalance.rebalance swap path
**Root cause:** rebalance performs arbitrary swaps through attacker-supplied tokens without a reentrancy guard, so a malicious token can reenter rebalance on another vault before the first vault's value snapshot is updated.
**Steps:**
1. Vaults A and C both rebalance into vault B; both eligible for rebalance.
2. Call `rebalance` on vault A; it snapshots vault B value ($100) then swaps via malicious ERC20.
3. Malicious token reenters `rebalance` on vault C, which also snapshots vault B as $100 (unchanged).
4. Vault C swaps flashloan to $50 of asset B, deposits into B, repays flashloan, validates B=$150.
5. Control returns to vault A rebalance, which siphons swapped funds to attacker via malicious pool and validates B=$150 without depositing.
**How found:** Recognized swap data is fully arbitrary and can route through a malicious ERC20, giving control transfer mid-rebalance; hypothesized two vaults rebalancing into the same vault would double-count value.
**Exploitation:** Attacker supplies malicious ERC20 in swap data to gain control mid-swap, reenters a second vault's rebalance to inflate the shared destination vault's value, then lets the first rebalance complete and siphons funds through the malicious pool, stealing up to half the total rebalance amount.
**Insight:** When a function snapshots a shared pool/vault value then performs an external arbitrary-token swap, check whether reentering via a second path that writes the same shared value lets you inflate it before the first path's validation.
