Citadel School — From Zero to Bitcoin


Citadel School — From Zero to Bitcoin

This article will discuss all levels of bitcoin from non-technical to technical from basic to complex- starting from absolute zero. It will be as all encompassing as possible but will be limited by the author’s understanding. Feel free to skip sections that you already know since all basics will attempt to be outlined. It will be constantly updated and added to in order to provide as succinct an explanation as possible.

1. The Ledger

Bitcoin has a single ledger, a record of every transaction that has ever been made. For instance, JP Morgan & Chase Bank keeps its own ledger which consists of dollar values in depositor accounts, in order to keep track of who possess how much money. Their ledger is private and not spread out among many individuals, therefore it is centralized. Chase has centralized ownership over their ledger, they can change it at will and they are the sole entity that control is. In fact, anyone else who tries to modify it is prohibited from doing so. Unlike Chase’s centralized ledger, bitcoin’s ledger is distributed among many peers and is therefore decentralized. The ledger consists of a blockchain and any willing participant can download it, even you. Download the bitcoin core software in order to begin downloading the entire ledger. A full node is a computer that has a copy of the entire blockchain and is constantly updating it. Having a full node is not a prerequisite to owning bitcoin. This is sort of the fundamental truth to bitcoin- that the ledger is fully transparent and anyone can download it / view it. It’s how we know everyone is playing by the rules and being honest. There can be no cooking the books.

2. The Bitcoin Ledger is Like DNA

A metaphor that I like to use compares the bitcoin ledger to DNA. A single DNA molecule contains all of the instructions needed to create your body and sustain it. The DNA is replicated and spread throughout your body in order to protect the information that it holds. If there are as many copies as possible, there is less risk of the information (contained in the DNA) being destroyed or nefariously manipulated. The bitcoin ledger is similar. If an entity wants to destroy or tamper with the bitcoin ledger, they would have to destroy every possible copy on the network. The easiest way to destroy the bitcoin ledger would be to destroy the earth, any other method would be significantly more difficult.

3. Peer-to-Peer

The bitcoin network is a peer-to-peer network, which means there is no central authority. Each user has the potential of dealing with any other user, eliminating the need for a leader / coordinator. We will look at the BitTorrent file distribution system in order to better understand what a peer-to-peer network is. When downloading a file through the BitTorrent file distribution system, you are downloading from many different people who have the file that you want. While you are downloading the file, you are also uploading parts that you already have to others who are trying to download it. Peer-to-peer networks are used because they scale better than client-server networks. In the latter the server upload speed is the bottleneck, and assuming a sufficient quantity of clients, it can be very slow at transmitting data. For example: say Microsoft has an upload rate of 50 megabytes per second. If 5 people are trying to download a file from them, each person will download at a rate of 10 megabytes per second (assuming each person’s download rate is that high). However if there are 1000 people trying to download that file then each person will only download at 0.05 megabytes per second because Microsoft’s upload rate is split among so many users. If every user is uploading to each other in a peer-to-peer network then it can scale to infinite users without problem.

4. Blockchain Intro

The bitcoin ledger, as stated previously, is a blockchain. Quite literally a chain of blocks linked one to another.

Roughly every ten minutes a new block is added onto the chain. Each block has a size capacity of 1 megabyte. A block is like a container which holds transaction data. Each block contains roughly 1609 transactions. As of writing this there are 649653 blocks on the bitcoin blockchain. How does a block get added to the chain and who chooses which transactions will go in the next block?

5. The Miners Intro

A bitcoin mining node is a full node that also expends energy (work) securing the network. They can be viewed as transaction processors. To illustrate what a miner does let’s have an imaginary miner called Anton. Anton has a chance of creating the next block. If he succeeds in doing so he is rewarded with bitcoin, this is know as the block reward. He will take transactions from the mempool (the backlog of pending transactions) and place them into the block to be validated.

This process requires a lot of work, ie: electricity and computing hardware. Mining for profit requires powerful computers that attempt to solve difficult algorithms, when they do solve one, they get to create a block and are rewarded for it. Miner’s that successfully solve the algorithm are rewarded with bitcoin, but a majority of their revenue goes towards electricity costs and future hardware acquisition.

It’s not possible to make profit from using a normal computer because the electricity / computational ratio is not efficient enough. Application-Specific Integrated Circuit (ASIC) are computers that are only good at doing one thing, solving the bitcoin mining algorithm. Since they are so specialized, they easily outperform any generalized hardware such as a personal computer. However on a software level, anyone can download the mining software and participate in the network as a miner.

6. The Protocol Intro

IE: How transactions are made, what transactions are allowed, and who can make them. The bitcoin protocol consists of rules that are enforced on the network to ensure the integrity of transactions and monetary supply. The full nodes enforce protocol rules in addition to having a copy of the entire blockchain. If a nefarious miner tries to break these rules they will be forked off of the network and their blocks deemed invalid. More detail on this below.

7. Proof of Work

Bitcoin uses a consensus mechanism know as proof of work. Think of it like voting power, but instead of every person having a vote, the more computing power you have, the larger the weight of your vote. The idea is to have enough computers on the network, thus high computing power (known as hashing power in regards to mining), that a single person is incapable of having a majority of the voting power.

Example: Fork

Let’s say our blockchain is on block 3 and two miners create a block 4 at the same time. Now there are two block 4s.

Miner A most likely put different transactions into his block 4 than Miner B did. Therefore there are two different block 4s. So now we essentially have 2 blockchains. The first block chain consisting of blocks 1–4(but with Miner A’s 4th block) and the second chain consisting of blocks 1–4 (but with Miner B’s 4th block. The bitcoin network cannot consist of two chains, only one of them will win and be the real chain. The longest chain will be the valid chain as per the protocol rules, so whichever chain has block 5 added onto it first will be selected as the valid chain. This is the proof of work mechanism in play.

Imagine for a second that Miner A and Miner B are the only two miners. Whichever miner is faster at producing blocks (has more hashpower) will be the one that produces the 5th block and has the longest chain.

Miner B began to work on block five (indicated by the dotted line), however he was not able to solve it before Miner A.

If Miner A has 51% or more of the hashpower, he will most likely produce block 5 before Miner B. Therefore, according to proof of work, as illustrated in this section, whoever has 51% or more of the hashpower has an advantage in terms of creating the longest chain, aka: the valid chain. Suppose instead of using Miner B, we used all of the miners on the network in his place. Now we have Miner A, and the rest of the miners.

The same would still hold true: If Miner A has 51% or more of the hashpower, then he will most likely produce the longest chain, and therefore adding his block to the chain and still having it be valid.

Let’s say Miner A is a nefarious miner. He saw Miner B add block 4 to the block chain:

Miner B is now trying to add block 5 to the block chain, but he has not succeeded in solving it yet. This is indicated by the dotted blue line. Miner A wants to subvert Miner B’s blue block 4. Miner A thinks to himself that if he creates his own block 4 and his own block 5 before Miner B can finish the blue block 5, then Miner A’s chain will be the longest and therefore the valid one and he will get to choose which transactions go into his own block 4 and 5.

If Miner A has more hashrate than Miner B (51% or more), and both block 4s were created in a relatively close time frame, then Miner A will most likely create the green block 5 before Miner B creates the blue block 5. This would nullify (throw out) the transactions that were in the blue block 4 even after the blue block 4 was confirmed.

Even though the blue block 4 was confirmed, it now belongs to the shorter chain, and the longest chain is always considered to be the valid one.

This is an attack vector where Miner A can double spend a transaction. Let’s look at it in greater detail:

Miner A has 51% or more of the hashpower. Miner A sends 100 bitcoin to Alice and that transaction is placed into block 4 by Miner B. It’s validated and added to the blockchain. Alice sees that the transaction has been confirmed so she pays Miner A $1,000,000 for the 100 bitcoin she has received from Miner A. Miner A creates his own 4th block (the green one) on top of the third block, and he also creates his 5th block (green) before Miner B can create his own 5th block (blue). Since Miner A’s chain is the longest chain, everyone adopts it as being the valid chain. The bitcoin network no longer recognizes the bitcoin transaction that Miner A made to Alice. Now Miner A still has the $1,000,000 in cash and still has his 100 bitcoin. This is called a double spend attack because Miner A can spend his bitcoin again. This scenario is what we don’t want to happen, but thankfully achieving 51% of the hashpower is virtually impossible to do and to sustain over a long period of time. Currently the bitcoin network consumes energy equivalent to the country of Denmark. It would be too expensive to buy the hardware and electricity for such an undertaking. The profit from the attack would not justify the cost incurred to commit it.

When dealing with very large sums of money, the recipient of the bitcoin usually waits many days to ensure that the transaction block cannot be reversed. In the above example we saw how someone could reverse one block by having 51% of the hashpower, but to reverse 144 blocks (the amount of blocks generated in a single day) would require far more than 51% of the hashpower. If one wanted to erase a block 144 blocks ago, they would have to produce 144 new blocks before anyone else could produce 1. To create 144 blocks in a row would require basically 99% of the hashpower. And that would only reverse a days worth of transactions.

Let’s look at a slightly different situation. Miner A and Miner B are still the only miners on the network. And Miner A wants to change block 5, but now Miner B’s chain has blocks all the way up to block 7 in the confirmed state. In this case Miner A has to mine blocks 5, 6, 7, and 8 before Miner B can mine block 8. Essentially Miner A must have 4 times the hashpower that Miner B has in order to produce 4 blocks to his 1 block.

Current mining pools operating on the bitcoin network over the last seven days. source

This chart above implies that will create a block 17.4% of the time. There are 144 blocks per day, so we can expect to create roughly 25 blocks per day. There is only a 3.02% chance that will create 2 blocks in a row, the percent chance dramatically decreasing as target blocks in a row increase.

8. The Hardest Money to Exist

The most important aspect of bitcoin to many of its holders, is the fact that there will never be more than 21 million bitcoin. When Satoshi Nakamoto designed the bitcoin protocol he had a very specific issuance schedule that was and is set in stone. In the beginning miners were awarded with 50 bitcoin after they solved a block. (Every ten minutes a miner has a chance to solve a block, and their success in doing so is directly correlated to what percent of the total network hashpower they possess. If I have 20% of all the mining hashpower on the network, then I have a 20% chance, every 10 minutes, to successfully create a block and get rewarded for doing so.) Satoshi Nakamoto set the issuance to decrease by half every four years, a term that has been coined as “halving”. The first having was in 2012 when the issuance, per block, decreased from 50 bitcoin to 25 bitcoin. The most recent halving occurred in May of 2020 where the block subsidy dropped from 12.5 bitcoin per block to only 6.25 per block. Satoshi Nakamoto understood that this abrupt drop in issuance would create a supply shock which would further create speculation bubbles and therefore more awareness of bitcoin every four years. He believed the supply shock and speculation bubbles would create a positive feedback loop.

As we can see, the black line indicates the total supply of bitcoin, which is logarithmic. The yellow line indicates the slow and gradual drop of the supply every four years. Satoshi Nakamoto designed it so that the rate of issuance would continue to cut in half, every four years, until the year 2140.

Many consider bitcoin to be “digital gold” so let’s make some comparisons between the two:

The gold supply, while generally known, is not exactly known whereas the bitcoin supply is perfectly known and can be audited by any individual. We also know exactly how much bitcoin is being created per time frame. Gold’s issuance rate depends on its price. When the price of gold increases, gold mining companies can afford to spend more money mining for gold, thereby increasing the issuance rate. The increased supply hits the market causing the price to decrease and reach an equilibrium. With bitcoin, the issuance rate is static. It’s independent of all other variables, including the price of bitcoin, and it’s decreasing by 50% every four years.

Bitcoin is able to encapsulate perfect scarcity which is not possible with any material good. We don’t know how much gold is in the earth or in the sea. We don’t know how far off we are from being able to mine gold from asteroids as per the plan of Elon Musk. But we can know with mathematical certainty, all aspects of the bitcoin supply, and we can plan accordingly by knowing the exact inflation schedule. These qualities make bitcoin the hardest deflationary money with the highest wealth preserving capacity.

9. An Army of Full Nodes

Full nodes protect the integrity of the bitcoin protocol by thwarting attacks from miners who hold a majority of the hashpower. Without full node representation, a miner with 51% or more of the hashpower would be able to do a lot more damage than just double spend attacks. They would be able to change all the protocol rules.

Thankfully, full nodes prevent this by maintaining the honest chain and recognizing when a nefarious miner has forked off the network, creating their own chain.

When Miner A changes the protocol rules to, say, increase the issuance rate to 1,000,000 bitcoin per block, the full nodes will immediately recognize his chain as invalid and they will not add his block to their own copy of the blockchain, thus preserving the “honest” chain.

10. Encryption as the Chain

Why can we not remove a block and replace it with a different one in the blockchain? Each block requires the hash of the previous block to work. First we will go over what encryption and hashing are:

If I take my name, Andrew, and encrypt it using a sha256 algorithm (using a simple tool here) it will output: c10873196eb1124ed74461c20a67094e395f2310f6305607b9694ee6b1ee8b43

It would be impossible to come up with that same output (hash) using a different word. Similarly, bitcoin blocks are just a really long string of text which can be hashed.

We could play a game where I would encrypt my name, give it to you, and then you add your name to my hash. We could do this with a chain of people. Let our chain be: Andrew, Alice, Bob.

We hash Andrew to yield: c10873196eb1124ed74461c20a67094e395f2310f6305607b9694ee6b1ee8b43

Now Alice can take my output and add her name to the end of it:


which would yield:


Now Bob can take that output and add his name to the end of it:


which would yield:


If we were to tamper with any of the names: Andrew, Alice, or Bob, the result would not be the same. If we were to switch even two names: Alice, Andrew, Bob, it would still not be the same. Having the final hash ensures that the names and order must be exact and uncompromising.

If we wanted to modify Alice to Alex it would look like:

Notice there is a different hash for Alex.

Hash: b43aa9436cba75718a089b0e310313502d3ee2e118988610cab4528677bafa1f

If we were to add Bob to this hash and hash it again we would get:

This is a completely different hash than what appeared when the chain was Andrew, Alice, Bob. There is no way to have the old final hash if we change Alice to Alex. Now the result is completely different.

The same things are true with the bitcoin blockchain. If you were to modify a previous block, the current hash would be different and everyone would immediately recognize it as an invalid chain. The only way to make this work is if you modified a block, then mined every block on top of it again as we saw in the previous examples with Miner A and Miner B. We can hash blocks in the same manner that we hashed Andrew, Alice, Bob:

Instead of adding just the name of the block like we did in the previous example, the transaction data inside of each block would be added to the previous hash. If anyone tried to tamper with any of the data inside block 2, it would produce a different hash and therefore could not be linked to block 3. Block 3 would have to mined again taking into consideration the new hash of block 2. So all of the blocks on top of the modified block would have to be hashed again, which is virtually impossible.

11. Block Size Debate

The block size debate came to a head in 2017 when the chain forked into two: the original bitcoin chain and the new bitcoin cash chain. Since only one block is added to the chain every ten minutes and each block cannot be larger than 1 megabyte that means that only 1609 transactions, maximum, can be processed every ten minutes. This limited amount of transactions has become a bottleneck for the bitcoin network in that there are more people who want to transact than there are available space to be written to the chain. Since block space is a scarce resource, transaction fees occur because some people want to get their transaction processed faster than others, which leads to a bidding on block space. It’s sort of like a tip to the miners. A miner is more likely to include your transaction in their block if you tip them more than the next person. As of writing, the fee is about $1.40 per transaction, which may seem like a lot, but considering you can move billions of dollars in one transaction and have the transaction confirm in a matter of 30 minutes to an hour with high security, it’s pretty cheap.

During the block size debate there was a group of people who wanted to increase the block limit from 1 megabyte, thereby allowing more transactions to be processed every ten minutes which lowers the cost of transaction fees as block space supply increases. Everything that is written on the blockchain is permanent and it wouldn’t be a good situation if the entire blockchain were 100 Terabytes big. The beauty of bitcoin is that anyone can audit it by running their own full node. Currently running a full node, which contains the entire blockchain, takes up about 300 gigabytes of space. If it were to grow very large, regular, everyday users would not be able to audit the bitcoin network on their own.

A majority of the bitcoin network decided to stick with the 1 megabyte block to ensure a healthy future for the chain. Since then the community has really hardened its opinions and has become extremely conservative, resisting any changes to the protocol. The philosophy is that if we are to have a decentralized money, it should be as conservative and safe as possible. We cannot risk disaster when dealing with a market cap of $200 billion and a potential one of much higher.

12. Difficulty Adjustment

The stronger the miner is, the faster it creates blocks, so what's to prevent everyone from upgrading their hardware and mining a block every 1 minute? The difficulty adjustment algorithm is in place to ensure that 10 minute block times being met (within a margin of error). When all the miners dramatically increase their hashpower to the point where blocks are being solved quickly, the difficulty adjustment algorithm will increase the mining difficulty making it harder to mine therefore slower to solve blocks. The difficulty adjustment is scheduled to happen roughly once every two weeks, or more literally, every 2016 blocks. If all the miners are mining faster than usual (due to everyone upgrading hardware at the same time, for instance) then the difficulty adjustment after the 2016 block period will be reach quicker than two weeks. Similarly, if there is a decrease in overall hashpower (due to halving event where the miners are suddenly making half the revenue they did previously) then blocks will be mined slower, therefore, it will take longer than 2 weeks to reach the 2016 block difficulty adjustment.

Also, Read

Get Best Software Deals Directly In Your Inbox

Citadel School — From Zero to Bitcoin was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story.