Blocks All the Way Down
The blockchain will go down in history as one of the most important innovations in history.
Happy Saturday, everyone! I hope all of you have had a good week. For me, it’s been quite productive in terms of my Web3 journey. I’ve bought some more NFTs and have even begun staking some Solana to earn that sweet, sweet crypto cash.
It’s been a productive week for crypto on the whole, too. Bitcoin passed its all-time high (again), and Ether got pretty darn close.
BTC all-time high: $66,999.00 on 20 Oct, 2021 (via Coinbase)
Ether all-time high: $4,384.43 on 11 May, 2021 (via Coinbase)
It’s been a crazy past few weeks, to say the least.
But I digress. Last week, we talked about what NFTs are and how they can be used. My sibling and I also experimented with a podcast version of the newsletter, which kind of flopped? Apple Podcasts doesn’t seem to like the Substack RSS feed and ended up making the podcast a private feed only accessible with an appropriate link.
I still want to do a podcast version of CryptoCurious, but will have to experiment with it further to get it right! If you have any ideas, suggestions, feedback, or anything, please reach out to me! I want to make the best publication possible and I take every piece of advice to heart.
And now, into the newsletter.
This week, I want to talk about blockchain. Probably the most important innovation of the 21st century, it’s the technology that powers the entire cryptoverse. The literal backbone of everything crypto.
But what is it? And how does it work?
Blocks All the Way Down
Uh, no. Not quite. In this context, a block is a device that records transactions on a network. When a transaction is initiated, it is sent to a network of nodes (computers) and requests validation. The computers all start working on validating that transaction by solving a complex math problem (using an algorithm, don’t worry).
To understand how that works, we need to talk a little bit about cryptography. I’ll do my best to keep it understandable, but this is fairly technical.
What are Hashes and Why Do They Matter?
Blockchains are built on cryptography. That’s why the money used is called cryptocurrency. A hash is a unique cryptographic signature for a piece of data and is what makes blockchains secure and immutable (non-changeable). But how does that work?
Bitcoin, the OG blockchain and cryptocurrency, uses the SHA256 hashing algorithm to mine and validate transactions and blocks. SHA256 is part of the SHA2 family of hashing functions published by the NSA in 2001. SHA stands for Secure Hashing Algorithm and is just that - incredibly secure.
Security note: several hashing algorithms like the MD5 have been thoroughly broken and should not be used to verify anything.
SHA256 has been broken by a small number of organizations, but from everything I can find, it still requires a lot of computing power to achieve.
At a high level, SHA256 works by taking any piece of data - from a string like ‘abc’ to an entire database - and uses the unique aspects of every byte of data to produce a perfectly unique number. That number can be recreated every single time, but only if the data is the same every time. One small change and the number becomes totally different. Let’s look at some examples.
Here, I use andersbrownworth.com to test out the SHA256 hashing function. I put the string ‘abc’ and it produces a very large hexadecimal (base 16) number:
abc hash → ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
ab hash → fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603
Notice how changing a single letter produces a very different hash?
This is universal. If you were to calculate the hashes of those strings, you’d get the same value. And no matter how hard you tried (unless you had a massive supercomputer), you wouldn’t be able to recreate the same hash with any other combination of data. What about blockchain applications?
Mining Blocks: Nonces and Difficulty
On the same webpage as above, there’s an example block miner. You enter the data in the block and ‘mine’ it to find a specific enough hash that the block is now solved and anyone else on the network can verify it.
Here I have an example of it:
This is an empty block. It’s colored green because it’s been ‘solved’ (more on that later). Now, if we enter some fake transaction data, what will it do?
I’ve entered some example transactions using some names and values I just randomly came up with. Notice how the nonce is the same (72608), but the block hash is different. The block itself is also red, meaning it hasn’t been solved. Let’s fix that.
There we go! Our block has been mined and now has a nonce of 107218.
Have you noticed the difference between the solved and unsolved blocks? The solved blocks’ hashes start with four zeros. That’s what’s known as the difficulty level.
When mining, the miners (also referred to as nodes or validators) are given a difficulty level of a certain number of zeros. In this case, that number is 4. For our block to be considered solved, the block’s hash must start with 4 zeros. Because we can’t manufacture hashes, the miners must keep working to find a nonce that will produce any hash that starts with that number of zeros.
If that’s not super clear, don’t worry. As I said earlier, it can get really technical. Why don’t we look at a real-world example?
As of the time of this writing, the most recent Bitcoin block mined was #706,353. If you want, you can see the details of that block here. The hash of the block was 0x00000000000000000004034fd41a4c6bc4fda0b99cc0b313bf6268b5f7376f64, or 19 zeros of difficulty! 🤯
The nonce was 1,638,967,068.
Quick sidebar: the 0x preceding the hash is just to denote that the number is in hexadecimal
Now I should probably explain what a nonce is. When I say nonce, I’m referring to the cryptographic definition. In cryptography, a nonce is a fairly random number only to be used a single time. When used in a blockchain context, that’s the number used to find the hash with the appropriate number of zeros to solve a block.
Now that we’ve talked about the ‘block’ in ‘blockchain’, what about the ‘chain’ part?
The Chain
If you look back at the picture of the mined block, you’ll see that it has a block number. The real brilliance of the blockchain is that it’s a chain of an ever-increasing number of blocks. Whenever a new one is solved, the network starts working on the next one with a new set of transactions.
Going back to the blockchain demo website, you can play with this idea too!
Notice in the picture that each block uses the hash of the block before it. This is what chains each block together. Each time a new block is mined, part of the input is the hash value of the previous block. If you’ll remember the earlier example of hashing simple strings, a small change in the input produces a very different output. When you hear people saying that the blockchain is immutable, this is what they mean.
Technically, changing data in a block is possible, but doing so invalidates all following blocks because the hash value is now completely different and every single block now needs to be mined over again. Let’s see what it looks like.
Here, I added the same first transaction from the first block example. You can see that each following block is now invalid. Let’s fix that (and add some new transactions).
There we go! Each block has now been solved using the previous block’s hash. This is now our ledger (or collection of recorded transactions). After each one has been mined, it cannot be reversed. Otherwise, the entire chain becomes invalid.
But there’s one problem with our blockchain: there’s only one person validating transactions. If I wanted, I could change anything and would be able to spend as much time as I needed to validate the rest of the chain. If I wanted all the Bitcoin in the world, I could say that everyone’s Bitcoin goes to me and no one could tell me otherwise. That is known as centralization. There is a central entity making all the decisions.
Decentralization
Conversely, decentralization is when 2 or more entities are voting on the state of the network. This is where the nodes come in. For the Bitcoin network, miners mine new blocks, broadcast the answer out to the rest of the miners, and they verify the answer is correct.
When a network is decentralized, it relies on a pure majority-rules model to make decisions. If someone wants to make a change to the network, they have to propose it to the rest of the nodes. The nodes then vote on the proposal and whatever the majority decides becomes the consensus. If two or more nodes that aren’t the majority decide on something together, they can fork from the primary network and create their own ‘spinoff’ blockchain that has the same history as the previous network, but with only one change.
This is what happened to Ethereum in 2016. A company built on the Ethereum blockchain was hacked and had millions of dollars worth of Ether stolen because of a bug in the company’s codebase. At the time, the company (called The DAO) held roughly 14% of all Ether in circulation.
The hack was so devastating that the founder of Ethereum, Vitalik Buterin, proposed forking the network to essentially delete the hack from the ledger. Most of the Ethereum community was on board and the fork passed, but a large subset of miners didn’t agree and continued mining the original chain.
This created two chains that still exist today. The hard fork, Ethereum, and the original, Ethereum Classic. Both versions of Ether are valid, even though Classic is far less valuable due to not being as popular.
Getting Paid
After talking about how hashing works, you might be wondering why nodes would sign up to mine blocks. They’re doing incredibly complex and computationally expensive calculations all the time. There’s not much time to take a break. This is why miners need to be paid.
For a node to verify a transaction, they need to download the data being created or changed so they can run their own hashing function and make sure the answer is correct. With transactions being made constantly, the total size of that data adds up fast.
If the miners didn’t get compensated for how much power they used running these functions, they would all quit. I mean, would you do that much work for free? It doesn’t matter how decentralized you can be if you don’t have anyone doing the work. So, instead of forcing miners to mine for free, blocks come with rewards to create an economic incentive for there to be as many miners as possible. The more there are, the more decentralized and secure the network is.
A simple yet effective example is, again, the Bitcoin network. Bitcoin was programmed so that only 21 million bitcoins can ever exist and those coins are given out to miners when they mine new blocks. So, every time a new block is mined, the miner that came to the correct answer first receives an allocation of new bitcoins. Currently, the rate of new bitcoins minted every block is 6.25 BTC. This rate gets cut in half every 210,000 blocks and will most likely end in 2140.
But what happens when all the bitcoins are in circulation?
This is where network fees come into play. Bitcoin does use transaction fees, but most of the reward is still in newly-minted coins. For example, the block I referenced earlier (706,353), had an additional reward to the miner of 0.11633354 BTC on top of the 6.25 brand-new coins. The total block reward for this miner was 6.36633354 BTC or $389,804.24 at an exchange rate of $61,229 per BTC. That’s a lot of money.
It’s incredibly expensive to get into Bitcoin mining, but very lucrative if you are willing to upfront the cost to get a competitive mining rig (just a super fancy and powerful computer).
To Finish Out…
Blockchain technology is insanely complicated. It’s also insanely cool. Because of its architecture, anyone can make any sort of transaction and not be worried about needing to keep track of receipts. Can you imagine how much easier it would be if you could just have information on a blockchain and not need to constantly verify it or worry about a hacker trying to steal your identity?
Because of crypto wallets (unique on-chain destinations that hold tokens and only the owners have access to), all of your information could be tied to you and you wouldn’t need to constantly reenter that information at places like doctor’s offices, websites, etc. Just connect your wallet and you’re logged in! It’s like the best password manager ever.
If you can’t tell, I get very excited about these things. Blockchains have enabled a brand new version of the internet where the power lies in the hands of us normal folks. That’s what decentralization does. No government or corporation controls a blockchain, but we do. What we do with our money governs where the future of society goes. Isn’t that cool?