When deploying or auditing a Uniswap v4 Hook, the PoolManager does not inspect your contract ABI to decide which callbacks to invoke — it reads the lowest 14 bits of the deployed contract address (uint160(address) & 0x3FFF).
Even more importantly, many tutorials still cite older draft bit positions. Under official Uniswap/v4-core Hooks.sol, the exact bit layout is:
| Bit | Mask | Constant | Risk Class |
|---|---|---|---|
| 13 | 0x2000 | BEFORE_INITIALIZE_FLAG | Lifecycle |
| 12 | 0x1000 | AFTER_INITIALIZE_FLAG | Lifecycle |
| 11 | 0x0800 | BEFORE_ADD_LIQUIDITY_FLAG | Lifecycle |
| 10 | 0x0400 | AFTER_ADD_LIQUIDITY_FLAG | Lifecycle |
| 9 | 0x0200 | BEFORE_REMOVE_LIQUIDITY_FLAG | Lifecycle |
| 8 | 0x0100 | AFTER_REMOVE_LIQUIDITY_FLAG | Lifecycle |
| 7 | 0x0080 | BEFORE_SWAP_FLAG | Lifecycle |
| 6 | 0x0040 | AFTER_SWAP_FLAG | Lifecycle |
| 5 | 0x0020 | BEFORE_DONATE_FLAG | Lifecycle |
| 4 | 0x0010 | AFTER_DONATE_FLAG | Lifecycle |
| 3 | 0x0008 | BEFORE_SWAP_RETURNS_DELTA_FLAG | Custody / Delta |
| 2 | 0x0004 | AFTER_SWAP_RETURNS_DELTA_FLAG | Custody / Delta |
| 1 | 0x0002 | AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG | Custody / Delta |
| 0 | 0x0001 | AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG | Custody / Delta |
Notice bits 0..3: any hook with a RETURN_DELTA bit set can directly modify swap or liquidity settlement balances (custom fees, custom AMM curves, or value extraction), so decoding uint160(addr) & 0x3FFF is step one of every hook security review.
Minimal Offline Decoder (JavaScript)
const mask = parseInt(address.slice(-4), 16) & 0x3fff; const beforeSwap = Boolean(mask & (1 << 7)); const afterSwap = Boolean(mask & (1 << 6)); const hasDelta = Boolean(mask & 0x000f); Combining 14-Bit Hook Flags with Leading-Zero Calldata Gas Savings
Because every zero byte (0x00) in EVM calldata costs 4 gas instead of 16 gas, mining 3–5 leading zero bytes alongside your 14-bit hook mask saves 36–60 gas permanently on every transaction.
On a single-threaded CPU (HookMiner.sol, ~400 KH/s), finding 0x000000 + 14-bit flags (38 bits) takes ~8 days. On a single NVIDIA L4 running single-block CUDA Keccak-256 (1.36 GH/s), the same 38-bit search finishes in ~3.4 minutes.
Free Browser Tools & Open-Source CLI
We published free 100% client-side developer utilities (zero private keys, pure JS / Python Keccak-256) so you can decode addresses and verify EIP-1014 salts offline:
- Browser Uniswap v4 Hook 14-Bit Decoder & Offline CREATE2 Verifier: trxvanity.xyz/tools/uniswap-v4-hook-decoder
- Zero-Trust GPU CREATE2 & v4 Hook Salt Miner (1.36 GH/s L4): trxvanity.xyz/create2
- Free Client-Side EVM (ETH / BSC / Base) Vanity & Nonce-0 Generator: trxvanity.xyz/tools/evm-vanity-generator
- Open-Source Zero-Dependency Python CLI (MIT): github.com/a5768549/uniswap-v4-hook-verifier

