Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: luv2drnkbr on September 07, 2016, 04:20:31 PM



Title: [Closed] Help generating segwit txcopy for signature verification
Post by: luv2drnkbr on September 07, 2016, 04:20:31 PM
Using this guide (https://0bin.net/paste/nfnSf0HcBqBUGDto#7zJMRUhGEBkyh-eASQPEwKfNHgQ4D5KrUJRsk8MTPSa), and the segwit BIP, I feel like I'm reasonably comfortable constructing and verifying transactions in the new segwit format.  Except for the life of me, I cannot figure out how to format the transaction to the format that gets hashed for the signature.  Can somebody help me out and paste the txcopy for the example transaction in the link, so I can see where my error was.  I have no trouble making txcopies for non-segwit transactions, and I'm not sure what I'm doing wrong here.  (And also, maybe somebody can tell me what changes are needed, given that the example uses a P2SH-wrapped segwit output.)

Thanks for the help guys!

EDIT:  I just now found out that BIP 143 exists and explains exactly my problem.


Title: Re: Help generating segwit txcopy for signature verification
Post by: achow101 on September 07, 2016, 04:22:43 PM
So you want the actual input to the hashing functions before the signing? Read the BIP, it explains it pretty well.

Also, can you post what you think is right so that we can see what you have done wrong?


Title: Re: Help generating segwit txcopy for signature verification
Post by: luv2drnkbr on September 07, 2016, 05:48:46 PM
So you want the actual input to the hashing functions before the signing?

Yes, that would be extremely helpful.

Read the BIP, it explains it pretty well.

I could not find anything about signature verification, barring the change in transaction serialization format.

Also, can you post what you think is right so that we can see what you have done wrong?

I have tried formatting it in almost every imaginable way.  With and without the segwit marker and flag, with the segwit script hash in the scriptsig area, with the redeem script in the scriptsig area, with and without the redeem script in the witness field after the output, with and without the witness script in the witness field, and every combination of mixing and matching of all of those.  (Including with and without the SIGHASH_ALL 8-byte flag at the end.)

That's why I was hoping to just have somebody who knows better post what the actual txcopy should be.  It will be immediately obvious what I should or should not have done if I can see the correct serialized txcopy.

EDIT:  I just now found out that BIP 143 exists and explains exactly my problem.