Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: victorkimba17 on November 10, 2017, 03:35:59 PM



Title: Pay to public key hash
Post by: victorkimba17 on November 10, 2017, 03:35:59 PM
In P2PKH, the public key

scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
scriptSig: <sig> <pubKey>

is the public key of the sender? the hash is from the sender public key? the signature is of the sender?


Title: Re: Pay to public key hash
Post by: DannyHamilton on November 10, 2017, 03:59:10 PM
In P2PKH, the public key

scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
scriptSig: <sig> <pubKey>

is the public key of the sender? the hash is from the sender public key?

No.

The hash is of the receiver's public key.

the signature is of the sender?

Yes.  The sender generates the signature using their private key.

Notes:

The scriptPubKey is in the OUTPUT of the transaction and is used to encumber the bitcoin value with a requirement that can only be satisfied by the recipient when they later want to spend the output that they have received.

The scriptSig is in the INPUT of the transaction and is how the sender satisfies the requirements of the previously received outputs that they are spending in the new transaction.


Title: Re: Pay to public key hash
Post by: pebwindkraft on November 10, 2017, 09:41:04 PM
next to bitcoin.org and the developpers section and  Andreas' book "Mastering Bitcoin", this helped me alot to understand the underlying details:
http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html



Title: Re: Pay to public key hash
Post by: victorkimba17 on November 11, 2017, 02:26:34 AM
next to bitcoin.org and the developpers section and  Andreas' book "Mastering Bitcoin", this helped me alot to understand the underlying details:
http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html



I read the link. I am still not clear. In
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
scriptSig: <sig> <pubKey>

The scriptSig contains the <sig> sender signature and <pubKey> sender public key, the scriptPubKey contains <pubKeyHash> which is the hash of receiver public key.

Then, how can the hash of sender <pubKey> matches with the receiver <pubKeyHash>  ?


Title: Re: Pay to public key hash
Post by: Taras on November 11, 2017, 05:23:28 AM
next to bitcoin.org and the developpers section and  Andreas' book "Mastering Bitcoin", this helped me alot to understand the underlying details:
http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html



I read the link. I am still not clear. In
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
scriptSig: <sig> <pubKey>

The scriptSig contains the <sig> sender signature and <pubKey> sender public key, the scriptPubKey contains <pubKeyHash> which is the hash of receiver public key.

Then, how can the hash of sender <pubKey> matches with the receiver <pubKeyHash>  ?

The scriptSig part is what the receiver uses to spend the money that they got from pay-to-public-key-hash. Because they're spending the money, at that point they'd be the new sender. The <pubKey> for this new transaction hashes to the receiver's <pubKeyHash> from the old transaction when they first got the money.

Here's an example P2PKH transaction (https://blockchain.info/tx/b741507ec0b2edf0b51c9b5f785e975f7f5a6a84c9ab66f05a51923cf0c0df65?show_adv=true). It pays 0.00063664 BTC to my address with the script OP_DUP OP_HASH160 0507135dd0ec75f539b304d8641bf00372989b27 OP_EQUALVERIFY OP_CHECKSIG. Then, in the next transaction (https://blockchain.info/tx-index/32924676?show_adv=true), I spend that 0.00063664 BTC, and you can see in the input script (scriptSig) that there is both a signature and the public key that hashes to 0507135dd0ec75f539b304d8641bf00372989b27, which is the pubKeyHash in the script of the other transaction where I was the receiver.


Title: Re: Pay to public key hash
Post by: victorkimba17 on November 11, 2017, 07:24:12 AM

The scriptSig part is what the receiver uses to spend the money that they got from pay-to-public-key-hash. Because they're spending the money, at that point they'd be the new sender. The <pubKey> for this new transaction hashes to the receiver's <pubKeyHash> from the old transaction when they first got the money.


Thank you very much. finally understand it.