Uniswap v4 hook security
Guides writing and auditing Uniswap v4 hooks against known attacks, so you catch fund draining bugs before launch.
What we improved
The template imported BaseHook from v4-periphery/src/base/hooks/BaseHook.sol and overrode the external beforeSwap and afterSwap functions. Current v4-periphery has BaseHook at src/utils/BaseHook.sol, where the external callbacks are not vir
Improved by YourAISkill from the original by Uniswap, under its MIT licence. The download includes the author's licence and a CHANGES.md listing every change. Both Claude reviews read the improved version.
Claude's review
9/10 Accurate Uniswap v4 hook security guide: permission bits, NoOp return-delta attack, delta settlement, BaseHook layout check, address mining, risk scoring and audit checklist.
We asked Claude the question you would ask: would I be glad I installed this? Two separate reviews, the second blind to the first, must both rate a skill 7 or higher before we sell it.
In detail
Security-first Uniswap v4 hook development. Use when user mentions "v4 hooks", "hook security", "PoolManager", "beforeSwap", "afterSwap", or asks about V4 hook best practices, vulnerabilities, or audit requirements.
How you use it
- Add it to your pack, then download your pack (1 credit).
- In Claude, open Customize > Skills and upload the zip. Code execution needs to be on under Settings > Capabilities.
- Ask Claude for the job in your own words. It uses the skill when your request matches what it does. Step by step guide
Safety check
Nothing risky found: no hidden instructions, no download and run, no reading of saved passwords or keys.
An automated scan lowers risk but cannot promise zero risk. How we check skills
Preview
The first lines of SKILL.md
---
name: v4-security-foundations
description: "Security-first guide to writing, reviewing and auditing Uniswap v4 hooks. Covers the hook threat model, the risk of each of the 14 permission flags and how they are encoded in the hook address, the NoOp (beforeSwapReturnDelta) rug pull, delta accounting with sync, settle and take, PoolManager and router verification, dynamic fee abuse, token hazards, a BaseHook template using the current internal override pattern, address mining for deployment, a risk score and pre-deployment checklists. Use when building or reviewing a v4 hook, when someone mentions v4 hooks, PoolManager, beforeSwap, afterSwap, BeforeSwapDelta or hook permissions, when deciding whether a hook is safe to trade through, or when preparing a hook for audit."
license: MIT
metadata:
author: uniswap
version: '1.1.0'
---
<!-- Modified by YourAISkill (youraiskill.com) on 2 December 2026 from the original by Uniswap. See CHANGES.md. -->
# v4 Hook Security Foundations
Hook bugs drain user funds. Understand these concepts before writing or approving any hook code.
## First: Which BaseHook Do You Have?
The hook base contract moved and changed shape during v4 development. Code written for the old layout does not compile against the new one.
| Layout | Import | How you implement a callback |
|--------|--------|------------------------------|
| Current v4-periphery | `v4-periphery/src/utils/BaseHook.sol` | Override the internal `_beforeSwap(...)`, `_afterSwap(...)` etc. The external `beforeSwap` is defined by BaseHook, is not virtual, and already has `onlyPoolManager`. |
| Older v4-periphery | `v4-periphery/src/base/hooks/BaseHook.sol` | Override the external `beforeSwap(...)` directly |
| OpenZeppelin uniswap-hooks | see that library's `BaseHook` | Same internal override pattern as current v4-periphery |
Check before writing code:
```bash
grep -rn "function _beforeSwap" lib/v4-periphery/src/ # found: use the internal pattern
grep -rn "struct SwapParams" lib/v4-core/src/ # PoolOperation.sol (current) or IPoolManager.sol (older)
```
Current v4-core defines `SwapParams` and `ModifyLiquidityParams` in `v4-core/src/types/PoolOperation.sol`; older code uses `IPoolManager.SwapParams`. v4 uses transient storage, so compile with Solidity 0.8.24+ and `evm_version = "cancun"` (or later) in `foundry.toml`. All code below uses the current layout.
## Threat Model
| Threat Area | Description | Mitigation |
|-------------|-------------|------------|
| **Caller verification** | Only the PoolManager should invoke callbacks | BaseHook's external entry points check this; a hook written directly against `IHooks` must check `msg.sender == address(poolManager)` itself |
| **Sender identity** | Inside a callback `msg.sender` is the PoolManager | Use the `sender` parameter |
...From Uniswap's repository, MIT licence.
Related skills
-
Checked
Codebase quality audit
Audits a whole code repo for bugs, security holes, slow paths and dead code, ranked in plain English.
7/101 credit -
Checked
Security and CVE audit
Runs a security and CVE audit on code in any language and scores it out of 100, with false alarms filtered.
7/101 credit -
Checked
OWASP code review
Reviews code for security flaws using the latest OWASP Top 10 lists, including those for AI and agent apps.
7/101 credit -
Checked
Code security hardening
Hardens code that handles user input, logins and data against the OWASP Top 10, starting from a threat model.
7/101 credit -
Checked
Secure web backend code
Writes and reviews login, access control and input handling for web backends, so common attacks are blocked.
8/101 credit -
Checked
Android intent security
Audits Android components and incoming intents to fix redirection and unauthorised access holes in your app.
8/101 credit