<blockquote>
  <p>Is 1 byte appended to the signature in the the same way, but in the witness data rather than the legacy part of the transaction?</p>
</blockquote>

<p>Yes. The signature serialization (which includes the sighash type) remains exactly the same.</p>

<p>Look at the <a href="https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#native-p2wpkh" rel="nofollow noreferrer">first example in BIP 143</a>, the generated signature (before serialization) is <code>304402203609e17b84f6a7d30c80bfa610b5b4542f32a8a0d5447a12fb1366d7f01cc44a0220573a954c4518331561406f90300e8f3358f51928d43c212a8caed02de67eebee</code>. When it is serialized, it becomes <code>47304402203609e17b84f6a7d30c80bfa610b5b4542f32a8a0d5447a12fb1366d7f01cc44a0220573a954c4518331561406f90300e8f3358f51928d43c212a8caed02de67eebee01</code>. Notice how when serialized there is an additional byte appended to the signature; that is the sighash type.</p>

CC BY-SA 3.0
2017-11-02T05:02:26.317Z
Thanks, I see it now. I think the example would be more readable if the size, signature, sighash type and pubkey are put on seperate lines.
Sjors Provoost
CC BY-SA 3.0
2017-11-01T03:11:41.347Z
2017-11-01T03:11:41.347Z
Ava Chow
<p>When preparing or verifying a signature, a transaction pre-image is created in memory. This pre-image exists purely for the purpose of creating a signature and is not published to the blockchain. At the end of this pre-image is a 4 bytes <code>SIGHASH_TYPE</code>.</p>

<p>When serializing the resulting transaction, the <code>SIGHAH_TYPE</code> is truncated to one byte and added at the end of each signature. The remaining 4 bytes are not put at the end of the final transaction (<a href="https://bitcoin.stackexchange.com/questions/48108/why-are-sighash-flags-signed-as-4-bytes-when-only-1-byte-is-included-in-the-tran">here's why</a>, probably).</p>

<p>How does this work with SegWit? Is 1 byte appended to the signature in the the same way, but in the witness data rather than the legacy part of the transaction? It's not immediately obvious to me based on the examples in <a href="https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki" rel="nofollow noreferrer">BIP143</a>.</p>

<signature><consensus>
Where is SIGHASH_TYPE serialized in SegWit?
Sjors Provoost
# Where is SIGHASH_TYPE serialized in SegWit?

(Asked by: username_0 on 2017-11-01)

When preparing or verifying a signature, a transaction pre-image is created in memory. This pre-image exists purely for the purpose of creating a signature and is not published to the blockchain. At the end of this pre-image is a 4 bytes `SIGHASH_TYPE`.

When serializing the resulting transaction, the `SIGHAH_TYPE` is truncated to one byte and added at the end of each signature. The remaining 4 bytes are not put at the end of the final transaction ([here's why](https://bitcoin.stackexchange.com/questions/48108/why-are-sighash-flags-signed-as-4-bytes-when-only-1-byte-is-included-in-the-tran), probably).

How does this work with SegWit? Is 1 byte appended to the signature in the the same way, but in the witness data rather than the legacy part of the transaction? It's not immediately obvious to me based on the examples in [BIP143](https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki).

**Tags:** signature, consensus


---

## 1 answers

### Answer by username_1 on 2017-11-01. Score: 4 | Accepted answer

> Is 1 byte appended to the signature in the the same way, but in the witness data rather than the legacy part of the transaction?

Yes. The signature serialization (which includes the sighash type) remains exactly the same.

Look at the [first example in BIP 143](https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#native-p2wpkh), the generated signature (before serialization) is `304402203609e17b84f6a7d30c80bfa610b5b4542f32a8a0d5447a12fb1366d7f01cc44a0220573a954c4518331561406f90300e8f3358f51928d43c212a8caed02de67eebee`. When it is serialized, it becomes `47304402203609e17b84f6a7d30c80bfa610b5b4542f32a8a0d5447a12fb1366d7f01cc44a0220573a954c4518331561406f90300e8f3358f51928d43c212a8caed02de67eebee01`. Notice how when serialized there is an additional byte appended to the signature; that is the sighash type.

> **Comments:**
> **username_0**: Thanks, I see it now. I think the example would be more readable if the size, signature, sighash type and pubkey are put on seperate lines.  

---

