Protocol
sBridge

HTLC

Hash Time Locked Contracts: trustless atomic swaps without an intermediary

HTLC is a trustless atomic swap primitive built directly into the SBChain protocol. It enables cross-chain asset exchanges without a trusted intermediary, using cryptographic hash locks and time locks.

How HTLC Works

An HTLC locks funds on-chain under two conditions:

  • Hash lock: funds are released to the recipient if they provide the correct preimage (secret) that hashes to a pre-agreed hash
  • Time lock: if the preimage is not revealed before the expiry, funds are automatically returned to the sender

Atomic Cross-Chain Swap Flow

Alice wants to swap SBChain tokens with Bob who holds Bitcoin:

  • Alice generates a secret preimage and computes its hash
  • Alice creates an HTLC on SBChain locking her tokens for Bob, using the hash and a time lock (htlc_create_operation)
  • Bob sees the HTLC on-chain and creates a corresponding HTLC on Bitcoin locking his BTC for Alice, using the same hash with a shorter time lock
  • Alice redeems Bob's Bitcoin HTLC by revealing the preimage (htlc_redeem_operation), which reveals the secret on Bitcoin's chain
  • Bob uses the now-public preimage to redeem Alice's SBChain HTLC
  • Both transfers complete atomically — if either party fails to act, both HTLCs expire and funds are returned

HTLC Operations

OperationDescriptionFee
htlc_create_operationLock funds under a hash lock with a time expiry1 × precision + fee_per_day
htlc_redeem_operationClaim locked funds by providing the correct preimage1 × precision + fee_per_kb
htlc_extend_operationExtend the time lock expiry on an existing HTLC1 × precision + fee_per_day
htlc_redeemed_operation (virtual)Emitted when an HTLC is successfully redeemedNone
htlc_refund_operation (virtual)Emitted when an HTLC expires and funds are returnedNone

HTLC Fields

FieldDescription
fromAccount locking the funds
toAccount that can claim the funds with the correct preimage
amountAsset and amount locked
preimage_hashHash of the secret (typed: RIPEMD160, SHA1, SHA256, or Hash160)
preimage_sizeExpected size of the preimage in bytes
claim_period_secondsTime until the HTLC expires and funds are returned

Supported Hash Algorithms

  • RIPEMD160
  • SHA1
  • SHA256
  • Hash160

HTLC vs Gateway

Gateway (IOU)HTLC
Trust requiredYes, trust the gatewayNo, cryptographic guarantee
User experienceSimple deposit/withdraw flowRequires coordination between both parties
SpeedDepends on gateway processingDepends on both chains' confirmation times
Use caseOngoing liquidity, tradingOne-time atomic swaps between counterparties
Counterparty riskGateway custodial riskNone — protocol enforced