powered by Coinlib

Wednesday, February 27, 2019

Software Wallets & Hardware Wallets



You may hear that bitcoins are stored in wallets. If this were true, then if you copied your wallet you’d own double the number of bitcoins. Clearly you couldn’t have digital money that works this way. So no, bitcoins are not stored in wallets. So where are bitcoins stored? Ownership of bitcoins is recorded on Bitcoin’s blockchain, which is, as we have seen, the database replicated on over 10,000 computers around the world containing every Bitcoin transaction ever. So you can look at that database and see that at this time, a specific address has a specific number of bitcoins associated with it. Bitcoin’s blockchain doesn’t store balances of accounts (it is not a list of account numbers and corresponding BTC balances), it stores transactions. So to get the current balance of any account, you need to look at all the inbound and outbound transactions through that account. Bitcoin wallets store private keys (not bitcoins) and their software makes it easy for the user of the wallet to see how many coins they control and to make payments. If you cloned your wallet, you would be cloning your private keys, not doubling your bitcoins.

Bitcoin wallets are apps that can: create new Bitcoin addresses and store the corresponding private keys; display your addresses to someone who wants to send you a payment; display how many bitcoins are in your addresses; make Bitcoin payments.Creating new Bitcoin addresses is an offline operation and involves creating a public and private key pair.

When someone wants to send you bitcoins, you need to tell them your address - like telling someone your bank account number so they can send you money. There are a few ways to do this. One popular way is by showing it as a QR code. QR codes are not magic. They are just text, encoded in a visual way that makes it easy for QR code scanners to read the code and convert it back into text. Another way is just to copy and paste the address itself.

The wallet needs to access an up to date version of the blockchain in order to be aware of all the transactions going in and out of the addresses it is keeping tabs on. The wallet, software can do this by either storing the entire blockchain and keeping it up to date (this is called a full node wallet) or by connecting to a node elsewhere which does the heavy lifting (this is called a lightweight wallet). A full node wallet would contain over a hundred gigabytes of data and would need to be constantly connected over the internet to other Bitcoin nodes. So in many cases, especially on mobile phones, this is not practical so the wallet software is lightweight and connects to a server which hosts the blockchain.

As well as reading the account balances, the wallet needs to be able to make payments. To make a Bitcoin payment, the wallet generates a bundle of data called a ‘transaction,’ which includes references to the coins that are going to be spent (transaction inputs consisting of unspent outputs of previous transactions), and which accounts the coins will be sent to (new outputs). This transaction is then digitally signed using the relevant private keys of the addresses holding the coins. Once signed, the transaction is sent to neighboring nodes, via its server node if it is a lightweight wallet, or directly to other peers if it is a full node wallet. The transactions eventually find their way to miners who add them to blocks.

Good wallet software has more functionality, including the ability to back up private keys (encrypted with a passphrase) either to a user’s hard drive or to a cloud storage server somewhere, to generate one-time use addresses for privacy, to hold addresses and private keys for multiple cryptocurrencies. Some are even integrated with exchanges to allow users to convert between one cryptocurrency and another directly from within the wallet software. Often wallets will allow you to split keys or set up addresses that require multiple digital signatures to spend from.

Sometimes Bitcoin wallets can have a hardware component. Private keys are stored in chips on small handheld devices. Two popular hardware wallets are called ‘Trezor’ and ‘Ledger Nano’, but there are others. These devices are specifically designed to store private keys securely and only respond to certain pre-programmed requests, for example, ‘Please sign this transaction’, and not, ‘Show me the private key you are storing’. Because the private key is stored on hardware that is not connected to the internet and can communicate with the outside world only via a limited set of pre-programmed interfaces, it is much harder for a hacker to gain access to the private keys.

The user interface software is run on an online machine. When it comes to the critical part of the transaction (the signing), the unsigned transaction is sent to the hardware wallet, which returns the signed transaction without revealing the private key. Hardware wallets are more secure than
software-only wallets, but nothing is infallible.

The phrase ‘keeping coins in cold storage’ was popular in 2013-17 before hardware wallets became widely available. Remember, you don’t store bitcoins, you store private keys. ‘Cold storage’ is keeping a note of those private keys on offline media, such as a piece of paper or a computer not connected to the internet. There are many ways of storing them. You can memorise keys if you have a good memory, you can print them out on bits of paper, you can even engrave them on a ring that you wear. You could store them on an offline computer which, for increased security, should not have a modem or network card. You could write them down and put them in a bank’s locked deposit box. These are all methods of storing your private keys offline.

If you do keep private keys on a device or printed out, you wouldn’t want someone else to be able to see it and use it to steal your bitcoins. So one way of increasing security is to first encrypt the private key with a passphrase that you can remember and then store or print out the encrypted result. Passphrases are a lot easier to remember than private keys. This means that even if someone gets hold of the device or print out, they’d need to decrypt it with your passphrase before the private key is revealed. You can split keys or use multi-sig addresses for further security. This means if one part is found by a thief, it is useless without another part, and also means if one part is lost, the other two will still work. Remember, you are trying to simultaneously guard against two things: loss of keys and theft of keys.

A hot wallet is a wallet that can sign and broadcast transactions without manual intervention. Exchanges, who control many bitcoins need to manage lots of Bitcoin payments, as we will see later. They often have a ‘hot wallet’ that controls a small proportion of their total bitcoins. Customers of exchanges like to withdraw bitcoins from the exchanges by clicking a button, causing an automated process to run to make and sign a Bitcoin transaction moving bitcoins from the exchange’s hot wallet to the user’s personal wallet. This means that somewhere, a private key belonging to the exchange must be stored on a ‘hot’ machine connected to the internet. There is a trade-off between security and convenience. Online machines are easier to hack than offline machines, but can automate the process of creating and broadcasting Bitcoin transactions. Due to this trade-off, exchanges keep only a small fraction of BTC in hot wallets, enough to satisfy customer demand, similar to banks that keep a small amount of cash in tellers’ tills at branches.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.