HookTax

What a Uniswap v4 hook takes from your swap today, and what it could take tomorrow.

HookTax

Created At

ETHGlobal Mumbai

Project Description

Every Uniswap v4 pool can attach a hook: a contract that runs inside your swap. A hook can take a cut on top of the LP fee, and if it is upgradeable, its owner can change what it does tomorrow without changing its address. Today a trader has no simple way to know what a pool's hook takes, or what it could take.

HookTax answers both questions for any v4 pool on Ethereum mainnet:

  1. Measured take (today). On a local mainnet fork, HookTax swaps about $50 through the real pool, in both directions, through the real PoolManager, and traces every token movement (ERC-20 transfers, ERC-6909 claims and native ETH). It reports the share of the swap that went to the hook, its owner or anyone other than the swapper, the PoolManager and the LPs, separately from the LP fee.

  2. Capability ceiling (tomorrow). From onchain facts alone (the 14 permission bits encoded in the hook's address, EIP-1967 / UUPS / beacon proxy slots, and the dynamic-fee flag) it computes the worst case. For example, "can change swap amounts" plus "code can be replaced" means up to 100% of swap value. Where it can, it proves it on the fork: it impersonates the real upgrade authority, upgrades the hook, and swaps again.

  3. HookAtlas. A public directory of every v4 hook, mirrored to Arkiv and read straight from the browser. There is no HookTax server in the read path: every filter on the page is an Arkiv query, shown with a curl anyone can run. A Chainlink CRE workflow reacts to each new hooked pool on the PoolManager and triggers a refresh and re-measurement. We ran it with the CRE CLI simulator on a real mainnet transaction.

What one import found (mainnet block 26,347,887): 186,872 v4 pools, 47,130 with a hook, 11,242 unique hooks. 8,716 hooks can change swap amounts, 687 are upgradeable, and 35 are both, so their worst case is 100% of your swap. 24 of those 35 had a pool we could swap through, so we tried the upgrade on them. For 19, impersonating the real upgrade authority on a fork turned a take of 0-10% into 98-100%. For the other 5, HookTax records why: for example, two ProxyAdmins whose ownership was renounced, so nobody can upgrade them.

Use it three ways: the live HookAtlas (https://bilgin-kocak.github.io/hooktax/), a HookTax card for each hook or pool, and a CLI (hooktax check <poolId|hookAddress>).

HookTax is a measurement tool, not an audit, and it never labels a hook. Fork results describe one block and one swap size, so measurements on Arkiv expire after 7 days. A power we could not exercise is reported as "not demonstrated", never "absent".

How it's Made

HookTax is a TypeScript monorepo (pnpm workspace, TypeScript 5.9, viem 2.57, Vitest) plus a Foundry project for the fork work. Every number comes from public Ethereum mainnet JSON-RPC: no Etherscan, no Sourcify, no indexing service.

UNISWAP V4

  • Indexer: scans every PoolManager Initialize event since the deploy block (21,688,329) with adaptive block ranges and an append-only cache. "hooks" is not an indexed topic, so hooked pools are filtered in code. Each hook is enriched with its bytecode, EIP-1967 implementation/admin/beacon slots, UUPS proxiableUUID, owner() and pool state via StateView.
  • Core rules: decode the 14 permission bits from the hook address, classify the proxy, and turn both into capability rules and a worst case. Constants were checked against v4-core v4.0.0. v4 putting the permissions in the address is what makes a capability ceiling computable for 11,242 hooks without their source code.
  • Fork measurement (Foundry 1.5.1): TakeMeter.sol swaps through the real PoolManager with v4-core's PoolSwapTest router in both directions. It records every Transfer log (vm.recordLogs) plus a state diff (vm.startStateDiffRecording). Native ETH moves leave no event, so the state diff is how we see ETH a hook takes. Flows are netted per address and valued at the pre-swap mid price; the LP fee comes from the Swap event.
  • Worst case, proved: SneakyFeeHook is a UUPS hook whose address we mine with v4-periphery's HookMiner to carry exactly BEFORE_SWAP | BEFORE_SWAP_RETURNS_DELTA. On the fork its owner upgrades it from 0.3% to 100%. ProbeUpgrade.t.sol does the same to real hooks: it finds the real upgrade authority, impersonates it, tries ProxyAdmin.upgradeAndCall and UUPS upgradeToAndCall, re-measures, and decodes the revert when an upgrade fails.

ARKIV (@arkiv-network/sdk 1.0.1, Rabdi testnet)

  • Hook, Pool, SimResult and Import entities with indexed attributes (31 on Hook), so every HookAtlas filter is a native Arkiv query. The web app (Vite + React, static on GitHub Pages) queries Arkiv straight from the browser, scoped with .ownedBy(writer), so all the data comes from one wallet anyone can check. Arkiv let the atlas be a public, queryable dataset with no backend of ours.
  • Expiry does real work: SimResults are readonly and expire 7 days after the measurement, so a stale safety number deletes itself. Hooks and pools live 30 days and are extended by each import.
  • The sync is state-derived and idempotent: it diffs content hashes and writes only the needed creates, patches and extensions. The writer follows Arkiv's write-safety guidance (one process, explicit nonce and gas, a journal of every submission) and writes the riskiest hooks first when the budget is short. The full mirror (11,242 hooks, 24,535 pools with live liquidity, 70 SimResults) cost about 13.7 tGLM.

CHAINLINK CRE (cre-sdk 1.23.0, CRE CLI 1.39.0)

  • The hooktax-refresh workflow is our orchestration layer. An EVM log trigger fires on PoolManager Initialize (finalized), and the workflow filters hooks != 0 in code. It POSTs {poolId, txHash} to our refresh API with a bearer token from CRE secrets, using HTTP consensus. It accepts the answer only if the poolId and permission bits match. The API re-checks the log on mainnet, re-indexes the hook, re-measures it on a fork and mirrors it to Arkiv. No server of ours polls the chain. We ran it with cre workflow simulate on a real mainnet pool creation.

HACKY BITS

  • Unsigned gas estimates: a custom viem transport runs the Arkiv SDK's real encoding, intercepts eth_estimateGas and throws before anything is signed. That gives an exact cost estimate even for an unfunded wallet. When the node refused to estimate a large batch (its 128 KiB transaction cap), the executor halves the batch.
  • The first real CRE simulation caught a bug the unit tests missed: inside the CRE WASM runtime, zod's .url() rejects http://localhost because it uses the SDK's URL polyfill.
  • Probe swaps are sized by price (about $50 a side), and a guard leaves any take above 100% out of the headline. The guard caught dust-sized probes of unpriced tokens.

There are 144 unit tests plus 8 CRE workflow tests, and "make demo" reproduces the 0.3% -> 100% proof on a fork in seconds. Built with Claude Code from a spec the developer wrote; docs/ai.md in the repo records what was generated and from which prompt.

background image mobile

Join the mailing list

Get the latest news and updates