Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: croraf on November 26, 2017, 11:14:12 PM



Title: Why is scriptSig filled with scriptPubKey before signing a transaction?
Post by: croraf on November 26, 2017, 11:14:12 PM


I'm checking the transaction signing as described here https://bitcoin.stackexchange.com/questions/32628/redeeming-a-raw-transaction-step-by-step-example-required.

What is the reason for steps 5 and 6: temporarily filling scriptSig with scriptPubKey of the output we want to redeem?

Can't this just be skipped, as with txid and output index we uniquely specify the output thus scriptPubKey and we don't get any value with this filling?


Title: Re: Why is scriptSig filled with scriptPubKey before signing a transaction?
Post by: pebwindkraft on November 27, 2017, 10:59:19 AM
I posted my answer as well on your question in stackexchange...

https://bitcoin.stackexchange.com/questions/63489/why-is-scriptsig-filled-with-scriptpubkey-before-signing-a-transaction/63519#63519



Title: Re: Why is scriptSig filled with scriptPubKey before signing a transaction?
Post by: croraf on November 27, 2017, 01:32:11 PM
Thanks man.

I have kind of a follow up question, that I will also post on SE.

So to make transaction the following is done.

For each input
 
- all inputs and outputs are taken
- the respective input scriptSig is filled with txPrev.pubScript, other inputs's scriptSigs are left blank?
- this is signed and signature is put in respective scriptSig


Is there any benefit for bundling all inputs in each signature? Could just respective input (and all outputs) be used when signing for that input?

This will give N_inputs different templates.

But if currently other inputs' scriptSig than respective are left blank (instead of each being filled with txPrev.pubScript) then we currently also have N_inputs different templates.

The ideal would be to leave all scriptSigs blank when making signing template and use all inputs and outputs. This will give us 1 template that is signed N_input times.

What you think? Were you able to follow my thoughts?


Title: Re: Why is scriptSig filled with scriptPubKey before signing a transaction?
Post by: achow101 on November 27, 2017, 04:36:48 PM
Is there any benefit for bundling all inputs in each signature? Could just respective input (and all outputs) be used when signing for that input?
The benefit is that each signature commits to the inputs and outputs of the transaction so that they cannot be changed. If each input only commit to one input, then more inputs could be added and malleate the transaction. However there is a sighash type that allows this, sighash ANYONECANPAY.


Title: Re: Why is scriptSig filled with scriptPubKey before signing a transaction?
Post by: croraf on November 28, 2017, 09:08:05 AM
Is there any benefit for bundling all inputs in each signature? Could just respective input (and all outputs) be used when signing for that input?
The benefit is that each signature commits to the inputs and outputs of the transaction so that they cannot be changed. If each input only commit to one input, then more inputs could be added and malleate the transaction. However there is a sighash type that allows this, sighash ANYONECANPAY.

Cool. Understood.