In Bitcoin, we're using two variations of signature schemes. You could have a Taproot transaction, or you could have the legacy transaction, and they both use different signature schemes. We've been talking about the Taproot example so far, which is the Schnorr signature scheme. Taproot is a Bitcoin upgrade, and its Schnorr signatures are specified in BIP-340. And the other version, that we haven't discussed much because it's quite messy, is ECDSA, which stands for elliptic curve digital signature algorithm.
A digital signature scheme has three functions: a key generation algorithm, a signing algorithm, and lastly a verify algorithm. We'll talk about the digital signature scheme for both of these constructions: keygen, sign and verify.
For Schnorr, it's quite simple. You have a private key, which is a scalar, which you randomly pick from 1 up to n − 1, where n is the order of the elliptic curve, specifically the secp256k1 elliptic curve. Then you compute your public key, which we'll call P = d·G. The generator G is a point, so it has x and y coordinates, and you add it to itself d times, where d is your private scalar value. And then your public key is another coordinate point on the secp256k1 curve. With Schnorr specifically, we only care about points where the y value is even.
For signing:
We spoke about what happens if we first have our challenge. From that, we could basically cheat and create a nonce R that cancels out the verification without us needing to know the private key. So this is why you first calculate R and then c. You can only find c by hashing the value of R, so there's no way you could calculate c before R.
For verification, we calculate our own R by multiplying this s value with our generator, which is public, and then we subtract our challenge times P from that. They're checking if the x coordinate of this R that they found is equal to the x coordinate of the original R. For this c, they can recompute this themselves. They don't need the signer to send them this information, because xP is public, xR has been sent with the signature, and the message is a common thing between the prover and the verifier.
What about the elliptic curve digital signature algorithm? That's also being used, and that's an older signature scheme, and Bitcoin has since upgraded. So what is this, and why did we upgrade?
For key generation, again, you pick your private key, and again, you compute your public key, P = d·G. For signing, again, we pick a random value k, a scalar value, and we find our nonce, R = k·G. Now the computation that we do for s is a little bit more involved, and not as nice to look at. You calculate the modular inverse of the k that you just picked, and you multiply it by the hash of the message plus the x coordinate of R times the private key d. And all of that is mod n, again.
For verify, it will output accept or reject, and we have to compute our own R value as c (the hash of the message) times the modular inverse of s, times G, plus the x coordinate of R times, again, the modular inverse of s, times P. And what we're then checking is if the x coordinate of the R that we calculated is congruent to the x coordinate of the random nonce the signer sent to us, mod n.
If we simply compare this with this, even if we say c equals the hash of the message, you can already see how this extra thing, this modular inverse, makes things hard. Why? It makes things hard for multisignatures.
When multiple people have their own random nonce values, their own challenge values, their own private keys, we're able to do simple addition. We can just add nonce values, and the addition of those nonce values scales linearly, meaning it increases linearly as you add. But with a modular inverse, that's not the case. You can pick random numbers and try to do it yourself with two people.
If you want to have five people be part of a transaction, and if you want all five to sign that transaction, and if the five people don't sign, then the transaction doesn't go through, to enable that sort of behaviour, you need multisignatures. For ECDSA, it's quite messy. For the ECDSA multisig setup, you have to first list out all the public keys that are part of the multisignature, P1, P2, all the way up to Pu. And each of these will have its own signature: signature one, signature two, signature u.
The problem with ECDSA is there's no easy way to combine these. It's not the case that signature one plus signature two is equal to their values added. It's not linear in that regard. So what the code has to do is verify each signature individually. First you would have to verify whether signature one came from P1, whether signature two came from P2, and then if all those verifications pass, then the multisignature passes. There's no one signature which you can run that just verifies everyone's signature altogether. You have to do it one by one.
With Schnorr, suppose we have two people, and let's call them Alice and Bob. They both have a private key, dA and dB, and they both have a public key, PA and PB. With Schnorr, the aggregate of the public keys is PA + PB, and the nonces can also just be added, so the aggregate will be RA + RB. That's not the case for ECDSA.
So we have a challenge value c, which is found from the aggregate of the public keys of Alice and Bob and the aggregate of the random nonce values. Now they can compute their s values. This would be a step that each of them would have to do, because they both have their own private keys. Alice would have to calculate her own s, because only she knows her private key.
And now we can even find a combined signature s, which is sA + sB. If I move things around, I can factor out the c:
If you notice this equation, and if you notice the regular equation, which is s = k + c·d, you can see that as we are adding people, Alice and Bob in this case, we can just add the k's, and we can just add the private keys too. And c is a shared challenge value between all the people who are doing the signatures. Here it does scale linearly. By linearly, I mean if this is two and this is two, then the final answer is four. With modular inverse, that's not true.
How do we find the verification now? It's exactly the same as this verify. What we're verifying is if s·G is equal to Ragg + c·Pagg. If I isolate R, then Ragg = s·G − c·Pagg.
| Alice | Bob | |
|---|---|---|
| private key d | ||
| public key P = d·G | ||
| nonce k, R = k·G |
Someone asked: if we make verification easier by making it linear, don't we make it easier for an attacker as well, and which scheme is safer?
What I have on the screen right now is not safe, and you are right to doubt it. With the Schnorr one, there's a very big problem here. If we have five people who are doing a multisignature, with this scheme right now, I could just disregard the signatures of all the other four, and I could be the only one providing signatures, and verification would pass. Let me first write this, otherwise people would think this is correct: this is not safe.
How one signer does that, the rogue-key attack, and how MuSig2 keeps the addition while stopping it, is next week.