Uniswap v4 hook vulnerabilities: what to check before you deploy a hook

A Uniswap v4 hook vulnerability is a bug in the contract a pool calls around swaps and liquidity changes that lets an attacker trigger or steer that logic. The most direct one is a callback anyone can call, not only the PoolManager. Others come from permission flags that don't match the code, unsettled deltas, state shared between pools and trusting the sender argument.

Last updated . 5 minute read. By the QuillShield team.

How do hooks change the attack surface?

In Uniswap v4 a pool can name a hook contract, and the PoolManager calls it before and after swaps, liquidity changes and donations. Flags in the low bits of the hook's address decide which callbacks run. Hooks with return-delta permissions can also take tokens from a swap or add tokens to it.

So a hook runs inside every trade of its pools and can move value. One hook can serve many pools, anyone can create a pool that names it, and the sender argument it receives is the contract that called the PoolManager, usually a router, not the trader.

What does vulnerable code look like?

This hook pays a small rebate on every swap. It never checks who is calling.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

// Minimal stand-ins for Uniswap v4 types, to keep the example short.
struct PoolKey {
    address currency0;
    address currency1;
    uint24 fee;
    int24 tickSpacing;
    address hooks;
}

struct SwapParams {
    bool zeroForOne;
    int256 amountSpecified;
    uint160 sqrtPriceLimitX96;
}

contract RebateHook {
    address public immutable poolManager;
    mapping(address => uint256) public rebates;

    constructor(address poolManager_) {
        poolManager = poolManager_;
    }

    // The PoolManager calls this before each swap. Nothing checks the caller,
    // so anyone can call it with made-up arguments.
    function beforeSwap(address sender, PoolKey calldata, SwapParams calldata params, bytes calldata)
        external
        returns (bytes4)
    {
        int256 amount = params.amountSpecified;
        uint256 size = amount < 0 ? uint256(-amount) : uint256(amount);
        rebates[sender] += size / 1000;
        return this.beforeSwap.selector;
    }
}

Anyone can call beforeSwap directly with a made-up sender and a huge amountSpecified, and credit themselves any rebate they like. Even through the PoolManager, sender is the router, so the rebate goes to the wrong address.

How do you fix it?

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

// Minimal stand-ins for Uniswap v4 types, to keep the example short.
struct PoolKey {
    address currency0;
    address currency1;
    uint24 fee;
    int24 tickSpacing;
    address hooks;
}

struct SwapParams {
    bool zeroForOne;
    int256 amountSpecified;
    uint160 sqrtPriceLimitX96;
}

contract SafeRebateHook {
    address public immutable poolManager;
    address public immutable owner;
    mapping(address => bool) public trustedRouters;
    mapping(address => uint256) public rebates;

    constructor(address poolManager_) {
        poolManager = poolManager_;
        owner = msg.sender;
    }

    modifier onlyPoolManager() {
        require(msg.sender == poolManager, "only PoolManager");
        _;
    }

    function setTrustedRouter(address router, bool trusted) external {
        require(msg.sender == owner, "not owner");
        trustedRouters[router] = trusted;
    }

    function beforeSwap(address sender, PoolKey calldata, SwapParams calldata params, bytes calldata hookData)
        external
        onlyPoolManager
        returns (bytes4)
    {
        // `sender` is whoever called the PoolManager, usually a router. Credit the
        // trader only when a router you trust passes it in hookData.
        if (trustedRouters[sender] && hookData.length == 32) {
            address trader = abi.decode(hookData, (address));
            int256 amount = params.amountSpecified;
            uint256 size = amount < 0 ? uint256(-amount) : uint256(amount);
            rebates[trader] += size / 1000;
        }
        return this.beforeSwap.selector;
    }
}
  • Accept callbacks only from the PoolManager. Every hook entry point needs the check. Cork's post-mortem notes that Uniswap later added an explicit authorization check upstream, which the version Cork used did not have.
  • Don't treat sender as the user. Credit a trader only when a router you trust passes them in hookData.
  • Restrict pool creation. If the hook should serve only some pools, check the pool key in beforeInitialize.
  • Key state by PoolId. One pool's swaps must not change another pool's numbers.
  • Match flags to code. The permission bits in the hook's address must match the callbacks it implements, including the return-delta flags.

How has it been exploited?

At 11:39 UTC on 28 May 2025 an attacker took 3,761 wstETH, about $12M, from Cork Protocol's wstETH:weETH Liquidity Vault. Cork's post-mortem describes two vectors used together. One was a rollover pricing exploit. The other was an access control flaw in the Cork Hook, Cork's Uniswap v4 hook: the attacker passed malicious parameters through the hook's beforeSwap function and reached privileged functions of Cork's FlashSwapRouter. The attacker's own contract was itself a hook, built for that path.

BlockSec's analysis shows the missing line, a check that the caller of beforeSwap is the PoolManager.

What should a reviewer check?

  • Does every callback check that msg.sender is the PoolManager?
  • Do the permission flags in the hook's address match the callbacks the contract implements, including the return-delta flags?
  • Who can create a pool with this hook, and does beforeInitialize limit it to the pools you expect?
  • Is state keyed by PoolId, so one pool can't read or change another pool's values?
  • Does the hook treat sender as the router, and trust hookData only from known routers?
  • Do the deltas the hook takes or returns settle exactly, with rounding in the pool's favor?
  • Can a callback revert on purpose and block swaps or liquidity removal for everyone?
  • Do tests run against the real PoolManager, in a fork or with v4-core's test helpers, rather than against mocks?

How does QuillShield check for it?

A hook's risk sits where it meets the PoolManager, the routers and the rest of your protocol, as Cork's FlashSwapRouter showed. A QuillShield full audit covers the hook together with the rest of the Foundry codebase in scope, and a separate reviewer agent tries to disprove each finding before you see it. Each finding that holds up comes with the exact lines, the impact and a recommended fix.

When the hook changes after launch, to add a fee or a new reward, each pull request is checked against the audit, so a new callback, a changed permission flag or a new hookData field is reviewed in context.

Full audits start at $49 and are priced from the lines of Solidity in scope, as the pricing page shows. The guide to running your first audit walks through getting a quote for your own code. Sign up free and you see the exact price before anything is charged.

Common questions

Does every hook callback need a caller check?

Yes. Any external function can be called by anyone, so each callback should require msg.sender to be the PoolManager. Cork's hook lacked that check on beforeSwap.

What is the sender argument in beforeSwap?

The address that called the PoolManager, usually a router. It is not the trader, so don't base rewards or limits on it unless you trust that router.

Can anyone create a pool that uses my hook?

Yes, unless the hook refuses. Check the pool key in beforeInitialize if the hook should only serve certain pools.

Do Uniswap's audits cover my hook?

No. They cover Uniswap v4's own contracts. Each hook is a separate contract and needs its own review.

Sources

QuillShield is building the security layer between AI and money, so you can keep shipping between audits.

Sign-up is free, and new accounts get $50 in credit, good for up to half of an order.

  1. 1Sign up and import a repo
  2. 2See the exact price before anything is charged
  3. 3Approve it, and the audit starts