# PancakeV3SwapHelper: signed swap delta drains WBNB inventory

PancakeV3SwapHelper used the positive USDT input delta as the WBNB output amount to unwrap, draining its own WBNB inventory via a flash-loan-funded swap.

- Payout: Real-world hack
- Severity: high
- Program: PancakeV3SwapHelper
- Analysis by: DeFiHackLabs
- Disclosed: 2026-09-23
- Write-up quality: 7/10
- Original: https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2026-09/PancakeV3SwapHelper_exp.sol
- Library page: https://bugbountylibrary.com/r/dhl%3A20260923-pancakev3swaphelper
- Tags: area:web3 domain:web3 impact:funds-loss kind:incident platform:defihacklabs sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic vuln:flash-loan

**Target:** Unverified on-chain swap helper contract (Pancake V3 wrapper)
**Root cause:** Pancake V3 returns signed swap deltas; the helper treated the positive USDT input delta as the WBNB amount to unwrap and pay out, instead of the negative WBNB output delta.
**Steps:**
1. Flash-borrow `amountIn + 2 USDT` from Moolah (amountIn = victim's WBNB balance, 1.651021225164017256).
2. Approve victim and call selector `0x6c26c88a` with `(USDT, fee=100, amountIn, param4=1, deadline, attackContract)`.
3. Pool returns only ~0.002089 WBNB, but helper unwraps and pays 1.651021225164017256 BNB from its inventory.
4. Wrap 0.05 BNB, swap via Pancake V2 `swapTokensForExactTokens` to buy back exactly amountIn USDT (spends ~0.0020957 WBNB).
5. Unwrap remaining WBNB, repay Moolah principal, send 1.648925501026157960 BNB to attacker EOA.
**How found:** Inferred from the unverified helper's runtime behavior and attack trace: the helper held 1.651 WBNB but the pool returned only 0.002089 WBNB, revealing it used the positive USDT input delta as the unwrap amount rather than the negative WBNB output delta.
**Exploitation:** Single atomic tx: Moolah flash loan of USDT funds the vulnerable helper call; the helper pays out its pre-existing WBNB inventory as BNB to the attacker; a small Pancake V2 buyback restores the USDT principal for repayment; residual BNB is profit (~1.6489 BNB before gas).
**Insight:** When a wrapper consumes Uniswap-V3-style signed deltas, check which sign the code trusts: using the positive input delta as the output amount lets an attacker drain any pre-existing token inventory the contract holds.

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

**Attack contract calling victim swap selector**

```
USDT_TOKEN.approve(VICTIM, amountIn);
        (bool success,) = VICTIM.call(
            abi.encodeWithSelector(
                SWAP_SELECTOR, address(USDT_TOKEN), POOL_FEE, amountIn, PARAM4, block.timestamp, address(this)
            )
        );
        require(success, "victim swap call reverted");
```

**Flash loan trigger with amountIn buffer**

```
function attack(
        uint256 amountIn
    ) external {
        MOOLAH.flashLoan(address(USDT_TOKEN), amountIn + FLASHLOAN_BUFFER, abi.encode(amountIn));
```

**Test invoking attack with victim inventory**

```
uint256 amountIn = WBNB_TOKEN.balanceOf(VICTIM);
        assertEq(amountIn, EXPECTED_VICTIM_INVENTORY, "victim inventory changed at attack tx");

        attackContract.attack(amountIn);
```

