How to build a blockchain

Why write about Blockchain?

After more and more people asked me how a blockchain works, I decided to write about it. For the visualization a small test tool was written in C#.

A block chain is a continuously expandable list of data sets, called „blocks“, which are linked together by cryptographic methods. Each block typically contains a cryptographically secure hash (scatter value) of the previous block, a time stamp and transaction data.

The idea of Blockchain is not new. Stuart Haber and W. Scott Stornetta described the first principles of cryptographically secured linking of individual blocks in 1991.

What’s a hash?

Before we look at a blockchain, I’ll explain the principle of a HASH value. In he following picture you can see a hash value. It looks like a random collection of letters and numbers.

Image 1: Hash of an empty string

 

In easy words, a hash is like a kind of digital fingerprint of data. That means every data has another HASH. This hash value reflects the data above, that means an empty string.

When you change the data, the hash value also changes.

The hash is always exactly the same length.  It doesn´t matter if you hash the book “Moby Dick” or a short message. In the next picture you see hash value of „Jochen“

Image 2: That´s the Hash value of „Jochen“

What’s a block?

The next thing you need to know is what a block is. There are different possibilities how a block can look like. Normally a block has at least one block number, a thing called nonce, data and a hash value.I’ll explain what a nonce is later.

Image 3: How a Block looks like.

In this example, the hash value in the block is generated via the number, the nonce and the data. This means that if one of these values changes, the hash value also changes. Please note that the hash value is shown in green. Please also note that the hash value in this example starts with 4 zeros. Therefore, this block is a valid block for us.

Image 4: Invalid block with „jochen“

If the data field changes, e.g. in „Jochen“, the hash value also changes. This hash value is now shown in red. The hash value no longer starts with 4 zeros, and is therefore invalid.

How do we get a valid block again, i.e. with 4 zeros at the beginning. This is where the „nonce“ comes in. If we change the nonce, e.g. to „1“, „2“, „3“, etc. we will find a valid block with 4 zeros at the beginning of the hash.

Image 5: Invalid block with „jochen“ and nonce „3“

Mining

As trying it out by hand takes a long time, we can also let the computer search for a nonce. This process is called mining.

Image 6: Valid block with „jochen“ and nonce „72292“

In this case a Nonce 72292 was found by mining which generates a valid hash code.

Blockchain

Now that you know how a hash and a block works, let’s get to the blockchain. In addition to the block number, the nonce, the data field, the hash of the block bevor is used for hashing.

Image 7: A valid blockchain

This means that if a block is manipulated, its hash value changes. Because this hash value is included in the hash calculations of the following blocks, the hash changes there as well and is therefore also invalid. Thus this and all following blocks would have to be mined again, so that they are valid again.

The majority wins

Imagine that these block chains are now not only on one server, they are on many servers.

It’s very unlikely that anyone could manipulate all servers at once. A blockchain works according to the majority principle. That means you want to know if a block is really valid. the hash value is compared with other copies of the blockchain. The majority wins. This procedure makes Blockchain so secure for e.g. transactions.

Use cases and Business Models with Bockchain

Bitcoin can be used in a wide range of applications. Most famous became Blockchain by Bitcoin. Here I have listed some possible applications.

4 main Applications Groups:

  • Smart Contracts
  • Digital Currency
  • Record Keeping (transactions)
  • Security

Examples: Food & drugs tractability, Payment, Energy market (transactions), Elections, Machine 2 Machine transaction

Image 8: A blockchainexample with money transactions

Author: Jochen Müller, Dec 2017

 

Schreibe einen Kommentar