Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: Alicatraz on January 03, 2022, 09:52:46 PM



Title: Script PubKey
Post by: Alicatraz on January 03, 2022, 09:52:46 PM
Greetings,
what is the difference between the Public key and the script pubkey ?
can one derive one from the other ?
thank you !


Title: Re: Script PubKey
Post by: BitMaxz on January 03, 2022, 11:35:58 PM
According to Google search (https://www.google.com/search?q=what+is+scriptpubkey&oq=what+is+scriptpubkey&aqs=chrome..69i57j69i60.5449j0j7&sourceid=chrome&ie=UTF-8)
Quote from: Google
Pubkey script is a script that controls how bitcoin can be spent. In English, most bitcoin scripts translate as follows: “In order to spend this bitcoin, one must produce a signature belonging to this public key…”, followed by a public key

And the public key is the unique Bitcoin address that allows you to receive Bitcoins.

Check this link below for other explanations about these.
- https://nominex.io/blog/education/bitcoin-script/


Title: Re: Script PubKey
Post by: pooya87 on January 04, 2022, 03:48:28 AM
And the public key is the unique Bitcoin address that allows you to receive Bitcoins.
Public key is the ellilptic curve point computed from the private key using  a one way operation. It can then be converted to an address, usually by computing its hash. Public key is not the address though.


Title: Re: Script PubKey
Post by: ranochigo on January 04, 2022, 05:02:39 AM
ScriptPubKey does not actually contain the public key. It is just the conditions that can be used to spend the funds, in cases like P2PKH outputs, you will find the HASH160 of the public key and only if you have the P2PK output, then you can see the actual ECDSA public key.

For normal scenarios like P2PKH, P2WPKH, since it dictates the HASH160 (SHA256 and then RIPEMD-160), the conditions to be fulfilled requires for the public key to be revealed. As such, you can validate that the public key hashes to the key in the unlocking script and for the signature to match the public key. With a public key, you can use it to produce the various scripts that requires your public key, and from there you can derive the possible ScriptPubKeys that corresponds to it.


Title: Re: Script PubKey
Post by: odolvlobo on January 05, 2022, 01:49:28 AM
@ranochigo explained it, but I'm going to simplify. scriptPubKey is the name of the script in a transaction that sets the conditions for spending the bitcoins "received" by the transaction.

Originally, the scriptPubKey script specified a public key whose private key is required to spend the "received" bitcoins. A transaction containing this kind of script is called a P2PK (pay-to-public-key) transaction. You can find P2PK transactions in the earliest blocks and their scriptPubKey scripts will contain public keys.

But P2PK transactions are no longer used and scriptPubKey scripts no longer contain public keys. A public key may still be required to spend the "received" bitcoins, but the scriptPubKey script no longer refers to it directly.


Title: Re: Script PubKey
Post by: pooya87 on January 05, 2022, 04:48:33 AM
scriptPubKey scripts no longer contain public keys.
They can and they do. What you should've said is that they are no longer as common as early days (that is until Taproot becomes common).

The old types such as P2PK are standard and can be used, P2MS is another script type contains multiple public keys, there are nonstandard scripts that contain public keys.
And finally the newest script types used in Taproot scripts contains the x-only public key.

These are the most recent P2PK transactions with the most recent from 2021-12-31:
https://blockchair.com/bitcoin/outputs?s=time(desc)&q=type(pubkey)#f=transaction_hash,type,time
Keep in mind that blockchair shows a P2PKH address by mistake, if you check the raw transaction you see the actual script is a P2PK one.