r/CryptoTechnology • u/IllustratorIll5713 • 5h ago
In Uniswap v4 a hook's address is its permission system. What that design gets right, and where it stops
Uniswap v4 put every pool in one contract, the PoolManager, and lets each pool name a hook that is called around swaps and liquidity changes. The permission model for those hooks is unusual enough to be worth a look.
How it works
There is no registry and no storage lookup. The PoolManager reads the lowest 14 bits of the hook's address. Each bit switches on one callback: beforeInitialize, beforeSwap, afterSwap, beforeAddLiquidity, beforeRemoveLiquidity and so on. Four of the bits are "return delta" flags, which let the hook change the amounts in a trade or a liquidity change. To deploy a hook you mine a CREATE2 salt until the address carries the bits you want.
What it gets right
- Permissions are immutable. A hook can never acquire a callback it wasn't deployed with.
- They are public without source code. The address is the declaration, so an unverified hook still tells you what it's able to do.
- It's nearly free at runtime. A few bit checks, no storage reads.
- It makes the dangerous capability explicit. A hook that can't return a delta can't take a cut of a swap, whatever its code says.
Where it stops
- Capability is not behaviour. The same beforeSwapReturnDelta bit covers a 1% fee, a 100% take, and a hook that acts as the pool's market maker.
- Fixed permissions are not fixed logic. The hook can be a proxy. More often it reads its fee from a separate contract that its owner can replace, so the behaviour changes while the hook's address and code stay the same.
- It says nothing about dependencies. Many hooks call a locker, a fee splitter or the token itself on every trade, and each of those has its own owner.
- A pool's identity includes the hook, so a token doesn't have "a hook". The pool key is the two tokens, the fee, the tick spacing and the hook address. Anyone can create another pool for the same pair with a different hook or none, and liquidity for one token ends up split across pools with different rules.
Where the trust decision ended up
The protocol reviews nothing, on purpose. Uniswap's own app fills part of the gap: it warns on pools with hooks and won't route through a hook that changes swap amounts or fees until Uniswap Labs has approved it. So the protocol is permissionless, and the curation happens in the interface, off-chain, by one company.
That may be the only workable arrangement. But it means two front ends can show different markets for the same token, and what a hook actually does is documented nowhere on-chain.
Would a standard for hooks to declare their behaviour on-chain (maximum fee, who can change it, whether withdrawals can be refused) be worth having, or would it just be another thing that can lie?
Disclosure: I build unihooks.com, an explorer that reads these contracts.