Bitcoin Forum
December 13, 2024, 07:15:26 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Question on scriptSig and scriptPubKey  (Read 1090 times)
Manfred Macx (OP)
Full Member
***
Offline Offline

Activity: 205
Merit: 105


View Profile WWW
March 21, 2016, 05:13:42 PM
 #1

To redeem a particular transaction output, the spender needs to provide transaction signature and his pubkey:

<sig><pubkey> DUP HASH160 <address> EQUALVERIFY CHECKSIG

The provided pubkey will get (duplicated and) hashed HASH160(SHA56(pubkey)) and compared to the provided address. But how can this pubkey hash be equal to the address when the address also has checksum and network prefix? Does that mean the extra data gets removed from the script at some point? Also, is there any reason why provided address is in hex format instead of base58?

jl777
Legendary
*
Offline Offline

Activity: 1176
Merit: 1134


View Profile WWW
March 21, 2016, 05:32:07 PM
Merited by ABCbits (3)
 #2

To redeem a particular transaction output, the spender needs to provide transaction signature and his pubkey:

<sig><pubkey> DUP HASH160 <address> EQUALVERIFY CHECKSIG

The provided pubkey will get (duplicated and) hashed HASH160(SHA56(pubkey)) and compared to the provided address. But how can this pubkey hash be equal to the address when the address also has checksum and network prefix? Does that mean the extra data gets removed from the script at some point? Also, is there any reason why provided address is in hex format instead of base58?
it isnt the address that goes into the output script, but the rmd160 20 bytes of binary

doing a base58 decode on the address, you can make sure the checksum is valid and you end up with an address type, followed by 20 bytes (160 bits) and it is these 20 bytes that goes where you have <address> in the above.

<sig> <pubkey> <pubkey> HASH160 <rmd160 from address> EQUALVERIFY CHECKSIG

<pubkey> HASH160 -> that does the rmd160(sha256(pubkey)) and it should generate the identical 20 bytes:

<sig> <pubkey> <rmd160 from address> <rmd160 from address> EQUALVERIFY CHECKSIG

<rmd160 from address> <rmd160 from address> EQUALVERIFY -> verifies match or errors

which leaves us with:
<sig> <pubkey>  CHECKSIG

and the CHECKSIG makes sure the pubkey is from the privkey that did the signing

http://www.cs.princeton.edu/~tongbinw/bitcoinIDE/build/editor.html doesnt support all the script opcodes, but for most of the standard ones allows to single step and see things run and is a good way to learn the scripts

http://www.digitalcatallaxy.com/report2015.html
100+ page annual report for SuperNET
Manfred Macx (OP)
Full Member
***
Offline Offline

Activity: 205
Merit: 105


View Profile WWW
March 22, 2016, 08:39:49 AM
 #3

Great, thank you! So when I instruct my wallet to pay a certain amount to an address, the wallet first has to extract the hash160(sha256(pubkey)) and then uses that in the scriptPubKey part. Now the <pubkey hash> part makes sense.

DannyHamilton
Legendary
*
Offline Offline

Activity: 3514
Merit: 4894



View Profile
March 22, 2016, 01:09:49 PM
Merited by ABCbits (1)
 #4

Great, thank you! So when I instruct my wallet to pay a certain amount to an address, the wallet first has to extract the hash160(sha256(pubkey)) and then uses that in the scriptPubKey part. Now the <pubkey hash> part makes sense.

Exactly.  This is why these types of outputs are called Pay-to-pubkey-hash (P2PKH) and not Pay-to-address.

Addresses, address version numbers, and address checksums do not exist in the actual transactions.  Those are just things that are added at the user interface level to make bitcoin easier for us humans to use.
Manfred Macx (OP)
Full Member
***
Offline Offline

Activity: 205
Merit: 105


View Profile WWW
March 23, 2016, 08:30:04 AM
 #5

Exactly.  This is why these types of outputs are called Pay-to-pubkey-hash (P2PKH) and not Pay-to-address.

Addresses, address version numbers, and address checksums do not exist in the actual transactions.  Those are just things that are added at the user interface level to make bitcoin easier for us humans to use.

Thank you Smiley

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!