Altius JournalBack to Learning Hub
Interoperability & Cross-Chain

Atomic Swaps Explained: How Cross-Chain Trading Works

How atomic swaps enable trustless cross-chain trades using hash timelock contracts, including the mechanics, security model, and where they fall short.

Atomic Swaps Explained: How Cross-Chain Trading Works

Why Atomic Swaps Matter in a Multichain World

TL;DR

- Atomic swaps are peer-to-peer trades across blockchains without custodians.  

- Hashed Timelock Contracts (HTLCs) enforce “all or nothing” execution.  

- Bitcoin’s Script and Ethereum’s smart contracts both support HTLC patterns.  

- Real-world use: Komodo’s BarterDEX and Lightning Labs’ submarine swaps.  

- Limits include liquidity fragmentation and mismatched block times.  

- Future relies on standardized HTLC templates and relay chains.

Atomic Swaps: The Mechanics of Trustless Cross-Chain Exchange

Direct asset exchange between blockchains once required centralized order books or wrapped tokens. Atomic swaps invert that model. Two parties trade native coins, say, BTC for ETH, using cryptographic commitments that guarantee either both legs settle or neither does.

The core primitive is the hashed timelock contract (HTLC). An HTLC locks funds behind two conditions: revelation of a preimage to a known hash and expiration after a fixed block height. If either condition fails, the lock reverses.

How the Protocol Flows

The process starts with a random secret code; let’s call it S. This code gets hashed (scrambled into a fixed fingerprint) to create H(S). Both traders know the fingerprint but not the original code.

  1. Locking Bitcoin: The first trader sends Bitcoin into a special contract on the Bitcoin blockchain. The contract says, “Release the coins only if someone shows the original S (and signs as the intended recipient), or return them to me after 48 hours.” The transaction ID is shared with the second trader.
  2. Locking Ethereum: The second trader responds by locking Ether in a matching contract on Ethereum: “Pay out if the original S is revealed by the first trader, or let me reclaim after 24 hours.” The shorter window protects the second mover.
  3. Claiming Ether: The first trader enters S into the Ethereum contract. This proves they know the secret and releases the Ether while broadcasting S publicly on the blockchain.
  4. Claiming Bitcoin: The second trader sees S on Ethereum, copies it, and uses it to unlock the Bitcoin contract before the 48-hour deadline.

The swap either fully succeeds, with both getting their new coins, or fully fails, with each side reclaiming their original funds. The single shared secret guarantees the two steps are inseparable.

Cryptographic and Timing Guarantees

Security reduces to two assumptions:  

  • SHA-256 (Bitcoin) and Keccak-256 (Ethereum) are preimage-resistant.  
  • Network finality is probabilistic but economically enforced.

Block-time asymmetry creates the classic timeout cascade. Bitcoin’s 10-minute average forces longer absolute windows than Ethereum’s 12-second slots. Designers therefore set Bitcoin timeout ≈ 2× Ethereum timeout. Empirical data from Lightning Network route-finding shows 2–3× margins prevent griefing.

Mempool congestion adds variance. A sudden Bitcoin fee spike can delay Alice’s refund past her mental deadline, even if the protocol timeout is safe. Modern wallets mitigate with Replace-By-Fee (RBF) and Child-Pays-For-Parent (CPFP).

Real Implementations

Komodo Platform (2017–present)  

Komodo’s BarterDEX (now AtomicDEX) ran the first production atomic swap between Bitcoin and 95+ UTXO chains. It used a federated notary node set for order relay, not custody. By 2020 it had processed more than 200,000 swaps with zero reported exploits of the HTLC layer. The codebase remains open; the HTLC logic is less than 300 lines of C++.

Lightning Submarine Swaps (2018)  

Lightning Labs introduced submarine swaps to convert on-chain BTC ↔ Lightning BTC via an HTLC chain:  

on-chain BTC → HTLC → Lightning HTLC → claim

The service provider acts as a liquidity source, not a custodian. Blockstream and others run public providers; users pay 0.1–0.5% fees. Volume crossed 1,200 BTC equivalent in 2024.

Limits in Modular Infrastructure

Atomic swaps shine in theory but stumble on liquidity and UX.

Liquidity Silos

Each pair requires a direct counterparty. BTC↔ETH enjoys depth; BTC↔KMD does not. Order-books or automated market makers (AMMs) built atop HTLCs, remain experimental.

Capital Inefficiency

Locked collateral sits idle during the timeout window—hours on Bitcoin, minutes on Solana. Compare to Uniswap v3 concentrated liquidity, where capital earns fees continuously.

Standardization Gaps

EVM chains share Solidity patterns, but Cosmos SDK, Substrate, and Bitcoin lack native HTLC opcodes. IBC’s ICS-20 fungible token transfer is packet-based, not atomic in the HTLC sense.

Engineering Trade-offs vs Alternatives

The four main approaches to moving assets across chains each make a different trade between trust and convenience.

Atomic swaps are the only fully trustless option, requiring no custodian or bonded validator set, but they pay for that with the longest capital lock: funds sit idle for the duration of the timeout window, and finality is bounded by the slowest chain in the swap. They work with any HTLC-capable chain, which is broad in principle but limited by which chains support the required scripting.

Thorchain reduces the lock time to seconds and settles in roughly six seconds by running continuous automated market makers secured by a two-thirds bonded validator stake. The trade is that it replaces pure trustlessness with a bonded-validator trust assumption, and it covers a smaller set of about eight chains.

Wrapped tokens settle almost instantly and lock no capital, but they depend on a mint-and-burn bridge, which reintroduces centralized custody risk, the weakest trust model of the four.

Message-relay systems like CCIP and LayerZero also settle at relay speed with no capital lock and cover the widest range, more than fifty chains, but their security rests on the relayer or messaging layer rather than on cryptographic guarantees.

The pattern across all four: atomic swaps minimize trust but maximize lock time, while every faster alternative buys speed by accepting some additional trust assumption.

Atomic swaps minimize trust but maximize lock time. Thorchain collapses lock time by running continuous AMMs secured by 2/3 bonded stake; it sacrificed pure trustlessness for usability.

Path to Scalable Interoperability

Standardized HTLC templates across substrates would help. Polkadot’s XCM reserves/transfer pattern already embeds timeout semantics; pairing it with an on-chain preimage oracle could automate atomic execution.

Zero-knowledge circuits can compress timeout enforcement. A zk-SNARK could prove “secret revealed on chain A before deadline” without waiting for chain B finality. Succinct Labs’ SP1 prover already compiles Rust HTLC logic; latency drops to <1 second cross-domain.

Conclusion

Atomic swaps remain the only purely trustless mechanism for native cross-chain transfer. Their engineering elegance belies real-world friction from timing and liquidity. In modular ecosystems, they serve as a reference design rather than a universal primitive, yet every serious interoperability stack still ships an HTLC library.