Uinspire Blockchain Course {Lesson 2: The Bitcoin Revolution}

Alfonso Delgado
Uinspire
Published in
17 min readApr 10, 2018

In Lesson 1, we drew a distinction between DLT networks and blockchain data structures. The latter is merely a data structure that the network’s distributed ledger may adopt. In the appropriate setting, DLT networks can allow users to:

  1. Reduce transactions costs;
  2. Streamline business processes;
  3. Enhance the auditability of transactions;
  4. Share and monetise information; and
  5. Store data in a trust minimised environment.

We now turn our attention to Bitcoin, which was the first network to implement the blockchain data structure. Brace yourselves, my friends, as we’re about to enter the rabbit hole of cryptocurrencies.

Alice and her Cryptokitty are looking for Bob

Bitcoin, the first of its kind

In 2008, Satoshi Nakamoto (pseudonym) introduced Bitcoin in a paper that was sent to an online mailing list of cryptographers. Satoshi’s goal was to create a decentralised payment system with an in-built virtual currency. Since the 80s, many projects had sought to issue their own versions of digital cash (e.g. DigiCash and b-money). Each of these earlier projects ended up failing, as they could not operate without a significant degree of centralisation. To address this challenge, Satoshi introduced the blockchain data structure and coupled this with a protocol that rewards users who maintain and update the shared data, allowing consensus to be reached in a distributed network.

In 2009, Satoshi created the first block of the Bitcoin network and added the following message to the block’s contents:

“The Times 03/Jan/2009 Chancellor on brink of second bailout for banks”

This message is taken from a newspaper headline and proves that Bitcoin did not commence its operations before the data stated. In addition, it indicates that Bitcoin was created as an alternative to the financial system, which had failed to prevent institutions from abusing the market and triggering a Global Financial Crisis. For some time, Nakamoto remained involved in the Bitcoin community by answering queries via email and blog posts. However, Nakamoto decided to disappear from the scene in December 2010, as an active community had already started to develop. Nakamoto never shared their personal details, thereby allowing the pioneering technology to be judged solely on its merits.

The different meanings of Bitcoin

“Writing a description for this thing for general audiences is bloody hard. There’s nothing to relate it to.” — Satoshi Nakamoto (2010) [pre-disappearance]

With this remark in mind, it is helpful to begin our discussion by unpacking the ambiguity that surrounds the term Bitcoin. This can serve various meanings depending on the context in which it is used. In particular, the term Bitcoin can refer to:

(i) the protocol that nodes in the network must follow to share information;

(ii) the collective of nodes that are networked via the internet; and/or

(iii) the virtual currency — BTC — that is created by running the Bitcoin software.

By convention, we capitalise the word Bitcoin when referring to the protocol, the software, or the network as a whole. In contrast, we do not capitalise bitcoin when referring to the virtual currency (BTC) alone, e.g. “the price of bitcoin is very high”. We will use BTC when referring to the currency component to avoid further confusion.

The layers and functions of the Bitcoin network

We can dissect the Bitcoin network into a series of layers with corresponding functions:

The 3 layers of the Bitcoin network (left) and their function (right)

The protocol is the set of rules that nodes must follow to form part of the Bitcoin network. These rules specify the format that the shared data must adopt and the process by which nodes must update their ledgers with new data entries. We can think of the protocol, and the networked nodes that enforce it, as laying down the foundations for the Bitcoin payment system. In turn, the ledger entries record the transfer of BTC amongst network users. BTC is acting as the network’s native currency, allowing users to transfer value from one to another and pay fees to keep the network running.

BTC is often referred to as the first cryptocurrency, as it relies on a set of cryptographic techniques to prevent users from spending funds that they do not own or creating new BTC without prior authorisation. Unlike fiat currencies such as the US Dollar ($) or British Pound (£), BTC (₿) is not issued or controlled by a central bank. It is not backed by (or pegged to) a commodity like gold either. Instead, it derives its value from the willingness of network users to accept BTC as a means of payment and their believe in the integrity of the system (that is, its resistance against malicious attacks).

The price of BTC has soared in recent years, catching the attention of investors and news publications across the world. In early 2013, 1 BTC was worth around $100. Following a strong rally, it peaked at around $20,000 in December 2017. At the time of writing, the price of BTC has fallen to $6,500 and the market value of all the BTC in circulation is $113 Billion.

You can check the current price of 1 BTC and the combined market value at CoinMarketCap

Given that the amount of BTC in circulation is limited, its price is driven by demand and supply principles. The speculation surrounding BTC’s potential for mainstream adoption has caused its price to skyrocket. Somewhat ironically, this volatility is discouraging the adoption of BTC amongst businesses, as it is too risky to accept BTC if the value is fluctuating vastly from one day to another. In January 2018, the exuberance of the BTC market started to take a noticeable hit. This can be attributed to two main factors. First, users have realised that the growth could no longer be justified, as this did not match the rate of adoption of BTC. Second, regulators have brought a wave of legal actions against people in this space who have violated securities legislation (Lesson 4). Many have warned of a coming crypto-recession to correct for BTC's unprecedented growth. Others point out that Bitcoin has mistakenly been declared dead over 278 times in the past (and counting).

2017: A man urges you to buy BTC while the (former) Chair of the Federal Reserve Board speaks

Note: this section is designed to give you an overview of the cryptocurrency mania. This should not be taken as financial advice and blah blah blah.

The Bitcoin software

The devices connected to the network are running Bitcoin-compatible software, which users can either download in one of its standard forms or build from scratch for greater customisation. In turn, Bitcoin-compatible software can be divided into node software and BTC wallets. Node software can be used to transfer BTC, store the entire blockchain data structure and/or confirm transactions. In Bitcoin, the subset of nodes that confirm transactions by incorporating them into new blocks are referred to as miners. We will examine the role of miners in the sections that follow.

On the other hand, wallet software is solely used to store and transfer BTC from one user to another. To calculate a user’s BTC balance, the wallet will initially run through the historical list of transactions taking place since the network launched. In going through the ledger entries, the wallet software will look for the amount of BTC that the user has received and not yet spent.

The Bitcoin protocol

In Lesson 1, we learnt that a protocol is a set of the rules that nodes must follow to form part of the network. The three most important rules in the Bitcoin protocol, programmed into all Bitcoin-compatible software, can be written in natural language as follows:

  1. users cannot send BTC that they have not previously received from another person (or via mining, see rule 3). Transactions that violate this principle are invalid and must be ignored by users of the software;
  2. approximately every 10 minutes one of the nodes will have the chance to mine (or register) a new block, by which a group of valid, pending transactions will be confirmed; and
  3. in exchange for mining this new block, the miner can create new BTC and keep this as a reward. In addition, it is expected that users will attach a voluntary fee to transactions, which will be collected by the miner who incorporates these transaction into a new block.

While rules 1 and 3 are self-explanatory, rule 2 requires further elaboration. The Bitcoin network is composed of nodes that are distributed across the world and use the internet to pass on messages to one another. Since information can take some time to propagate itself across the network, a node is likely to receive data from those nodes that are geographically closest to it first. This means that if a node in China receives transactions in order (A, B, C), a US node may pick them up in reverse order (C, B, A). Therefore, rule #2 allows a single miner to create an authoritative record of transactions. Without this rule, it would be impossible for the nodes to agree on which data has already been confirmed, as there is no central entity to perform this task on their behalf.

Bitcoin’s consensus mechanism: proof-of-work

In Bitcoin, the mechanism by which a miner confirms a group of pending transactions is referred to as proof-of-work (PoW). Nodes that choose to participate in the PoW process are racing each other to solve a cryptographic puzzle. In general, whichever node is able to solve this cryptographic puzzle first will obtain the right to mine a new block of transactions and earn the associated reward.

In Lesson 1, we learned about the role of hashes in ensuring that alterations to the ledger entries can be detected and rejected with ease. Hashes also play an important (though slightly different) role in the mining process. Apart from being data-specific, hashes are produced by one-way functions. While it is easy to verify that a set of input data produces a specific hash, it is difficult to reverse engineer this process. In other words, it is hard to obtain the correct input data if you are only given the resulting hash.

When we talk about a cryptographic puzzle, what we mean is that miners have to come up with a piece of input data that leads to a special hash value. This hash is special because it will only be valid if it commences with a number that is lower than the prescribed target threshold.

If the current target threshold is:

000000000000000000502ab70000000000000000000000000000000000000000

Then any input data that creates a hash below that number will be valid. Here’s an example of a valid hash (though many combinations are possible):

000000000000000000302cb70000000000000000000000000000000000000000

To find this hash, miners must add a variable (called a nonce) to the block before they start hashing its contents. This nonce is a number that miners will increment until a valid hash is obtained. This process allows miners to look for a valid solution without having to modify the other contents of the block — there is no need to replace the transactions that they have already selected for inclusion. Once a valid solution is reached, it will be stored in the block’s header section along with the previous block’s hash value.

The process of finding a valid nonce requires miners to pursue a method of trial and error (“brute force”) and consume significant computing resources (“work”). The target threshold is adjusted periodically to ensure that a valid nonce is discovered by a miner every 10 minutes (on average). This period is referred to as the block-creation interval. To keep this interval consistent, the target value will be adjusted approximately every 2 weeks to account for changes in the network’s mining power (the total “hash rate”). For instance, if more nodes decide to join the race, or miners start using more powerful computers, the target value will decrease to narrow down the set of valid solutions. In turn, this increase in the mining difficulty will keep the block-creation interval consistent. In theory, the protocol could be modified to reduce this interval. However, this is deliberately kept at 10 minutes to provide ample time for nodes across the network to incorporate the new block to their ledgers and join the new race before the next block is found.

The purpose of mining

Mining is not the process by which nodes validate transactions. Transactions are continuously being validated by every node in the system, whether they are participating in the mining race or not. For instance, nodes verify that these relate to existing funds and have been signed by the appropriate private key. In addition, when a new block is broadcast by a miner, every node will check that its contents are valid. The process of validating both transactions and blocks is simple, enabling nodes to discard erroneous and malicious data.

Mining is the process by which a node confirms a new block of transactions and instructs others to add this block to their ledgers. As such, mining creates an authoritative order of transactions and allows consensus to be formed in a distributed environment. The mining process is deliberately expensive, as it requires a lot of electricity to be consumed. This incentivises miners to refrain from producing invalid blocks, as these will be rejected by the system and the miner will receive no compensation for its work.

Mining also doubles up as the network’s currency issuance mechanism. The winning miner in each period will be compensated for the computing resources consumed with newly-issued BTC. Indeed, every BTC in existence has been generated via mining, a process that was started by Satoshi in 2009. The first transaction in each block is called the coinbase transaction and indicates that new BTC have been generated to reward the miner. The amount of this reward is based on a predefined schedule and cannot be arbitrarily set by the miner. However, miners also get to keep the fees that users attach to their transactions. In the year 2140, the supply of BTC will have reached its predefined maximum. At this point, it is intended that the network will be able to rely only on fees, as no further BTC will be issued.

In theory, PoW is designed to ensure that a random miner wins the race in each interval. This is done to prevent attacker from maliciously influencing or attacking a miner, as the attacker cannot predict which miner will be the first to find a valid nonce and win the race. In practice, the mining process is far from random: a miner with X% of the total hash rate has X% chance of mining the next block. Wealthy individuals can afford to buy specialised mining computers to ensure that you and I have little chance of winning. Further, many miners have organised themselves into profit-sharing collectives known as mining pools to combine their computing resources. The diagram below shows the current hash rate distribution (i.e. X%) across the network, which is concentrated amongst a small number of mining pools.

Source: Blockchain.info

This concentration is problematic because it makes 51% attacks more likely. With a majority of the hashing power, attackers could prevent certain transactions from being included in the ledger while they are in control. In addition, an attacker could double spend transactions by sending the same funds to multiple addresses, temporarily tricking users into thinking that a valid payment has been made. To be clear, neither attacks allows the malicious entity to spend other user’s funds, as nodes in the network would refrain from adding invalid transactions to their ledgers. It is often argued that it would be prohibitively expensive for a single attacker to conduct an attack. Similarly, groups of attacks could face coordination issues and lack the incentive to act maliciously, as this would lead users to abandon the network. Nevertheless, the concentration levels depicted above raise questions about the extent to which the network is decentralised and attack-resistant.

Public-key cryptography

Since Bitcoin launched in 2009, millions of transactions have been added to the network’s ledger. The main transactional information contained in each block can be depicted as follows:

Public-key cryptography plays a crucial role in the transactional process. Each party to a transaction can be identified by reference to a unique string of characters known as a blockchain address. This address is similar to a bank account number that allows users to send and receive BTC in a pseudonymous manner (without sharing their personal details). Users can generate addresses in a costless manner by using Bitcoin-compatible software. Apart from creating an address, this process will also generate a private key and a public key for that address. Each of these keys also comprises a unique string of characters that is mathematically related to the other (and to the address).

A private key can be thought of as a password that enables users to sign off transfers of BTC from the corresponding address. Each time a transfer is made, the software will enter the private key into a signing algorithm to produce a transaction-specific signature. This signature will then be embedded into the transaction message itself, along with the user’s public key. The nodes in the network can use this public key and the verification algorithm to confirm that the signature was produced by the user’s private key. Importantly, the algorithm does not reveal the private key itself and each signature can only be used once. This mechanism is designed to ensure that only the private key-holder can authorise the expenditure of those funds.

Source: CryptoCompare

BTC: A collection of inputs and outputs

Let’s take a closer look at how a Bitcoin transaction works under the hood. When you send BTC to another address, you are not really sending anything directly to the other person. Instead, your wallet is reassigning the ownership of BTC from one address to another by adding a transaction to the ledger.

Unlike credit in a bank account, BTC is not fully fungible. Consider the following scenario. You generate a new address using the wallet software and send 3 BTC to this new address. In addition, Alice sends 0.2 BTC and 0.01 BTC to your new address in two different transactions.

These transactions will be confirmed once they are registered within a new block. At this point, your wallet software will conveniently report that your balance is 3.21 BTC. However, if you were to virtually peek into the wallet, you would observe three distinct amounts that are grouped together by reference to their previous transaction — the BTC received do not mix.

The amounts that you received via those three transactions are called outputs, or more formally, Unspent Transaction (Tx) Outputs (UTXOs). Each of these UTXOs are waiting to be spent and will remain locked until you provide them as inputs for a new transaction.

Let’s say that you now decide to send 0.15 BTC from your wallet to Bob’s address. Your wallet software would use the 0.2 BTC as an input for your transaction, as this is closest to the sum you wish to send. The transaction will send 0.15 BTC to Bob, which will now reside in Bob’s wallet as an output. In addition, it will create 0.05 BTC in change, which will be sent back to your wallet as an output too.

Source: CryptoCoinsNews

The UTXOs system prevents users from spending the same amount of BTC more than once. Once an output is spent, it is destroyed and a corresponding set of inputs will be created. Once a set of UTXOs has been destroyed, it can no longer be used as an input for a transaction. Equally, you cannot send BTC which you have not previously received as an output from a prior transaction.

Note: As an exception, a coinbase transaction has no inputs (only outputs). However, UTXOs will be used to pay transactions fees (not depicted above). More than one set of UTXOs can be sent in a single transaction. Technically, you receive BTC to an address and send BTC from your wallet (which contains the collection of private keys that correspond to your addresses).

The Merkle tree data structure: hashes of hashes

In the Bitcoin network, a transaction is a merely a string of bits that carries a message. Amongst other data, this message will contain (i) the address of the sender and recipient, (ii) the UTXOs to be spent, (iii) the sender’s public key, and (iv) the transaction-specific signature. Apart from incorporating this transaction into a block, a miner will hash the transaction and store this in a data structure known as a Merkle tree (named after its creator).

A Merkle tree is a hierarchical data structure that is composed solely of hashes and is also stored in a block. Once an individual transaction has been hashed, the new hash values will be grouped in two and hashed again. This process will be repeated until a final hash value is obtained — the Merkle root.

Transactions are stored separately inside the block too. Source: Ghoshal & Paul

The Merkle tree data structure is useful for two reasons. First, it maintains the integrity of the transactional data. If any transactions are altered, the Merkle root will change and the other nodes will dismiss this version of the block. Second, it enables nodes to use a method called simple payment verification (SPV) to check whether a particular transaction has been included within a block without having to store all of its contents. These nodes are referred to as light nodes, as opposed to full nodes that store the entire blockchain.

Source: Mastering Bitcoin

If a node wants to verify whether Transaction K has been included in a block, it starts by hashing the relevant transaction (in green). If this hash is found in the tree, the node will work its way up until it reaches the Merkle root or encounters a disparity. The data that the node needs to retrieve to complete this process is coloured in blue. The blue dashes indicate the data that the node can generate itself, while the remaining data can be discarded. Wallets tend to be light nodes, as they download only block headers and use this process to verify whether a user’s transactions have been confirmed.

Lesson recap

It may take some time to digest all of the elements that we covered in this lesson. The following diagrams provide a detailed overview of how these different elements serve an important function in the Bitcoin network.

Overview of the transaction life cycle:

Source: Bambora. A more comprehensive version of this diagram can be found here

Components of a Bitcoin block:

Source: Bits on blocks

The images above are each taken from a larger infographic. Please click on their respective links to browse these infographics in their entirety — they are the optimal resources for you to consolidate on the material covered.

Exercises

  1. Check out the BTC transactions that taking place in real time with Bitcoin Ticker and BitBonkers.
  2. Browse a recent Bitcoin block using this block explorer:

3. Access a wallet provider to create a Bitcoin address (no need to buy BTC):

Note: somewhat confusingly, “Blockchain” is the trading name of a popular Bitcoin wallet provider.

4. Enter your Bitcoin address into the block explorer — your balance should show up a zero, but feel free to take a peek at other users’ addresses too ;)

Extend your knowledge

We have curated a set of articles for you to consolidate and expand on the material we covered in this lesson. Please make an effort to go through these!

Watch the following in-depth video to consolidate your knowledge:

In Lesson 3, we focus on the Ethereum network and smart contracts. As always, don’t forget to join the discussion on our Telegram group!

--

--