Please welcome Marko Ben-Kuhn. Thanks, Michael. Hi, Ron. I'm Marko. I work at Shift Crypto. We're based out of Switzerland and we're producing hardware wallets out of BitBox. Today I want to talk about security issues in crypto software wallets and more so from the perspective of software devs that want to write a wallet or maybe you want to integrate with wallets. And more so than this, then from a user perspective, I'm sure you all already know how to secure cryptocurrencies. I also am going to mention a couple of issues that are probably obvious to many of you, but still I don't want to talk about the standard stuff, like which data type do you use to represent Satoshi and so on. I want to talk about stuff represent Satoshi and so on. I want to talk about the stuff that I think is important to see in current software wallets that are not addressed properly. I want to kick this up with a small history lesson. So a couple years back there was an issue in an Android wallet. And a couple guys posted on BigmanTalk with the same issue. They had an address. They sent some coins to it. And immediately the coins were stolen. And a very suspicious thing, the address has had previous activity before they made it. So it's a classic. So the guy already suspected correctly, suspected correctly that it's about the, you know, bad random number generator. And it was completely right. So I want to go in and dissect the bug in detail. Roughly 235 people have been affected, 45 bitcoin lost by this bug. All right. So this is the function that they used to create the secret key that they used to create the secret key that they used to create the secret key that is used to create the public key that is used to create the receiving address, right? So fairly standard stuff. There's a secure random class from Java. They replaced the standard provider with their own that streams data from slash dev slash view random. And then there's this extra seed that they mix in. And here the set seed looks like it would replace the original seed, but it doesn't. They made sure to overwrite the function and actually mix the entropy. So everything looks good. So what is this extra seed, we wonder? So this is the function that is called to set the extra seed. It's called seed from random org. And it's the random org generator that they implemented. And this streams random data from random.org, a public service to give you random data. So you might think, okay, that's a little strange. Do I really trust some sites to give me random data? Probably not. But in the end, if you actually properly mix it with XORing, then, you know, everything should be all right. You can, in the worst case, just have the same entropy as before, but, you know, more doesn't hurt, really. Okay. Also, small risk condition I can spot here. There's a thread running to set the extra seed, but here the seed is set at some other point in time. You know, who knows if the seed is actually fetched in time, like the extra seed. So let's look at the code that gets the random data from that URL. So I want to go through this, like, code review style, like, if you were in a company and I review a pull request. So I start at the top and I see HTTP. Okay, that sounds a little bit, right? Why isn't it HTTPS? You know, there could be a man in the middle, et cetera, et cetera, right? So then, you know, connection is made. Get request. I'll find some connection timeouts. And then there's this line, which says that if random.org would respond with, you know, redirect response, then this should be ignored and we should just get the data from there. At least I would just question the offer. If, you know, there must be a reason he put it there, maybe thought it was secure in some way, maybe if you check the result or something. But I don't see any of this here. And in fact, random.org did do a redirect to the HTTPS version. They started enforcing that. And this is the response that they gave. So, because the redirect error was set, okay, I don't know what happened. So, I'm not sure if we can see the data. was ignored. This is what they got. And then also suspicious, you know, in the end you would hope to check for 200 okay response or if not that you would maybe if you get data from an untrusted source you would check that the output is what you think it is. For example, we have the length up there and it's the length here but you don't actually check if the output is the correct length. So what happens is in the end, bad luck, the random data from random.org is just those bytes, more than 32 but it doesn't matter. So constant. But going back to the setseed, you know you think, okay, well, so that data didn't help but it also didn't hurt because setseed as I said before is soaring the data so all is cool, right? What's the worst that can happen? Well, this is the function they used to set the provider, like their own implementation to override the standard implementation of secure random. And you can see, you know, it's a little bit more complicated than the standard one. You can see, you know, it gets the data from u random, all is good and it's set up here. But if the file does not exist, then u random is set to null and there is no exception thrown. So the implementation falls back to the standard one from Android. And that one doesn't sort the data. It just overwrites it. So there you have it. So the public key that they generated randomly. Ended up being a constant from random.org. It doesn't help that the random secure provider by Android in some versions also has severe bugs where the entropy is not 128 bits but just 31 because they just zero some bug bits. And, you know, what are the takeaways from this? You know, we all get it, you're a startup, you have, you know, market products that are not going to be able to do the same thing. You have to have a lot of products to market and the opportunity cost to write unit tests is high and to do lots of core reviews is high. And I think it's forgivable if you don't have full coverage on, like, in areas where bugs are at most an annoyance. But if it touches your balance or your crypto keys or crypto in general, like, you should have reviews and functional tests. And I think at least one review would have got at least one of the five issues before which would have prevented this outcome. The other takeaway is, if you, you know, fail, fail loudly, for example, if dash, um, def dash u random is not available, you should just abort an exception and not think and rely on something else. And the third and the most difficult part is to test your assumptions. Like in this part I assumed that the, that, um, the random source is available on all platforms but it turned out not to be the case. And it's a hard part because you really don't know what your assumptions are. Like it's, for me it helps to just take a step back and consciously figure out what am I assuming if I write this code. Like recently I had to port over some users from BitPay wallet service to our wallet and I assumed their gap limit was 20. In fact it was unlimited for all versions. So, you know, it's easy to just assume stuff even if you check the code but it's good to double check those things. Next I want to do a quick note on address replacing malware. Of course we all know them. There's malware out there that, you know, hijacks your clipboard and replaces your receiving addresses or just browser extensions or Tor proxies that do the same. And one funny instance of that was when the ransomware locker instructed their victims to pay their ransom to them via a Tor proxy and the Tor proxy decided in turn to replace the address. So the Tor proxy was stealing from both the victims and the ransomware offer. And they complained about that. It's like I heard. And there are a couple of ways you could deal with this and we are not there yet. I think in the end we will have a world where people are not copy pasting addresses of course. And there are various avenues to deal with this. One I'm interested in personally is in a kind of a standard where hardware wallets can be plugged in into any service and you can just transmit your keys in a secure way. So, yes, we have to do this. But we are way without any copy pasting. So one area that also interests me is memory errors. I've looked at various wallet implementations and I don't see many actually giving this the proper attention that it deserves. You know, bit flips coming from Cosmic Racer, etc. are way too improbable to actually hit your private key or whatever. But you know, old memory units that start to fail or degrade in bad ways, they can actually make your life bad. Where does this manifest? If you generate a public key, you know, you multiply your private key by the generator, then you have a public key. If you have a bit flip or an error in the memory there, then send funds to it. It's lost. Or what if you derive public keys from an XPUB. Also if you don't double check the result, you could actually have a bad memory error. So you could have a mistake in the hashing that is involved and also get an error. Also backups, of course, if you make a backup, you should check that it produces the right private keys. And, well, this is a Bitcoin Core implementation. It generates a public key and it immediately checks that the public key is valid by signing something. I think they could probably go a step further and also check it before making use of it. Yeah, if you have a password, if you have any hashing involved, like password stretching, derivations, then it doesn't hurt to do it twice in different memory locations just to reduce the likelihood. And then most wallet software also just keeps the data in memory without any checksums or error correcting codes, which could be an issue. Yeah. Actually, if you store a public key, you're better off just storing the address instead if the only thing we're going to do is receive money on it. Except you're in e-commerce. So, yeah. So, yeah. So, yeah. So, yeah. So, yeah. So, yeah. So, yeah. So, yeah. So, yeah. So, yeah. Yeah. So, yeah. So, yeah. So, yeah. So, yeah. So, yeah. So, yeah. So, yeah. So, yeah. So, yeah. So, yeah. Next topic is pretty trivial and I'm kind of embarassed to even speak about it but I feel I have to because I've seen so many local web servers running without any authentication. And you might be, you know, the guy that wants to someday try to make a local web service because as bitcoin RPC or Lightning client or whatever you think because you're local, it doesn't matter because I'm the egomotor and I'm only user, I connect to it, no one else, so I don't need any documentation. But, you know, most people are not aware that browsers can access localhost. And I don't mean like localhost, if you type in localhost in the URL, I mean every website can do this. Small exchange here. One guy, also like I was in his shoes a couple years ago, I thought this was ridiculous, but, to be honest, I'm unsure why browsers even allow this. Anyway, case in point, there was an issue in Electrum last year. And Electrum, as you may know, is like one of the most used and widely popular wallets, and they also enable JSON RPC over HTTP by default. And it had no password protection, so every website that you go to could, in fact, steal your privacy, at least, and you wouldn't be able to access it. So it's a user concept best. Or the other way. Not only websites can do this, also like if you're a shared web server or if you have users on your machine or maybe, you know, you have a local Apache running and there's a guy that can hack in and escalates privileges to the user, www-user, then they can, of course, just scan the local ports and access your server, even if it's in a different user. So that was the point. It goes without saying, if you have authentication, you should also use SSL, otherwise people can just sniff your authentication. And I think, I have to check, but I think I need to file an issue also with Electrum. They still don't have SSL there. It's kind of scary, so. Phishing. Phishing is one of the worst problems in the worldwide experience. And web because it can be arbitrarily sophisticated. Like there's no real way to just eliminate a thread of it. It's just a red trace. You could go to, of course, you know, classics, malicious wallet, download a malicious wallet, go to a malicious web wallet. A guy from the Monero community, the HiHo guy, made a nice instructional post. So this wasn't real but was showing how you can buy a VPS and some adverts and make a fake URL like with a small Unicode O, very subtle, so no one will see this, to scam people into going to my Monero and giving up their private keys. And, you know, there is something you can do about this, which is use hardware, especially U2F and hardware wallets. They go a very, very long way in solving the, a lot of the problems. Of course, it's not fail-safe but it helps a lot. Like Google mentioned, they hadn't had a single phishing attempt, a successful phishing attempt since they introduced or required it. Even more than using U2F and hardware wallets which help you because, you know, you don't give up your private keys, you actually have to confirm manually on your device that you are giving up your coins. The hardware wallets can help you if they implement something like whitelist, so this is an excerpt from the bitbox firmware. Like a couple of web wallets are just whitelisted and if you connect anywhere else it just doesn't work. And couple of our users send us while others have no idea how to open their wallet. So it's not a problem. thank you notes because they went on my wallets.com or whatever. And they couldn't connect and they were happy that nothing worse happened. I'm toying with an idea. It's like early stage. I don't know. In the web you can eliminate phishing attempts this way because the browser makes sure that the URL is encoded in the protocol. But what if you download a native app which in many ways is more secure than a web wallet. But there you're out of luck. I'm thinking maybe you could use hardware to install or launch any kind of wallet locally after making integrity checks. Also, please, like I don't see nearly enough services supporting you to app. Like there's Dropbox and GitHub, et cetera. But I'm thinking Bitcoin exchanges, all of them still are stuck with Google authenticator which is not secure. I want to do a brief note on the choice of the tech stack if you want to build a web wallet or a wallet. And I don't want to go into, you know, too many of the hot topics where people debate if this is better or not. Just want to make a couple points here. One is that if you have a web wallet in the browser, even though you might be safer from phishing attacks, a browser is just a wild west of security. Like, I mean, everything goes. Especially if you have a malicious browser extension that's subverts your phishing prevention. Like they can just put in arbitrary data and, you know, you can, I don't know, you can ask the user to move their funds to a secure location because Trezor said so. But it's not Trezor. It's just some extension. All of those web wallets would be probably better off packaging it just in a native app. Of course the most popular one is Electrum. A lot of apps run on Electrum. I'm not a big fan. It's a little bit more of a web browser. But it has issues because in the front end as well as in the back end there's JavaScript. So the bridge to, you know, remote code execution is very small. You just have to find a small hole and then you have access to everything. And not sandbox by default, end and end. But there's other easier ways. You can use QT with Web Engine or you could use the Chromium embedded framework. They are more secure and also almost just as easy to actually build. You know, most people use, you know, they use the Chrome, they use the Chrome and they use the web front ends because they are easier to build. They use less resources. You have more talent, more access to people who can use it. But, of course, if you have the resources, you know, skip the web part altogether and do native like Monero GUI is a great example. Yeah, quick note on programming languages. As I said before, if you use JavaScript in the front end and back end, you might have some issues. If you use C++, you have like a lot of memory issues where it's really hard to get rid of even if you are very careful. So if you have a lot of memory issues and people tend to gravitate towards those two languages because they run everywhere. Like JavaScript runs on Android, runs on iOS, C++ as well. And, you know, practically every wallet is one of those two languages nowadays. And I just want to make the point that since maybe last year, Go and Rust and other languages that compile to C are a very viable alternative. And you can use them effectively to make a full application on Android, iOS, Mac, and, you know, you don't have any remote execution. Well, no buffer overflows, no smash protection that you have to put in place. Privacy. It's not only about security. If you leave your privacy, you're also not secure. I don't want to go too much into why privacy matters. I want to just refer you to this great guy, Glenn Greenwald, and check out his YouTube video. It's amazing. Today's wallet, leak your privacy. For example, before, blockchain.com was the only wallet that was an Android wallet. If you go to random.org, then they know, and their provider knows, and their hosting center knows that you're using this Android wallet, which is not great. You know, if you use Electrum servers, if you use MyMonero, any web wallet, Trezor, if they connect to a server, you're leaking privacy. Maybe not to the same level, but you are. We can educate users about VPN and Tor and integrate it into the wallet and make it a one-click experience. But I think this is still probably not feasible in the future. So, first, let's go back to the or too hard. I want to, you know, encourage every wallet offer to enable the user to connect their own full node. And our wallet that we just recently released for the bit box does that from the start. Like I think it's very important. But more so I want to dream about the world where everyone has a plug and play node that they can install next to their router and it does everything in a very simple manner. And with a bit of luck we can reach that goal. Like at Shift we've been trying a little bit with the idea. Like an intern made some mugs and we are trying with the idea how or if this would be a good future. I do think this will be amazing. So where does this leave us with Monero? You'll have noticed that my talk has been focused mostly on Bitcoin and stuff like that, other coins. In Monero the current state is that Monero is a little bit behind Bitcoin, maybe a couple of years in terms of the wallet experience. There is Monero GUI and Monero client. There is myMonero.com and that's basically it as of today. And myMonero makes no effort to be secure. It's deliberate. They have a really nice disclaimer that it's not secure, so that's okay. The Monero GUI is awesome. It is a full node. It runs. Everything is good. But, of course, users will want to have their own clients eventually because running your node is very difficult. Especially so. So I expect in the next couple of years to see a lot more like wallets being implemented for Monero on various platforms and then maybe you can take away some of the nodes I made today. Thank you. Which implications? . So institutions have different requirements than end users mostly. As of today there is no good solution for institutions to start doing real business on top of crypto. But lot of companies are in this space trying to make those solutions. Yeah, if you're going to have a hard time as an institution if you want to just pull together some of the existing clients and hardware wallets and do something on your own, it works. Banks and institutions are doing it today to crazy amounts of money. But I wouldn't recommend it and solutions are being rolled out as we speak. Thank you. I haven't thought about it a lot. I don't think, well, intuitively speaking, I don't think verifiable remote hardware works. I might be wrong. Although, it still might be a reasonable solution. There's never, you know, you're secure or insecure. There's levels and if you can have a remote hardware which you can trust in some ways but not fully, then that's good. And it's a step in the right direction. Still, in the end, it's not going to work. It's going to depend. I think it's best if you can have your own node at home. Also, like, your own node, if you buy it from a company like us, then how do you trust that? Like, the goal is, of course, also to have an instruction to build it yourself with off-the-shelf, very cheap hardware and all that stuff. Yeah. I didn't quite get it. Come again. Are you talking about Monero? It's the first choice for what? Sorry. So, I was asking that this coin is maybe because of privacy, it's kind of first choice for the actors behind like, you know, like, you know, like, you know, like, you know, like, you know, like, you can use it for the like, exploit case, like, drop the crime ways. And any crime way that, you know, involves crypto minors, they usually, uh, drop for Monero. I didn't, still couldn't get the part about Monero, I think you're asking if about malicious activity of Monero and privacy? Right. So, I just want to refer you to... This one over here. I urge you to watch it. Like this mirrors my view on privacy. Thank you. Thank you.