Bitcoin—an overview
Since its introduction in 2008 by Satoshi Nakamoto, Bitcoin has gained immense popularity and is currently the most successful digital currency in the world, with billions of dollars invested in it. The current market cap at the time of writing for this currency is 168,923,803,898 USD.
Its popularity is also evident from the high number of users and investors, the increasing price of Bitcoin, daily news related to Bitcoin, and the many start-ups and companies that are offering Bitcoin-based online exchanges. It is now also traded as Bitcoin futures on the Chicago Mercantile Exchange (CME).
Interested readers can read more about Bitcoin futures at http://www.cmegroup.com/trading/bitcoin-futures.html.
It is built on decades of research in the field of cryptography, digital cash, and distributed computing. In the following section, a brief history is presented to provide the background required to understand the foundations behind the invention of Bitcoin.
Digital currencies have always been an active area of research for many decades. Early proposals to create digital cash go as far back as the early 1980s. In 1982, David Chaum, a computer scientist and cryptographer, proposed a scheme that used blind signatures to build an untraceable digital currency. This research was published in a research paper entitled Blind signatures for untraceable payments. We covered this history in Chapter 1, Blockchain 101, which readers can review if required.
Interested readers can read the original research paper in which David Chaum invented the cryptographic primitive of blind signatures at http://www.hit.bme.hu/~buttyan/courses/BMEVIHIM219/2009/Chaum.BlindSigForPayment.1982.PDF.
In this scheme, a bank would issue digital money by signing a blind and random serial number presented to it by the user. The user could then use the digital token signed by the bank as currency. The limitation of this scheme was that the bank had to keep track of all used serial numbers. This was a centralized system by design and required a trusted party such as a bank to operate.
Later on, in 1988, David Chaum et al. proposed a refined version named eCash that not only used blind signatures, but also some private identification data to craft a message that was then sent to the bank.
The original research paper for this is available at http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.26.5759.
This scheme allowed the detection of double-spending, but did not prevent it. If the same token were used at two different locations, then the identity of the double-spender would be revealed. Also, this eCash scheme could only represent a fixed amount of money.
Adam Back, a cryptographer and current CEO of Blockstream, who is involved in Blockchain development, introduced hashcash in 1997. It was initially proposed to thwart email spam. The idea behind hashcash was to solve a computational puzzle that was easy to verify but comparatively difficult to compute. The idea was that for a single user and a single email, the extra computational effort was negligible, but someone sending a large number of spam emails would be discouraged as the time and resources required to run the spam campaign would increase prohibitively.
In 1998, Wei Dai, a computer engineer who used to work for Microsoft, proposed b-money, which introduced the idea of using Proof of Work (PoW) to create money. The term PoW emerged and got popular later with Bitcoin, but in Wei Dai's b-money, a scheme of creating money was introduced by providing a solution to a previously unsolved computational problem. This concept is similar to PoW, where the money is created by broadcasting the solution to a previously unsolved computational problem.
The original paper on b-money is available here: http://www.weidai.com/bmoney.txt.
A significant weakness in the system was that an adversary with higher computational power could generate unsolicited money without allowing the network to adjust to an appropriate difficulty level. The system lacked details on the consensus mechanism between nodes and some security issues such as Sybil attacks were also not addressed. At the same time, Nick Szabo, a computer scientist, introduced the concept of BitGold, which was also based on the PoW mechanism but had the same problems as b-money, with the exception that the network difficulty level was adjustable. Tomas Sander and Amnon Ta-Shma at the International Computer Science Institute, Berkley, introduced an e-cash scheme in a research paper named Auditable, Anonymous Electronic Cash in 1999. This scheme, for the first time, used Merkle trees to represent coins and zero-knowledge proofs to prove the possession of coins.
The original research paper, Auditable, Anonymous Electronic Cash, is available at http://www.cs.tau.ac.il/~amnon/Papers/ST.crypto99.pdf.
In this scheme, a central bank was required that kept a record of all used serial numbers. This scheme allowed users to be fully anonymous. This was a theoretical design that was not practical to implement due to inefficient proof mechanisms.
RPOW (Reusable Proof of Work) was introduced in 2004 by Hal Finney, a computer scientist, developer, and the first person to receive Bitcoin from Satoshi Nakamoto. It used the hashcash scheme by Adam Back as a proof of computational resources spent to create the money. This was also a central system that kept a central database to keep track of all used PoW tokens. This was an online system that used remote attestation, made possible by a trusted computing platform (TPM hardware).
All the previously mentioned schemes are intelligently designed but had weaknesses in one aspect or another. Specifically, all these schemes rely on a central server that is required to be trusted by the users.
Having covered some of the fundamentals of Bitcoin, let's talk about how Bitcoin started.
The beginnings of Bitcoin
In 2008, Bitcoin was introduced in a paper called Bitcoin: A Peer-to-Peer Electronic Cash System.
This paper is available at https://Bitcoin.org/Bitcoin.pdf.
Satoshi Nakamoto wrote the Bitcoin paper. The name of the author is believed to be a pseudonym, as the true identity of the inventor of Bitcoin is unknown and is the subject of much speculation. The first key idea introduced in the paper was of a purely peer-to-peer electronic cash that does need an intermediary bank to transfer payments between peers.
Bitcoin is built on decades of research. Various ideas and techniques from cryptography and distributed computing such as Merkle trees, hash functions, and digital signatures were used to design Bitcoin. Other ideas such as BitGold, b-money, hashcash, and cryptographic time-stamping also provided some groundwork for the invention of Bitcoin. Ideas from many of these developments were ingeniously used in Bitcoin to create the first ever truly decentralized currency. Bitcoin solves a number of historically difficult problems related to electronic cash and distributed systems, including:
- The Byzantine generals problem
- The double-spending problem
- Sybil attacks
Bitcoin is an elegant solution to the Byzantine generals problem and the double-spending problem. We examined both of these concepts in Chapter 1, Blockchain 101.
A Sybil attack is a type of attack where a single adversary creates a large number of nodes with fake identities on the network, which are used to gain influence over the network. This attack is also prevented in Bitcoin by using PoW, where miners are required to consume a considerable amount of computing power to earn rewards. If fake nodes try to add fake blocks to the Bitcoin blockchain, they will be rejected because those blocks will not have the required amount of work, that is, the PoW, associated with them. For an adversary to add a fake block, they will have to work at the same difficulty level as the other honest miners and compete honestly; otherwise, their work (as long as they do not control more than 51% of the network) will always be rejected by the network due to the insufficient amount of work performed to create blocks.
Bitcoin is currently the most valuable cryptocurrency. The value of Bitcoin fluctuates quite heavily but has increased quite significantly over time, as shown in the following graph:
Figure 6.1: Bitcoin price trend since mid-2017
Before we talk about the specifics of Bitcoin, let's briefly discuss the philosophy behind it, go over the official definition of Bitcoin, and consider Bitcoin from a user's perspective before delving deeper into the topic in later sections.
Egalitarianism versus authoritarianism
For people with a libertarian ideology, Bitcoin is a platform that can be used instead of banks. However, some think that due to regulations, Bitcoin may become another institution that cannot be trusted. The original idea behind Bitcoin was to develop an e-cash system, which requires no trusted third party and where users can be anonymous. If regulations require checks like Know Your Customer (KYC) and detailed information about business transactions to facilitate the regulatory process, then it might be too much information to share. As a result, Bitcoin may not remain attractive to some entities.
The regulation of Bitcoin is a controversial subject. As much as it is a libertarian's dream, law enforcement agencies, governments, and banks are proposing various regulations to control it. One prime example is the BitLicense, issued by New York State's Department of Financial Services, which is a permit issued to businesses that perform activities related to virtual currencies. Due to the high cost and stringent regulatory requirements to obtain a BitLicense, many companies have withdrawn their services from New York.
There are now many initiatives being taken to regulate Bitcoin, cryptocurrencies, and related activities such as Initial Coin Offerings (ICOs). The Securities and Exchange Commission (SEC) has recently announced that digital tokens, coins, and relevant activities such as ICOs fall under the category of securities. This announcement means that any digital currency trading platforms will now need to be registered with the SEC and all relevant securities' laws and regulations will be applicable to them. This situation impacted the Bitcoin price directly, and it fell almost 10% on the day this announcement was made. Bitcoin has even been made illegal in some countries.
Interested readers can read more about the regulation of Bitcoin and other relevant activities at https://cointelegraph.com/tags/Bitcoin-regulation.
At this point, the question arises that if Bitcoin is under so much pressure from regulatory bodies, then how it has managed to grow so significantly? The simple answer is due to its decentralized and trustless nature. In this context, the term trustless refers to the distribution of trust between users, rather than a central entity. No single entity can control this network, and even if some entities try to enforce some regulations, they can only go so far because the network is owned collectively by its users instead of a single entity. It also protected by its PoW mechanism, which thwarts any adversarial attacks on the network.
The growth of Bitcoin is also due to the so-called network effect. Also called demand-side economies of scale, it is a concept that means that the more users use the network, the more valuable it becomes. Over time, an exponential increase has been seen in Bitcoin network growth. This increase in the number of users is mostly driven by financial incentives. Also, the scarcity of Bitcoin and its built-in inflation control mechanism gives it value, as there are only 21 million Bitcoins that can ever be mined. Also, the miner reward halves every four years, which increases scarcity, and consequently, the demand increases even more.
Bitcoin definition
Bitcoin can be defined in various ways; it's a protocol, a digital currency, and a platform. It is a combination of a peer-to-peer network, protocols, and software that facilitates the creation and usage of the digital currency. Nodes in this peer-to-peer network talk to each other using the Bitcoin protocol.
Decentralization of currency was made possible for the first time with the invention of Bitcoin. Moreover, the double-spending problem was solved in an elegant and ingenious way in Bitcoin. The double-spending problem arises when, for example, a user sends coins to two different users at the same time and they are verified independently as valid transactions. The double-spending problem is resolved in Bitcoin by using a distributed ledger (the blockchain) where every transaction is recorded permanently, and by implementing a transaction validation and confirmation mechanism. This process will be explained later in the chapter, in the Mining section.
Bitcoin—A user's perspective
In this section, we will see how the Bitcoin network looks from a user's point of view — how a transaction is made, how it propagates from the user to the network, and how transactions are verified and finally accumulated in blocks. We will look at the various actors and components of the Bitcoin network. Finally, some discussion on how all actors and components interact with each other to form the Bitcoin network will also be provided.
First, let's see that what the main components of a Bitcoin network are. Bitcoin is composed of the elements in the following list. We will further expand on these elements as we progress through the chapter:
- Digital keys
- Addresses
- Transactions
- Blockchain
- Miners
- The Bitcoin network
- Wallets (client software)
Now, we will see how a user utilizes the Bitcoin network. The following example will help you to understand how the Bitcoin network looks from the end user's perspective. We will see what actors and components are involved in a Bitcoin transaction. One of the most common operations is sending funds to someone else; therefore, in the following example, we will see how a payment transaction can be sent from one user to another on the Bitcoin network.
Sending a payment
This example will demonstrate how money can be sent using the Bitcoin network from one user to another. There are several steps that are involved in this process. In this example, we are using the Blockchain wallet for mobile devices.
The steps are described as follows:
- First, either the payment is requested from a user who sends their Bitcoin address to the sender via email or some other means such as SMS, chat applications, or in fact any appropriate communication mechanism. The sender can also initiate a transfer to send money to another user. In both cases, the address of the beneficiary is required. As an example, the Blockchain wallet is shown in the following screenshot, where a payment request is being created:
Figure 6.2: Bitcoin payment request (using the Blockchain wallet)
- The sender either enters the receiver's address or scans the QR code that has the Bitcoin address, amount, and an optional description encoded in it. The wallet application recognizes this QR code and decodes it into something like:
"Please send <amount> BTC to address <receiver's Bitcoin address>".
- With actual values, this will look like the following:
"Please send 0.00033324 BTC to address 1JzouJCVmMQBmTcd8K4Y5BP36gEFNn1ZJ3".
- This is also shown in the following screenshot:
Figure 6.3: Bitcoin payment QR code
The QR code shown in the preceding screenshot is decoded to:
bitcoin://1JzouJCVmMQBmTcd8K4Y5BP36gEFNn1ZJ3?amount=0.00033324
, which can be opened as a URL in a Bitcoin wallet. - In the wallet application of the sender, this transaction is constructed by following some rules and is then broadcast to the Bitcoin network. This transaction is digitally signed using the private key of the sender before broadcasting it. How the transaction is created, digitally signed, broadcasted, validated, and added to the block will become clear in the following sections. From the user's point of view, once the QR code is decoded, the transaction will appear, similar to what is shown in the following screenshot:
Figure 6.4: Sending BTC using the Blockchain wallet
Note that in the preceding screenshot, there are a number of fields such as From, To, BTC, and Fee. While other fields are self-explanatory, it's worth noting that the fee is calculated based on size of the transaction and a fee rate, which is a value that depends on the volume of the transactions in the network at that time. This is measured in Satoshis per byte. Bitcoin network fees ensure that your transaction will be included by miners in the block.
At times in the past, Bitcoin fees were so high that even for smaller transactions, a high fee was charged. This was due to the fact that miners are free to choose which transactions they pick to verify and add to a block, and they naturally select the ones with higher fees. A high number of users creating thousands of transactions also played a role in causing this situation of high fees because transactions were competing with each other to be picked up first and miners picked up the ones with the highest fees. This fee is also usually estimated and calculated by the Bitcoin wallet software automatically before sending the transaction. The higher the transaction fee, the greater the chances are that your transaction will be picked up as a priority and included in the block. This task is performed by the miners. Mining and miners are concepts that we will look at a bit later in this chapter in the section about Mining.
Once the transaction is sent, it will appear in the wallet software as shown in the following screenshot:
Figure 6.5: Transaction sent
- At this stage, the transaction has been constructed, signed, and sent out to the Bitcoin network. This transaction will be picked up by miners to be verified and included in the block. Also note that in the preceding screenshot, confirmation is pending for this transaction. These confirmations will start to appear as soon as the transaction is verified, included in the block, and mined. Also, the appropriate fee will be deducted from the original value to be transferred and will be paid to the miner who has included it in the block for mining.
The transaction flow described in the preceding list is illustrated in the following diagram, where a payment of 0.001267 BTC (approximately 11 USD) originated from the sender's address and has been paid to the receiver's address (starting with 1Jz). The fee of 0.00010622 (approximately 95 cents) has also been deducted from the transaction as a mining fee:
Figure 6.6: Transaction flow visualization (blockchain.info)
The preceding diagram visually shows how the transaction flowed on the network from the origin (the sender) to the receivers on the right-hand side.
A summary view of various attributes of the transaction is shown in the following screenshot:
Figure 6.7: Snapshot of the transaction taken from blockchain.info
Looking at the preceding screenshot, there are a number of fields that contain various values. Important fields are listed as follows with their purpose and explanation:
- Size: This is the size of the transaction in bytes.
- Weight: This is the new metric given for the block and transaction sizes since the introduction of the segregated witness (SegWit) soft fork version of Bitcoin. Please see Chapter 7, Bitcoin Network and Payments, for more information on SegWit.
- Received time: This is the time when the transaction was received.
- Included in blocks: This shows the block number on the blockchain in which the transaction is included.
- Confirmations: This is the number of confirmations completed by miners for this transaction.
- Total input: This is the number of total inputs in the transaction.
- Total output: This is the number of total outputs from the transaction.
- Fees: This is the total fee charged.
- Fee per byte: This field represents the total fee divided by the number of bytes in the transaction; for example, 10 Satoshis per byte.
- Fee per weight unit: For legacy transactions, this is calculated using the total number of bytes * 4. For SegWit transactions, it is calculated by combining a SegWit marker, flag, and witness field as one weight unit, and each byte of the other fields as four weight units.
The transaction ID of this transaction on the Bitcoin network is d28ca5a59b2239864eac1c96d3fd1c23b747f0ded8f5af0161bae8a616b56a1d
. This can be further explored using the following link via the services provided by blockchain.info. This transaction ID is available in the wallet software after the transaction has been sent to the network. From there, it can be further explored using one of many Bitcoin blockchain explorers available online. We are using blockchain.info as an example, which can be found here:
https://blockchain.info/tx/d28ca5a59b2239864eac1c96d3fd1c23b747f0ded8f5af0161bae8a616b56a1d
Bitcoin transactions are serialized for transmission over the network and encoded in hex format. As an example, the transaction shown at the preceding URL is also shown in hex format as follows. We will see later, in the Transactions section, how this hex-encoded transaction can be decoded and which fields make up a transaction:
01000000017d3876b14a7ac16d8d550abc78345b6571134ff173918a096ef90ff0430 e12408b0000006b483045022100de6fd8120d9f142a82d5da9389e271caa3a757b017 57c8e4fa7afbf92e74257c02202a78d4fbd52ae9f3a0083760d76f84643cf8ab80f5e f971e3f98ccba2c71758d012102c16942555f5e633645895c9affcb994ea7910097b7 734a6c2d25468622f25e12ffffffff022c820000000000001976a914c568ffeb46c6a 9362e44a5a49deaa6eab05a619a88acc06c0100000000001976a9149386c8c880488e 80a6ce8f186f788f3585f74aee88ac00000000
In summary, a payment transaction in the Bitcoin network can be divided into the following steps:
- The transaction starts with a sender signing the transaction with their private key.
- The transaction is serialized so that it can be transmitted over the network.
- The transaction is broadcast to the network.
- Miners listening for transactions pick up the transaction.
- The transaction is verified for its legitimacy by the miners.
- The transaction is added to the candidate/proposed block for mining.
- Once mined, the result is broadcast to all nodes on the Bitcoin network.
- Usually, at this point, users wait for up to six confirmations to be received before a transaction is considered final; however, a transaction can be considered final at the previous step. Confirmations serve as an additional mechanism to ensure that there is probabilistically a very low chance for a transaction to be reverted, but otherwise, once a mined block is finalized and announced, the transactions within that block are final at that point.
Mining, transactions, and other relevant concepts will become clearer in the following sections in the chapter.
Bitcoin, being a digital currency, has various denominations, as shown in the following table. A sender or receiver can request any amount. The smallest Bitcoin denomination is the Satoshi. Bitcoin currency units are described as follows:
Figure 6.8: Bitcoin denominations
Now, we will introduce the building blocks of Bitcoin. First, we will look at the keys and addresses that are used to represent the ownership and transfer of value on the Bitcoin network.