6

When a Segwit transaction is signed, among the many hashes that are calculated to create the data that is going to be signed, the hash of the concatenated [input + index] is calculated (hashPrevouts) and so is the hash of the concatenated [nSequence] numbers (hashSequence).

My question is why are those hashes computed separately, instead of just hashing the concatenation of the [inputs + indexes + Sequence number].

1 Answer 1

8

The reason is increasing the ability to precompute and/or cache those hash values once for the whole transaction (potentially allowing them to be used for many signatures).

In "normal" (SIGHASH_ALL) signatures, both the prevouts and sequence values of all inputs are committed to by the sighash. However:

  • With sighash types that include SIGHASH_ANYONECANPAY, neither prevouts or sequence values are included.
  • With sighash types that include SIGHASH_NONE or SIGHASH_SINGLE, but not SIGHASH_ANYONECANPAY, the prevouts are included in the hash, but the sequence values are not.

Splitting the two pieces of data up means that all sighashes can be computed based on just these two precomputed values, even when non-SIGHASH_ALL signatures occur.

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.