Reproduced Exploit

Zaros liquidation drops positive unrealized PnL and pays the liquidator only the collateral

liquidate reads unrealized PnL and then deducts maintenance from collateral only. The positive PnL is never minted.

Jul 2024•Ethereum•logic•2 min read

Loss

300 USDZ of positive PnL is discarded. The liquidator is paid 900 instead of 1100, and the account is left at…

Chain

Ethereum

Category

logic

Date

Jul 2024

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

The attack replays in your browser. Step through it by Solidity line or by opcode.

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. Query opens a search over the trace: previous and next writes, balance changes and calls, breakpoints, and a diff of everything that changed between two steps. No backend, no live RPC.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 37975-positive-pnl-is-lost-for-all-parties-when-liquidating-an-acc. Standalone Foundry PoC and full write-up: 37975-positive-pnl-is-lost-for-all-parties-when-liquidating-an-acc_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/unrealized-pnl · vuln/defi/liquidation

Key info#

FieldValue
Loss300 USDZ of positive PnL is discarded. The liquidator is paid 900 instead of 1100, and the account is left at 0 instead of 100
Vulnerable contractEngine.liquidate
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit at 0x15452ec016c4dc8c549e7fe6ff4b26324ea8b7a4
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2024-07
Compilersolc 0.8.27, cancun, via IR
Bug classLiquidation deducts collateral without minting positive unrealized PnL
flowchart TD A["Account has 900 collateral and +300 unrealized PnL"] --> B["Maintenance requirement is 1100"] B --> C["VULN liquidation ignores the PnL and takes all 900"] C --> D["PnL is stored as 0 and the liquidator receives 900"] B --> E["Control mints the 300 onto collateral first"] E --> F["Liquidator receives 1100 and the account keeps 100"]

TL;DR#

liquidate reads unrealized PnL and then deducts maintenance from collateral only. The positive PnL is never minted.

The account has 900 collateral and +300 PnL. Maintenance is 1100. The vulnerable call treats 900 as the whole balance, transfers that 900 to the liquidator, and stores PnL as 0. The 300 is gone. The account balance is 0.

The fixed call mints 300 USDZ onto the account first. Collateral becomes 1200. It then transfers the 1100 maintenance and leaves 100.

The vulnerable code#

SOLIDITY
int256 pnl = unrealizedPnl[user];
uint256 col = collateral[user];
uint256 margin = col;
require(requiredMaintenance > margin, "healthy");
require(requiredMaintenance > margin && pnl > 0, "healthy");
usdz.transfer(msg.sender, take); // @> VULN: pays the 900 collateral; the +300 PnL was never minted

The quoted liquidateAccounts path loads unrealized PnL, checks maintenance against margin, and calls deductAccountMargin without the mint that SettlementBranch performs for a positive PnL.

Impact#

300 USDZ of positive PnL is not minted and is not paid. The liquidator receives 900 instead of 1100. The account is emptied instead of keeping 100.


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.