Live
USD · 24h
DeFi

Risks in Uniswap v4 hooks and concentrated liquidity exploits

Unauthorized callback execution and logic flaws in Uniswap v4 hooks pose significant security threats to liquidity pools. The Cork Protocol lost $12 million due to missing modifiers, highlighting how permission gaps allow attackers to manipulate hook-local state and steal funds.

Risks in Uniswap v4 hooks and concentrated liquidity exploits

The Cork Protocol lost $12 million because developers failed to gate the beforeSwap function with the onlyPoolManager modifier. This oversight allowed any address to call the hook directly with arbitrary data. Such unauthorized access lets attackers manipulate hook-local state, like limit order books or fee accumulators, without performing a real swap. Hacken reports that missing the onlyPoolManager check remains the most frequent finding in hook reviews. You should watch for these permission gaps when interacting with custom liquidity strategies. The BEFORE_SWAP_RETURNS_DELTA permission carries even higher risk. A malicious hook uses this bit to claim it handled the entire swap. The PoolManager then accepts the fake delta and settles the trade, leaving the user with nothing. This NoOp attack vector enables complete fund theft by deceiving the PoolManager about the actual swap amounts. Attackers also exploit the msg.sender trap. While msg.sender always equals the PoolManager in hooks, the sender parameter identifies the router, not the end user. If a hook fails to implement router allowlisting, an attacker can bypass intended restrictions by using a different router to interact with the pool without the user’s knowledge or permission.

Logic Flaws and Parameter Manipulation

Attackers bypass intended hook logic by interacting with the underlying Uniswap v4 contracts directly. If a developer fails to implement hooks that revert on direct calls, the PoolManager executes standard behavior instead of the custom logic. Doppler faced issues where anyone could call beforeInitialize to overwrite stored pool keys. Improper validation of tokens during pool registration enables reentrancy attacks. A malicious user registers a pool containing counterfeit tokens. When the hook calls the take function, the interaction between the PoolManager and those fraudulent assets hands control back to the attacker. Can developers effectively prevent these architectural flaws in highly complex, multi-token environments? Additionally, improper use of the afterSwap hook causes issues. The Take Profits hook provides a way for users to place orders, but its _handleSwap function lacks protection from unauthorized callers. An attacker can call this function to trigger swaps that the user never intended. Furthermore, flawed logic in the beforeRemoveLiquidity hook can trap user funds by preventing successful withdrawals. This risk grows if the hook fails to validate the underlying assets in the registering pool, which allows a malicious user to reenter the hook via the tokens’ transfer function.

Permission Risks and Mitigation Strategies

Developers mitigate these risks by inheriting from the BaseHook abstraction. This library provides the poolManagerOnly modifier to restrict calls to the official PoolManager. It also includes the selfOnly modifier to ensure that significant state-changing functions only accept calls from the hook itself. This prevents external contracts from directly invoking these sensitive functions for malicious purposes.

Permission Flag Risk Level Primary Threat
beforeSwapReturnDelta CRITICAL NoOp rug pull or complete theft
beforeRemoveLiquidity HIGH Fund trapping
afterSwapReturnDelta HIGH Value extraction
afterAddLiquidityReturnDelta HIGH LP shortchanging
afterRemoveLiquidityReturnDelta HIGH Fund theft
beforeSwap HIGH Price manipulation
beforeAddLiquidity MEDIUM Legitimate LP blocking
afterSwap MEDIUM State observation

Gamma’s V4 Limit Orders suffered because it shipped with unprotected beforeSwap and afterSwap functions. This allowed direct manipulation of the limit order mechanism. Developers must also consider the timing of their logic. A hook that executes a calculation in beforeRemoveLiquidity instead of afterRemoveLiquidity might use outdated liquidity data, leading to incorrect incentive distributions or failed transactions. This error leads to incorrect incentive distributions or failed transactions. If a user fails to call sync() before a settle() call, the settlement fails. Furthermore, unhandled ‘dust’ balances might cause a Denial of Service (DoS) if the developer forgets to use the clear() function.

Join the discussion

Leave a Reply

Your email address will not be published. Required fields are marked *