What does it mean to have a Bitcoin?

What does it mean to have a Bitcoin?

What is a Bitcoin? According to the white paper released by a pseudonymous “Satoshi Nakamoto” in 2018, Bitcoin is “A purely peer-to-peer version of electronic cash that would allow online payments to be sent directly from one party to another without going through a financial institution”.

This electronic payment system by design would not be backed by any government or issuing system, and there would not be any banks to manage accounts or verify transactions. It would be decentralized and entirely peer-to-peer-based.

In this article, we are going to walk through how you might have invented your own version of bitcoin.

Introduction

Let’s say you want to keep track of payments made between you and your friends. You start with keeping a public, communal ledger that is accessible to everyone. Anyone can go and add new lines to the list of transactions.

The first issue that might arise is how do we ensure that Alice does not add a line saying “Bob pays Alice $10” without Bob’s approval. How do we trust that the transactions on the ledger are what the sender meant them to be?

Like an actual bank transaction, each sender can have a signature which they add to their transaction to prove that they have seen and approved the transaction. This signature should be infeasible for anyone else to forge.

How do digital signatures work?

Everyone generates what is called a public key/ private key pair. The private key is usually a secret that you want to keep to yourself. This private key is used to create a digital signature for each transaction.

Unlike a physical signature that is usually always the same for every transaction, the digital signature changes for different messages. Altering the message slightly completely changes what the signature on that message should look like.

Producing a signature involves a function that depends on the message and the private key. The private key ensures that only you can produce that signature. The fact that it also depends on the message means that no one can copy your signature and forge it on another message.

There is another function to verify that the signature is valid. This function requires the public key and tells us if the signature is produced by the private key associated with the public key being used for verification.

The idea of these two functions is that it should be completely infeasible to find a valid signature if you don’t know the private key. When you verify that a signature against a given message is valid, you can feel confident that the only way someone would have produced that message, is if someone knew the private key associated with the public key you used for verification.

Another loophole ensues. Even though one cannot forge the signature on a new message. There is the possibility of copying that same line many times since the message, signature combination remains valid. When you sign a transaction, the message has to contain a unique id associated with that transaction. So with that even if Bob pays Alice $100 many times, each one of those requires a completely new signature.

Ledger

Now we have established how we can secure and prevent fake transactions from being listed on the ledger. This brings us to the question, who controls the ledger? For our fictional currency, we would allow everyone to keep their own copy of the ledger.

When you want to make a transaction, you broadcast it into the world for people to record in their own ledger. This creates yet another problem. Since everyone has their own ledger, how do we get everyone to agree on what the right ledger is?

What method can we create to accept or reject transactions? In what order do we record transactions so that we can feel confident that anyone else in the world who is following that same method would have a ledger that looks the same as yours? This is the problem addressed in the original Bitcoin white paper.

The solution that bitcoin offers is to trust the ledger with the most computational work put into it. The tool used here is cryptographic hash functions. If you use computational work as a basis of what to trust you can make it so that fraudulent transactions and conflicting ledgers would require an infeasible amount of computation to bring about.

Hash Function

hash function.png

A hash function is any function that can be used to map data of arbitrary size to fixed-size values. The input is any message or file and the output is a string of bits with some kind of fixed length, for example, 256bits. The output is called the hash or digest of the message. It always gives the same output for a given input. But if you slightly change the input maybe editing one of the characters, the resulting output is completely random.

A cryptographic hash function is infeasible to compute in the reverse direction. So if given a random output and you are to find an input so that the hash of that input is equivalent to the output, you have no better method to find that than by just guessing.

Let’s imagine we have a list of transactions, with a special number, let’s say “638928632“. And when you add that number to the list of transactions and apply a hash function to the entire thing, the first 30 bits of the output are all zeros.

For a random message, the possibility that the output starts with 30 bits of zero is 1/2^30. That’s one in a billion. So this person almost has to go through a billion numbers to find that special one. That’s definitely a lot of work.

Once you know that number though, it’s really quick to verify. You just run the hash and see that there are thirty zeros. So you can verify that the individual went through a lot of work without you going through the same work. This is called proof of work.

This proof of work is tied to the list of transactions. If you change one of the transactions slightly, it would change the hash completely and you have to find a new special number.

So how do we organize our ledger? We organize our ledger into blocks, where each block consists of a list of transactions with a proof of work. In the same way a transaction is considered valid when it is signed by the sender, a block is only considered valid if it has a proof of work.

To maintain a standard order and history, we make it so that a block contains the hash of the previous block. So if you go back and change one of the previous blocks, you render the hash of the next block invalid, and so on. That would require redoing all of the work, finding a new number that makes the hashes of the block start with 30 zeroes. Since our ledger is now a chain of blocks linked together we call it a blockchain.

Blockchain

So anyone in the world can be a block creator. The block creator listens for transactions being broadcasted, collects them into a block, and then does a whole lot of work to find a special number that makes the hash of that block start with 30 zeroes. Once they find that special number they broadcast the block they found.

The block creator is rewarded for this work by allowing them to add in a transaction where they pay themselves some amount, called the block reward. Creating a block is called mining since it involves work and introduces new units of currency into the economy.

For anyone else who just wants to use this system to make payments, they just listen for blocks broadcast by miners and update their copy of the ledger. If you hear two distinct blockchains with conflicting transaction histories you revert to the longest one, the one with the most work put into it. If there is a tie, wait till you hear an additional block that makes it longer.

So here instead of trusting a central authority, we trust computational work. This method of agreeing to use the blockchain with the most computational work is what is referred to as a consensus.

Summary

Using our fictional ledger, we have gotten an insight into how bitcoin works. Bitcoin’s public ledger is readily available and public for everyone to see. The details of a sample block can be found here. The proof of work is called the nonce.

This article is by no means an exhaustive explanation of how Bitcoin works, but it gives a good foundation for understanding the Bitcoin blockchain.

References

But how does bitcoin actually work?

Bitcoin whitepaper