1

For my understand, when building a new TX, need to produce a new scriptSig for the TX; and need add a sigHash code at the end of the TX. If the sighash type is SIGHASH_SINGLE, for a TX with multiple input and output, how to specify the right input and output to sign.

1 Answer 1

1

A signature is applied to the input being signed by default, so you don't really pick the input.

You have two options:

SIGHASH_SINGLE - All inputs are signed, and a single output with the same vout index as your vin index is signed. That is to say, if you have a tx with 5 inputs, out of which your input is the second one, and 4 outputs, all five inputs and the second output will be signed.

SIGHASH_SINGLE | SIGHASH_ANYONECANPAY - This will only sign your input and the corresponding output, instead of signing all the inputs. Essentially, in the above example, input 2 and output 2 will be signed.

5
  • Thanks! In my case, I have 1 input and 5 output, so the SIGHASH_SINGLE will sign the only input, and which output, Vout0 or Vout1 or Vout2? Why?
    – yrm23
    Sep 2, 2018 at 14:05
  • From your answer, my understand is that the only new signed vout' index depended on the index of pre vout, is that right. So, if the pre vout's index is 4, the signature will only include the vout 4 for output. Is my understand right?
    – yrm23
    Sep 2, 2018 at 14:15
  • It will only sign vout 0, since, you have only one input, which will be at vin0. Sep 2, 2018 at 14:19
  • Thanks again. one more question, in your example, why the second output is selected from the four output, not others? my understand is the Sighash code is put at the end of the whole TX message for the whole TX not for a single input. I think maybe there is something wrong with my understand.
    – yrm23
    Sep 2, 2018 at 14:34
  • 1
    Each input is signed individually, and the sighash can be different for each input. I wrote a blog post some time ago on how multi-sighash transactions can be useful, if you are interested in that Sep 2, 2018 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.