I'm trying to build a native Segwit transaction programmatically, however, whenever I attempt to broadcast the transaction, it returns this error: non-mandatory-script-verify-flag (Non-canonical DER signature)

My raw, unsigned tx (testnet) is here:


My signed tx here:


Both decoded look okay to me, so I I think it it's either the sighash or signing of the sighash that's going wrong. The sighash I get of the unsigned tx, for the only input is: e54c499bfef6f5f0b12b819de82220aa7de532f9b72ae0f74638a647e147f884

This is created using: https://docs.rs/bitcoin/0.25.1/bitcoin/util/bip143/struct.SigHashCache.html#method.signature_hash

using SigHashType::All passing the pubKeyScript and value (22,000)

and when signing the sighash I get: 30440220465c93c725454f7bda3e3453ce09e99f7636560935be9377c3ae1138cfa0bb4702206f45290b2c06fc7e2298c6778fbccd1a805e34535247c49e098bc7229e745334

I am completely stuck on what to try next. Any direction would be appreciated.

1 Answer 1


You're missing the sighash flag byte at the end of the signature.

"Signature" objects in Bitcoin Script consist of the actual DER-encoded ECDSA signature, plus the sighash type byte (in your case, 0x01 for SIGHASH_ALL).

  • Thanks for the quick reply. I had noticed that, however, after adding that byte I get Signature must be zero for failed CHECK(MULTI)SIG operation instead.
    – Kyle
    Oct 23, 2020 at 3:25
  • 1
    That means you signed the wrong sighash, mostly likely. Oct 23, 2020 at 3:38
  • In the end it was because I was using a p2pwkh when creating the sighash instead of the required p2pkh :/.
    – Kyle
    Oct 23, 2020 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.