feat(contract): HTLC atomic swaps with key-bound secret hash#291
Merged
Solomonsolomonsolomon merged 2 commits intogear5labs:masterfrom Mar 30, 2026
Merged
Conversation
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[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
htlccontract added to the workspaceinit_swap— locks tokens into the contract, stores swap keyed by a derived swap_id.Caller provides
secret_hash = SHA-256(preimage || recipient_pubkey), binding thehash to the intended recipient's Stellar public key at creation time.
claim— recipient reveals(preimage, recipient_pubkey). Contract recomputesSHA-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 afterexpiry_ledgerhas passed.get_swap— read-only view of any swap by ID.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 preimageleaks on-chain or off-chain, only the address whose pubkey was committed at swap
creation can successfully call
claim.Branch
feat/htlc-atomic-swaps