Ledgers
Let’s start by understanding the concept of a ledger. Ledgers have been used for thousands of years to keep track of accounts and transactions. Whether it was the production of barley in Mesopotamia or the ownership of property.
A ledger essentially logs transactions along with other details such as amount, the date, and the person who authorized it (a signature). So there were some basic security mechanisms in place. For example, ink cannot be easily replaced, pages and entries were chronological and numbered so new entries couldn’t be faked.
For years ledgers were books kept in trustworthy locations held by a trustworthy person. You essentially trust the owner of the ledger to not cheat or add fake entries or tear out pages. So there are some terms here to keep a good ledger. A signature to verify transactions were real and trust in who keeps the ledger. This is not too different from our current system today.
Banks
As I tap to pay for groceries, the terminal detects a unique code on my card and sends that information to their bank. The bank uses the VISA network to talk to my bank, CIBC. CIBC checks their ledger to confirm that I have funds to pay. Then my bank sends confirmation back via the VISA network to the store's bank. The terminal finally confirms at the grocery store that everything is all good and I get to leave with my groceries.
Each bank keeps a general ledger for every one of their customers. You see glimpses of this when you get your account statements every month. Your ledger essentially says that you deposited some money to open your account. Then you tap to pay for dinner. So the bank checks your record to confirm you have enough funds, and adds a record saying that you paid that money to the restaurant. Meaning some money moved from your account to theirs. And this gets tracked on the ledger.
Then someone pays you back for covering dinner, so a certain amount of money is moved from their account to yours. Then say you want to buy some dessert so you tap again but this time the bank sees that your balance is not enough so the transaction is denied.
As the owner of the account you are signing these transactions by using your card. Which in this case functions as a password of sorts. The same way your password functions in online banking. We think of this as bills exchanging hands as physical money moving from one account to the other.
In this day and age, there is no physical money involved. There are no bills moving from an account to another. There is just a huge ledger that’s keeping track of everything. Numbers being added and subtracted from accounts.
Your bank's ledger is what’s called a centralized ledger. They own it, they are the only ones who can make changes to it and it’s their job to maintain it and make sure it is not tampered with or deleted. You essentially trust the bank to keep a good track of that ledger.
However, they have full control of the ledger so there is a remote possibility that the bank could make a mistake or even shut down.
Bitcoin
Bitcoin was conceptualized by an anonymous person who uses Satoshi Nakomoto as a pseudonym. They brought together a bunch of concepts and technologies to write a whitepaper that was published in 2009. This was in the middle of the real estate market crash so it rode a wave of mistrust in the banking system.
This proposed cryptocurrency offered theoretical solutions to many problems in centralized banking. The fees to send money and accept payments, the trust problem with banks and even the central banks ability to print new money based on political decisions.
Bitcoin as a currency that can be used to pay for things is built on top of a blockchain. A blockchain is essentially a ledger, similar to the one a bank keeps.
The Bitcoin ledger doesn’t depend on a single entity or server. It’s not a book, it is distributed. It was designed as a way for multiple computers to work together, each one with a stored copy of the ledger with a creative and super secure system to ensure that none of the transactions could be tampered with.
This ledger isn’t a list of transactions, instead it is divided into blocks. Which is a really smart way Satoshi figured out to allow this thing to work.
Blockchain
Each block contains a batch of transactions. Whenever you send money to someone using the blockchain, what you are essentially doing is adding an entry to the ledger. Saying that a certain value moved from one account to the other.
In traditional banking, the bank itself is the only entity that can add to the ledger. In the blockchain, anyone can add transactions and therefore is open. The technology uses an incredibly secure system to make sure transactions are real.
So in a blockchain transactions are grouped into blocks. On Bitcoin specifically each block is about 1MB in size, which means it can store about 2400 transactions. Just like your credit card transaction, in order for a transaction to be valid the origin account needs to have enough funds and the record needs to be signed by the owner of the account to verify that it’s real.
As transactions are made between accounts they are broadcasted to all computers in the network. Each one of them begins grouping them into a new block.
Block Creation
Let’s see how a new block is created. The first thing the computers do is get the code of the last block in the network. That way we know we are linked in between each other, linked to that last block. This gives us a chain. As transactions are seen by computers on the network they begin listing them inside this incomplete block. Once the block is finished they send it to the rest of the network, so instead of pointing to the previous block, they point to this new latest block.
If creating a block was easy different computers could create multiple blocks at the same time, broadcast them and the blockchain would fork. There would be no way to see which fork to follow. By design, creating a new block must be hard. Just like each transaction needs to be verified by the sender of the money. Each block must be verified by the creator. Creating a block needs to be deliberately hard so that only one block is created at a time.
Proof of Work
On Bitcoin, this is done with a system called proof of work. As the incomplete block begins filling up with transactions, the computer creating the block automatically tries to solve a puzzle. This is where cryptography comes in. What the network wants from any computer in the network is to go through a lot of work to create a block. But we don’t want every computer to go through that work to check if a block is valid.
Because of this a cryptography function called SHA256 is used. This is being used all throughout the internet and your browser is likely using it now to read this blog post. Technically, it’s called a hash function. If you took the information in this incomplete block, everything inside it, the number of the block behind it, every transaction and you run it through a SHA256 formula a number will come up.
This number is extremely unpredictable and looks random. It’s made up of 1s and 0s and is 256 characters long. Changing any value in the block will produce a new number, not just one digit different but all 256 digits are different. Since this number is so unpredictable, changing something would create billions if not trillions of possibilities. Really advanced math, but very easy to calculate for a computer.
In order to create a block and prove it wasn’t easy, the computer creating the block needs to find a way that the result of this operation starts with thirty 0s, that is attaching a number at the end of the date so that the result of the SHA starts with thirty 0s.
Here’s the trick: there is nothing you can do to calculate that number in reverse. We can know the formula of the SHA256, but it cannot be reverse engineered. No one has solved it and it’s likely anyone will anytime soon.
The only way to find this number is to try one then another and another until one of the results gives you thirty 0s. On average, you will have to test a billion numbers to get a result. This is a lot of work, even for computers. There are so many unpredictable options that getting the number right is almost like winning the lottery. A computer should take a few minutes to solve this puzzle.
Now, why would anyone burn out their computer to log transactions, try random numbers to find a random number to complete this formula? Because when you create a block, you create money for yourself.
Putting it all together
So a new block has been created. But remember this is a ledger. The ledger records transactions between accounts. It is not a money printer. So if all these accounts are zero. Where do the values that populate the accounts come from? If you create a transaction from an empty account or if you just add money to an account it’ll get rejected.
Except for one, the creator of a block gets to add a reward for themselves. They get to create new coins in the supply of coins in the network. This reward is the reason why this is called mining. The computer is performing this repetitive task of finding a special number in exchange for this reward.
Once the block is created it gets broadcast to the network. Once half of the computers in the network adopt it and add it to their own copy of the blockchain and start mining the next block, the original block is considered confirmed and unchangeable.
Each block contains the hash of the previous block, if someone tried to change something in a block made days ago it would mean that the hash of this block would change. Which would change the hash of the next block, and the next. All blocks would need to be recalculated. That is the main reason the blockchain is such a trustworthy way to store data.
Future Consideration of Proof of Work
Satoshi predicted that as the network grew a lot more people and advanced computers would join and start calculating this puzzle at the same time. As the network grows bigger, the difficulty needs to grow as well. It is adjusted automatically by changing the number of 0s required on the proof of work. The more 0s, the harder it is to find the number that works.
Another important difference is that the amount of coins that get created is limited. The ledger started with a balance of 0 for everyone. For the first few blocks the reward for solving the puzzle was 50 bitcoin. Every coin in circulation today was created this way. Mined by a miner, then sold to someone else.
You can actually go and look at the first block of the blockchain here: https://www.blockchain.com/btc/block/0. It has no transactions, it points to the previous block which is block 0 and it had a 50 BTC award for the miner who found it.
The reward for finding a block decreases with time. Right now it’s at 6.25 BTC. This means that by 2140 all bitcoins allowed will be mined and no new ones will be created. Inflation will not be possible. The supply is limited to 21 million coins.
At the very beginning no one would pay anything for a unit of this. Someone decided to put a computer to mine for nothing. Numbers on a screen, or technically numbers in a ledger.
As people began trusting the system, they began assigning value to the numbers in that ledger. Real world value. Dollar value to having an account number with Bitcoin.
This was cents on the dollar a couple years ago, but now a Bitcoin is worth north of 60 thousand dollars.
The Future
This post is not about Bitcoin, it’s about blockchain. That is the most important part of this whole mess. Just as a currency Bitcoin was the first to get popular. There are completely different blockchains with a different ledger, their own rules and different algorithms. The fact that people adopted and used Bitcoin opened a whole new world of developers and cryptographers to put their computers to mine or develop applications on top of the blockchain. They’ve also invented new variations of the technology that could be put to other uses. Two fantastic examples are smart contracts and NFTs.
I hope this post has taught you more about how the blockchain works and gets you excited for the future that will come from this.