Skip to content

feat(contract): HTLC atomic swaps with key-bound secret hash#291

Merged
Solomonsolomonsolomon merged 2 commits intogear5labs:masterfrom
success-OG:feat/htlc-atomic-swaps
Mar 30, 2026
Merged

feat(contract): HTLC atomic swaps with key-bound secret hash#291
Solomonsolomonsolomon merged 2 commits intogear5labs:masterfrom
success-OG:feat/htlc-atomic-swaps

Conversation

@success-OG
Copy link
Copy Markdown
Contributor

[Contract] Hashed Timelock Contract (HTLC) for Atomic Swaps

closes #261

Summary

Implements a full HTLC in Soroban for cross-chain atomic swaps with a cryptographic
defense against intercept attacks by the agent or any third party.

What's included

  • New htlc contract added to the workspace
  • init_swap — locks tokens into the contract, stores swap keyed by a derived swap_id.
    Caller provides secret_hash = SHA-256(preimage || recipient_pubkey), binding the
    hash to the intended recipient's Stellar public key at creation time.
  • claim — recipient reveals (preimage, recipient_pubkey). Contract recomputes
    SHA-256(preimage || recipient_pubkey) and checks it matches the stored hash.
    An attacker who intercepts the preimage cannot claim because their pubkey won't
    produce the correct hash.
  • refund — initiator reclaims funds after expiry_ledger has passed.
  • get_swap — read-only view of any swap by ID.
  • 8 unit tests: happy-path init, successful claim, wrong preimage rejected,
    intercept attack blocked, refund after expiry, refund before expiry blocked,
    double-claim blocked, expired claim blocked.

Security note

The key-binding SHA-256(preimage || recipient_pubkey) means even if the preimage
leaks on-chain or off-chain, only the address whose pubkey was committed at swap
creation can successfully call claim.

Branch

feat/htlc-atomic-swaps

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 29, 2026

@success-OG Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Solomonsolomonsolomon Solomonsolomonsolomon merged commit 035fdbc into gear5labs:master Mar 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Contract] Hashed Timelock Contract (HTLC) for Atomic Swaps

2 participants