Bitcoin Forum
November 13, 2024, 10:54:09 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Pay to Script Hash  (Read 530 times)
victorkimba17 (OP)
Jr. Member
*
Offline Offline

Activity: 113
Merit: 5


View Profile
November 11, 2017, 08:06:27 AM
 #1

For P2SH, i understand it lets the sender funds a transaction using 20 byte hash. The script supplied to redeem must hash to the scriptHash.

scriptPubKey: OP_HASH160 <scriptHash> OP_EQUAL
scriptSig: 0 <sig1> ... <script> OP_m <pubKey1> ... OP_n OP_CHECKMULTISIG

For this example, the processing is:

The checking process:
Stack   Script   Description
Empty.0 <sig1> <sig2> OP_2 <pubKey1> <pubKey2> <pubKey3> OP_3 OP_CHECKMULTISIG OP_HASH160 <scriptHash> OP_EQUAL   locking script combined with redeem script
0 <sig1> <sig2> OP_2 <pubKey1> <pubKey2> <pubKey3> OP_3   OP_CHECKMULTISIG OP_HASH160 <scriptHash> OP_EQUAL   Constants are added to the stack.
trueOP_HASH160 <scriptHash> OP_EQUAL   Signatures validated in the order of the keys in the script.

what happens after OP_CHECKMULTISIG, what value does OP_HASH160 hash to?



pebwindkraft
Sr. Member
****
Offline Offline

Activity: 257
Merit: 343


View Profile
November 11, 2017, 11:29:04 AM
 #2

Looks like the formatting is a bit shuffled, can't get it clearly.
This is what I understand happens on the stack for a multisig P2SH tx (I ignore the 0 at the beginning for the CHECKMULTISIG bug):

Quote
Redeem Script     OP_2 PubKey1 PubKey2 PubKey3 OP_3 CHECKMULTISIG
Locking Script      HASH160 <20-byte hash of redeem script> EQUAL
Unlocking Script   Sig1 Sig2 <redeem script>
 

So when I want to unlock the tx, I drop Sig1, Sig2 and <redeem script> on the stack. Then the part of the locking script, and it gives:

Quote
Sig1
Sig2
<redeem script>
HASH160
<20-byte hash of redeem script>
EQUAL

(from Andreas' book "Mastering Bitcoin"):
The two scripts are combined in two stages. First, the redeem script is checked against the locking script to make sure the hash matches.

Replacing the <redeem script> and assuming the 20-byte hash of redeem script is "54c557e07dde5bb6cb791c7a540e0a4796f5e97e", we get this:

Quote
OP_2 PubKey1 PubKey2 PubKey3 OP_3 CHECKMULTISIG
HASH160
54c557e07dde5bb6cb791c7a540e0a4796f5e97e
EQUAL

And then, if the redeem script hash matches, this will be executed:
    <Sig1> <Sig2> OP_2 PK1 PK2 PK3 OP_3 CHECKMULTISIG

oh, the reference is on pages 151ff on the second edition of the book I mentioned.




victorkimba17 (OP)
Jr. Member
*
Offline Offline

Activity: 113
Merit: 5


View Profile
November 11, 2017, 01:25:43 PM
 #3

Looks like the formatting is a bit shuffled, can't get it clearly.
 
I try to draw the table row and column line, but i don't know how to draw the line using the post reply formatter.

Quote
(from Andreas' book "Mastering Bitcoin"):
The two scripts are combined in two stages. First, the redeem script is checked against the locking script to make sure the hash matches.
I found his book online, the scripting chapter is at
https://github.com/bitcoinbook/bitcoinbook/blob/second_edition/ch07.asciidoc

victorkimba17 (OP)
Jr. Member
*
Offline Offline

Activity: 113
Merit: 5


View Profile
November 11, 2017, 03:14:24 PM
 #4

where are the bitcoin core files that handle P2SH transaction ?
victorkimba17 (OP)
Jr. Member
*
Offline Offline

Activity: 113
Merit: 5


View Profile
November 12, 2017, 02:24:38 AM
 #5

where are the bitcoin core files that handle P2SH transaction ?

i figure it out.
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!