TorrentSwap
Concepts

Atomic Swaps Explained: HTLCs vs Cross-Chain Swaps

How atomic swaps use hashed time-locked contracts, a short history from 2013 to Garden Finance, why they never went mainstream, and how they compare with liquidity networks, intents and bridges.

By TorrentSwap Editorial Team6 min read

An atomic swap is a peer-to-peer trade of coins on two blockchains in which either both transfers happen or neither does. It relies on hashed time-locked contracts (HTLCs): funds unlock only for someone who reveals a secret before a deadline, and otherwise they go back to the sender. There's no custodian and no wrapped token.

Atomic swaps were one of the first answers to the question of how to trade across chains without trusting anyone. They're elegant and they work, but they never became the default. Here's how they work, where they came from, why they stayed niche, and how they compare with the liquidity-network swaps and bridges most people use today.

How an HTLC works

An HTLC combines two conditions in one script:

  • A hashlock. The funds can be spent by whoever provides data (the "preimage") that hashes to a specific value.
  • A timelock. If nobody claims the funds that way before a set time or block height, the original owner can take them back.

Bitcoin's BIP 199, written by Sean Bowe and Daira Hopwood, documents the standard pattern. Simplified, it looks like this:

OP_IF
  OP_SHA256 <digest> OP_EQUALVERIFY  (+ check seller's key)
OP_ELSE
  <timeout> OP_CHECKLOCKTIMEVERIFY OP_DROP  (+ check buyer's key)
OP_ENDIF
OP_CHECKSIG

The first branch lets the seller spend by revealing the preimage. The second lets the buyer recover the funds after the timeout. BIP 199 notes that the Lightning Network uses the same construction to route payments across channels.

An atomic swap, step by step

Say Alice has BTC and Bob has LTC, and they've agreed on a price.

  1. Alice picks a random secret and computes its hash. Only she knows the secret.
  2. Alice locks her BTC in an HTLC. Bob can claim it with the secret, and Alice can reclaim it after a long timeout.
  3. Bob checks Alice's contract on the Bitcoin chain. He then locks his LTC in an HTLC with the same hash. Alice can claim it with the secret, and Bob can reclaim it after a shorter timeout.
  4. Alice claims the LTC. To do that she has to publish the secret on the Litecoin chain.
  5. Bob reads the secret from Alice's Litecoin transaction and uses it to claim the BTC.

The timeouts are staggered on purpose. If Bob's lock lasted as long as Alice's, Alice could wait until the last moment to claim the LTC and then reclaim her BTC before Bob had time to use the secret. Giving the initiator the longer lock guarantees the other party a window. Garden Finance, discussed below, uses this pattern: 48 hours before a user can reclaim, and 24 hours for the solver.

If anyone walks away at any point, the timelocks send everything home. The worst outcome is waiting, not losing funds.

A short history

YearMilestone
2012Daniel Larimer's P2PTradeX protocol, often cited as a precursor to cross-chain trades without a middleman
2013Tier Nolan's Bitcoin Forum post "Alt chains and atomic transfers," usually credited as the first description of atomic swaps
2014Tier Nolan posts a BIP draft for an atomic cross-chain transfer protocol to the bitcoin-development mailing list
2017 (March)BIP 199, the HTLC specification, is assigned
2017 (September)Decred and Litecoin complete an on-chain atomic swap on September 19. Decred releases open-source tools for DCR, BTC and LTC.
2017 (November)Lightning Labs tests a cross-chain atomic swap over Lightning between the Bitcoin and Litecoin testnets
2023 onwardGarden Finance, founded in 2023, builds a production Bitcoin swap service on HTLCs with professional solvers

The 2017 Decred release was the turning point from theory to practice. Its blog post listed the prerequisites: both chains need branching transaction scripts, the same hash algorithm, signature checks, and lock-time support (CLTV or CSV). Bitcoin forks such as Litecoin and Decred met all four, which is why the first swaps happened between them.

Why atomic swaps didn't go mainstream

Decred's own launch post was candid about the limits, and most of them still apply to raw peer-to-peer swaps:

  • Finding a counterparty. The 2017 tools had no order book. Participants swapped contract details over email or chat.
  • Speed. Every step waits for block confirmations. With Bitcoin involved, Decred estimated a worst case of about an hour.
  • Fees on both sides. Each party pays to lock funds and again to redeem them, on two chains.
  • Chain compatibility. Both chains must support the same hash function and time-locked scripts. Chains without them need different, more complex techniques.
  • Linkability. The same hash appears on both chains, so an observer can link the two legs, even though no identity data is exposed.

There's also an economic catch built into the mechanism. Once both contracts are funded, the initiator decides whether to reveal the secret and finish the trade. If the price moves against them before the timeout, they can let the swap expire and take their coins back. In effect they hold a free option, and the counterparty's capital is tied up for the whole timelock. Market makers price that in, or avoid it.

Lightning-based swaps fixed the speed and fee problems by moving off-chain. Lightning Labs' 2017 test settled without recording a transaction on either blockchain. But they need channels and liquidity on both networks.

Atomic swaps vs liquidity-network swaps vs bridges

Today, most "swap BTC to ETH" products aren't atomic swaps in the strict sense. Our explainer on how cross-chain swaps work goes deeper. In brief:

HTLC atomic swapLiquidity networkIntent networkLock-and-mint bridge
CounterpartyOne peer or solverA shared pool or market makersCompeting solversThe bridge contract
What you receiveThe native assetThe native assetUsually the native assetA wrapped token
Who holds funds mid-swapA script you can always refund fromValidator-controlled vaults (threshold signatures)A settlement contract, then the solverBridge custodians or contracts
Typical failure modeTimeout refund after hoursNetwork halt or vault compromiseNo fill, or a settlement or bridge bugTheft of locked collateral
ExamplesDecred atomicswap, GardenTHORChain, ChainflipNEAR IntentsClassic token bridges

The trade-off is clear. HTLCs give the strongest guarantee that no third party can take your coins, but they are slower and need a willing counterparty for every trade. Liquidity and intent networks quote instantly and handle any size their liquidity allows, but you trust validators, contracts or bridges while the swap is in flight. Bridges carry the most concentrated risk: by early August 2022, Chainalysis had counted 13 bridge hacks that year, worth about $2 billion.

Garden Finance: the modern atomic-swap bridge

Garden Finance is the most visible current attempt to make HTLC swaps practical for Bitcoin. Its docs describe an intent-based design. You state the swap you want, an auction picks a solver, and settlement happens through HTLCs on both chains. The flow mirrors the Alice and Bob example. You lock first, the solver locks on the other chain, you claim, and the solver claims with the revealed secret.

Garden adds economic backing on top. Solvers are backed by stakers who get slashed when a swap fails:

  • If the solver locks but you never claim, stakers lose 1% of the order value. The solver is refunded after 24 hours and you after 48.
  • If the solver never locks, the solver and its stakers lose 0.5%, and you get your deposit back after 48 hours along with the slashed compensation.

The model has been tested in production. In October 2025, an attacker took about $11 million after compromising one of Garden's solvers. In July 2026, roughly $450,000 was drained from Garden HTLC contracts on Ethereum, Base, Arbitrum and BNB Chain after an attacker inserted fake swap records into an independent solver's off-chain database. Both times Garden said user funds weren't affected, and both times it took the app offline. The HTLC guarantee did its job for users, but it couldn't protect solver capital or keep the service running.

Which approach fits which job

  • Trading with a known peer over the counter, when you can wait: a raw HTLC atomic swap gives the strongest guarantees.
  • Swapping native BTC quickly at a quoted price: liquidity or intent networks are faster, at the cost of trusting their validators or contracts for a few minutes.
  • Using BTC inside Ethereum DeFi: you'll end up with a wrapped token either way, so weigh the custodian rather than the swap mechanism.

Ready to move native bitcoin? Our BTC to ETH swap compares live routes from NEAR Intents, Chainflip and Flashnet, includes every fee in the quote, needs no account, and never holds your funds.

Sources

  1. BIP 199: Hashed Time-Locked Contract transactions
  2. Decred Blog: On-Chain Atomic Swaps (Sept 20, 2017)
  3. Decred: Decred adds support for on-chain atomic swaps
  4. Lightning Labs: Connecting Blockchains, Instant Cross-Chain Transactions on Lightning
  5. Bitcoin Magazine: Lightning Network now supports transactions across blockchains
  6. bitcoin-dev mailing list: BIP Draft, Atomic Cross Chain Transfer Protocol (Tier Nolan, 2014)
  7. BTC-ECHO: Atomic Swap (history incl. Tier Nolan and P2PTradeX)
  8. Komodo: Komodo and the Early Pioneers of Atomic Swaps
  9. Garden Finance Docs: Atomic Swaps
  10. The Register: Attackers dig up $11M in Garden Finance solver exploit
  11. Cointelegraph: Garden Finance takes app offline after $450K HTLC exploit
  12. Chainalysis: Cross-chain bridge hacks emerge as top security risk (Aug 2022)

Facts were checked against these sources on October 22, 2026. See our editorial policy.

Swap across chains without an account

Compare live routes from NEAR Intents, THORChain, Chainflip, Flashnet and Pact Swap. All fees already in the quote.