Fixing DER Signature Issues in Bitcoin Transactions

22 replies 123 views
viper2015Member
Posts: 7 · Reputation: 116
#1Aug 10, 2021, 03:26 AM
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?
4 Reply Quote Share
mr_apeNewbie
Posts: 401 · Reputation: 35
#2Aug 10, 2021, 06:41 AM
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.
4 Reply Quote Share
viper2015Member
Posts: 7 · Reputation: 116
#3Aug 11, 2021, 01:53 PM
Wait, did you just add an extra part like e5d9a102205aaad1...? That's a mistake, right?
2 Reply Quote Share
mr_apeNewbie
Posts: 401 · Reputation: 35
#4Aug 11, 2021, 06:33 PM
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?
4 Reply Quote Share
viper2015Member
Posts: 7 · Reputation: 116
#5Aug 11, 2021, 11:02 PM
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.
1 Reply Quote Share
viper2015Member
Posts: 7 · Reputation: 116
#6Aug 12, 2021, 03:27 PM
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.
1 Reply Quote Share
0xChadNewbie
Posts: 513 · Reputation: 3
#7Aug 15, 2021, 01:33 AM
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.
0 Reply Quote Share
viper2015Member
Posts: 7 · Reputation: 116
#8Aug 15, 2021, 07:51 AM
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.
1 Reply Quote Share
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.
0 Reply Quote Share
mr_apeNewbie
Posts: 401 · Reputation: 35
#10Aug 17, 2021, 09:54 AM
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.
2 Reply Quote Share
0xChadNewbie
Posts: 513 · Reputation: 3
#11Aug 17, 2021, 10:34 AM
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.
1 Reply Quote Share
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.
1 Reply Quote Share
viper2015Member
Posts: 7 · Reputation: 116
#13Aug 17, 2021, 04:50 PM
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.
4 Reply Quote Share
orbit1337Senior Member
Posts: 434 · Reputation: 941
#14Aug 18, 2021, 04:49 PM
I hear ya. Just thought it was polite to ask instead of accusing anyone.
0 Reply Quote Share
mr_apeNewbie
Posts: 401 · Reputation: 35
#15Aug 18, 2021, 08:38 PM
Listen, guys, I just need to push this transaction through. It’s a long story, but here’s the raw transaction. 0100000001fe84d378379a44b5751e89f5145916abe2ec18c03735ad811fc656a34628dd220000000008c493046022100ac792f9d39b644835b9eabbeba9d48897385c721291267d07a850fbb07e5d9a1022100a552e1f28efb3dbd3ca6a360bc0e28f5cf0d73f4ba96202451be1129433a67b501410493249c6c4b75ce574e4f1ecc07117668f5ca7fd73ead514843ad4a9d4195c8f7b41662586dc61bcf920ef53031770afa183be244e88d6cc75d16de97f2da6d1dfeffffff02006d7c4d00000000160014bce56fa1231ff207fee8c421060faeb08f47813cf09c8a29000000001976a914687ff91a
2 Reply Quote Share
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.
0 Reply Quote Share
0xChadNewbie
Posts: 513 · Reputation: 3
#17Aug 19, 2021, 10:42 PM
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.
3 Reply Quote Share
viper2015Member
Posts: 7 · Reputation: 116
#18Aug 20, 2021, 04:12 AM
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 =
4 Reply Quote Share
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.
4 Reply Quote Share
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.
6 Reply Quote Share

Related topics