Skip to content
Business logic Audit finding Intermediate

MIMOEmptyVault.sol executeOperation() does not transfer the Vault leftover assets to the owner, it is locked in the MIMOEmptyVault

The MIMOEmptyVault contract's executeOperation function repaid a flash loan but did not transfer leftover collateral back to the vault owner, leaving the funds locked in the contract. An attacker could not directly steal the funds, but the owner permanently lost access to the excess collateral.

bin2chen Follow

Originally disclosed on Code4rena

*Submitted by bin2chen, also found by Bnke0x0*

`MIMOEmptyVault.sol executeAction()` is supposed to pay off the debt and return the leftover assets to the owner of the Vault. But in fact the emptyVault contract, after executing the executionOperation(), only pays back the flash loan, and does not transfer the leftover assets to the owner, and locked in the emptyVault contract.

### Proof of Concept

```
  function executeOperation(
    address[] calldata assets,
    uint256[] calldata amounts,
    uint256[] calldata premiums,
    address initiator,
    bytes calldata params
  ) external override returns (bool) {

    ....
    ....

    require(flashloanRepayAmount <= vaultCollateral.balanceOf(address(this)), Errors.CANNOT_REPAY_FLASHLOAN);

    vaultCollateral.safeIncreaseAllowance(address(lendingPool), flashloanRepayAmount);

    //****Paid off the flash loan but did not transfer the remaining balance back to mimoProxy or owner ***//

    return true;
  }
```

Add logs to test case

test/02_integration/MIMOEmtpyVault.test.ts

```
  it("should be able to empty vault with 1inch", async () => {
  ...
  ...
  ...
  ++++ console.log("before emptyVault balance:--->", (await wmatic.balanceOf(emptyVault.address)) + "");
    const tx = await mimoProxy.execute(emptyVault.address, MIMOProxyData);
    const receipt = await tx.wait(1);
  ++++ console.log("after emptyVault balance: --->", (await wmatic.balanceOf(emptyVault.address)) + "");
```

print:

```
before emptyVault balance:---> 0
after emptyVault balance: ---> 44383268870065355782
```

### Recommended Mitigation Steps

```
  function executeOperation(
    address[] calldata assets,
    uint256[] calldata amounts,
    uint256[] calldata premiums,
    address initiator,
    bytes calldata params
  ) external override returns (bool) {

    ....
    ....

    require(flashloanRepayAmount <= vaultCollateral.balanceOf(address(this)), Errors.CANNOT_REPAY_FLASHLOAN);

    vaultCollateral.safeIncreaseAllowance(address(lendingPool), flashloanRepayAmount);

    //****transfer the remaining balance back to mimoProxy or owner ***//
    ++++ vaultCollateral.safeTransfer(address(mimoProxy), vaultCollateral.balanceOf(address(this)) - flashloanRepayAmount);

    return true;
  }
```

**[RayXpub (Mimo) confirmed and commented](https://github.com/code-423n4/2022-08-mimo-findings/issues/18#issuecomment-1210512990):**

> We confirm this is a vulnerability and intend to fix this - only the amount needed to repay the flashloan should be transferred from the `MimoProxy` to the `MIMOEmptyVault` action contract.

**horsefacts (warden) reviewed mitigation:**

> **Status:** �
 Resolved

> **Finding:** Wardens identified that `MIMOEmptyVault` transferred in a vault’s full collateral balance when repaying vault rebalance flash loans, but did not return excess collateral to the vault owner when the flash loan repayment amount was less than the vault’s collateral balance. Instead, the excess amount would be locked in the action contract.

> **What changed:** The Mimo team updated `MIMOEmptyVault#emptyVaultOperation` to transfer collateral exactly equal to the [flashloan repayment amount](https://github.com/mimo-capital/2022-08-mimo/blob/5186ef4be23f9dda81c8474096edb1f0594d70c3/contracts/actions/MIMOEmptyVault.sol#L142), rather than the full vault balance. This behavior is demonstrated by an [integration test](https://github.com/mimo-capital/2022-08-mimo/blob/5186ef4be23f9dda81c8474096edb1f0594d70c3/test/02_integration/MIMOEmtpyVault.test.ts#L297).

> **Why it works:** Since excess collateral is never transferred to `MIMOEmptyVault`, it can no longer be locked in the contract.

---

The original report as published on Code4rena, by bin2chen. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

The vault owner's leftover collateral becomes permanently locked in the MIMOEmptyVault contract, causing a loss of funds for the owner.

What the attacker needed

A vault with collateral and debt; ability to call the empty vault action

The fix

The Mimo team updated the contract to transfer only the flash loan repayment amount from the proxy, so excess collateral is never sent to the empty vault contract.

How it was found

  1. Set up a vault with collateral and debt.
  2. Call the empty vault action via the MIMOProxy.
  3. Observe that after execution the emptyVault contract holds leftover WMATIC.
  4. The leftover balance remains locked in the emptyVault contract.

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.

When you close a loan, you expect any extra money to come back to you. Here, the contract paid back the loan but kept the leftover money inside itself, so the owner could not get it back. This is a bug because the contract should send the extra money to the owner.

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.

More by bin2chen

View all

139 more disclosed reports, best first.

More from Mimo DeFi contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.