Reproduced Exploit

Nested Finance: a delegatecall to an empty account reports success and the position is liquidated

functionDelegateCallUnverified delegatecalls a target and treats a true success flag as "the payload ran". The EVM returns success for an account with no code. Bob's topUp(500) against a codeless HyVM address reports success, collateral stays 1000, the position needed 1500, and liquidation transfer…

Feb 2023•Other•dependency•3 min read

Loss

1000 NEST seized. The top-up that would have saved the position did not run

Chain

Other

Category

dependency

Date

Feb 2023

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. 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: 29664-lack-of-contract-existence-checks-on-low-level-calls-trailof. Standalone Foundry PoC and full write-up: 29664-lack-of-contract-existence-checks-on-low-level-calls-trailof_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/dependency/unsafe-external-call

Key info#

FieldValue
Loss1000 NEST seized. The top-up that would have saved the position did not run
Vulnerable contractNestedWallet.functionDelegateCallUnverified
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit (liquidator)
Attack txExploit.run()
Chain / block / dateLocal synthetic · 2023-02
Compilersolc 0.8.27, cancun, via IR
Bug classLow-level delegatecall succeeds when the target has no code

TL;DR#

functionDelegateCallUnverified delegatecalls a target and treats a true success flag as "the payload ran". The EVM returns success for an account with no code. Bob's topUp(500) against a codeless HyVM address reports success, collateral stays 1000, the position needed 1500, and liquidation transfers the 1000 NEST to the caller. The report reaches the empty account by destroying the HyVM. This reduction starts from that end state: address(0xBEEF) has no code, which is exactly the condition the missing extcodesize check fails to reject. Cancun SELFDESTRUCT no longer clears code across transactions, so the synthetic does not pretend a later selfdestruct deleted the runtime code.

The vulnerable code#

SOLIDITY
(bool success, bytes memory returndata) = target.delegatecall(data); // @> VULN
if (success) {
    return returndata;
}

executeChecked adds require(target.code.length > 0) before the same delegatecall. Against a live HyVM, topUp(500) raises collateral from 1000 to 1500 and liquidation reverts. Against address(0xBEEF) the checked path reverts and the 1000 NEST stays in the wallet.

Root cause#

CALL, DELEGATECALL, and STATICCALL return success when the destination has no code. Nested's helper documents that it skips the existence check to save gas, on the assumption the target is always a contract. Trail of Bits notes that assumption is already broken by a separate issue that can destroy the HyVM.

Preconditions#

  • The wallet holds a position token balance (1000 NEST) and collateral of 1000 against a required 1500.
  • The execution target is an account with empty code.
  • Liquidation is permissionless once collateral is short.

Attack walkthrough#

  1. The wallet is told to delegatecall topUp(500) to address(0xBEEF).
  2. The delegatecall returns success and empty returndata. credit is never called. Collateral stays 1000.
  3. lastSuccess is stored as true.
  4. liquidate sees collateral under 1500 and transfers 1000 NEST to the caller.

Diagrams#

flowchart TD A["Wallet delegatecalls topUp on an account with no code"] --> B["EVM returns success and runs nothing"] B --> C["Collateral stays 1000 and the call is marked successful"] C --> D["Liquidation seizes 1000 NEST"]

Impact#

The user believes the save transaction worked. The position is liquidated and the 1000 NEST moves to the liquidator. With the codesize check, the same top-up either reverts (empty target) or actually credits collateral (live HyVM) and cannot be liquidated.

How to reproduce#

BASH
cd 29664-lack-of-contract-existence-checks-on-low-level-calls-trailof_exp
forge test -vv

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.