Bitcoin Forum
May 27, 2026, 12:12:31 PM *
News: Latest Bitcoin Core release: 31.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: HTLC Atomic Swap | How the Secret Key Works Across Different Chains?  (Read 38 times)
Mahiyammahi (OP)
Sr. Member
****
Offline

Activity: 644
Merit: 368



View Profile
May 26, 2026, 10:30:50 AM
Merited by ertil (1)
 #1

So I was exploring the safest option to trade with some one without being getting scammed. Then learned about HTLC but no matter how hard I'm trying to understand the mechanism behind this it's but It's just messing with my head.  I will try to clearly presents my confusion. 

Let's say Alice will swap her 0.1 BTC with 100 USDT with BOB
Steps that would take in the process,  correct me if I'm wrong.
  • Alice Locks her BTC with a secrete key on a hash & Give it to  (The hash)
  • Bob Locked the USDT with the same hash Alice provided
  • Alice Claimed the USDT with the secrete key (This key has been genertaed by Alice) and the key has been stored on that Blockchain(BSC) permanently
  • Bob sees the Secrete key and claimed his BTC,  both trade has done no ome scammed.

So my question is -
1. Since the secrete key has not been shared with Bob , how that hash do knows this is the correct key for the hash Alice provided?
2. Alice could have entered the wrong key for claiming the USDT . Since BTC & BSC both is in the different chain they can't contact each other.
3. Since secrete key is not some numerical value/string how it's findout the correct key ?

ertil
Full Member
***
Offline

Activity: 233
Merit: 408


View Profile
May 26, 2026, 11:29:43 AM
 #2

Quote
how that hash do knows this is the correct key for the hash Alice provided?
Hashing goes in one direction. You can take some data, and calculate a hash of it. But you cannot take a hash, and find a matching data easily. If you can, then a given hash function is broken.

Some example: https://emn178.github.io/online-tools/sha256.html
Code:
SHA-256("Hello World!")=7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069
And then, by requiring a message, which will hash exactly to 0x7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069, you can be quite sure, that it will be "Hello World!". If you could go in an opposite direction, and find a different message, which would hash to this value, or have any software, which will find you a valid message for any hash, then this hash function would be broken.

Quote
Alice could have entered the wrong key
If you use a wrong key, or a wrong hash, then coins will be unspendable. Sending coins to random public keys or hashes is possible. And then, if nobody knows the key, and the message, then they will stay on a given address, potentially forever, or until someone will break a given public key or hash. Also, there are invalid public keys and hashes, and then coins are just provably unspendable.

More technical details: https://en.bitcoin.it/wiki/Atomic_swap
Cookdata
Legendary
*
Online Online

Activity: 1680
Merit: 1373


Not Your Keys, Not Your Bitcoin


View Profile
May 26, 2026, 11:52:50 AM
 #3

So my question is -
1. Since the secrete key has not been shared with Bob , how that hash do knows this is the correct key for the hash Alice provided?

A hash is a fingerprint to a text or some characters and you can verify the hash if you know the the text. Any characters that is hashed, you can verify if it's real or it has been tempered.
In your example, Alice provide the hash when btc was locked and only provide the secret key to the hash only if Bob lock his equivalent USDT and can be claim by Alice if she provide the secret key to that hash.

https://learnmeabitcoin.com/technical/cryptography/hash-function/

You can play around with some data to understand fingerprints with this hash function.

Quote
2. Alice could have entered the wrong key for claiming the USDT . Since BTC & BSC both is in the different chain they can't contact each other.

You can't cheat the smart contract, Alice key must be verified if it match the hash before the USDT can be claimed by Alice so that Bob can be safe in the transaction.

Quote
3. Since secrete key is not some numerical value/string how it's findout the correct key ?

Check the link I provided above to understand hash function, any character or text you hash gives an equivalent 32 bytes and it's unique to that data. If you change the data, the hash changes.

███████████████████████████
███████▄████████████▄██████
████████▄████████▄████████
███▀█████▀▄███▄▀█████▀███
█████▀█▀▄██▀▀▀██▄▀█▀█████
███████▄███████████▄███████
███████████████████████████
███████▀███████████▀███████
████▄██▄▀██▄▄▄██▀▄██▄████
████▄████▄▀███▀▄████▄████
██▄███▀▀█▀██████▀█▀███▄███
██▀█▀████████████████▀█▀███
███████████████████████████
.
.Duelbits PREDICT..
█████████████████████████
█████████████████████████
███████████▀▀░░░░▀▀██████
██████████░░▄████▄░░████
█████████░░████████░░████
█████████░░████████░░████
█████████▄▀██████▀▄████
████████▀▀░░░▀▀▀▀░░▄█████
██████▀░░░░██▄▄▄▄████████
████▀░░░░▄███████████████
█████▄▄█████████████████
█████████████████████████
█████████████████████████
.
.WHERE EVERYTHING IS A MARKET..
█████
██
██







██
██
██████
Will Bitcoin hit $200,000
before January 1st 2027?

    No @1.15         Yes @6.00    
█████
██
██







██
██
██████

  CHECK MORE > 
Mahiyammahi (OP)
Sr. Member
****
Offline

Activity: 644
Merit: 368



View Profile
May 26, 2026, 06:38:08 PM
 #4

@Ertil & @Cookdata I was able to understand how that secrete key works. But I saw that for my Text the Hash is consistent. Like I entered "Hibro" it was
Code:
d80a208c6ca4e93a2fdb564624115d41be4ac4cfc2caac903e7874dc920f8824


It's rare to two person in the world choosing same secrete key , also some person can be brute force the string/secrete key to findout. Even though only the receiver can claim the fund. So is it possible that one hash can be used by diff person at diff times if the secret key somehow matched?

Cookdata
Legendary
*
Online Online

Activity: 1680
Merit: 1373


Not Your Keys, Not Your Bitcoin


View Profile
May 26, 2026, 07:18:01 PM
 #5

@Ertil & @Cookdata I was able to understand how that secrete key works. But I saw that for my Text the Hash is consistent. Like I entered "Hibro" it was
Code:
d80a208c6ca4e93a2fdb564624115d41be4ac4cfc2caac903e7874dc920f8824

By consistent, you mean the same?

Code:
Hibro ==> d80a208c6ca4e93a2fdb564624115d41be4ac4cfc2caac903e7874dc920f8824
Hybro ==> 181b4b1fbef01f14c42bae63ed57f844254cff02ed30601fbfa6ec74b714fd1c

You see the output hash is different when I changed the "i" to "y" and are 32 byte output each.

Quote
It's rare to two person in the world choosing same secrete key , also some person can be brute force the string/secrete key to findout. Even though only the receiver can claim the fund. So is it possible that one hash can be used by diff person at diff times if the secret key somehow matched?

You may understand hash but I'm not sure about Atomic swap. Two people cannot choose the same secret key because it's not manual, they are randomly generated. The chance of two people generating the same key is zero in a real transaction.

You can't brute force Sha256 hash function to get a secrete key, they are one way and irreversible.

███████████████████████████
███████▄████████████▄██████
████████▄████████▄████████
███▀█████▀▄███▄▀█████▀███
█████▀█▀▄██▀▀▀██▄▀█▀█████
███████▄███████████▄███████
███████████████████████████
███████▀███████████▀███████
████▄██▄▀██▄▄▄██▀▄██▄████
████▄████▄▀███▀▄████▄████
██▄███▀▀█▀██████▀█▀███▄███
██▀█▀████████████████▀█▀███
███████████████████████████
.
.Duelbits PREDICT..
█████████████████████████
█████████████████████████
███████████▀▀░░░░▀▀██████
██████████░░▄████▄░░████
█████████░░████████░░████
█████████░░████████░░████
█████████▄▀██████▀▄████
████████▀▀░░░▀▀▀▀░░▄█████
██████▀░░░░██▄▄▄▄████████
████▀░░░░▄███████████████
█████▄▄█████████████████
█████████████████████████
█████████████████████████
.
.WHERE EVERYTHING IS A MARKET..
█████
██
██







██
██
██████
Will Bitcoin hit $200,000
before January 1st 2027?

    No @1.15         Yes @6.00    
█████
██
██







██
██
██████

  CHECK MORE > 
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!