# Blockchain 101: Part 1

Since starting at Wallet.Services I have learned a fair bit about blockchain but I still find it difficult to explain it to other people! This is partly because it is such a massive subject which can be approached from many different angles. So, I thought I would write this post to organise my understanding of blockchain fundamentals and hopefully help a few of you who are trying to get their first bite of the blockchain learning apple.

To make this post a manageable read, I am going to focus on a specific flavour of blockchain: Bitcoin. I have chosen Bitcoin as it is the original blockchain based solution and so it introduced a lot of the key concepts that all recent innovations build upon. If you can understand Bitcoin you are a good way along the path to understanding blockchain in general. So, without any further ado, let me begin…

First off let’s get a few basics out of the way. Bitcoin was started by a person with the pseudonym Satoshi Nakamoto. Whilst Bitcoin is complex in some regards, it can be viewed as just a set of rules that Satoshi designed and coded in C++; the Bitcoin network comprises many people running these rules simultaneously and independently. The magic of Bitcoin is the fact that everyone acts independently but they still end up agreeing on the same truth i.e. who owns what Bitcoins. This is achieved because the rules are designed in such a way that anyone not following them, e.g. trying yo cheat, will effectively be ignored.

So how does Bitcoin achieve this? The rules make heavy use of public key cryptography, in particular digital signatures. Public key cryptography systems (such as digital signature schemes) require all participants to have a pair of keys (one public, one private) that have a special mathematical relationship.

The mathematical relationship is such that you can derive a public key from a private key but the reverse (i.e. figuring out the private key from a public key) is almost impossible. The rules of Bitcoin are a constructed from cryptographic operations and, together, these rules are known as a “Consensus Mechanism”. The outputs of these operations are stored in a special data structure which is the actual Blockchain that we hear so much about. With these basics in place, let’s take a deeper dive into what some of the consensus rules are and the details of what gets stored on the blockchain. I’m going to do this by looking at (roughly) how the inventor Satoshi started the blockchain (after he finished writing the code).

The first thing he would have done is generate a set of keys for himself, then he could set about creating the first block, known as the “genesis block”. Every block in a blockchain contains one or more messages that are structured and encoded in a specific way; these messages are known as “transactions”. The first transaction in any block is a special type called a “coinbase transaction”. The rules of Bitcoin state that the creator of the block can assign themselves a certain number of Bitcoin out of thin air! The coinbase transaction in the genesis block (the first ever transaction) encodes the following statement:

*“The owner of the private key corresponding to Satoshi Nakamoto’s public key has 50 bitcoins!”*

But how does Satoshi prove that he has his private key without revealing it (which would allow anyone to impersonate him)? This is where digital signatures come in. Digital signature schemes comprise 2 functions, one for “signing” and one for “verifying”. The functions look like this:

The sign function is used in secret by the holder of the private key to create the signature. The verify function can be used by anyone as it involves the public key. The verify function checks two things:

- That the transaction is exactly the same as the one that was signed.
- That the signature was created using the correct private key i.e. the one that corresponds to the public key.

Ever since Satoshi created the first block containing the first transaction which assigns him 50 Bitcoins, they have been sitting there waiting to be spent. All he had to do was provide proof, using a digital signature, that he is the owner of the private key referred to in the transaction. However, (interesting fact alert!) due to a quirk in the bitcoin code Satoshi will never be allowed to spend the 50 Bitcoins he received in the genesis block! But, to keep this post simple, let’s pretend that Satoshi could “spend” the coins from the genesis block, how would he do this?

To “spend” Bitcoin you record in a transaction that the value assigned to your public key in one transaction is now assigned to someone else’s public key. So to assign his first 50 Bitcoin to his friend (let’s call him “Hal”), Satoshi would ask Hal to first generate his own set of keys and send him the generated public key. Satoshi would then create a new transaction that represents the message:

*“The bitcoins refernced in the 1st transaction of the 1st block now belong to **the owner of the private key related to Hal’s public key**.”*

To prove that Hal now has 50 Bitcoins two things need to happen:

- Satoshi needs to prove that he is the owner of the private key corresponding to the public key mentioned in the first transaction.
- Satoshi needs to authorise the second transaction.

Both these things can be accomplished in one step by Satoshi creating a digital signature for the second transaction with the private key corresponding to the public key referenced in the first transaction. Hal (and anyone else for that matter) can then check that the bitcoins are now his by simply using the “Verify” function from the digital signature scheme.

This seems like a massive leap, but we can break it down as follows: If the verification passes, that proves that Satoshi is the holder of the private key corresponding to the public key used in the first transaction. The clever part is that the check is done using the second transaction as the input so it also proves that the holder of the private key relating to the first transaction has authorised the second transaction.

And there you have it, this forms the basis of how Bitcoins are created (coinbase transactions) and how they are spent (“normal” transactions). I have glossed over a lot of details along the way but there is one critical piece of the puzzle missing; what stops anyone creating loads of new blocks containing whatever transactions suit them? The simple answer is that there are rules to prevent this, they follow a pattern known as “Proof of Work”.

This post is already quite long so I will save “How Proof of Work Works” for part 2.

I hope this has helped some of you who have started down the road of trying to understand blockchain. If you have any questions please contact me at matthew@wallet.services and I am more than happy to help.

Matthew