# Uniswap v4 Singleton, EIP-1153 Flash Accounting & Hooks

> Audit Uniswap v4 singleton PoolManager architecture, EIP-1153 transient storage flash accounting, bitmask hook permissions, and dynamic volatility fees.

Canonical: https://nftvenueledger.com/protocols/uniswap-v4-singleton-flash-accounting-dynamic-fee-hooks
Last updated: 2026-11-14T20:04:23.364Z

**Publication:** NFTVenue Ledger
**Category:** Amm Clob Intent Dex Settlement
**Published:** 2026-11-14T08:20:25.915Z
**Author:** Dr. Devon Kurosawa, PhD (PhD in Distributed Systems & Cryptographic Protocol Verification)
**Reviewer:** Not recorded

## Answer-first summary

By consolidating all AMM pools into a single PoolManager contract powered by EIP-1153 transient storage, Uniswap v4 slashes multi-hop swap gas and enables programmable hooks.

## Key takeaways

- Uniswap v4 replaces per-pool smart contracts with a single PoolManager singleton, cutting new pool creation gas by ~98.5% and multi-hop swap gas by 55%–72%.
- Flash accounting tracks net currency balances inside EIP-1153 transient storage (100 gas per TSTORE/TLOAD) and requires zero-sum settlement only when unlock exits.
- Hook permissions are encoded directly into the least-significant 14 bits of the hook contract address via CREATE2 salt mining, avoiding storage reads to check active callbacks.
- Dynamic fee hooks adjust swap fees per-block or per-trade up to 100% (in 0.01-bps pips), charging toxic momentum arbitrageurs higher spreads while discounting mean-reverting flow.

## Related financial entities

- **Concentrated Liquidity AMM Mathematical Specification** (CL-AMM) — product: Algorithmic market-making protocol allowing liquidity providers to allocate capital within discrete price intervals, maximizing capital efficiency.
- **ERC-3643 Tokenized Securities Standard (T-REX)** (ERC-3643) — product: Suite of open-source smart contracts enabling the compliant issuance, management, and transfer of permissioned security tokens using on-chain identity.
- **Uniswap v4 Singleton & Hook Architecture** (UNI-V4) — product: Fourth-generation decentralized exchange protocol featuring a unified singleton contract and modular hooks that customize pool execution logic.

## Analysis

In Uniswap v2 and v3, every trading pair deployed a standalone smart contract via `CREATE2`, forcing a 3-hop swap (`WBTC -> WETH -> USDC -> DAI`) to execute four external ERC-20 `transfer` storage writes across separate pool vaults. The **[Uniswap v4 singleton architecture](/tokens/uniswap-v4-singleton-architecture)** consolidates every pool across the entire chain into a single `PoolManager.sol` contract, pairing internal **Flash Accounting** backed by Cancun **EIP-1153 Transient Storage (`TSTORE` / `TLOAD`)** with address-encoded lifecycle **Hooks** and native `ETH` support (eliminating `WETH` wrap/unwrap gas).

Situated within our [concentrated AMM, CLOB & intent DEX master guide](/protocols/concentrated-liquidity-amm-clob-intent-dex-mev-guide-2026), singleton flash accounting fundamentally transforms routing economics compared to legacy multi-contract DEXs in our [marketplaces directory](/marketplaces) such as [Apeswap](/marketplaces/apeswap), [Auraswap](/marketplaces/auraswap), and [9mm Pro](/marketplaces/9mm-pro).

## EIP-1153 `TSTORE` Flash Accounting & the `unlockCallback` Pattern

Instead of requiring callers to transfer input tokens prior to each hop, external routers invoke `PoolManager.unlock(bytes calldata data)`, which acquires a transient reentrancy lock and triggers `IUnlockCallback(msg.sender).unlockCallback(data)`. Inside that callback, the router can execute an arbitrary sequence of `swap`, `modifyLiquidity`, `donate`, and ERC-6909 internal claim mints/burns:

1. **100-Gas Transient Balance Deltas**: Every pool operation mutates `BalanceDelta` accumulators keyed by `(caller, Currency)` using `TSTORE` and `TLOAD` (~100 gas each vs 20,000 / 5,000 gas for persistent `SSTORE`!), automatically zeroing out at transaction end without gas-refund complexity.
2. **Outer-Boundary Zero-Sum Enforcement**: Before `unlock` returns, `PoolManager` verifies `NonzeroDeltaCount == 0`. Only the **net** residual input and output tokens across the entire multi-hop DAG are settled via `sync/settle` and `take`, cutting pool deployment gas by ~99% (a state struct initialization rather than bytecode deployment) and multi-hop swap gas by 55% to 72%.

![Uniswap v4 PoolManager unlockCallback flash accounting lifecycle with EIP-1153 TSTORE delta settlement](/api/figure?type=flow&title=PoolManager%20Flash%20Accounting%20%26%20Hook%20Execution%20Loop&subtitle=Single-lock%20transient%20delta%20accumulation%20across%20multi-hop%20swaps%20and%20custom%20hook%20callbacks&steps=1.%20unlock%28%29%20Entry%3A%3ASet%20transient%20lock%20%26%20invoke%20router%20unlockCallback%28data%29%7C2.%20beforeSwap%20Hook%3A%3AExecute%20dynamic%20fee%20override%2C%20KYC%20check%2C%20or%20custom%20curve%7C3.%20TSTORE%20Netting%3A%3AAccumulate%20multi-hop%20Currency%20deltas%20at%20100%20gas%20per%20op%7C4.%20Net%20Settle%20%2F%20Take%3A%3ATransfer%20net%20input%2Foutput%20%26%20verify%20NonzeroDeltaCount%20%3D%3D%200&metrics=POOL%20DEPLOY%20GAS%3A%3A-99.0%25%20Cost%3A%3AState%20mapping%20init%20vs%20CREATE2%20bytecode%7CTSTORE%20%2F%20TLOAD%3A%3A100%20Gas%3A%3AEIP-1153%20Cancun%20transient%20opcode%7CNATIVE%20ETH%20GAS%3A%3A-26k%20to%20-40k%3A%3AEliminates%20WETH9%20deposit%2Fwithdraw%7CERC-6909%20CLAIMS%3A%3AInternal%20Ledger%3A%3AOptional%20vault%20deposit%20for%20HFT%20solvers)

## Address-Bitmask Hook Permissions & Custom Accounting (`beforeSwapReturnDelta`)

Every `PoolKey` binds an immutable `IHooks` contract address whose **least-significant 14 bits** encode exactly which lifecycle callbacks (`beforeInitialize`, `afterInitialize`, `beforeAddLiquidity`, `afterAddLiquidity`, `beforeRemoveLiquidity`, `afterRemoveLiquidity`, `beforeSwap`, `afterSwap`, `beforeDonate`, `afterDonate`, plus four **ReturnDelta** custom-accounting flags) the pool will invoke. Practitioners mine vanity hook deployment salts via `CREATE2` so only active flags equal `1`, ensuring pools without `afterSwap` pay zero external call overhead on completion.

Crucially, enabling `BEFORE_SWAP_RETURNS_DELTA_FLAG` allows a hook to intercept taker orderflow *before* touching the [Concentrated Liquidity AMM curve](/tokens/concentrated-liquidity-amm-spec)—enabling JIT internal orderbooks, asynchronous TWAMM execution, permissioned [ERC-3643 RWA compliance checks](/tokens/erc-3643-rwa-standard), or custom stable/weighted curves directly inside `PoolManager`!

## Gas & Capability Benchmark: Uniswap v3 vs Uniswap v4 Singleton

| Architectural Feature | Uniswap v3 Multi-Contract | Uniswap v4 Singleton (`PoolManager`) | Measured Institutional Impact |
| :--- | :--- | :--- | :--- |
| New Pool Deployment | `CREATE2` full contract (~4.6M gas) | `initialize(PoolKey)` struct (~65k gas) | ~98.6% cheaper pool creation |
| 3-Hop Swap Token Transfers | 4 ERC-20 `transfer` storage writes | 2 net outer transfers + `TSTORE` netting | Saves ~75,000–115,000 gas per route |
| Native Ether (`ETH`) Pairs | Forced `WETH9` wrap/unwrap | Direct `Currency.wrap(address(0))` ETH | Saves ~28,000+ gas on ETH swaps |
| Swap Fee Mutability | Fixed at deployment (1, 5, 30, 100 bps) | `DYNAMIC_FEE_FLAG` (`0x800000`) up to 100% | Real-time realized-volatility LVR defense |
| High-Frequency Solver Balances | External wallet ERC-20 transfers | Built-in **ERC-6909** internal token claims | Solvers keep float inside `PoolManager` |

![EVM gas consumption comparison across 1-hop, 3-hop, and ERC-6909 solver swaps in Uniswap v3 vs v4](/api/figure?type=bars&title=EVM%20Gas%20Consumption%3A%20Multi-Contract%20v3%20vs%20Singleton%20v4&subtitle=Measured%20mainnet%20gas%20units%20across%20progressive%20routing%20topologies%20after%20EIP-1153%20activation&steps=Pool%20Initialization%3A%3Av3%3A%204%2C620%2C000%20gas%20vs%20v4%3A%2068%2C000%20gas%20%28-98.5%25%29%7C1-Hop%20Native%20ETH-%3EUSDC%3A%3Av3%20%28via%20WETH%29%3A%20134%2C000%20gas%20vs%20v4%3A%2082%2C000%20gas%20%28-38.8%25%29%7C3-Hop%20ERC-20%20Route%3A%3Av3%3A%20318%2C000%20gas%20vs%20v4%3A%20136%2C000%20gas%20%28-57.2%25%29%7CSolver%20ERC-6909%20Net%3A%3Av4%20internal%20claim%20burn%2Fmint%3A%20~59%2C000%20gas%20per%20hop&metrics=DYNAMIC%20FEE%20MAX%3A%3A1%2C000%2C000%20pips%3A%3A1%20pip%20%3D%200.0001%25%20%28100ths%20of%20a%20bps%29%7CHOOK%20FLAG%20BITS%3A%3A14%20LSB%20Bits%3A%3AZero%20SLOAD%20permission%20check%20via%20address%7C3-HOP%20GAS%20SAVING%3A%3A-57.2%25%3A%3AEliminates%20intermediate%20ERC-20%20SSTOREs%7CHOOK%20AUDIT%20RISK%3A%3AMalicious%20Delta%3A%3ARouters%20must%20verify%20trusted%20hook%20code!)

## Quantitative Directional Volatility Dynamic Fee Hook Formula

To shield passive LPs from [Loss-Versus-Rebalancing](/protocols/loss-versus-rebalancing-lvr-black-scholes-amm-adverse) without choking calm-market retail volume, institutional dynamic-fee hooks return `lpFeeOverride | OVERRIDE_FEE_FLAG` inside `beforeSwap` as a convex function of trailing EWMA tick-jump velocity and trade direction:

```formula
Asymmetric Volatility & Toxic-Flow Dynamic Fee Hook (in pips, 1 bps = 100 pips):
 sigma_ewma^2(t) = lambda * sigma_ewma^2(t - 1) + (1 - lambda) * (tick_current - tick_prev_block)^2
 f_symmetric = f_min + beta_vol * sigma_ewma^2(t)
 f_directional = f_symmetric + gamma_impact * max(0, sign(swap_dir) * (tick_current - tick_twap_5m))
 lpFee_pips = clamp(round(f_directional), f_min, f_max)

Worked Volatile Macro Print Block (ETH/USDC Pool):
 Baseline f_min = 400 pips (4.0 bps); beta_vol = 0.85; gamma_impact = 18; f_max = 10,000 pips (100 bps)
 ETH jumps +85 ticks (+0.85%) in 1 block while 5m TWAP lags by +110 ticks:
 sigma_ewma^2 spikes to 2,400 => f_symmetric = 400 + 0.85 * 2,400 = 2,440 pips (24.4 bps)
 Taker_A buys WITH momentum (toxic arb): f_dir = 2,440 + 18 * 110 = 4,420 pips (44.2 bps fee!)
 Taker_B sells AGAINST momentum (rebalancing): f_dir = 2,440 + 0 = 2,440 pips (or discounted to 4.0 bps!)
```

## Hook Security Auditing & Auction-Managed Extensions

Because an untrusted custom-accounting hook with `beforeSwapReturnDelta` can extract arbitrary `Currency` amounts from `msg.sender`'s open `unlock` session, aggregators whitelist audited hooks or isolate untrusted pools in separate transactions—compare advanced hook monetization in [am-AMM auction-managed pools](/protocols/diamond-hook-vrda-am-amm-auction-managed-pool-fee-capture) and [tick-spacing depth math](/protocols/uniswap-v3-tick-spacing-concentrated-liquidity-depth) across our [AMM, CLOB & Intent DEX hub](/topics/amm-clob-intent-dex-settlement).

## Frequently asked questions

### How does EIP-1153 transient storage make Uniswap v4 flash accounting cheaper?

EIP-1153 opcodes TSTORE and TLOAD cost roughly 100 gas and automatically discard state when the transaction finishes, allowing PoolManager to net multi-hop balances without paying 5,000 to 20,000 gas for persistent SSTORE writes.

### Why are Uniswap v4 hook flags encoded inside the hook smart contract address?

Encoding the 14 boolean callback flags in the hook address bits allows PoolManager to inspect permissions via a 3-gas bitwise AND on the PoolKey parameter in memory, avoiding a 2,100-gas external call or SLOAD.

### What are ERC-6909 claim tokens inside Uniswap v4 PoolManager?

ERC-6909 is a minimalist multi-token accounting ledger built directly into PoolManager, letting high-frequency solvers, market makers, and liquidity hooks mint/burn internal token balances without external ERC-20 transfers.

### Can a malicious Uniswap v4 hook steal user funds if routed carelessly?

Yes. A pool using unverified custom-accounting flags (beforeSwapReturnDelta) can alter swap prices arbitrarily or consume open transient balances inside an shared unlock session, requiring routers to isolate or whitelist hooks.


## Source URLs

- https://github.com/Uniswap/v4-core/blob/main/docs/whitepaper-v4.pdf
- https://eips.ethereum.org/EIPS/eip-1153
- https://eips.ethereum.org/EIPS/eip-6909

## Citation

- APA: Dr. Devon Kurosawa, PhD. (2026). Uniswap v4 Singleton PoolManager: EIP-1153 Flash Accounting & Dynamic Fee Hooks. NFTVenue Ledger. https://nftvenueledger.com/protocols/uniswap-v4-singleton-flash-accounting-dynamic-fee-hooks
- Canonical article: [Uniswap v4 Singleton PoolManager: EIP-1153 Flash Accounting & Dynamic Fee Hooks](https://nftvenueledger.com/protocols/uniswap-v4-singleton-flash-accounting-dynamic-fee-hooks)
- Site research index: [NFTVenue Ledger](https://nftvenueledger.com/llms-full.txt)
