<blockquote>
<p>So how long SIGHASH is?</p>
</blockquote>
<p>The sighash type is a number (it is 1, 2, 3, 129, 130, 131; or since BIP341/BIP342 also 0). It doesn't have a length per se.</p>
<p>When computing the signature hash, the sighash type is serialized as a 4-byte value at the end of the message. In the signature itself, it is serialized as a 1-byte value.</p>
<p>I can't tell you why Bitcoin's creator chose to serialize a value that fits in 1 byte as 4 bytes in the signature hash, but perhaps it was intended for future extensions.</p>
<blockquote>
<p>in the pizza transaction, the r takes 33 bytes, whit 0x00 in the first. When i use ecdsa in python, i have to delete the first byte 0x00. So when DER process, why not just use 32 bytes.</p>
</blockquote>
<p>Since BIP66 it is a network rule that signatures must use the minimal DER encoding. The pizza transaction predates the introduction of that rule.</p>

CC BY-SA 4.0
2022-02-18T14:59:55.187Z
2022-02-18T14:59:55.187Z
Pieter Wuille
<p>I am reading these two posts <a href="https://bitcoin.stackexchange.com/questions/32305/how-does-the-ecdsa-verification-algorithm-work-during-transaction">1</a> <a href="https://bitcoin.stackexchange.com/questions/62446/signature-verification-in-python">2</a>, and following step by step.
I almost understand, but I still have some questions.</p>
<ol>
<li><p>Before signing, input script should be removed and replaced by pre locking script. In the last, SIGHASH should be appended. in this time, SIGHASH is 4 bytes(0x01000000).
However, after signing, SIGHASH should also be appended. in this time(DER), SIGHASH is 1 byte(0x01), as seen in the raw transaction. So how long SIGHASH is?</p>
</li>
<li><p>in the pizza transaction, the r takes 33 bytes, whit 0x00 in the first. When i use ecdsa in python, i have to delete the first byte 0x00. So when DER process, why not just use 32 bytes.</p>
</li>
</ol>

CC BY-SA 4.0
2022-02-18T12:30:29.683Z
Hi, could you please use titles that summarize the topic of your question?
Murch
<signature><raw-transaction><ecdsa><verification><sighash>
How long is SIGHASH?
KHJUAF403456ZS3K564WAEF
# How long is SIGHASH?

(Asked by: username_0 on 2022-02-18)

I am reading these two posts [1](https://bitcoin.stackexchange.com/questions/32305/how-does-the-ecdsa-verification-algorithm-work-during-transaction) [2](https://bitcoin.stackexchange.com/questions/62446/signature-verification-in-python), and following step by step.
I almost understand, but I still have some questions.

1. Before signing, input script should be removed and replaced by pre locking script. In the last, SIGHASH should be appended. in this time, SIGHASH is 4 bytes(0x01000000).
   However, after signing, SIGHASH should also be appended. in this time(DER), SIGHASH is 1 byte(0x01), as seen in the raw transaction. So how long SIGHASH is?
2. in the pizza transaction, the r takes 33 bytes, whit 0x00 in the first. When i use ecdsa in python, i have to delete the first byte 0x00. So when DER process, why not just use 32 bytes.

**Tags:** signature, raw-transaction, ecdsa, verification, sighash

> **Comments:**
> **username_1**: Hi, could you please use titles that summarize the topic of your question?  

---

## 1 answers

### Answer by username_2 on 2022-02-18. Score: 2

> So how long SIGHASH is?

The sighash type is a number (it is 1, 2, 3, 129, 130, 131; or since BIP341/BIP342 also 0). It doesn't have a length per se.

When computing the signature hash, the sighash type is serialized as a 4-byte value at the end of the message. In the signature itself, it is serialized as a 1-byte value.

I can't tell you why Bitcoin's creator chose to serialize a value that fits in 1 byte as 4 bytes in the signature hash, but perhaps it was intended for future extensions.

> in the pizza transaction, the r takes 33 bytes, whit 0x00 in the first. When i use ecdsa in python, i have to delete the first byte 0x00. So when DER process, why not just use 32 bytes.

Since BIP66 it is a network rule that signatures must use the minimal DER encoding. The pizza transaction predates the introduction of that rule.


---

