Bitcoin Forum
May 10, 2024, 01:35:45 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Question about ScriptPubKey and Scriptsig  (Read 107 times)
?QuestionMark? (OP)
Member
**
Offline Offline

Activity: 79
Merit: 28


View Profile
January 13, 2021, 12:16:46 PM
Merited by o_e_l_e_o (2), ABCbits (1)
 #1

A locking script: OP_DUP OP_HASH160 fde0a08625e327ba400644ad62d5c571d2eec3de OP_EQUALVERIFY OP_CHECKSIG

First I thought in the bold marked area is always the address of the receiver but know after analyzing some blockchain transactions I found out that the public key is provided (I guess it is).
When someone sends me his address, how is it possible to get the public key since hashes are irreversible? Is it the hex of the address?

A unlocking script: <sig> <PubK>

The unlocking script is clear to me. But what is acctually signed? The txid?
1715304945
Hero Member
*
Offline Offline

Posts: 1715304945

View Profile Personal Message (Offline)

Ignore
1715304945
Reply with quote  #2

1715304945
Report to moderator
1715304945
Hero Member
*
Offline Offline

Posts: 1715304945

View Profile Personal Message (Offline)

Ignore
1715304945
Reply with quote  #2

1715304945
Report to moderator
According to NIST and ECRYPT II, the cryptographic algorithms used in Bitcoin are expected to be strong until at least 2030. (After that, it will not be too difficult to transition to different algorithms.)
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715304945
Hero Member
*
Offline Offline

Posts: 1715304945

View Profile Personal Message (Offline)

Ignore
1715304945
Reply with quote  #2

1715304945
Report to moderator
o_e_l_e_o
In memoriam
Legendary
*
Offline Offline

Activity: 2268
Merit: 18510


View Profile
January 13, 2021, 12:30:16 PM
 #2

First I thought in the bold marked area is always the address of the receiver but know after analyzing some blockchain transactions I found out that the public key is provided (I guess it is).
It is actually neither. It is what is known as the public key hash, hence the term P2PKH (Pay to pubkey hash). This is calculated as RIPEMD160(SHA256(pubkey)) - that is to say, first we hash the pubkey using SHA256, then we hash the result using RIPEMD160. These are the first steps in calculating an address, and from this pubkey hash you would prepend a network byte and then append a checksum, before encoding in Base58Check. Therefore, by converting back to hex and then stripping away the network byte and the checksum, you can convert an address back in to a pubkey hash, all without ever knowing the pubkey, which as you say would be impossible since hash functions are not reversible.
BrewMaster
Legendary
*
Offline Offline

Activity: 2114
Merit: 1292


There is trouble abrewing


View Profile
January 13, 2021, 12:32:40 PM
 #3

First I thought in the bold marked area is always the address of the receiver
in a way the whole script is the "address of the receiver". an address is the same as these scripts but in a user friendly way. you take the hash and encode it with a version to indicate type of the script. the OP codes are the same if you know the type.

Quote
but know after analyzing some blockchain transactions I found out that the public key is provided (I guess it is).
the public key (and the signature) are provided in the script signature part (or the witness in SegWit transactions).

Quote
When someone sends me his address, how is it possible to get the public key since hashes are irreversible? Is it the hex of the address?
you don't need their public key and it is impossible to get it from the hash. (address only contains that hash).

Quote
The unlocking script is clear to me. But what is acctually signed? The txid?
the receiver signs the transaction not you so they provide the public key and since they have the private key they can provide the public key too.
what is being signed is the transaction itself but with some modifications. for example for a simple P2PKH that you posted above the script pub is placed inside scriptsig and the rest of the inputs (if present) are set to empty scriptsigs. then the sighash byte is added at the end as 4 bytes and the whole thing is hashed twice with SHA256 and then that hash is signed.

see https://bitcoin.stackexchange.com/questions/32628/redeeming-a-raw-transaction-step-by-step-example-required
but there are a lot more details about signing transactions based on the type of the input being spent.

There is a FOMO brewing...
DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4653



View Profile
January 13, 2021, 01:44:47 PM
Merited by ABCbits (1)
 #4

Note that a P2PKH script is only 1 type of "locking script".

There are many script command codes that can also be used. The data that must be provided (both in the "locking script" and the "unlocking script") will depend on exactly what the script commands are doing.

Other common "locking script" examples are:
P2PK
P2SH
P2WPKH
OP_RETURN

It is also possible to create non-standard scripts if you understand what the OP codes do.

So, when you see scripts in transactions, be aware that they may not always be something you can interpret as:
OP_DUP OP_HASH160 pubKeyHash OP_EQUALVERIFY OP_CHECKSIG
?QuestionMark? (OP)
Member
**
Offline Offline

Activity: 79
Merit: 28


View Profile
January 13, 2021, 08:50:24 PM
 #5

I got it now. Thank you all, it helped a lot!
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!