<blockquote>
<p>Witness Signature: 304402204af85395dd8c758ac379c343bc278351f73cdf9d8548d933aada5fa4e13194a80220126c0614f75520709e63ac41 9308344c00a4a22c021e1b9d8b42115aa73e37b01</p>
</blockquote>
<p>It seems that the signature value contains white space.</p>
<p>Isn't the correct signature value below?</p>
<p><code>30440220722ed739d8a69832ecf6e5d636b2949ab6dc00026b88129a8652916904b80c6e0220370d30e8fb3e2d76f6c64b6d89e050ab47faefd3ca017752496035329534207e01</code></p>
<p>And full tx is:</p>
<p><code>01000000000101471157b07c3f6f5243c0b98a02614636cc6cde24371bcb69dc0bbd4efe52a7420000000000ffffffff01e8fd0000000000001600143778e5361fdad0d209de8a16c2ec4ca64618993e024730440220722ed739d8a69832ecf6e5d636b2949ab6dc00026b88129a8652916904b80c6e0220370d30e8fb3e2d76f6c64b6d89e050ab47faefd3ca017752496035329534207e012102ad2a42eed9fecc022093e8682b62b034690b06587be18f01bb8e60df1afeaaf800000000</code></p>

CC BY-SA 4.0
2021-10-01T00:06:41.783Z
2021-10-01T00:06:41.783Z
Shigeyuki Azuchi
<p>tx_hash_big_endian&quot;:&quot;5da8f74aa4d6612c58c0a740b4740579db57c95828e4cdf04e7d18c23b66cb4a&quot;,&quot;tx_hash&quot;:&quot;4acb663bc2187d4ef0cde42858c957db790574b440a7c0582c61d6a44af7a85d&quot;,
Auto-correct ^ class S256Point(Point): ... def sec(self): '''returns the binary version of the SEC format'''    return b'\x04' + self.x.num.to_bytes(32, 'big') \ + self.y.num.to_bytes(32, 'big')</p>

CC BY-SA 4.0
2021-12-23T00:59:50.757Z
2021-12-23T00:59:50.757Z
Veci V
<p>I have this testnet transaction that I created:</p>
<pre><code>Version: 01000000
Marker: 00
Flag: 01
Input Count: 01
    Input #1 TXID: 42a752fe4ebd0bdc69cb1b3724de6ccc364661028ab9c043526f3f7cb0571147
    Input #1 VOUT: 00000000
    Input #1 ScriptSize: 00
    Input #1 ScriptSig:
    Input #1 Sequence: ffffffff
Output Count: 01
    Output Value: e8fd000000000000
    Output Script Length:16
    Output Script: 00143778e5361fdad0d209de8a16c2ec4ca64618993e
Witness:
    Witness Stack Size: 02
    Witness Signature Length: 47
    Witness Signature: 304402204af85395dd8c758ac379c343bc278351f73cdf9d8548d933aada5fa4e13194a80220126c0614f75520709e63ac41 9308344c00a4a22c021e1b9d8b42115aa73e37b01
    Witness PubKey Length: 21
    Witness PubKey: 02ad2a42eed9fecc022093e8682b62b034690b06587be18f01bb8e60df1afeaaf8
Locktime: 00000000
</code></pre>
<p>When I try to broadcast it, it gives me this error:</p>
<pre><code>Mempool accept test failed: 64: non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation)
</code></pre>
<p>I believe this error occurs because the signature is incorrect, but I am having a hard time identifying how I created the wrong signature.</p>
<p>Here are the steps I took to sign the transaction:</p>
<pre><code>Sign the hash of the following with the signing key:
1. Transaction version (4 bytes little endian)
2. The hash of all input outpoints (32 bytes)
3. The hash of all input sequences (32 bytes)
4. The outpoint (32 + 4 bytes)
5. The script code (26 bytes consisting of 0x1976a914&lt;20 byte pub key hash&gt;88ac)
6. The value of the input being signed (8 bytes little endian)
7. The sequence of the input being signed (4 byte little endian)
8. The hash of all the outputs (32 byte)
9. The locktime of the transaction (4 bytes little endian)
10. Sighash type (4 bytes little endian)
</code></pre>
<p>this signature was then used in conjunction with the Public key of the signing key to create the Witness script as seen above.</p>
<p>Here is the info I used to create the transaction:</p>
<pre><code>Input #1:
    txid: 471157b07c3f6f5243c0b98a02614636cc6cde24371bcb69dc0bbd4efe52a742
    out: 0
    signing key wif: 3a8c0c731cba400917f66bc3435a405387a9a5b20cdbfdedb19e37d0c6cad8b9

Output #1
    value: 65000
    recipient: tb1qxauw2dslmtgdyzw73gtv9mzv5erp3xf7mt83vq
</code></pre>

CC BY-SA 4.0
2021-09-30T09:18:14.850Z
The sighash type is missing in the sighash calculation.

`10. sighash type of the signature (4-byte little endian)`
Shigeyuki Azuchi
CC BY-SA 4.0
2021-09-30T09:49:07.363Z
@ShigeyukiAzuchi My mistake when writing out the steps. My code was appending the sig hash type but still am getting the wrong signature.
Keijyu
CC BY-SA 4.0
2021-09-30T14:15:39.303Z
As a result, what is the value of the sighash you generated?
Shigeyuki Azuchi
CC BY-SA 4.0
2021-10-02T04:22:51.243Z
I found my mistake. I was not reversing the TXID when serializing the tx according to BIP143. Thanks @ShigeyukiAzuchi
Keijyu
<segregated-witness><message-signing><bip143>
Error broadcasting SegWit transaction
Keijyu
# Error broadcasting SegWit transaction

(Asked by: username_0 on 2021-09-30)

I have this testnet transaction that I created:

```
Version: 01000000
Marker: 00
Flag: 01
Input Count: 01
    Input #1 TXID: 42a752fe4ebd0bdc69cb1b3724de6ccc364661028ab9c043526f3f7cb0571147
    Input #1 VOUT: 00000000
    Input #1 ScriptSize: 00
    Input #1 ScriptSig:
    Input #1 Sequence: ffffffff
Output Count: 01
    Output Value: e8fd000000000000
    Output Script Length:16
    Output Script: 00143778e5361fdad0d209de8a16c2ec4ca64618993e
Witness:
    Witness Stack Size: 02
    Witness Signature Length: 47
    Witness Signature: 304402204af85395dd8c758ac379c343bc278351f73cdf9d8548d933aada5fa4e13194a80220126c0614f75520709e63ac41 9308344c00a4a22c021e1b9d8b42115aa73e37b01
    Witness PubKey Length: 21
    Witness PubKey: 02ad2a42eed9fecc022093e8682b62b034690b06587be18f01bb8e60df1afeaaf8
Locktime: 00000000

```

When I try to broadcast it, it gives me this error:

```
Mempool accept test failed: 64: non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation)

```

I believe this error occurs because the signature is incorrect, but I am having a hard time identifying how I created the wrong signature.

Here are the steps I took to sign the transaction:

```
Sign the hash of the following with the signing key:
1. Transaction version (4 bytes little endian)
2. The hash of all input outpoints (32 bytes)
3. The hash of all input sequences (32 bytes)
4. The outpoint (32 + 4 bytes)
5. The script code (26 bytes consisting of 0x1976a914<20 byte pub key hash>88ac)
6. The value of the input being signed (8 bytes little endian)
7. The sequence of the input being signed (4 byte little endian)
8. The hash of all the outputs (32 byte)
9. The locktime of the transaction (4 bytes little endian)
10. Sighash type (4 bytes little endian)

```

this signature was then used in conjunction with the Public key of the signing key to create the Witness script as seen above.

Here is the info I used to create the transaction:

```
Input #1:
    txid: 471157b07c3f6f5243c0b98a02614636cc6cde24371bcb69dc0bbd4efe52a742
    out: 0
    signing key wif: 3a8c0c731cba400917f66bc3435a405387a9a5b20cdbfdedb19e37d0c6cad8b9

Output #1
    value: 65000
    recipient: tb1qxauw2dslmtgdyzw73gtv9mzv5erp3xf7mt83vq

```

**Tags:** segregated-witness, message-signing, bip143

> **Comments:**
> **username_1**: The sighash type is missing in the sighash calculation.  `10. sighash type of the signature (4-byte little endian)`  
> **username_0**: @username_1 My mistake when writing out the steps. My code was appending the sig hash type but still am getting the wrong signature.  
> **username_1**: As a result, what is the value of the sighash you generated?  
> **username_0**: I found my mistake. I was not reversing the TXID when serializing the tx according to BIP143. Thanks @username_1  

---

## 2 answers

### Answer by username_1 on 2021-10-01. Score: 1

> Witness Signature: 304402204af85395dd8c758ac379c343bc278351f73cdf9d8548d933aada5fa4e13194a80220126c0614f75520709e63ac41 9308344c00a4a22c021e1b9d8b42115aa73e37b01

It seems that the signature value contains white space.

Isn't the correct signature value below?

`30440220722ed739d8a69832ecf6e5d636b2949ab6dc00026b88129a8652916904b80c6e0220370d30e8fb3e2d76f6c64b6d89e050ab47faefd3ca017752496035329534207e01`

And full tx is:

`01000000000101471157b07c3f6f5243c0b98a02614636cc6cde24371bcb69dc0bbd4efe52a7420000000000ffffffff01e8fd0000000000001600143778e5361fdad0d209de8a16c2ec4ca64618993e024730440220722ed739d8a69832ecf6e5d636b2949ab6dc00026b88129a8652916904b80c6e0220370d30e8fb3e2d76f6c64b6d89e050ab47faefd3ca017752496035329534207e012102ad2a42eed9fecc022093e8682b62b034690b06587be18f01bb8e60df1afeaaf800000000`


---

### Answer by username_2 on 2021-12-23. Score: 0

tx\_hash\_big\_endian":"5da8f74aa4d6612c58c0a740b4740579db57c95828e4cdf04e7d18c23b66cb4a","tx\_hash":"4acb663bc2187d4ef0cde42858c957db790574b440a7c0582c61d6a44af7a85d",
Auto-correct ^ class S256Point(Point): ... def sec(self): '''returns the binary version of the SEC format''' return b'\x04' + self.x.num.to\_bytes(32, 'big') \ + self.y.num.to\_bytes(32, 'big')


---

