<p>I triple confirm the signature is good, but your transaction isn't well encoded. My script gives this deserialization</p>

<blockquote>
  <p>{:ins=>[{:outpoint=>{:hash=>"94f5d2df254de934037a1266923115cb4e7e9300484920024430478a00000000",
  :index=>"a346f8e8"},
  :scriptSig=>"B5F36C362B0220750237958D23D390E6137B251399C5A5CE335DEC850D99A090EF3CC43259E5E3014104FFFFFFFF011976A91488AC0000000001000000",
  :sequence=>""}], :outs=>[], :version=>"00000001", :locktime=>""}</p>
</blockquote>

<p>Which makes no sense.Even the previous transaction id is wrong. It should be small endian. And transaction version should be 1, or when you encode it in little endian 8 bytes 010000000.</p>

CC BY-SA 3.0
2016-12-16T21:25:13.160Z
2017-08-12T15:33:59.763Z
2017-08-12T15:33:59.763Z
ManfredMacx
<p>This error means your signature failed some sanity checks designed to prevent accidental network forks due to non-standard but still valid signature encodings. <a href="https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L110" rel="noreferrer">This function</a> in the script interpreter performs the actual check.</p>

<p>However, I took a look at your signature, and I can't find anything wrong with it (looking at it manually, not actually running the code). Is it possible the preceding byte is wrong, so the signature isn't pushed completely onto the stack?</p>

<p><strong>EDIT</strong>:</p>

<p>I actually ran the signature checking algorithm on your signature.
The code I used is <a href="https://gist.github.com/maservant/e1b8423f6a1f385af99283e9dfd185c0" rel="noreferrer">here</a>.
<a href="https://i.sstatic.net/Sg8cu.png" rel="noreferrer"><img src="https://i.sstatic.net/Sg8cu.png" alt="Signature passes DER check"></a>
There is, indeed, nothing wrong with the signature itself. How did you generate it, and what does the rest of the transaction look like?</p>

CC BY-SA 3.0
2016-12-14T02:47:36.877Z
That looks good. Did you try to send the transaction returned in the `hex` attribute of the response, or did you attempt to copy-paste the `result` attribute into the signature script of the transaction? The former method works, while the latter will produce invalid results. Also, was the `complete` attribute set to true in the response? If not, the transaction needs more signatures to be valid (though not enough signatures in a multisig will result in a different error than DER sanity check failure).
maservant
CC BY-SA 3.0
2016-12-14T03:05:59.743Z
I'm asking you what the rest of the transaction is. The short answer is that the signature itself is correctly formatted and passes all checks. The long answer is that if the transaction is improperly formatted, something other than the signature above might have been passed to OP_CHECKSIG, and of course something that is not a signature will fail to parse, even if there is a valid signature somewhere else within the transaction.
maservant
CC BY-SA 3.0
2016-12-16T10:09:16.427Z
thank you very much for you answer! But I still did not understand where error is hide.
Denis Leonov
CC BY-SA 4.0
2019-06-14T18:26:19.467Z
I'm also getting: `2019-06-14T01:16:35Z ERROR: ConnectBlock(): CheckInputs on c2de0a7014853898bde9319cb347225d4ee6cef9025dc56773b0b57010060d48 failed with non-mandatory-script-verify-flag (Script evaluated without error but finished with a false/empty top stack element) (code 64)`

* before that, node was making progress
* after, constant failures 2019-06-14T01:16:54Z ERROR: AcceptBlockHeader: block 0000000000000000000104e5800f4ea259c5ab92a18e15320d8879d6c9e09e5b is marked invalid
Aleksandr Levchuk
CC BY-SA 3.0
2016-12-13T20:56:15.450Z
2016-12-14T00:47:29.153Z
2016-12-14T00:47:29.153Z
maservant
<p>I try to send transaction via <code>sendrawtransaction</code> in console of <code>bitcoind</code>.</p>

<p><code>Sig</code> is:</p>

<blockquote>
  <p>30440220494800937E4ECB15319266127A0334E94D25DFD2F594E8F846A3E7B5F36C362B0220750237958D23D390E6137B251399C5A5CE335DEC850D99A090EF3CC43259E5E301</p>
</blockquote>

<p><code>bitcoind</code> answer is:</p>

<blockquote>
  <p>16: mandatory-script-verify-flag-failed (Non-canonical DER signature) (code -26)</p>
</blockquote>

<p>Who knows why?</p>

<p>TX raw:</p>

<blockquote>
  <p>0100000001<strong>A</strong>000000008A4730440220494800937E4ECB15319266127A0334E94D25DFD2F594E8F846A3E7B5F36C362B0220750237958D23D390E6137B251399C5A5CE335DEC850D99A090EF3CC43259E5E3014104<strong>B</strong>FFFFFFFF01<strong>C</strong>1976A914<strong>D</strong>88AC0000000001000000</p>
</blockquote>

<p><code>A</code> = 32 bytes of TXhash of "from" transaction</p>

<p><code>B</code> = 64 bytes of my public key</p>

<p><code>C</code> = 8 bytes value of BTC that I try to send</p>

<p><code>D</code> = 20 bytes of "to" address</p>

CC BY-SA 3.0
2016-12-16T17:19:36.970Z
Do you mind posting the full hex of your transaction, so I can try it myself?
Nick ODell
CC BY-SA 3.0
2016-12-17T03:20:38.973Z
I get a -22 error when I try that - both with and without the ABCD.
Nick ODell
<bitcoind><bitcoin-core><bitcoin-core-development>
16: mandatory-script-verify-flag-failed (Non-canonical DER signature) (code -26)
Denis Leonov
# 16: mandatory-script-verify-flag-failed (Non-canonical DER signature) (code -26)

(Asked by: username_0 on 2016-12-13)

I try to send transaction via `sendrawtransaction` in console of `bitcoind`.

`Sig` is:

> 30440220494800937E4ECB15319266127A0334E94D25DFD2F594E8F846A3E7B5F36C362B0220750237958D23D390E6137B251399C5A5CE335DEC850D99A090EF3CC43259E5E301

`bitcoind` answer is:

> 16: mandatory-script-verify-flag-failed (Non-canonical DER signature) (code -26)

Who knows why?

TX raw:

> 0100000001**A**000000008A4730440220494800937E4ECB15319266127A0334E94D25DFD2F594E8F846A3E7B5F36C362B0220750237958D23D390E6137B251399C5A5CE335DEC850D99A090EF3CC43259E5E3014104**B**FFFFFFFF01**C**1976A914**D**88AC0000000001000000

`A` = 32 bytes of TXhash of "from" transaction

`B` = 64 bytes of my public key

`C` = 8 bytes value of BTC that I try to send

`D` = 20 bytes of "to" address

**Tags:** bitcoind, bitcoin-core, bitcoin-core-development

> **Comments:**
> **username_1**: Do you mind posting the full hex of your transaction, so I can try it myself?  
> **username_1**: I get a -22 error when I try that - both with and without the ABCD.  

---

## 2 answers

### Answer by username_3 on 2016-12-13. Score: 8 | Accepted answer

This error means your signature failed some sanity checks designed to prevent accidental network forks due to non-standard but still valid signature encodings. [This function](https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L110) in the script interpreter performs the actual check.

However, I took a look at your signature, and I can't find anything wrong with it (looking at it manually, not actually running the code). Is it possible the preceding byte is wrong, so the signature isn't pushed completely onto the stack?

**EDIT**:

I actually ran the signature checking algorithm on your signature.
The code I used is [here](https://gist.github.com/username_3/e1b8423f6a1f385af99283e9dfd185c0).
[![Signature passes DER check](https://i.sstatic.net/Sg8cu.png)](https://i.sstatic.net/Sg8cu.png)
There is, indeed, nothing wrong with the signature itself. How did you generate it, and what does the rest of the transaction look like?

> **Comments:**
> **username_3**: That looks good. Did you try to send the transaction returned in the `hex` attribute of the response, or did you attempt to copy-paste the `result` attribute into the signature script of the transaction? The former method works, while the latter will produce invalid results. Also, was the `complete` attribute set to true in the response? If not, the transaction needs more signatures to be valid (though not enough signatures in a multisig will result in a different error than DER sanity check failure).  
> **username_3**: I'm asking you what the rest of the transaction is. The short answer is that the signature itself is correctly formatted and passes all checks. The long answer is that if the transaction is improperly formatted, something other than the signature above might have been passed to OP_CHECKSIG, and of course something that is not a signature will fail to parse, even if there is a valid signature somewhere else within the transaction.  
> **username_0**: thank you very much for you answer! But I still did not understand where error is hide.  
> **username_4**: I'm also getting: `2019-06-14T01:16:35Z ERROR: ConnectBlock(): CheckInputs on c2de0a7014853898bde9319cb347225d4ee6cef9025dc56773b0b57010060d48 failed with non-mandatory-script-verify-flag (Script evaluated without error but finished with a false/empty top stack element) (code 64)`  * before that, node was making progress * after, constant failures 2019-06-14T01:16:54Z ERROR: AcceptBlockHeader: block 0000000000000000000104e5800f4ea259c5ab92a18e15320d8879d6c9e09e5b is marked invalid  

---

### Answer by username_2 on 2016-12-16. Score: 1

I triple confirm the signature is good, but your transaction isn't well encoded. My script gives this deserialization

> {:ins=>[{:outpoint=>{:hash=>"94f5d2df254de934037a1266923115cb4e7e9300484920024430478a00000000",
> :index=>"a346f8e8"},
> :scriptSig=>"B5F36C362B0220750237958D23D390E6137B251399C5A5CE335DEC850D99A090EF3CC43259E5E3014104FFFFFFFF011976A91488AC0000000001000000",
> :sequence=>""}], :outs=>[], :version=>"00000001", :locktime=>""}

Which makes no sense.Even the previous transaction id is wrong. It should be small endian. And transaction version should be 1, or when you encode it in little endian 8 bytes 010000000.


---

