Reproduced Exploit

StationX: crossChainBuy spends protocol fees on the LayerZero refund

crossChainBuy sends the 0.8 ETH deposit out of the factory balance, then calls the comm layer with msg.value - fees. A 1 ETH call therefore forwards another 0.9 ETH. The factory already held 5 ETH of fees, so it supplies the shortfall. The comm layer keeps 0.05 ETH and refunds 0.85 ETH to the calle…

Oct 2024•Ethereum•logic•3 min read

Loss

0.65 ETH of the factory 5 ETH fee balance is taken. The factory is left with 4.3 ETH

Chain

Ethereum

Category

logic

Date

Oct 2024

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: 41384-c-03-native-tokens-can-be-drained-from-the-factory-contract. Standalone Foundry PoC and full write-up: 41384-c-03-native-tokens-can-be-drained-from-the-factory-contract_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/missing-check

Key info#

FieldValue
Loss0.65 ETH of the factory 5 ETH fee balance is taken. The factory is left with 4.3 ETH
Vulnerable contractFactory.crossChainBuy
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2024-10
Compilersolc 0.8.27, cancun
Bug classmsg.value minus fees is forwarded after the deposit was already paid

TL;DR#

crossChainBuy sends the 0.8 ETH deposit out of the factory balance, then calls the comm layer with msg.value - fees. A 1 ETH call therefore forwards another 0.9 ETH. The factory already held 5 ETH of fees, so it supplies the shortfall. The comm layer keeps 0.05 ETH and refunds 0.85 ETH to the caller. Net, the caller gains 0.65 ETH and the factory loses 0.7 ETH.

The vulnerable code#

SOLIDITY
(bool ok,) = dao.call{value: DEPOSIT}("");
uint256 fees = FEES;
comm.sendMsg{value: msg.value - fees}(refundTo); // @> VULN: value ignores the deposit already paid

Subtract the deposit, the owner share, and every fee before funding the message, which is what the report asks: the remaining value must account for the native deposit, the owner share, deposit fees, and KYC fees.

Root cause#

checkDepositFeesSent only requires msg.value to cover the deposit. The same msg.value is then reduced by fees alone and forwarded. Both transfers come out of the factory balance, so previously collected native fees pay the second one. The unused message value is refunded to an address the caller chooses.

Preconditions#

  • The factory holds 5 ETH of protocol fees before the call.
  • The caller sends 1 ETH. Deposit is 0.8 ETH, the formula fee is 0.1 ETH, and the message cost is 0.05 ETH.
  • The refund address is the caller.

Attack walkthrough#

  1. crossChainBuy receives 1 ETH. The factory balance is 6 ETH.
  2. 0.8 ETH is sent to the caller as the DAO deposit. Balance is 5.2 ETH.
  3. sendMsg is called with 0.9 ETH. Balance is 4.3 ETH.
  4. The comm layer keeps 0.05 ETH and refunds 0.85 ETH.
  5. Caller balance is 1.65 ETH. Profit after returning the 1 ETH capital is 0.65 ETH.
  6. That 0.65 ETH is what loot holds.

Diagrams#

flowchart TD A["Factory holds 5 ETH of fees"] --> B["Caller sends 1 ETH to crossChainBuy"] B --> C["0.8 ETH deposit is paid from the factory"] C --> D["VULN sendMsg value is msg.value minus fees"] D --> E["0.9 ETH leaves for the comm layer"] E --> F["0.85 ETH is refunded and loot keeps 0.65 ETH"] F --> G["Factory balance is 4.3 ETH"]

Impact#

The factory's accumulated native fees pay for a cross-chain buy the caller did not fully fund. In this run 0.7 ETH leaves the 5 ETH fee balance, 0.05 ETH is the real message cost, and 0.65 ETH is profit to the caller. Repeating the call drains the rest.

How to reproduce#

BASH
cd 41384-c-03-native-tokens-can-be-drained-from-the-factory-contract_exp
forge test -vv

output.txt is the captured passing run. The control test checks the recommended fix.

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.