<p>Although the field is named &quot;hash&quot;, it is not actually a hash of the entire transaction. That is actually the txid. Since the inputs are segwit, the signatures are excluded from the txid calculation. As the only difference between these two transactions are the signatures, they have the same txid.</p>
<p>Looking at the signatures of both transactions, I believe it is actually tx2 that is failing. The error message &quot;Non-canonical DER signature&quot; gives us a hint of what to look for.</p>
<p>ECDSA signatures using the DER encoding, and since the activation of <a href="https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki" rel="nofollow noreferrer">BIP 66</a>, must adhere to a strict set of rules. Analyzing the signatures following the rules specified in the BIP, I find that the signature <code>30440220780eedf386e77f5acaceaf948251fa3bbf51e7fcc401bf7973a08f65b99eadc702200019a281127211a29c5b827b80967154d05b9224f6bf7b77baff13e63d57654501</code> in tx2 fails the rule that &quot;Null bytes at the start of S are not allowed, unless S would otherwise be interpreted as a negative number.&quot; The S value in the signature is <code>0019a281127211a29c5b827b80967154d05b9224f6bf7b77baff13e63d576545</code> and we can immediately see that it begins with a null byte. The byte following it is not greater than or equal to <code>0x80</code>, so this signature fails this check and is therefore a non-canonical signature.</p>
<p>The correct encoding of this signature would simply exclude that null byte and adjusting the lengths accordingly. The correct signature should be <code>30430220780eedf386e77f5acaceaf948251fa3bbf51e7fcc401bf7973a08f65b99eadc7021f19a281127211a29c5b827b80967154d05b9224f6bf7b77baff13e63d57654501</code></p>

CC BY-SA 4.0
2024-07-13T07:59:27.463Z
I just checked again and you're correct. It is Tx 2 that is failing. Thank you for pinpointing the null byte in R. Is there a way to quickly analyze these values using any tool so that I could've found the issue myself? 

I have a few more txns failing and apparently, the error rate is 1/300. 

I'll try and fix the bull byte issue and see if that reduces the error rate. If it does, that litecoin-utils lib definitely needs a PR as fix.
Ravi Ojha
CC BY-SA 4.0
2024-07-14T04:40:56.047Z
Nit: R is the first integer in a signature; the second integer (with the error here) is S. But this doesn't make a difference because DER rules are the same for all integers -- as defined in ASN.1; the coordinate(s) in a public key for a curve on an F_p field (including secp256k1) are semantically integers, but the X9 representation makes them an octet string in ASN.1, so the ASN.1 integer rules don't apply there.
dave_thompson_085
CC BY-SA 4.0
2024-07-14T17:25:15.010Z
@dave_thompson_085 Oops, good catch, fixed.
Ava Chow
CC BY-SA 4.0
2024-07-13T00:17:51.477Z
2024-07-14T17:24:40.877Z
2024-07-14T17:24:40.877Z
Ava Chow
<p>I have two transactions, they produce the same hash. But the first one throws Non-canonical DER signature error and the second one doesn't. This is a standard 2/3 multi-sig transaction.</p>
<p>Tx 1:</p>
<pre><code>020000000001018b4025d76e67ac4b05010832917b3407ee11c17f3ac1f8537ad92dbda905d2760000000000ffffffff020355ea4000000000160014104d11991b81471fce9439dfb22ff144fb5ecf0cabdca700000000001600145809ea020e7a3ff5c09f57b0a52c98ae7e7aee7a040047304402201b4b4642b9bea7274ea74a39d7657867308efbd5866ccedf62f5e2cd0b5f2c9902200996fb466241a1a715d9a93128fe5efd8bde0a3453c109ea0b47a1b0dd4d38150147304402201db836dacb6290d4014f87ecd95ec5fe1c618973437d0e86f2a6266b8861e20c02207415a722f64070f12d2d2b18031b6c9f1829a88dfb8c0f871571a57aaf34930b016952210325da1b6830e251da8acb91d09d7fc162568e9c68dd12bd0f94643fed936dc87c21035497f2acb88278b2323d88f1bc353c0daa3c42abc289fab6ccbd8edb718ae8cd2103cbe6dec1b7944f5e4d4385acaf2fb6980eaa54169b6d422e24db2de61e01a5f553ae00000000
</code></pre>
<p>Tx 1 decoded:</p>
<pre><code>{
    &quot;addresses&quot;: [
        &quot;ltc1qunwwcdm45r94n0vun35pvhh8d7duxzfcxe4dc9vlwlhe9ych7ufqvp9nn3&quot;,
        &quot;ltc1qzpx3rxgms9r3ln55880mytl3gna4ancvuw4pyz&quot;,
        &quot;ltc1qtqy75qsw0glltsyl27c22tyc4el84mn65mnej2&quot;
    ],
    &quot;block_height&quot;: -1,
    &quot;block_index&quot;: -1,
    &quot;confirmations&quot;: 0,
    &quot;double_spend&quot;: false,
    &quot;fees&quot;: 300,
    &quot;hash&quot;: &quot;b86b27a622ce8b5336debda81e0dc33e8ab3eb07354789e4bc708e38caa2dce4&quot;,
    &quot;inputs&quot;: [
        {
            &quot;addresses&quot;: [
                &quot;ltc1qunwwcdm45r94n0vun35pvhh8d7duxzfcxe4dc9vlwlhe9ych7ufqvp9nn3&quot;
            ],
            &quot;age&quot;: 2718775,
            &quot;output_index&quot;: 0,
            &quot;output_value&quot;: 1100100314,
            &quot;prev_hash&quot;: &quot;76d205a9bd2dd97a53f8c13a7fc111ee07347b91320801054bac676ed725408b&quot;,
            &quot;script_type&quot;: &quot;pay-to-witness-script-hash&quot;,
            &quot;sequence&quot;: 4294967295,
            &quot;witness&quot;: [
                &quot;&quot;,
                &quot;304402201b4b4642b9bea7274ea74a39d7657867308efbd5866ccedf62f5e2cd0b5f2c9902200996fb466241a1a715d9a93128fe5efd8bde0a3453c109ea0b47a1b0dd4d381501&quot;,
                &quot;304402201db836dacb6290d4014f87ecd95ec5fe1c618973437d0e86f2a6266b8861e20c02207415a722f64070f12d2d2b18031b6c9f1829a88dfb8c0f871571a57aaf34930b01&quot;,
                &quot;52210325da1b6830e251da8acb91d09d7fc162568e9c68dd12bd0f94643fed936dc87c21035497f2acb88278b2323d88f1bc353c0daa3c42abc289fab6ccbd8edb718ae8cd2103cbe6dec1b7944f5e4d4385acaf2fb6980eaa54169b6d422e24db2de61e01a5f553ae&quot;
            ]
        }
    ],
    &quot;outputs&quot;: [
        {
            &quot;addresses&quot;: [
                &quot;ltc1qzpx3rxgms9r3ln55880mytl3gna4ancvuw4pyz&quot;
            ],
            &quot;script&quot;: &quot;0014104d11991b81471fce9439dfb22ff144fb5ecf0c&quot;,
            &quot;script_type&quot;: &quot;pay-to-witness-pubkey-hash&quot;,
            &quot;value&quot;: 1089099011
        },
        {
            &quot;addresses&quot;: [
                &quot;ltc1qtqy75qsw0glltsyl27c22tyc4el84mn65mnej2&quot;
            ],
            &quot;script&quot;: &quot;00145809ea020e7a3ff5c09f57b0a52c98ae7e7aee7a&quot;,
            &quot;script_type&quot;: &quot;pay-to-witness-pubkey-hash&quot;,
            &quot;value&quot;: 11001003
        }
    ],
    &quot;preference&quot;: &quot;low&quot;,
    &quot;received&quot;: &quot;2024-07-12T17:33:01.857762451Z&quot;,
    &quot;relayed_by&quot;: &quot;3.239.118.85&quot;,
    &quot;size&quot;: 367,
    &quot;total&quot;: 1100100014,
    &quot;ver&quot;: 2,
    &quot;vin_sz&quot;: 1,
    &quot;vout_sz&quot;: 2,
    &quot;vsize&quot;: 177
}
</code></pre>
<p>Tx 2:</p>
<pre><code>020000000001018b4025d76e67ac4b05010832917b3407ee11c17f3ac1f8537ad92dbda905d2760000000000ffffffff020355ea4000000000160014104d11991b81471fce9439dfb22ff144fb5ecf0cabdca700000000001600145809ea020e7a3ff5c09f57b0a52c98ae7e7aee7a040047304402201db836dacb6290d4014f87ecd95ec5fe1c618973437d0e86f2a6266b8861e20c02207415a722f64070f12d2d2b18031b6c9f1829a88dfb8c0f871571a57aaf34930b014730440220780eedf386e77f5acaceaf948251fa3bbf51e7fcc401bf7973a08f65b99eadc702200019a281127211a29c5b827b80967154d05b9224f6bf7b77baff13e63d576545016952210325da1b6830e251da8acb91d09d7fc162568e9c68dd12bd0f94643fed936dc87c21035497f2acb88278b2323d88f1bc353c0daa3c42abc289fab6ccbd8edb718ae8cd2103cbe6dec1b7944f5e4d4385acaf2fb6980eaa54169b6d422e24db2de61e01a5f553ae00000000
</code></pre>
<p>Tx 2 decoded:</p>
<pre><code>{
    &quot;addresses&quot;: [
        &quot;ltc1qunwwcdm45r94n0vun35pvhh8d7duxzfcxe4dc9vlwlhe9ych7ufqvp9nn3&quot;,
        &quot;ltc1qzpx3rxgms9r3ln55880mytl3gna4ancvuw4pyz&quot;,
        &quot;ltc1qtqy75qsw0glltsyl27c22tyc4el84mn65mnej2&quot;
    ],
    &quot;block_height&quot;: -1,
    &quot;block_index&quot;: -1,
    &quot;confirmations&quot;: 0,
    &quot;double_spend&quot;: false,
    &quot;fees&quot;: 300,
    &quot;hash&quot;: &quot;b86b27a622ce8b5336debda81e0dc33e8ab3eb07354789e4bc708e38caa2dce4&quot;,
    &quot;inputs&quot;: [
        {
            &quot;addresses&quot;: [
                &quot;ltc1qunwwcdm45r94n0vun35pvhh8d7duxzfcxe4dc9vlwlhe9ych7ufqvp9nn3&quot;
            ],
            &quot;age&quot;: 2718775,
            &quot;output_index&quot;: 0,
            &quot;output_value&quot;: 1100100314,
            &quot;prev_hash&quot;: &quot;76d205a9bd2dd97a53f8c13a7fc111ee07347b91320801054bac676ed725408b&quot;,
            &quot;script_type&quot;: &quot;pay-to-witness-script-hash&quot;,
            &quot;sequence&quot;: 4294967295,
            &quot;witness&quot;: [
                &quot;&quot;,
                &quot;304402201db836dacb6290d4014f87ecd95ec5fe1c618973437d0e86f2a6266b8861e20c02207415a722f64070f12d2d2b18031b6c9f1829a88dfb8c0f871571a57aaf34930b01&quot;,
                &quot;30440220780eedf386e77f5acaceaf948251fa3bbf51e7fcc401bf7973a08f65b99eadc702200019a281127211a29c5b827b80967154d05b9224f6bf7b77baff13e63d57654501&quot;,
                &quot;52210325da1b6830e251da8acb91d09d7fc162568e9c68dd12bd0f94643fed936dc87c21035497f2acb88278b2323d88f1bc353c0daa3c42abc289fab6ccbd8edb718ae8cd2103cbe6dec1b7944f5e4d4385acaf2fb6980eaa54169b6d422e24db2de61e01a5f553ae&quot;
            ]
        }
    ],
    &quot;outputs&quot;: [
        {
            &quot;addresses&quot;: [
                &quot;ltc1qzpx3rxgms9r3ln55880mytl3gna4ancvuw4pyz&quot;
            ],
            &quot;script&quot;: &quot;0014104d11991b81471fce9439dfb22ff144fb5ecf0c&quot;,
            &quot;script_type&quot;: &quot;pay-to-witness-pubkey-hash&quot;,
            &quot;value&quot;: 1089099011
        },
        {
            &quot;addresses&quot;: [
                &quot;ltc1qtqy75qsw0glltsyl27c22tyc4el84mn65mnej2&quot;
            ],
            &quot;script&quot;: &quot;00145809ea020e7a3ff5c09f57b0a52c98ae7e7aee7a&quot;,
            &quot;script_type&quot;: &quot;pay-to-witness-pubkey-hash&quot;,
            &quot;value&quot;: 11001003
        }
    ],
    &quot;preference&quot;: &quot;low&quot;,
    &quot;received&quot;: &quot;2024-07-12T17:39:55.39046822Z&quot;,
    &quot;relayed_by&quot;: &quot;3.227.22.189&quot;,
    &quot;size&quot;: 367,
    &quot;total&quot;: 1100100014,
    &quot;ver&quot;: 2,
    &quot;vin_sz&quot;: 1,
    &quot;vout_sz&quot;: 2,
    &quot;vsize&quot;: 177
}
</code></pre>
<p>Why is the first one failing? What am I doing wrong?
I'm using this python lib: <a href="https://github.com/karask/python-litecoin-utils" rel="nofollow noreferrer">litecoin-utils</a></p>

CC BY-SA 4.0
2024-07-13T00:11:58.177Z
Is it tx1 or tx2 that is failing? Your question says tx1, although analyzing these txs, I believe it should be tx2.
Ava Chow
<multi-signature><signature><litecoin><ecdsa><encoding>
Trying to figure out non-canonical DER signature error for a specific tx
Ravi Ojha
# Trying to figure out non-canonical DER signature error for a specific tx

(Asked by: username_0 on 2024-07-12)

I have two transactions, they produce the same hash. But the first one throws Non-canonical DER signature error and the second one doesn't. This is a standard 2/3 multi-sig transaction.

Tx 1:

```
020000000001018b4025d76e67ac4b05010832917b3407ee11c17f3ac1f8537ad92dbda905d2760000000000ffffffff020355ea4000000000160014104d11991b81471fce9439dfb22ff144fb5ecf0cabdca700000000001600145809ea020e7a3ff5c09f57b0a52c98ae7e7aee7a040047304402201b4b4642b9bea7274ea74a39d7657867308efbd5866ccedf62f5e2cd0b5f2c9902200996fb466241a1a715d9a93128fe5efd8bde0a3453c109ea0b47a1b0dd4d38150147304402201db836dacb6290d4014f87ecd95ec5fe1c618973437d0e86f2a6266b8861e20c02207415a722f64070f12d2d2b18031b6c9f1829a88dfb8c0f871571a57aaf34930b016952210325da1b6830e251da8acb91d09d7fc162568e9c68dd12bd0f94643fed936dc87c21035497f2acb88278b2323d88f1bc353c0daa3c42abc289fab6ccbd8edb718ae8cd2103cbe6dec1b7944f5e4d4385acaf2fb6980eaa54169b6d422e24db2de61e01a5f553ae00000000

```

Tx 1 decoded:

```
{
    "addresses": [
        "ltc1qunwwcdm45r94n0vun35pvhh8d7duxzfcxe4dc9vlwlhe9ych7ufqvp9nn3",
        "ltc1qzpx3rxgms9r3ln55880mytl3gna4ancvuw4pyz",
        "ltc1qtqy75qsw0glltsyl27c22tyc4el84mn65mnej2"
    ],
    "block_height": -1,
    "block_index": -1,
    "confirmations": 0,
    "double_spend": false,
    "fees": 300,
    "hash": "b86b27a622ce8b5336debda81e0dc33e8ab3eb07354789e4bc708e38caa2dce4",
    "inputs": [
        {
            "addresses": [
                "ltc1qunwwcdm45r94n0vun35pvhh8d7duxzfcxe4dc9vlwlhe9ych7ufqvp9nn3"
            ],
            "age": 2718775,
            "output_index": 0,
            "output_value": 1100100314,
            "prev_hash": "76d205a9bd2dd97a53f8c13a7fc111ee07347b91320801054bac676ed725408b",
            "script_type": "pay-to-witness-script-hash",
            "sequence": 4294967295,
            "witness": [
                "",
                "304402201b4b4642b9bea7274ea74a39d7657867308efbd5866ccedf62f5e2cd0b5f2c9902200996fb466241a1a715d9a93128fe5efd8bde0a3453c109ea0b47a1b0dd4d381501",
                "304402201db836dacb6290d4014f87ecd95ec5fe1c618973437d0e86f2a6266b8861e20c02207415a722f64070f12d2d2b18031b6c9f1829a88dfb8c0f871571a57aaf34930b01",
                "52210325da1b6830e251da8acb91d09d7fc162568e9c68dd12bd0f94643fed936dc87c21035497f2acb88278b2323d88f1bc353c0daa3c42abc289fab6ccbd8edb718ae8cd2103cbe6dec1b7944f5e4d4385acaf2fb6980eaa54169b6d422e24db2de61e01a5f553ae"
            ]
        }
    ],
    "outputs": [
        {
            "addresses": [
                "ltc1qzpx3rxgms9r3ln55880mytl3gna4ancvuw4pyz"
            ],
            "script": "0014104d11991b81471fce9439dfb22ff144fb5ecf0c",
            "script_type": "pay-to-witness-pubkey-hash",
            "value": 1089099011
        },
        {
            "addresses": [
                "ltc1qtqy75qsw0glltsyl27c22tyc4el84mn65mnej2"
            ],
            "script": "00145809ea020e7a3ff5c09f57b0a52c98ae7e7aee7a",
            "script_type": "pay-to-witness-pubkey-hash",
            "value": 11001003
        }
    ],
    "preference": "low",
    "received": "2024-07-12T17:33:01.857762451Z",
    "relayed_by": "3.239.118.85",
    "size": 367,
    "total": 1100100014,
    "ver": 2,
    "vin_sz": 1,
    "vout_sz": 2,
    "vsize": 177
}

```

Tx 2:

```
020000000001018b4025d76e67ac4b05010832917b3407ee11c17f3ac1f8537ad92dbda905d2760000000000ffffffff020355ea4000000000160014104d11991b81471fce9439dfb22ff144fb5ecf0cabdca700000000001600145809ea020e7a3ff5c09f57b0a52c98ae7e7aee7a040047304402201db836dacb6290d4014f87ecd95ec5fe1c618973437d0e86f2a6266b8861e20c02207415a722f64070f12d2d2b18031b6c9f1829a88dfb8c0f871571a57aaf34930b014730440220780eedf386e77f5acaceaf948251fa3bbf51e7fcc401bf7973a08f65b99eadc702200019a281127211a29c5b827b80967154d05b9224f6bf7b77baff13e63d576545016952210325da1b6830e251da8acb91d09d7fc162568e9c68dd12bd0f94643fed936dc87c21035497f2acb88278b2323d88f1bc353c0daa3c42abc289fab6ccbd8edb718ae8cd2103cbe6dec1b7944f5e4d4385acaf2fb6980eaa54169b6d422e24db2de61e01a5f553ae00000000

```

Tx 2 decoded:

```
{
    "addresses": [
        "ltc1qunwwcdm45r94n0vun35pvhh8d7duxzfcxe4dc9vlwlhe9ych7ufqvp9nn3",
        "ltc1qzpx3rxgms9r3ln55880mytl3gna4ancvuw4pyz",
        "ltc1qtqy75qsw0glltsyl27c22tyc4el84mn65mnej2"
    ],
    "block_height": -1,
    "block_index": -1,
    "confirmations": 0,
    "double_spend": false,
    "fees": 300,
    "hash": "b86b27a622ce8b5336debda81e0dc33e8ab3eb07354789e4bc708e38caa2dce4",
    "inputs": [
        {
            "addresses": [
                "ltc1qunwwcdm45r94n0vun35pvhh8d7duxzfcxe4dc9vlwlhe9ych7ufqvp9nn3"
            ],
            "age": 2718775,
            "output_index": 0,
            "output_value": 1100100314,
            "prev_hash": "76d205a9bd2dd97a53f8c13a7fc111ee07347b91320801054bac676ed725408b",
            "script_type": "pay-to-witness-script-hash",
            "sequence": 4294967295,
            "witness": [
                "",
                "304402201db836dacb6290d4014f87ecd95ec5fe1c618973437d0e86f2a6266b8861e20c02207415a722f64070f12d2d2b18031b6c9f1829a88dfb8c0f871571a57aaf34930b01",
                "30440220780eedf386e77f5acaceaf948251fa3bbf51e7fcc401bf7973a08f65b99eadc702200019a281127211a29c5b827b80967154d05b9224f6bf7b77baff13e63d57654501",
                "52210325da1b6830e251da8acb91d09d7fc162568e9c68dd12bd0f94643fed936dc87c21035497f2acb88278b2323d88f1bc353c0daa3c42abc289fab6ccbd8edb718ae8cd2103cbe6dec1b7944f5e4d4385acaf2fb6980eaa54169b6d422e24db2de61e01a5f553ae"
            ]
        }
    ],
    "outputs": [
        {
            "addresses": [
                "ltc1qzpx3rxgms9r3ln55880mytl3gna4ancvuw4pyz"
            ],
            "script": "0014104d11991b81471fce9439dfb22ff144fb5ecf0c",
            "script_type": "pay-to-witness-pubkey-hash",
            "value": 1089099011
        },
        {
            "addresses": [
                "ltc1qtqy75qsw0glltsyl27c22tyc4el84mn65mnej2"
            ],
            "script": "00145809ea020e7a3ff5c09f57b0a52c98ae7e7aee7a",
            "script_type": "pay-to-witness-pubkey-hash",
            "value": 11001003
        }
    ],
    "preference": "low",
    "received": "2024-07-12T17:39:55.39046822Z",
    "relayed_by": "3.227.22.189",
    "size": 367,
    "total": 1100100014,
    "ver": 2,
    "vin_sz": 1,
    "vout_sz": 2,
    "vsize": 177
}

```

Why is the first one failing? What am I doing wrong?
I'm using this python lib: [litecoin-utils](https://github.com/karask/python-litecoin-utils)

**Tags:** multi-signature, signature, litecoin, ecdsa, encoding

> **Comments:**
> **username_1**: Is it tx1 or tx2 that is failing? Your question says tx1, although analyzing these txs, I believe it should be tx2.  

---

## 1 answers

### Answer by username_1 on 2024-07-13. Score: 3

Although the field is named "hash", it is not actually a hash of the entire transaction. That is actually the txid. Since the inputs are segwit, the signatures are excluded from the txid calculation. As the only difference between these two transactions are the signatures, they have the same txid.

Looking at the signatures of both transactions, I believe it is actually tx2 that is failing. The error message "Non-canonical DER signature" gives us a hint of what to look for.

ECDSA signatures using the DER encoding, and since the activation of [BIP 66](https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki), must adhere to a strict set of rules. Analyzing the signatures following the rules specified in the BIP, I find that the signature `30440220780eedf386e77f5acaceaf948251fa3bbf51e7fcc401bf7973a08f65b99eadc702200019a281127211a29c5b827b80967154d05b9224f6bf7b77baff13e63d57654501` in tx2 fails the rule that "Null bytes at the start of S are not allowed, unless S would otherwise be interpreted as a negative number." The S value in the signature is `0019a281127211a29c5b827b80967154d05b9224f6bf7b77baff13e63d576545` and we can immediately see that it begins with a null byte. The byte following it is not greater than or equal to `0x80`, so this signature fails this check and is therefore a non-canonical signature.

The correct encoding of this signature would simply exclude that null byte and adjusting the lengths accordingly. The correct signature should be `30430220780eedf386e77f5acaceaf948251fa3bbf51e7fcc401bf7973a08f65b99eadc7021f19a281127211a29c5b827b80967154d05b9224f6bf7b77baff13e63d57654501`

> **Comments:**
> **username_0**: I just checked again and you're correct. It is Tx 2 that is failing. Thank you for pinpointing the null byte in R. Is there a way to quickly analyze these values using any tool so that I could've found the issue myself?   I have a few more txns failing and apparently, the error rate is 1/300.   I'll try and fix the bull byte issue and see if that reduces the error rate. If it does, that litecoin-utils lib definitely needs a PR as fix.  
> **username_2**: Nit: R is the first integer in a signature; the second integer (with the error here) is S. But this doesn't make a difference because DER rules are the same for all integers -- as defined in ASN.1; the coordinate(s) in a public key for a curve on an F_p field (including secp256k1) are semantically integers, but the X9 representation makes them an octet string in ASN.1, so the ASN.1 integer rules don't apply there.  
> **username_1**: @username_2 Oops, good catch, fixed.  

---

