hello everyone thank you for sticking with us that late in the day so my name is Niels I'm a security researcher at Kudelsky security I focus on privacy and I like to process large data sets and I'm a huge Linux fan and today I'm also here with my colleague Marco hello Marco Macchetti I work as a cryptographer for Kudelsky security and my background is other design cryptanalysis and applied cryptography in general so what are we going to talk about today this is a new attack that we devised against an algorithm to generate digital signatures which is called ecdsa and it's well known for being the digital signature argued beyond the Bitcoin blockchain this attack is called polynons and we will give you some details of the attack and the things we tried to put it in practice how we did it and what we learned in the process and there will be a brief demo and then we will give also some results and takeaways let's add over to the introduction what is a digital signature well basically a digital signature is just a proof of knowledge of a private key right everyone can verify your signatures with your public key but only you can generate signatures with the private key so in a real world your signature on a piece of paper is a proof of identity in the digital world the knowledge of your private key is a proof of identity and on blockchains the private key means ownership of the coins so everyone will try to steal your key uh if it's on backups paper notes brain wallets and sometimes it's it's a strong key to protect it with a weak password uh digital signatures are mildly complex objects uh signature argument is is actually a set of three arguments you have key generation signature generation and verification is there randomness inside all of this well yes essentially key generation is uh throwing the dice to obtain your keeper and randomness is also present in the signature generation process your private key and the message you throw the dice again and you obtain a signature and verification is just a deterministic algorithm well if everyone wants your private key is it possible to obtain your private key just by looking at the signatures well in general no but under some assumption yes for example if you generated the key with low entropy or with short seeds or using a brain wallet maybe it's easy to guess but provided that the key is properly generated is it possible to obtain it uh from your signatures well remember there is randomness in the signature generation so there is more attack surface that we can explore in this paper we we target the ecdsa algorithm this is probably the mostly deployed algorithm for digital signatures ec is for elliptic curve and elliptic curves is just a curve on a finite field with some parameters you all know the Bitcoin curve and the curve is also a set of points you can perform operation with the points you can add the numbers as a scalar this is called scalar point multiplication and why it is so useful because scalar point multiplication it's easy to do in one direction but it's hard to invert and this is called the discrete logarithmic problem and this is the basis of the security for ecdsa so what is in detail the the set of algorithms for ecdsa well key generation is quite simple you just pick an integer D in a certain range and this is your private key and the public key you just obtain it through scalar point multiplication to generate a signature you hash the message first and then again you have to pick an integer in uh in the same range again uniformly at random and this is called the nonce and you have to to have a different noise nonce for each signature then the the signature is just two numbers R and S and R is just the X coordinate of the point which correspond to your nonce and S is obtained with the expression that is in the slide and verification is just deterministic so we are not very interested so the takeaway is that you also performing key generation for every signature basically and if the nonces can be predicted or or some beats are known then you can use lattice attacks and you can also use side channel attacks in combination with lattice attacks to retrieve the key so what you have to choose to to generate this the randomness is to choose your dice there are good dice like those uh RNGs based on cryptographic algorithms like HMAC and AES these are the good ones and then you have bad ones like algebraic generators LFSRs and then they are the awful ones like fixed secret constant the round functions and these kind of things and once you choose the dice you also have to seed it with entropy let's pick one of these bad RNGs the linear congruential generator this is has been known for decades I mean it's a it's a generator that is implemented basically everywhere it's in GMP other libraries and it was also referenced from the NIST documentation basically an LCG works in this way you generate a random number and then you apply a linear relation to obtain new numbers with known coefficients A and B there is no bias in this so it's good but in fact it has been shown by by previous projects that you can use lattice attacks to retrieve the private key so if your LCG is in full state but it's 128 bit for example for the Bitcoin curve then with as low as 22 signatures you can get the private key but here we want to go beyond what if you use a full state LCG there are no results published so far on this and what if you increase the degree to quadratic or even cubic then lattice attacks are not possible and what if you keep the coefficients unknown secret then you you may think you are safe right but in fact no we show that we've announced we can retrieve the private key in a fraction of a second so how does it work basically we don't care about the air part of the signature but we just look at the S part of the signature and we rewrite the expression of S to be a linear relationship between the nonce and the private key what does it mean it means that there is only one secret behind all your signatures you can think that it's the private key or you can think that is one of the nonces or partial information on more nonces and so we want to exploit this additional information that is in the S part of the signatures how can we do it basically suppose that you are you are generating your nonces with an LCG so you generate a first nonce K0 and then you generate K1 K2 K3 in this way and suppose that the attacker doesn't know A1 and A0 these are the secret coefficients but basically what we can do you can subtract the second equation from the first and the third from the second and we get this pair of equations here and then we can solve for A1 in both and we can just equate the results and we get this expression here and we got a completely rid of the unknown secret coefficients and then this is the trick we can replace every nonce in this way we get a polynomial which where the only unknown is D we find the roots of the polynomial it's easy to do and we get the private key and we extended this to all n degree polynomial relationships so we we are able to attack quadratic and cubic and higher degrees and this is a recursive algorithm it's a fast generic it's not using lattice and if you want to take a look there is an e-print paper on this and then I add over to nice we'll explain how we put this into practice thank you Marco so with all of that how can we actually attack things in practice well to to run the polynons attack what you will need is at least four signatures but that's for the linear case if you want to target a higher degree relation then you need more than four signatures in any case you'll need to make sure that these signatures are sorted by the time in which they have been generated on top of that you'll need to also have associated with each signature the message and the public key if you have all of that and the nonces were indeed generated in a biased way then you can retrieve the private key so where can we find eCDS signatures in practice well one good source of that is Bitcoin in Bitcoin you have blocks and inside blocks you have transactions and these transactions they contain inputs and outputs and good for us these inputs are signed with ecdsa so how do we get what we need well the public key in that input. The message, however, you have to compute it. And computing that message is a very error prone and under documented process. You will need to use fields from the current transaction but also fields from previous transactions. So you will need to keep track of all of that to compute the message. So to actually get the data, what you will need is to let your Bitcoin client sync and download the whole chain. And we did that. It took about a day. And we got all of the blocks until September last year. And when it was synced, we dumped all of the signatures, the pop keys, the messages by just reading the block files from disk. And we with that, we dumped about 700 million signatures. We only covered the most common type of Bitcoin signature, which is pay to public key hash signatures. But that covers more than half of the Bitcoin transactions. Another good source is Ethereum because transactions in Ethereum are also signed with ECDSA. And in that case, the signature is directed to directly in the transaction. The public key, not directly. But there is actually a lesser known feature of ECDSA called ECDSA recover that you can use to compute the public key based on the signature and the message plus a third value that I won't discuss but which is in the transaction. The message also must be computed. To compute the message, the main challenge here is that Ethereum has multiple protocol versions. And these versions change based on the block number. Meaning if you want to compute the message for a specific transaction, depending on what block this is, the way you compute the message changes. So if you want to dump all of the signatures for the whole chain, you basically have to implement all of these Ethereum versions of the protocol. So we did that. If you want to have a look at the details, please check out our code. It's on GitHub. To actually get the data, you'll need two things. An execution client first, such as GIF, and a consensus client such as Lighthouse. You let these two sync so that it downloads the whole chain. For us, that took about three weeks and a ton of disk space. But then we got all of the blocks until October last year when we did that. We used the JSON RPC API of the execution client to get the blocks directly parsed in JSON and dumped the signatures, pub keys, and messages to a file. And we dumped 1.7 billion signatures that way. We also had a look at two more signature ‑‑ sorry, two more sources that are not blockchain related. The first is a sample of TLS servers. So why TLS servers? Well, if you make a TLS handshake with a server, it's going to send you a signature. And if the key is an ACDS key, you get an ACDS signature. So that's what we collected. The second one is actually a set of data sets from the Minerva attack. These are publicly available, and these are ACDS signatures that were generated from TPMs. So you can use them to get a lot of data and a bunch of software libraries. So a few stats. Here at the top, you see that about 97% of Bitcoin wallets only generated three signatures or less. And at the bottom, for Ethereum, this is a bit less extreme, but only 77% of wallets generated ‑‑ well, 77% of wallets generated only a fraction of the signatures. So generated less than four signatures. The rest, however, so those that have at least four signatures, we can try to attack. And that means there's at least a few million wallets we can try to break with that attack. So we implemented the attack in Sage and it's a multi-threaded implementation. The code is out there on GitHub. So just a quick demo. So here, we start a TLS server, which is vulnerable. It's going to generate biased nonces. We capture the network traffic, dump it to a PCAP file, then we make TLS handshakes to that vulnerable server. We stop the capture, stop the server, and then we start the attack. Then we read the traffic from that PCAP file and dump the signatures, messages, and public keys to a CSV file. And finally, we run the attack against the signatures in that file. And that's it. We got the private key here. . So how did it go? Well, no, we didn't drive in in a new Ferrari today. Well, for Bitcoin and Ethereum, we used a big machine with lots of cores. And for Bitcoin, the attack ran for about two days. And we were able to get the private key of about 700 wallets. But for Bitcoin, the attack was really bad. None of these had any money on them. So it looks like someone else had drained them before us. For Ethereum, we processed about 20% of the input file in two days, and we only got two private keys. So we stopped it because we thought the cost time ratio was not really worth it. These two also had a zero balance here. It turns out that all of the signatures that we had in the last three years that we used, that were generated by these vulnerable wallets, actually had repeated nonces. And, of course, the poly nonce attack is also going to find repeated nonces, because that's just a particular case of an LCG where the last unknown coefficient is the only one which is non-zero, and it's equal to that repeated nonce value. But this could also have been found with a simpler attack. For the two others, TLS and Minerva, this was actually pretty quick. So just a few seconds for the TLS set we had. And for Minerva, a few hours. So you could just run this on a laptop. We did N equals 4, 5, and 6 signatures because it was quick. But we got no successful attacks there. So we wanted to see what happened in the last three years. So we went back to those stolen Bitcoin. And we tracked that, and we found that about 140 Bitcoins were stolen in total. So that's about 10 million USD at Bitcoin's peak price. We also saw that some of the addresses that received that stolen money had readable names in them, like one hack, one gift, something like this. And there is one idiot address that sent the money it stole to another address called 1andreas. And this address is owned by a guy who made significant contributions to the Bitcoin ecosystem. And when people found out about this in 2017, they decided to make a ton of donations to that guy. So it looks like the one idiot guy stole Bitcoin to give it back to this guy as a donation. So this is a donation for charity. And we also saw on some public forums that people had been saying like how many Bitcoin they stole due to repeated attacks, repeated nonsense attacks just publicly on the forum. Like, oh, I have collected seven Bitcoins so far. So a few takeaways. Make sure you don't generate signatures with a biased nonce. And to make sure you don't do that, you should use something that does deterministic nonce generation, such as deterministic ECDSA or EDDSA. We just barely scratched the surface here. So there's plenty of other areas that we didn't touch and that you could apply this attack on. And it's very easy for you to check your own wallet. You don't need to have the whole chain. If you just have the signatures for your wallet, the pub key and the message, you can run this on your laptop, basically. So for more research from our team, please visit our blog. We have more exciting research on this topic. And we hope that people get more secure by releasing our code. It's public. It's on GitHub. Please check it out. And thank you. Do you have any questions?