The $717,000 same-coin swap
A plain-language teardown of the CometDEX / Blend hack that anyone can follow, then the full technical dossier behind every claim. Read to the divider and stop, or keep going for the source lines, the executed proof, and the on-chain forensics.
A sorohunter write-up. Root cause read from the source-verified bytecode; the dollar figures reconstructed from the public ledger.
Part 1 — In plain words
What happened, in one paragraph
On August 25, 2026, someone pulled about $717,000 out of a liquidity pool on the Stellar network. They did not steal a password and they did not break any cryptography. They found a bookkeeping bug. The pool would let you "trade" a coin for the exact same coin, and every time you did, the pool lost count of its own money. It recorded that it held less than it actually did. The attacker turned that wrong number into free ownership of the pool, cashed it out, and repeated the move 36 times in under an hour.
The rest of this explains each piece, in order, so it actually makes sense. First the vocabulary. Five words do all the work in this story. Learn these five and you understand the hack.
The five things you need to know
1. A liquidity pool (also called an AMM). Picture a self-service currency booth with no human inside. People stock it by depositing two kinds of coin. Anyone can walk up, put one coin in, and take the other coin out. The price is set automatically by how much of each coin the booth holds at that moment. This particular booth held two tokens: BLND (the coin of a Stellar lending app called Blend) and USDC (a digital dollar, worth one US dollar). The precise name for the booth is an automated market maker, a small program that prices trades from its own reserves.
2. A swap. The basic action at the booth. You hand in some of coin A, the program hands you back some of coin B, and it updates its record of how much of each it now holds.
3. The pool's two sets of books. Slow down here, because this is the heart of the bug. The pool keeps a written record of how much it holds. Call that the book. Separately, there are the actual coins sitting in the pool's vault. Call that the physical. In a healthy pool these always match. The record says 1,000,000 dollars, the vault holds 1,000,000 dollars. The entire hack is about making those two numbers quietly disagree.
4. A flash loan. You asked for this one first, so here it is in full. A flash loan is a loan you take and repay inside a single transaction. No collateral, no credit check, no waiting days. The one rule is that you must give everything back before the transaction ends. If you cannot, the whole transaction is cancelled as if it never happened, and the lender never actually risked a cent. That sounds impossible until you see why it is safe. On a blockchain a transaction is all-or-nothing, so the lender can hand you two million dollars for a few thousandths of a second, and either you return it inside the same transaction or the whole thing rewinds and the money was never really gone. For an honest builder this is a useful, safe tool. For an attacker it is a firehose of temporary cash: borrow a fortune for an instant, use it to make a small trick pay big, repay it in the same breath. The precise version: an atomic borrow, use, and repay inside one transaction, with a repayment check that reverts everything if it fails.
5. LP shares. When you deposit coins into the pool you get back "shares," like receipts for your slice of the booth. Later you redeem the shares for coins. The important part: the number of shares you get is calculated from how big the pool thinks it is, meaning from the book, not from the physical. Hold onto that. It is the exit door the attacker walks through.
That is the whole vocabulary. Now the trick.
The trick, in plain language
The pool was missing one rule it should have had: it never checked that the coin going in was different from the coin coming out. So you could ask it to swap USDC for USDC. Trading a dollar for a dollar is pointless on its face, which is probably why nobody thought to forbid it. But because of a coding mistake, every USDC-for-USDC swap made the pool's book shrink below its physical. The vault still held the money. The record just forgot some of it.
Here is the shape of it with no code at all. Imagine a clerk with the pool's ledger. A normal swap touches two different accounts, so the clerk pulls two different pages, writes on each, and files them back. Fine. On a same-coin swap, though, "the page for the coin going in" and "the page for the coin coming out" are the same page. The clerk does not notice, and makes a photocopy for each hand. On one copy he adds the money coming in. On the other copy he subtracts the money going out. Then he files both copies back into the same slot, one after the other. The second copy lands on top. The first copy, the one with the money added, goes in the bin. The subtraction survives, the addition disappears. The ledger now says the pool holds less than the vault really does.
The clerk picture is close but not exact. The difference worth naming: there is no clerk and no theft in that moment. The miscount is silent, and the attacker pockets nothing during the swap itself. The swap even costs them a small fee. The profit arrives one step later.
That later step is the shares. With the book now under-counting the real reserves, the attacker deposits into the pool, and the pool works out their shares against the too-small book number. A smaller pool on paper means each deposited coin buys more shares than it should. The attacker gets over-issued shares, then redeems them for real coins out of the vault, which is still full. Deposit cheap, redeem rich, keep the difference. Then do it again. The flash loan is simply the stack of cash that lets them run the whole cycle at full size and pay it back in the same instant.
The one-line cause, and where it came from
The pool is a port. Its code was copied from Balancer, a well-known Ethereum project, and rewritten for Stellar. The obvious story is "they copied it and forgot a safety check." That story is false, and it matters. Balancer has no same-coin check either. It never needed one, because in Balancer's language the pool's two records point at the same stored slot, so the add and the subtract combine correctly. The Stellar rewrite used a language where reading a record gives you a copy, not a live link. The exact same logic that was safe with links became a silent bug with copies. Nobody deleted a safety check. The safety was hiding inside a feature of the old language, and the translation quietly dropped it.
Where the money went, in one look
The attacker drained 717,518.92 USDC across 36 runs, with profit per run decaying from about $46,000 down to about $6,000 as the pool emptied. They cashed out to a service called NearIntents (not the bridge that was widely reported). Three regulated exchanges sit at the cold end of the trail: the account was funded through HitBTC, its working cash came from Binance, and the exit went to NearIntents. Each of those knows who its customer is. No news outlet has published these numbers; this is the first count, rebuilt from the public ledger.
Today the pool is nearly empty (whitehats pulled the rest to safety), and its code is still unpatched and unpaused on-chain. If anyone refills it, it is still exploitable.
You now have the whole story. Everything below is the evidence.
Part 1 was the plain telling, and it is complete on its own. Part 2 is the technical dossier: the exact source lines with their commit hash, the mirror to the reference implementation, the executed proof-of-concept, the full money trail with transaction hashes, and the fix at the code level. Read on for the receipts, or stop here.
Part 2 — The full teardown
Provenance: what is verified, what is reported
Three tiers, kept apart on purpose.
Verified against primary source, live-checked
2026-08-26. Repository
github.com/CometDEX/comet-contracts-v1, commit
ef4cbfad0a35202ad267c14d163d2f362995a8d3 (author
mootz12, "chore: prep wasm release", 2024-05-02), confirmed
via the GitHub API. The vulnerable file is
contracts/src/c_pool/call_logic/pool.rs, and there is no
token_in != token_out guard anywhere in it. Most important:
the deployed pool
CAS3FL6TLZKDGGSISDBWGGPXT3NRR4DYTZD7YOD3HMYO6LTJUVGRVEAM
carries wasm hash
8abc28913035c07411ed5d134e6bfeab4723d97ddd4d1a22a0605d35c94d1a36
and stellar.expert marks it verified against exactly that
commit. The bytecode that ran is certified to match the source that was
read. There is no gap between the two.
Verified against Balancer V1 source.
BPool.sol :: swapExactAmountIn uses
Record storage inRecord = _records[tokenIn] (a storage
reference) and mutates in place, and there is no
ERR_SAME_TOKEN require anywhere in the file. Balancer's
safety is structural, not a guard.
Reconciled on-chain (Horizon, 2026-08-26). Total
drained 717,518.92 USDC, confirmed two independent ways
that agree to the cent: the sum of net USDC extracted across the 36 runs
equals the exfiltration (747,800.9234056) minus the Binance-sourced
working capital (30,282). Exactly 36 runs, first at
03:51:02 UTC (tx 41c898a1…9e2fc622), last at 04:43:56 UTC.
Per-run profit decayed monotonically 46,372.24 → 6,140.53
USDC. The exit went to NearIntents
(GDJ4JZXZ…BJK, near.com), not Allbridge as widely reported.
Attribution triad on the cold ends: HitBTC (account
funding), Binance (working capital),
NearIntents (exit).
Pool state and rescue. The pool now holds roughly 35.76 USDC and 47,403 BLND; the "~$326K / ~770K BLND remaining" figure was a mid-incident snapshot, since drained. The deployed wasm is byte-identical to the original (instance last modified in 2024): no upgrade, no pause, no freeze on-chain, only a front-end deposit block. Two whitehat wallets re-ran the bug hours later and kept value on Stellar rather than bridging it out; WH2 holds ~23.17M BLND. Honest caveat: the "WH1 was SDF-funded" claim is overstated. WH1's primary funder is untagged; its only SDF link is a single 1.37 XLM inflow from an SDF hot wallet, a tag-trace, not funding.
No secondary press exists. Across Exa, web search,
and the incident trackers (defimon, smartcontractshacking, lumenloop),
zero sources carry the $717K / 36-run / decay / NearIntents figures. The
only citable public acknowledgment is Blend's own
@blend_capital statement: "There is an ongoing incident
with the BLND-USDC liquidity pool on Comet… no issue with Blend
contracts… backstop depositors are impacted." It independently
confirms the failure is in the Comet pool, not in Blend, exactly as the
code shows. Every dollar figure here was reconstructed from the ledger,
because nowhere else carries it.
The mechanism, with every line
Part 1 gave the intuition. Here is every line and guard. The function
is execute_swap_exact_amount_in,
pool.rs:112 @ef4cbfad.
Two copies out of one map:
let mut record_map = read_record(&e); // :127
let mut in_record = record_map.get(token_in.clone())...ErrNotBound; // :128 copy A
let mut out_record = record_map.get(token_out.clone())...ErrNotBound; // :131 copy B
Map::get returns an owned value. When
token_in == token_out, copy A and copy B are independent
clones of the same record. Independent mutation, colliding write:
in_record.balance = in_record.balance.checked_add(token_amount_in)...; // :156 credit leg (copy A)
out_record.balance = out_record.balance - token_amount_out; // :165 debit leg (copy B)
record_map.set(token_in, in_record); // :202 write copy A
record_map.set(token_out, out_record); // :203 write copy B → SAME KEY, overwrites A
write_record(&e, record_map); // :205
Both set calls hit the same key; the second wins; the
:156 credit is discarded. The book becomes
book_before - token_amount_out. None of the function's own
guards stop it: the MAX_IN_RATIO check (:134)
only caps a single swap at ≤50% of the reserve, which is exactly why the
attack needs many runs, and the spot-price monotonicity checks
(:169, :174, :175) all pass for a
same-asset input.
The real tokens move regardless of the bookkeeping bug:
pull_underlying(token_in, user, token_amount_in); // :193 +in real USDC enters
push_underlying(token_out, user, token_amount_out); // :200 −out real USDC leaves
The swap fee makes
token_amount_out < token_amount_in, so the vault nets
positive while the book drops. The gap:
physical_after = physical_before + token_amount_in − token_amount_out
book_after = book_before − token_amount_out
⇒ book_after = physical_after − token_amount_in (the book under-counts by token_amount_in)
Monetization reads the corrupted book: calc_spot_price
(c_math.rs:14) and
execute_dep_tokn_amt_in_get_lp_tokns_out
(pool.rs:303, minting via
calc_lp_token_amount_given_token_deposits_in at
:330) both price against the understated reserve, so a
deposit buys inflated LP shares (OBJ-MINT); redeeming them pays out real
tokens (OBJ-DRAIN). The flash loan only supplies the capital to run the
cycle at size and unwind atomically.
Root cause: a porting hazard, not a missing guard
Balancer V1, the reference Comet was ported from, has no
tokenIn != tokenOut guard. The only requires in its
swapExactAmountIn are ERR_NOT_BOUND (twice)
and ERR_SWAP_NOT_PUBLIC. It is safe for a different
reason:
// Balancer V1 BPool.sol :: swapExactAmountIn
Record storage inRecord = _records[address(tokenIn)]; // storage REFERENCE
Record storage outRecord = _records[address(tokenOut)]; // storage REFERENCE
...
inRecord.balance = badd(inRecord.balance, tokenAmountIn); // writes the slot
outRecord.balance = bsub(outRecord.balance, tokenAmountOut); // reads the JUST-WRITTEN slot, composes
When tokenIn == tokenOut, both references point at the
same storage slot, the writes compose in place
(B + in − out), and the book stays equal to the vault. The
Soroban port kept the logic and lost the aliasing:
| Balancer V1 (Solidity) | Comet (Soroban / Rust) | |
|---|---|---|
| Record binding | Record storage r = _records[k] (reference) |
let mut r = record_map.get(k) (owned copy) |
| Two same-key bindings | alias one slot | two independent clones |
| Mutate both, write both | compose in place → B+in−out |
last set clobbers → B−out |
| Same-asset swap | harmless no-op | reserve corruption |
tokenIn != tokenOut guard |
absent (not needed) | absent (now load-bearing) |
Stated plainly with the disanalogy: "Comet is Balancer" holds for the
math and the function shapes, and breaks precisely at the memory model.
Solidity storage structs are references into one mutable
store; Rust Map::get yields values. The class name is not
"missing check" but:
Aliased-key last-write-wins: a function reads two or more records from a single keyed store using distinct caller-supplied keys, mutates the copies independently, and writes them back, without ensuring the keys are distinct or that colliding keys accumulate. When two keys collide, one mutation is silently lost.
That generalizes past AMMs to any Soroban contract doing a
read-modify-write over a Map<Address, _> with two or
more externally-controlled keys: token bridges, internal ledgers, batch
transfers, self-referential escrow.
Placing it in the Soroban ATT&CK matrix: TM-03
sorohunter maintains a Soroban ATT&CK matrix where every mechanically-decidable technique ships as a fork-validated detector. This bug's sibling is already catalogued: TM-02 (fee-on-transfer accounting), where a vault credits the deposit argument instead of the measured delta, so the book ends up larger than the vault (anchor: Coinspect Tricorn Bridge TRI-005). TM-03 is its mirror:
| TM-02 fee-on-transfer | TM-03 aliased-key last-write-wins | |
|---|---|---|
| Divergence | book > physical | book < physical |
| Cause | credits the arg, not the measured delta | clobbers the credit leg on a key collision |
| Trigger | a deflationary token shrinks physical | a same-asset (X→X) swap |
| Terminal state | insolvency (withdraw > holdings) | inflated LP mint → over-redeem |
| Detector invariant | book/physical reconciliation | book/physical reconciliation |
| Anchor | Tricorn Bridge TRI-005 (audit) | CometDEX / Blend, 2026-08-25 (live mainnet) |
The matrix disclaims MITRE-style authority-by-campaign-breadth, since Soroban's public-exploit base is thin, and earns authority instead by fidelity and executability. TM-03 is a rare thing here: a genuine, observed, attributed, on-chain-verified mainnet exploit anchoring the accounting-integrity tactic, not an EVM analog.
The detector, executed
TM-03 is fork-decidable, the bar sorohunter sets before a technique
counts: no oracle, no false-positive, it either diverges or it does not.
It ships as probe_alias
(harness --alias), modeled on the existing
probe_feetoken / probe_econ. It loads the
target's public WASM into a local Env fork (never the live
contract; for CometDEX the deployed wasm is source-verified against
ef4cbfad, so the fork runs the exact exploited bytecode),
seeds a reconciled reserve (book == physical), runs a
same-asset swap, and flags Δbook ≠ Δphysical as an executed
breach.
Ground-truth corpus in bench/, matching the
econ_vuln/econ_safe and
fee_vault_vuln/fee_vault_safe pattern:
alias_vuln (the planted bug, faithful to
pool.rs@ef4cbfad), alias_safe (the same pool
with the distinctness guard), and honest_token (a correct
asset so physical holdings are real balances). Executed result (local
fork, soroban-sdk 25):
$ harness --alias alias_vuln.wasm out.json honest_token.wasm
verdict = alias-corruption
swap(token, 100000, token) executed;
book 1,000,000 -> 901,000 (Δ -99,000)
physical 1,000,000 -> 1,001,000 (Δ +1,000)
Δbook (-99,000) != Δphysical (+1,000) — reserve corrupted by 100,000,
book under-counts physical, mintable as inflated LP shares. [EXECUTED PROOF OF TM-03]
$ harness --alias alias_safe.wasm out.json honest_token.wasm
verdict = held # same-asset swap reverts on the guard — 0 false positives
The numbers match the source derivation to the unit: after the
same-asset swap the book reads B − amount_out while the
vault holds B + amount_in − amount_out, so it under-counts
by exactly amount_in. Plant caught, decoy clean, in a local
fork. A finding is a run, not an opinion.
Forensic dossier
All timestamps UTC, 2026-08-25.
| Time | Event | Evidence |
|---|---|---|
| 03:25:34 | HitBTC hot-wallet GD5NP74F…R6OT
creates + funds attacker GCENJ4XB…WYHC with 535.5768625
XLM |
create_account tx 51b4021b…539c2 |
| 03:27:29 | Attacker opens USDC / BLND trustlines | change_trust |
| 03:32:10 | 30,282 USDC of working capital from Binance
Withdrawals GC5LF63G… |
tx c76f9c07… |
| 03:47:32 → | Uploads throwaway wasm, deploys launcher / receiver contracts (staggered, not all upfront) | UploadContractWasm ×5, CreateContract
×10 |
| 03:51:02 | First exploit run — flash_seed on launcher
CC5DXEZ6…, hitting pool CAS3FL…VEAM. Net:
46,372.24 USDC |
exploit tx 41c898a1…9e2fc622 |
| 03:51 → 04:44 | 36 flash_seed runs, profit decaying
46,372.24 → 6,140.53 USDC |
121 InvokeContract ops: 36 flash_seed, 34
collect_seed |
| 04:43:56 | Last exploit run | — |
| 04:49:28 | Exfil leg 1 — 500,000.00 USDC to
NearIntents GDJ4JZXZ…BJK (memo
161699389) |
tx b4ed8e91…b24f8 |
| 04:53–04:54 | Throwaway accounts account_merged into the root; exfil
leg 2 — 247,800.92 USDC (memo
161702282) |
tx 3daa4753… |
Totals: 36 runs, 717,518.92 USDC
drained (reconciles to the cent, two ways), 747,800.92
USDC exfiltrated. From account birth to first hit: ~26 minutes.
The "4 throwaway contracts deployed ~26 min before" claim is corrected:
4 distinct launchers fired the 36 runs, but deployments were staggered
through the window (~10 CreateContract ops), not batched
upfront. Attribution rests on the stellar.expert community directory
(high-trust, third-party), not a cryptographic proof.
Whitehat rescue. Two wallets re-ran the bug later the same day (WH1 11:14–12:10, WH2 12:06–19:53 UTC) and kept value on Stellar, bridging nothing. WH2 holds ~23.17M BLND. WH1 is a long-lived redistributor (created 4 days after the February YieldBlox incident; 1,150 payments to 419+ recipients since); its SDF link is a single 1.37 XLM tag-trace, and its classic balances are unchanged since July, so "WH1 held new proceeds" is not visible on-chain.
Prevention: five layers, with code
One line stops this exploit. Five layers stop the class. Ship all five.
Layer 0 — the distinctness guard.
assert_with_error!(&e, token_in != token_out, Error::ErrSameToken);
At the top of every function taking a token_in and
token_out. Framing correction: this is a new guard
the Soroban VM's value semantics now require, not "the guard Balancer
has." Balancer needs none.
Layer 1 — never hold aliased copies of mutable state. The real fix. Resolve the collision to one net update, or accumulate deltas and apply each key once:
if token_in == token_out {
let mut r = record_map.get(token_in.clone()).unwrap();
r.balance = r.balance + token_amount_in - token_amount_out; // single net write
record_map.set(token_in, r);
} else { /* distinct-key path */ }
Layer 2 — post-condition reconciliation, done right.
The tempting one-liner is wrong.
assert!(record.balance <= physical) does not catch this
bug, because the same-asset swap makes
book = physical − amount_in, i.e.
book < physical, which passes. And you cannot flip it to
physical <= book, because execute_gulp
(pool.rs:24) legitimately absorbs donations
(physical > book). The invariant that catches both
directions is a per-operation delta check:
let delta_book = record.balance - book_before;
let delta_moved = amount_pulled - amount_pushed; // net physical movement this call
assert_with_error!(&e, delta_book == delta_moved, Error::ErrReserveDrift);
For the buggy swap delta_book = −out while
delta_moved = +in − out; they differ by in, so
it trips on the first run. Failure mode to name: a one-sided global
comparison feels like the same control but silently covers half the
space.
Layer 3 — test the aliased input on purpose. A random fuzzer almost never picks the same key twice; seed it. A same-asset swap must be a no-op or a revert (metamorphic), and differential testing against a reference Balancer model flags the divergence directly.
Layer 4 — process. When porting a battle-tested AMM,
diff the semantics, not the requires: this bug is a
memory-model divergence (storage reference → owned value),
and a require-by-require checklist would have passed. And publish loudly
that "source-verified ≠ audited": here the verified badge was correct
and the code was exploitable at the same time.
Responsible disclosure
The bug is already public and already exploited, and the pool is
nearly empty, so documenting the mechanics of a spent exploit helps
defenders and costs attackers nothing new. This document contains no
ready-to-run attack payload, only mechanics, taxonomy, and the fix. For
anything still live and not yet exploited, the order is fixed: a private
channel first (the protocol's security contact, or Immunefi Stellar;
SDF's channel for the core / SDK), public only after a patch.
sorohunter's own invariant is stricter: it only ever runs a target's
public bytecode in a local Env fork, and never signs or
sends a transaction to any live network.
Mechanism verified against source-verified bytecode; the Balancer
disanalogy against BPool.sol; dollar figures reconciled
on-chain and, where they are the community's, flagged as such. If a
number here is not backed by one of those, it is not in here.