v4-security-foundations

Identify and mitigate security risks in Uniswap v4 hook development.

Updated Sep 9, 2025
One-click install
npx skills add https://github.com/LennyDevX/nuxchain-app --skill v4-security-foundations-lennydevx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: v4-security-foundations
Source: https://github.com/LennyDevX/nuxchain-app/tree/main/.agents/skills/v4-security-foundations
Command: npx skills add https://github.com/LennyDevX/nuxchain-app --skill v4-security-foundations-lennydevx

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Security-first guide for building Uniswap v4 hooks. Hook vulnerabilities can drain user funds—understand these concepts before writing any hook code.

Core Features & Use Cases

  • Threat Model: Understand who can trigger hooks, how data flows, and where to enforce verification.
  • Permission Flags Risk Matrix: Learn risk levels for each hook point and prove correct guardrails.
  • Delta Accounting & Safety: Ensure funds balance and safe settlement patterns to prevent losses.
  • Access Controls & Verification: Patterns to verify PoolManager and router vs user identity.
  • Router Verification Patterns: Examples to allowlist routers and safely decode hookData.
  • Token Handling Hazards: Manage fee-on-transfer tokens and reentrancy hazards safely.
  • Base Hook Template: Reference structure for secure hooks with safe defaults.
  • Security Checklist: Steps to validate security before deployment.
  • External Resources: Links to Uniswap v4 docs and audit references.

Quick Start

Follow this guide to implement secure v4 hooks by validating PoolManager access and avoiding tx.origin.

Frequently Asked Questions about v4-security-foundations

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent reentrancy attacks in Uniswap v4 hooks?

Prevent reentrancy attacks in Uniswap v4 hooks by validating PoolManager access, avoiding tx.origin, and enforcing strict router allowlists. Safe data handling and delta accounting patterns ensure funds balance correctly and prevent malicious callbacks from draining user funds.

What security risks exist when decoding hookData in Uniswap v4?

Decoding hookData in Uniswap v4 risks data exposure and unauthorized access if not properly validated. Mitigate these risks by verifying caller identity, applying router verification patterns, and safely decoding payload data to ensure only permitted routers trigger specific hook callbacks.

How do I verify PoolManager and router identity for v4 smart contracts?

Verify PoolManager and router identity by implementing access control patterns that check msg.sender against allowed router addresses. Do not rely on tx.origin for verification, and ensure your hook validates the calling router to prevent unauthorized execution of before/after swap callbacks.

How do I handle fee-on-transfer tokens safely in Uniswap v4 hooks?

Handle fee-on-transfer tokens safely in v4 hooks by implementing accurate delta accounting and safe settlement patterns. Ensure your hook measures actual received token amounts rather than expected amounts to prevent accounting discrepancies and secure funds balance during swaps.

How do I use permission flags to secure Uniswap v4 hook points?

Secure Uniswap v4 hook points by consulting a permission flags risk matrix to understand risk levels for each callback. Prove correct guardrails are in place for before/after swap hooks and delta permissions to restrict unauthorized actions and mitigate potential fund drainage.

What steps should I follow for a Uniswap v4 hook security audit?

A Uniswap v4 hook security audit requires following a security checklist to validate PoolManager access, verify router allowlists, and check delta accounting. Review threat models and ensure safe data handling to confirm correct guardrails before deploying smart contracts.