Author

Topic: Pay to Script Hash (Read 532 times)

jr. member
Activity: 113
Merit: 5
November 11, 2017, 09:24:38 PM
#5
where are the bitcoin core files that handle P2SH transaction ?

i figure it out.
jr. member
Activity: 113
Merit: 5
November 11, 2017, 10:14:24 AM
#4
where are the bitcoin core files that handle P2SH transaction ?
jr. member
Activity: 113
Merit: 5
November 11, 2017, 08:25:43 AM
#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

sr. member
Activity: 257
Merit: 343
November 11, 2017, 06: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
 

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

Quote
Sig1
Sig2

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 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:
    OP_2 PK1 PK2 PK3 OP_3 CHECKMULTISIG

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




jr. member
Activity: 113
Merit: 5
November 11, 2017, 03: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 OP_EQUAL
scriptSig: 0 ...