On December 2, an attacker exploited a bug in ApeChain's native yield code. ApeChain is an Arbitrum Orbit chain that uses APE as its gas token, and APE reaches it over a LayerZero bridge from Ethereum. In one transaction the attacker's balance went from 1 APE to about 268 million, and 138 million of that was bridged to Ethereum, where it released real APE. Yuga Labs' Quit described the bug on X: the attacker pointed their yield at a contract and self-destructed that contract in the same transaction, and "a bug caused it to leave behind a copy of the attacker's balance." Blockaid flagged the attack at 18:48 UTC, and Yuga's CEO posted the damage that evening: 268 million unbacked APE, 130 million of them frozen on ApeChain.
The postmortem isn't out yet, so I'll leave the root cause in ApeChain's yield code to Yuga Labs and stick to what public RPC data shows.
What the trace shows
ApeChain's public RPC answers debug_traceTransaction with the callTracer, which returns the full call tree of a transaction. The exploit transaction has 56 CREATE2 frames and 56 SELFDESTRUCT frames spread over 28 addresses. At each address the same sequence repeats: deploy with CREATE2, self-destruct, deploy again at the same address, self-destruct again. The first self-destruct moves nothing. The second sends APE to the attacker's contract, and each address pays out exactly twice as much as the one before it:
1, 2, 4, 8, 16, ... 33554432, 67108864, 134217728 There are 28 payouts. The first is 1 APE and the last is 2^27, so the balance ends at 2^28 = 268,435,456 APE, the "1 ape to 268M ape in 28 rounds" from Quit's post. The trace also holds 28 calls that reverted.
On Ethereum, EIP-6780 keeps the old account-deleting SELFDESTRUCT only for a contract destroyed in the same transaction that created it. Every self-destructing address in this trace was deployed earlier in the same transaction.
Following the LayerZero packet to Ethereum
The same transaction emitted an OFTSent event from ApeChain's bridge contract (OrbitNativeOFTAdapter): 138,000,000 APE to endpoint ID 30101, which is Ethereum in LayerZero's numbering. ApeChain is 30312. The event's first indexed topic is the LayerZero guid, and the same value is the first indexed topic of OFTReceived on the receiving side, so one eth_getLogs filter on the Ethereum adapter's address and that guid finds the delivery, 85 seconds later:
- ApeChain block 56,533,726 at 18:03:34 UTC:
OFTSent, 138,000,000 APE - Ethereum block 26,544,111 at 18:04:59 UTC:
OFTReceived, 138,000,000 APE, same guid
Where the 138 million came from
The Ethereum side is ApeOFTAdapter, with verified source on Blockscout. It keeps the APE it holds staked. When APE leaves for ApeChain it calls depositSelfApeCoin on the ApeCoin Staking contract, and when APE comes back it calls withdrawSelfApeCoin for whatever it needs, so the delivery transaction pulled 138 million APE out of staking and passed it to the attacker. An archive eth_call of the APE token's balanceOf, one block before the delivery and at it, shows the effect on the staking contract: about 156.3 million APE before and about 18.3 million after. One message took 88.3% of the balance.
Then ApeChain stopped. Its newest block, 56,535,991, is stamped 18:29:04 UTC on December 2, and it was still the head when I ran the script 28 hours later.
The script
Node 18+ for the global fetch, no dependencies. It reads the ApeChain trace and OFTSent log, the matching OFTReceived on Ethereum, the staking balance around the delivery block and ApeChain's newest block.
// trace-apechain.mjs: follow the December 2, 2026 ApeChain exploit across two chains with plain JSON-RPC. // Node 18+ (global fetch), no dependencies. // // node trace-apechain.mjs trace the exploit on ApeChain and Ethereum (public RPCs) // node trace-apechain.mjs --selftest offline checks of the decoders and the doubling test // // What it reads: // 1. ApeChain: debug_traceTransaction (callTracer) on the exploit transaction, then its OFTSent log. // 2. Ethereum: the OFTReceived log with the same LayerZero guid, found with eth_getLogs. // 3. Ethereum archive state: APE held by the ApeCoin Staking contract one block before and at the delivery block. // 4. ApeChain: the newest block, to see whether the chain is producing blocks. const RPC = { ape: ['https://rpc.apechain.com/http', 'https://apechain.calderachain.xyz/http'], eth: ['https://ethereum-rpc.publicnode.com', 'https://rpc.mevblocker.io', 'https://gateway.tenderly.co/public/mainnet', 'https://eth.drpc.org', 'https://1rpc.io/eth'], // free endpoints differ: publicnode wants a token for archive state, 1rpc caps eth_getLogs at 50 blocks, so logs are read in 50-block chunks }; const EXPLOIT_TX = '0xee4ab556e8073393ee779d7381fed7528e520bf47f3e4145d56f643ac6cde949'; // ApeChain const APE = '0x4d224452801aced8b2f0aebe155379bb5d594381'; // ApeCoin (ERC-20) on Ethereum const OFT_ADAPTER = '0x5182fede730b31a9cf7f49c5781214b4a99f2370'; // ApeOFTAdapter on Ethereum (verified source) const APE_STAKING = '0x5954ab967bc958940b7eb73ee84797dc8a2afbb9'; // ApeCoinStaking on Ethereum, where the adapter deposits APE // event topics (keccak256 of the signatures) const TOPIC = { // OFTSent(bytes32 indexed guid, uint32 dstEid, address indexed fromAddress, uint256 amountSentLD, uint256 amountReceivedLD) OFTSent: '0x85496b760a4b7f8d66384b9df21b381f5d1b1e79f229a47aaf4c232edc2fe59a', // OFTReceived(bytes32 indexed guid, uint32 srcEid, address indexed toAddress, uint256 amountReceivedLD) OFTReceived: '0xefed6d3500546b29533b128a29e3a94d70788727f0507505ac12eaf2e578fd9c', }; const EID = { 30101: 'Ethereum', 30312: 'ApeChain' }; // LayerZero endpoint IDs (LayerZero deployments metadata) const WEI = 10n ** 18n; // ---------- JSON-RPC with fallbacks ---------- let rpcId = 0; async function rpc(chain, method, params) { let last; for (const url of RPC[chain]) { try { const res = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: ++rpcId, method, params }), signal: AbortSignal.timeout(30000), }); const j = await res.json(); if (j.error) throw new Error(`${method}: ${j.error.message}`); return j.result; } catch (e) { last = new Error(`${url} ${e.message}`); } } throw last; } const hex = (n) => '0x' + n.toString(16); const word = (data, i) => data.slice(2 + i * 64, 2 + (i + 1) * 64); // i-th 32-byte word of ABI data const addr = (w) => '0x' + w.slice(-40); const iso = (ts) => new Date(Number(ts) * 1000).toISOString().replace('.000Z', 'Z'); const ape = (wei) => (wei / WEI).toLocaleString('en-US') + ' APE'; // ---------- decoders ---------- export function decodeOFTSent(log) { return { guid: log.topics[1], from: addr(log.topics[2]), dstEid: Number(BigInt('0x' + word(log.data, 0))), amountSent: BigInt('0x' + word(log.data, 1)), amountReceived: BigInt('0x' + word(log.data, 2)), }; } export function decodeOFTReceived(log) { return { guid: log.topics[1], to: addr(log.topics[2]), srcEid: Number(BigInt('0x' + word(log.data, 0))), amount: BigInt('0x' + word(log.data, 1)), }; } // Flatten a callTracer result and pull out every SELFDESTRUCT with a non-zero value. export function selfdestructPayouts(trace) { const out = []; const counts = {}; const walk = (c) => { counts[c.type] = (counts[c.type] || 0) + 1; if (c.type === 'SELFDESTRUCT' && BigInt(c.value || '0x0') > 0n) out.push(BigInt(c.value)); (c.calls || []).forEach(walk); }; walk(trace); return { payouts: out, counts }; } // True if every payout is exactly twice the previous one. export const doublesEachStep = (xs) => xs.length > 1 && xs.every((x, i) => i === 0 || x === xs[i - 1] * 2n); // The check a release-side limit performs: how much of the backing would one message take? export function releaseCheck({ backing, amount, maxShare }) { const sharePpm = backing === 0n ? 1_000_000n : (amount * 1_000_000n) / backing; const share = Number(sharePpm) / 1e6; return { share, allowed: share <= maxShare }; } // ---------- the trace ---------- async function main() { // 1. ApeChain: the exploit transaction const tx = await rpc('ape', 'eth_getTransactionByHash', [EXPLOIT_TX]); const block = await rpc('ape', 'eth_getBlockByNumber', [tx.blockNumber, false]); console.log(`ApeChain tx ${EXPLOIT_TX.slice(0, 12)}… block ${Number(tx.blockNumber)} ${iso(block.timestamp)}`); console.log(` from ${tx.from} to ${tx.to}`); const trace = await rpc('ape', 'debug_traceTransaction', [EXPLOIT_TX, { tracer: 'callTracer' }]); const { payouts, counts } = selfdestructPayouts(trace); console.log(` frames: ${Object.entries(counts).map(([k, v]) => `${k} ${v}`).join(', ')}`); console.log(` non-zero SELFDESTRUCT payouts: ${payouts.length}, first ${ape(payouts[0])}, last ${ape(payouts.at(-1))}`); console.log(` each payout is twice the one before: ${doublesEachStep(payouts)}`); console.log(` 1 APE doubled ${payouts.length} times = ${(2n ** BigInt(payouts.length)).toLocaleString('en-US')} APE`); const receipt = await rpc('ape', 'eth_getTransactionReceipt', [EXPLOIT_TX]); const sentLog = receipt.logs.find((l) => l.topics[0] === TOPIC.OFTSent); const sent = decodeOFTSent(sentLog); console.log(` OFTSent ${ape(sent.amountSent)} to ${EID[sent.dstEid] ?? sent.dstEid} (eid ${sent.dstEid}), guid ${sent.guid.slice(0, 14)}…`); // 2. Ethereum: find the delivery by the same guid const ethHead = await rpc('eth', 'eth_getBlockByNumber', ['latest', false]); const sentTs = Number(block.timestamp); const guess = Number(ethHead.number) - Math.round((Number(ethHead.timestamp) - sentTs) / 12); let recvLog; for (let from = guess - 40; from < guess + 600 && !recvLog; from += 50) { const logs = await rpc('eth', 'eth_getLogs', [{ address: OFT_ADAPTER, topics: [TOPIC.OFTReceived, sent.guid], fromBlock: hex(from), toBlock: hex(from + 49) }]); recvLog = logs[0]; } if (!recvLog) throw new Error('delivery not found near the expected block'); const recv = decodeOFTReceived(recvLog); const recvBlock = await rpc('eth', 'eth_getBlockByNumber', [recvLog.blockNumber, false]); const n = Number(recvLog.blockNumber); console.log(`\nEthereum tx ${recvLog.transactionHash.slice(0, 12)}… block ${n} ${iso(recvBlock.timestamp)}`); console.log(` OFTReceived ${ape(recv.amount)} from ${EID[recv.srcEid] ?? recv.srcEid} (eid ${recv.srcEid}) to ${recv.to}`); console.log(` same guid: ${recv.guid === sent.guid}, ${Number(recvBlock.timestamp) - sentTs} s after the ApeChain transaction`); // 3. Ethereum archive state: what the release took out of ApeCoin Staking const balanceOf = async (who, blockNumber) => BigInt(await rpc('eth', 'eth_call', [{ to: APE, data: '0x70a08231' + who.slice(2).padStart(64, '0') }, hex(blockNumber)])); const before = await balanceOf(APE_STAKING, n - 1); const after = await balanceOf(APE_STAKING, n); console.log(` APE in ApeCoinStaking: ${ape(before)} -> ${ape(after)}`); const check = releaseCheck({ backing: before, amount: recv.amount, maxShare: 0.05 }); console.log(` one message took ${(check.share * 100).toFixed(1)}% of that balance; a 5% cap ${check.allowed ? 'allows' : 'rejects'} it`); // 4. ApeChain head const head = await rpc('ape', 'eth_getBlockByNumber', ['latest', false]); const age = Math.round(Date.now() / 1000 - Number(head.timestamp)); console.log(`\nApeChain newest block ${Number(head.number)} at ${iso(head.timestamp)} (${(age / 3600).toFixed(1)} h before this run, checked ${new Date().toISOString().slice(0, 16)}Z)`); } // ---------- offline self-test (fixtures copied from the real logs) ---------- function selftest() { const ok = (cond, msg) => { console.log(`${cond ? 'PASS' : 'FAIL'} ${msg}`); if (!cond) process.exitCode = 1; }; const sentLog = { topics: [TOPIC.OFTSent, '0xc2865a64125fe8a639eb9909ccd5535ee1612b2bc8ca3bcab2646fc49ff54536', '0x0000000000000000000000006c2e749eab6930450397b886d0a3347b98ebc60c'], data: '0x00000000000000000000000000000000000000000000000000000000000075950000000000000000000000000000000000000000007226a2fd7a7818ca0000000000000000000000000000000000000000000000007226a2fd7a7818ca000000', }; const recvLog = { topics: [TOPIC.OFTReceived, '0xc2865a64125fe8a639eb9909ccd5535ee1612b2bc8ca3bcab2646fc49ff54536', '0x000000000000000000000000484651ffacf3f43fc4861b4190b880a4e15f3db7'], data: '0x00000000000000000000000000000000000000000000000000000000000076680000000000000000000000000000000000000000007226a2fd7a7818ca000000', }; const s = decodeOFTSent(sentLog); const r = decodeOFTReceived(recvLog); ok(s.dstEid === 30101 && s.amountSent === 138_000_000n * WEI, 'OFTSent decodes to 138,000,000 APE for eid 30101'); ok(r.srcEid === 30312 && r.amount === s.amountSent && r.guid === s.guid, 'OFTReceived decodes to the same amount and guid from eid 30312'); const fake = { type: 'CALL', calls: [1n, 2n, 4n, 8n].map((v) => ({ type: 'SELFDESTRUCT', value: hex(v * WEI) })).concat([{ type: 'SELFDESTRUCT', value: '0x0' }]) }; const p = selfdestructPayouts(fake); ok(p.payouts.length === 4 && doublesEachStep(p.payouts), 'payout extractor skips zero-value frames and spots doubling'); ok(!doublesEachStep([1n, 2n, 5n]), 'doubling test rejects a broken sequence'); ok(2 ** 28 === 268_435_456, '1 doubled 28 times is 268,435,456'); const c = releaseCheck({ backing: 156_324_862n * WEI, amount: 138_000_000n * WEI, maxShare: 0.05 }); ok(!cSource:https://dev.to/nefiswap/a-chain-bug-turned-1-ape-into-268-million-tracing-it-across-apechain-and-ethereum-in-plain-nodejs-1mm4Related posts
What Fast Travel in Games Teaches About Jump Links on Law Firm Pages
بنيت موقع لتنظيم الجمعية في صفحة HTML واحدة: إيه اللي اتعلمته
