Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: whanau on December 29, 2023, 07:24:01 PM



Title: How does the blockchain know the public address?
Post by: whanau on December 29, 2023, 07:24:01 PM
Alice wants to send Bob some Bitcoin so he creates an address 1BOB.... which he sends to Alice.
Alice sends the Bitcoin and the transaction proceeds.

My understanding is that 1BOB.... is a more readable version of the X,Y co ordinates of the public key obtained after a 1 way hash function. (ripemd160)
So given that the co ordinates X,Y have been hashed, How does the blockchain work out X,Y (the full public key) in order to create the transaction ?

I am obviously missing something


Title: Re: How does the blockchain know the public address?
Post by: garlonicon on December 29, 2023, 09:13:08 PM
Quote
How does the blockchain work out X,Y (the full public key) in order to create the transaction ?
It simply does not. It is only checked, when the owner reveals that public key explicitly. Which means, you can send your coins, even to some invalid hash of some public key, and then it will never be moved.

And yes, it happened in the past, for example those coins are unspendable forever: https://bitcointalk.org/index.php?topic=50206.0


Title: Re: How does the blockchain know the public address?
Post by: pooya87 on December 30, 2023, 04:39:09 AM
Stop thinking in terms of addresses and public keys. In bitcoin we are "locking" up coins inside "smart contracts" and to spend those coins you need to provide an "unlocking mechanism/script" to be able to spend them.

It could be described as locked mailboxes. If you know the address of the mailbox you can go to it and insert the mail into its opening slot. But only the owner who has the key can open the lid and take the contents out.

In Bitcoin the "key" that unlocks your coins to allow you to spend them or the "unlocking mechanism" is a script in the Bitcoin's smart contract protocol.

For example take this very simple example: 3MaB7QVq3k4pQx3BhsvEADgzQonLSBwMdj
Coins sent to this address can be spent by providing a very simple unlocking script that only contains OP_TRUE.
<0x51> + OP_HASH160 da1745e9b549bd0bfa1a569971c77eba30cd5a4b OP_EQUAL
As you can see there is no public key here.

It's the same with everything else like when you send coins to a P2PKH address you are locking coins inside a OP_DUP OP_HASH160 <push20> OP_EQUALVERIFY OP_CHECKSIG smart contract. To unlock this the owner has to provide a script like <push72><push33> containing ECDSA signature and public key.

To verify the validity of these scripts, the nodes evaluate and execute these scripts in a FORTH (https://en.wikipedia.org/wiki/Forth_(programming_language)) like script language and if it ends up with a success, the transaction is valid and coins can be spent.


Title: Re: How does the blockchain know the public address?
Post by: ABCbits on December 30, 2023, 09:34:54 AM
My understanding is that 1BOB.... is a more readable version of the X,Y co ordinates of the public key obtained after a 1 way hash function. (ripemd160)
So given that the co ordinates X,Y have been hashed, How does the blockchain work out X,Y (the full public key) in order to create the transaction ?

I am obviously missing something

The wallet you use contain data which map between private key, public key, address and other related information. So when Bob want to spend his Bitcoin, his wallet create transaction with associated private key and create signature where you can extract associated public key.


Title: Re: How does the blockchain know the public address?
Post by: whanau on December 30, 2023, 04:52:21 PM
Thank you all for your very detailed replies.
Now I understand.  ;D