Reproduced Exploit

VII Finance — fees stolen from partially unwrapped `UniswapV4Wrapper` positions

1. Partial unwrap of a V4-wrapped position accumulates fees into tokensOwed and pays a proportional share to the unwrapper. 2. tokensOwed is never decremented, so the same fee claim can be reused. 3. After full-via-partial unwrap → recover NFT → re-wrap, the stale claim still

Jul 2025Otheruntagged4 min read

Chain

Other

Category

untagged

Date

Jul 2025

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

The attack is replayed in an in-browser EVM preloaded with the exact dumped fork state. The execution tree shows every call; step by Solidity line or by opcode across all depths — source, Stack, Memory, Storage, Balances (native / ERC-20 / NFT), Transient storage and Return value stay in sync. Click a tree node, opcode, or source line to jump. No backend, no live RPC.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 61328-fees-can-be-stolen-from-partially-unwrapped-uniswapv4wrapper. Standalone Foundry PoC and full write-up: 61328-fees-can-be-stolen-from-partially-unwrapped-uniswapv4wrapper_exp in the evm-hack-registry mirror.


Vulnerability classes: fee-theft · frozen-funds · fee-accounting · dos-resistance

Reproduction: a self-contained Foundry PoC that compiles & runs in an isolated project with only forge-std — no fork, no RPC. Full trace: output.txt. PoC: test/61328-fees-can-be-stolen-from-partially-unwrapped-uniswapv4wrapper_exp.sol.

AuditVault taxonomylang/solidity · platform/cyfrin · has/poc · severity/high · sector/dex · sector/lending · sector/nft · genome: frozen-funds · fee-theft · fee-accounting · dos-resistance · liquidation-underwater


Key info#

ImpactHIGH — LP fees held for other ERC-6909 holders of a partially unwrapped Uniswap V4 position can be drained by re-wrapping a position whose stale tokensOwed was never decremented
ProtocolVII FinanceUniswapV4Wrapper
Vulnerable codeUniswapV4Wrapper::_unwrap — pays proportional fees from tokensOwed but never decrements it
Bug classStale fee accounting after partial unwrap / re-wrap
FindingCyfrin 2025-07-15 vii-v2.0 · AuditVault #61328 · reporter Giovanni Di Siena
ReportCyfrin vii-v2.0
SourceAuditVault
StatusFixed in commit 8c6b6cc
Compiler^0.8.24 (PoC)

TL;DR#

  1. Partial unwrap of a V4-wrapped position accumulates fees into tokensOwed and pays a proportional share to the unwrapper.
  2. tokensOwed is never decremented, so the same fee claim can be reused.
  3. After full-via-partial unwrap → recover NFT → re-wrap, the stale claim still points at fee balances that belong to other partially unwrapped holders.
  4. Attacker drains those fees; victims' subsequent unwraps revert (DoS / bad debt path).

The vulnerable code#

SOLIDITY
function _unwrap(address to, uint256 tokenId, uint256 amount, bytes calldata extraData) internal override {
    // ... accumulate fees into tokensOwed, decrease liquidity ...
    poolKey.currency0.transfer(to, amount0 + proportionalShare(tokenId, tokensOwed[tokenId].fees0Owed, amount)); // @> VULN
    poolKey.currency1.transfer(to, amount1 + proportionalShare(tokenId, tokensOwed[tokenId].fees1Owed, amount)); // @> VULN
}

Recommended fix:

DIFF
+       uint256 proportionalFee0 = proportionalShare(tokenId, tokensOwed[tokenId].fees0Owed, amount);
+       uint256 proportionalFee1 = proportionalShare(tokenId, tokensOwed[tokenId].fees1Owed, amount);
+       tokensOwed[tokenId].fees0Owed -= proportionalFee0;
+       tokensOwed[tokenId].fees1Owed -= proportionalFee1;
-       poolKey.currency0.transfer(to, amount0 + proportionalShare(tokenId, tokensOwed[tokenId].fees0Owed, amount));
-       poolKey.currency1.transfer(to, amount1 + proportionalShare(tokenId, tokensOwed[tokenId].fees1Owed, amount));
+       poolKey.currency0.transfer(to, amount0 + proportionalFee0);
+       poolKey.currency1.transfer(to, amount1 + proportionalFee1);

Root cause#

Unlike Uniswap V3 (where tokensOwed lives in the NPM and is reduced by collect), V4 settles fees into the wrapper. The wrapper must track residual fees for multi-holder ERC-6909 positions. Paying from tokensOwed without decrementing leaves a reusable claim that outlives the position's fee balance.

Preconditions#

  • At least one position is partially unwrapped (fees sit in the wrapper).
  • Attacker can fully unwrap (via partial overload), recover, and re-wrap a position.
  • Stale tokensOwed for the attacker's tokenId is non-zero from a prior cycle.

Attack walkthrough#

  1. Victim wraps position V; attacker wraps position A; both accrue 100 fees.
  2. Victim partial-unwraps 10% → receives 10 fees; tokensOwed[V] still 100.
  3. Attacker full-via-partial unwraps A (takes own 100 fees); tokensOwed[A] still 100.
  4. Recover + re-wrap A (no new fees); stale tokensOwed[A] = 100 survives.
  5. Partial unwrap 90% of re-wrapped A pays 90 of stale claim from wrapper balance that still holds the victim's residual fees → 90 fee units stolen.
  6. Wrapper is short for the victim's remaining fee claim.

Diagrams#

sequenceDiagram participant V as Victim participant W as UniswapV4Wrapper participant A as Attacker V->>W: partial unwrap 10% Note over W: pays 10 fees#59; tokensOwed still 100 A->>W: full via partial unwrap Note over W: tokensOwed[A] still 100 stale A->>W: recover + rewrap A A->>W: partial unwrap 90% Note over W: pays 90 from victim residual fees Note over V,W: victim fee claim underfunded

Impact#

ERC-6909 holders of partially unwrapped positions lose accrued LP fees. Full unwrap for remaining holders can revert, blocking liquidators from recovering collateral and allowing bad debt to accrue (see also #61327).

Sources#


Sources & further analysis#

Reproductions & code

Alerts & third-party analyses

  • Web3Sec X hacked database: search.
  • Rekt leaderboard: search.
  • Solodit incident search: search.

These dashboards index community alerts tweets, post-mortems, and independent write-ups. Reach them through the protocol name above to cross-check this reproduction against other analyses.