---
title: "Building secure Uniswap v4 hooks"
description: "Uniswap v4 hooks shift security responsibility onto application code: the PoolManager enforces swap math, callback sequencing and end-of-session settlement, but not a hook's authorization or internal accounting."
url: "https://swe.quest/articles/building-secure-uniswap-v4-hooks-7105ffcb5aa554ad"
canonical: "https://blog.trailofbits.com/2026/07/30/building-secure-uniswap-v4-hooks/"
source: "Trail of Bits"
published: "2026-07-30"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 11
tags: ["appsec","security","vulnerability-research"]
---

# Building secure Uniswap v4 hooks

A post on [Trail of Bits](https://swe.quest/sources/trail-of-bits.md), published 2026-07-30, 11 min read, Deep dive. Original: [https://blog.trailofbits.com/2026/07/30/building-secure-uniswap-v4-hooks/](https://blog.trailofbits.com/2026/07/30/building-secure-uniswap-v4-hooks/)

## Summary

Uniswap v4 hooks shift security responsibility onto application code: the PoolManager enforces swap math, callback sequencing and end-of-session settlement, but not a hook's authorization or internal accounting. Drawing on audits and incidents like Cork (~$12M) and Bunni ($8.4M), seven recurring failure patterns emerge: unchecked callers, trusting arbitrary PoolKeys, leaky custom accounting that still passes settlement, logic in the wrong callback, address permission bits out of sync with implemented callbacks, non-essential hook code blocking exits, and shared state mutating across nested callbacks. Fixes include BaseHook/SafeCallback caller checks, pool allowlists keyed by PoolId, separate balance buckets, try/catch for optional calls, and fuzzing adversarial scenarios with Echidna and Medusa, packaged as checklists for builders and auditors.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Application security](https://swe.quest/tags/appsec.md) (Security)
- [Security](https://swe.quest/tags/security.md) (Security)
- [Vulnerability research](https://swe.quest/tags/vulnerability-research.md) (Security)

## Prerequisites

- Solidity smart contracts
- Uniswap AMM basics
- ERC-20 tokens
- reentrancy attacks

## Keywords

Uniswap v4, PoolManager, BaseHook, Bunni, Cork, Echidna, Medusa, Solidity

## Related posts

- [State divergence enables unauthorized access](https://swe.quest/articles/state-divergence-enables-unauthorized-access-436a19d8a315c057.md): Trail of Bits · 2026-08-25 · Medium · 6 min read · Vulnerability research, Identity & auth, Security, Go
  Provenance Blockchain's marker module let any account grant itself ACCESS\_ADMIN, mint and withdraw rights on non-fixed-supply markers.
- [After Binance, check what your signing systems can approve](https://swe.quest/articles/after-binance-check-what-your-signing-systems-can-approve-8695852207e4a776.md): Trail of Bits · 2026-11-06 · Hard · 4 min read · Security, Incidents & postmortems, Threat detection, Identity & auth
  Binance's October 2026 breach showed that attackers who compromise a service allowed to request signatures can misuse a protected key without ever extracting it.
- [Supabase Auth: Identity Linking, Hooks, and HaveIBeenPwned integration](https://swe.quest/articles/supabase-auth-identity-linking-hooks-and-haveibeenpwned-integration-8ed59b21ef27e3e6.md): Supabase · 2023-12-14 · Medium · 5 min read · Identity & auth, PostgreSQL
  Supabase Auth adds four features: manual Identity Linking via linkIdentity()/unlinkIdentity() for OAuth identities, session controls (time-boxed sessions, inactivity timeouts, single session per user on Pro and above), leaked password protection using the HaveIBeenPwned Pwned Passwords API with configurable password requirements, and Auth Hooks.
- [Post mortem on Linear security incident on March 24th, 2026](https://swe.quest/articles/post-mortem-on-linear-security-incident-on-march-24th-2026-f2351236ffd2af86.md): Linear · 2026-04-06 · Medium · 5 min read · Incidents & postmortems, Identity & auth, Testing, Security
  A performance optimization to Linear's "sync group" access-control resolvers contained a variable shadowing bug in the disabled code path.
- [When protections outlive their purpose: A lesson on managing defense systems at scale](https://swe.quest/articles/when-protections-outlive-their-purpose-a-lesson-on-managing-defense-systems-at-7fcb8ad566ecf603.md): GitHub Engineering · 2026-01-15 · Medium · 5 min read · Incidents & postmortems, Resilience, Observability, Threat detection
  Emergency protection rules added during past GitHub abuse incidents were left in place and began rate-limiting legitimate logged-out users with "Too many requests" errors.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
