Issues with Duplicate R and S in Signatures

17 replies 52 views
degen23Member
Posts: 4 · Reputation: 96
#1Feb 19, 2017, 06:50 AM
Hey there. I’ve been struggling to verify a signature. When I get the Z value, the Kx value of point K (or R) doesn’t match. Am I messing up the message calculation? I keep seeing repeated S and R values in the signatures. Here’s a TX for reference: https://www.blockchain.com/explorer/transactions/btc/bd17bfb7051bef5ca916931f06493a0af0db080b4df21ee9768fa0f3d775070a Anyone know how the math works for verifying this TX?
3 Reply Quote Share
gwei2019Hero Member
Posts: 11 · Reputation: 2066
#2Feb 19, 2017, 11:28 PM
Signature verification is pretty standard across all transactions. If you want a deep dive, check this link out: https://cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messages But to give you the gist, you need to calculate the proof of the signature s. Basically, it’s all about ensuring the math lines up between your message, public key, and the signature.
4 Reply Quote Share
degen23Member
Posts: 4 · Reputation: 96
#3Feb 20, 2017, 04:40 AM
Hey Albert, Thanks for the info! I’ll look it over again. I’ve been around this topic for a bit. I want to break it down with an example from the TX I mentioned. Gonna share my sagemath log. The signature isn’t verifying with these values; I tried a bunch of scripts and checked my Z value. And the signature type? It’s "pubkeyhash".
3 Reply Quote Share
Posts: 1 · Reputation: 24
#4Feb 20, 2017, 05:23 AM
Yo, Before diving deeper, check those message hashes. They’re definitely off.
2 Reply Quote Share
gwei2019Hero Member
Posts: 11 · Reputation: 2066
#5Feb 20, 2017, 05:36 AM
Exactly, that's the crux of this topic. According to the math, same R and S can only happen if the hash is identical across messages for the same public key. I checked the signatures too, and all are sharing the same R and S. But the UTXO values are different. Should mean the transaction’s invalid.
0 Reply Quote Share
stacksatsHero Member
Posts: 168 · Reputation: 2023
#6Feb 21, 2017, 12:43 PM
I’m betting this is from a bitcoin mixer, and yeah, might see more like this.
0 Reply Quote Share
0xChadNewbie
Posts: 186 · Reputation: 3
#7Feb 22, 2017, 03:52 PM
Yep. The inputs that show the same R and S have the [SINGLE|ANYONECANPAY] (0x83) sighash flag. That could be why they’re identical. But I can’t find a tool that checks for the sighash flag and adjusts the Z-value calculation accordingly. Just do your own research on it. Here’s some references for that: https://static.learnmeabitcoin.com/diagrams/png/keys-signature-hash-types.png, https://raghavsood.com/blog/2018/06/10/bitcoin-signature-types-sighash/.
0 Reply Quote Share
gwei2019Hero Member
Posts: 11 · Reputation: 2066
#8Feb 22, 2017, 05:03 PM
Thanks for the clear explanation. This definitely helps!
5 Reply Quote Share
degen23Member
Posts: 4 · Reputation: 96
#9Feb 22, 2017, 06:35 PM
Hey, appreciate the insights! Hoping I can do this manually. I want to really grasp the validation process. I’ve laid out an example: https://blockchain.info/rawtx/bd17bfb7051bef5ca916931f06493a0af0db080b4df21ee9768fa0f3d775070a?format=hex It’d be awesome if others jumped in and took a crack at it. I really wanna understand this verification algorithm.
3 Reply Quote Share
degen23Member
Posts: 4 · Reputation: 96
#10Feb 25, 2017, 03:23 AM
Hi, I think I figured this out. The issue is the "SIGHASH_SINGLE bug". After the first sig, the rest all have a hash of "0100000000000000000000000000000000000000000000000000000000000000". I tested it and got it to verify.
0 Reply Quote Share
mr_apeNewbie
Posts: 170 · Reputation: 35
#11Feb 25, 2017, 08:27 AM
Not a bug. That’s how SIGHASH_SINGLE is set up. It basically says you’ve gotta sign the output at the same index as the input, but Bitcoin lets you have different input/output counts. No rules saying they have to match.
3 Reply Quote Share
alex.byteLegendary
Posts: 78 · Reputation: 5910
#12Feb 25, 2017, 09:54 AM
Definitely a bug. Usually, that whole transaction should just be marked invalid.
0 Reply Quote Share
mr_apeNewbie
Posts: 170 · Reputation: 35
#13Feb 25, 2017, 11:33 AM
Not really. If you look at legacy and Segwit, they define it differently. For a "bc1q" address, it’s not just the SHA-256 of "1"; it's more complicated.
4 Reply Quote Share
alex.byteLegendary
Posts: 78 · Reputation: 5910
#14Feb 25, 2017, 09:52 PM
If we say "z=1" then it should switch endianness. They should just mark that specific case as invalid and reject it.
1 Reply Quote Share
Posts: 1362 · Reputation: 35
#15Feb 26, 2017, 02:18 AM
It’s only a bug if they’re unintentionally signing 1. But the code was written to do that on purpose in that case. If we force every SIGHASH_SINGLE transaction to match inputs and outputs, that’s just unreasonable. Users should have options here.
6 Reply Quote Share
Posts: 1362 · Reputation: 35
#16Feb 28, 2017, 11:06 AM
Looks like a bug to me. That "printf" seems to say "let’s report an error," not "let's legitimize this value". But when it returns "1", everything else just carries on.
3 Reply Quote Share
Posts: 1362 · Reputation: 35
#17Feb 28, 2017, 11:57 AM
No one knows the private key. The public key is out there but the private key remains a mystery. If anyone cracked it, they could do the same for any public key.
0 Reply Quote Share
Posts: 1362 · Reputation: 35
#18Feb 28, 2017, 05:46 PM
Exactly, we don't know d-value or k-value either.
3 Reply Quote Share

Related topics