Hey everyone
I’ve got a transaction signed back in 2016 and now I'm facing some issues. It was done on an old wallet and I'm getting this error: mandatory-script-verify-flag-failed (Non-canonical signature: S value is unnecessarily high). I corrected the S value, but now I’m getting a new error: mandatory-script-verify-flag-failed (Non-canonical DER signature). What’s the deal with that?
Fixing DER Signature Issues in Bitcoin Transactions
22 replies 123 views
If you calculated the -s value correctly, all you need to do is change the DER encoded signature to 0x3045022100ac....e5d9a102205aad1...
Here's the thing: in DER encoding, a positive integer shouldn't have the highest bit set. Your original S value starts with 0xa5 which means the highest bit is set. You add 0x00 at the start to fix it to 0x00a5. But your new S value is 0x5a which is fine.
Wait, did you just add an extra part like e5d9a102205aaad1...? That's a mistake, right?
Ugh, I see what you mean. That was an error on my part.
Your S value looks correct now. The new signature should actually match what you provided. But your other error might be unrelated to the signature itself. Have you checked the output amounts and fees to ensure they’re all good?
Yeah, I checked everything. Amounts are fine and fees are set right. I really can’t figure out why I’m getting this 'value out of range' error.
On another site, I got a different error message saying the transaction was rejected due to network rules. It said TX decode failed and something about needing at least one input.
If you don't mind sharing, post the signed transaction. It might help users figure out what’s wrong.
Don’t worry; no one can edit your outputs unless they’re using non-default sighash types. Just check the byte next to that signature, too.
No way, I'm not sharing the raw transaction. Last time I did that, everyone wanted payment for help. People just can't help for free.
AtomicLordMember
Posts: 34 · Reputation: 184
#9Aug 17, 2021, 06:46 AM
Honestly, sharing your transaction won’t mean someone can force payment from you.
Anyone who asks for money to help is probably a scammer. Trust me, most people here are willing to help without charging.
I get that, but how can I be sure that this whole signature thing is the real problem? Maybe there's something else going on.
This could just be a case where someone sold you a fake wallet.dat. You know, one of those files that looks legit but really isn’t.
AtomicLordMember
Posts: 34 · Reputation: 184
#12Aug 17, 2021, 11:19 AM
Lol, that sounds like a stretch. I mean, maybe it's just a weird coincidence with usernames here.
Right? I was thinking. But you know, the signature should have a sighash type after it and 0xFE isn’t valid for legacy transactions. Look closer at other parts of your transaction.
I hear ya. Just thought it was polite to ask instead of accusing anyone.
Listen, guys, I just need to push this transaction through. It’s a long story, but here’s the raw transaction.
0100000001fe84d378379a44b5751e89f5145916abe2ec18c03735ad811fc656a34628dd220000000008c493046022100ac792f9d39b644835b9eabbeba9d48897385c721291267d07a850fbb07e5d9a1022100a552e1f28efb3dbd3ca6a360bc0e28f5cf0d73f4ba96202451be1129433a67b501410493249c6c4b75ce574e4f1ecc07117668f5ca7fd73ead514843ad4a9d4195c8f7b41662586dc61bcf920ef53031770afa183be244e88d6cc75d16de97f2da6d1dfeffffff02006d7c4d00000000160014bce56fa1231ff207fee8c421060faeb08f47813cf09c8a29000000001976a914687ff91a
AtomicLordMember
Posts: 34 · Reputation: 184
#16Aug 19, 2021, 12:07 AM
Let me format that for clarity in the code tags so the forum doesn’t mess with spaces.
Also, you missed fixing the lengths for two other values: the script length at the start and the length for the signature.
Right, there are a couple of lengths to address here. You need to adjust the length values in the script too. The overall script length should go from 0x8c to 0x8b. And for the signature, it should change from 0x49 to 0x48.
Okay, thanks for that. I’ve broken down the transaction into its components below, hoping someone can double-check my work. It seems alright, except the signature might need more attention.
01000000 = version 1 transaction
01 =
matrix2021Full Member
Posts: 92 · Reputation: 612
#19Aug 21, 2021, 03:15 PM
You can test this with Bitcoin Core’s testmempoolaccept command to see if it gets accepted by your node without sending it.
AtomicLordMember
Posts: 34 · Reputation: 184
#20Aug 21, 2021, 05:48 PM
Result says it ‘failed CHECKSIG operation’. Looks like the tool you used to create the signature was buggy, or the key used was the wrong one.