Clicky

How does a blockchain work?

Like the name indicates, a blockchain is a chain of blocks that contains information.

This technique was originally described in 1991 by a group of researchers and was originally intended to timestamp digital documents so that it's not possible to back date them or to tamper with them, almost like a notary.

However, it went by mostly unused until it was adopted by Satoshi Nakamoto in 2009 to create a digital cryptocurrency Bitcoin.

Now, a blockchain is a distributed ledger that is completely open to anyone. They have an interesting property. Once some data has been recorded inside the blockchain, it becomes very difficult to change it.

So how does that work? Well, let's take a closer look at a block. Each block contains some data, the hash of the block, and the hash of the previous block.

The data that is stored inside the block depends on the type of blockchain. The Bitcoin blockchain, for example, stores the details about a transaction in here such as the sender, receiver, and the amount of coins.

A block also has a hash. You can compare a hash to a fingerprint. It identifies a block and all of its contents, and it's always unique, just as a fingerprint. Once a block is created, its hash is being calculated.

Changing something inside the block will cause the hash to change. So in other words, hashes are very useful when you want to detect changes to blocks. If the fingerprint of a block changes, it no longer is the same block.

The third element inside each block is the hash of the previous block. This effectively creates a chain of blocks, and it's this technique that makes a blockchain so secure.

Let's take an example

Here we have a chain of three blocks. As you can see, each block has a hash and the hash of the previous block. So block number three points to block number two, and number two points to number one.

Now, the first block is a bit special. It cannot point to previous blocks because well, it's the first one. We call this block the Genesis block.

Now, let's say that you'd tamper with the second block. This causes the hash of the block to change as well. In turn, that will make block three and all following blocks invalid because they no longer store a valid hash of the previous block.

So changing a single block will make all following blocks invalid. But using hashes is not enough to prevent tampering. Computers these days are very fast and can calculate hundreds of thousands of hashes per second.

You could effectively tamper with a block and recalculate all the hashes of other blocks to make your blockchain valid again.

So to mitigate this, blockchains have something that is called proof-of-work. It's a mechanism that slows down the creation of new blocks. In Bitcoin's case, it takes about 10 minutes to calculate the required proof of work and add a new block to the chain.

This mechanism makes it very hard to tamper with the blocks because if you tamper with one block, you will need to recalculate the proof-of-work for all the following blocks.

So the security of a blockchain comes from its creative use of hashing and the proof-of-work mechanism.

But there is one more way that blockchain secure themselves, and that is by being distributed. Instead of using a central entity to manage the chain, blockchains use a peer to peer network and everyone is allowed to join.

When someone joins this network, he gets a full copy of the blockchain. The node can use this to verify that everything is still in order.

Now, let's see what happens when someone creates a new block. That block is sent to everyone on the network. Each node then verifies the block to make sure that it hasn't been tampered with.

If everything checks out, each node adds this block to their own blockchain. All the nodes in this network create consensus. They agree about what blocks are valid and which aren't.

Blocks that are tampered with will be rejected by other nodes in the network. So to successfully tamper with a blockchain, you'll need to tamper with all the blocks in the chain, redo the proof-of-work for each block, and take control of more than 50% of the peer to peer network.

Only then will your tampered block become accepted by everyone else. So this is almost impossible to do.

Blockchains are also constantly evolving. One of the most recent developments is the creation of smart contracts.

These contracts are simple programmes that are stored on the blockchain and can be used to automatically exchange coins based on certain conditions.

How can blockchains be used?

Well, let's take a look at a few examples, but before we do that, let's quickly recap what a blockchain is. In simple terms, it's a distributed database that everyone can get a copy of. Every person with a copy can add new records to this database, but they cannot change any record that's already in there.

This property makes blockchains great to record data in a transparent way, because everyone gets to see what's in it. How can it be used?

Let's start with the most obvious and most popular application of blockchains, and that is cryptocurrencies.

When Bitcoin launched in 2008, it allowed people to directly transact with one another without having to trust third parties like banks. Since then, over 1,600 different cryptocurrencies have been created, but let's look beyond cryptocurrencies.

Let's look at how blockchain technology can be used in cars.

Ever heard of odometer fraud? By tampering with the odometer, someone can make a car appear to be newer and less worn out, resulting in customers paying more than what the car is actually worth. The government tries to counter this by collecting the mileage of cars when they get a safety inspection, but that's not enough.

Instead, we could replace regular odometers with smart ones that are connected to the internet, and frequently write the car's mileage to a blockchain. This would create a secure and digital certificate for each car, and because we use a blockchain, no one can tamper with the data, and everyone can look up a vehicle's history.

In fact, this is already being developed by Bosch's IoT Lab, and they are currently testing it on a fleet of 100 cars in Germany and Switzerland. So blockchains are great at keeping track of things over time, so besides odometers, you can also keep track of things like intellectual property, or patents, or it can even function as a notary.

See, a notary is someone who can confirm and verify signatures on a legal document, but we can just as well use a blockchain for that. The online website stampd.io allows you to add documents to the Bitcoin or Ethereum blockchain.

Once added, you can always prove that you created a document at a certain point in time, much like a notary, although right now, blockchains aren't on the same level as notaries in the legal perspective.

Another interesting application is digital voting. Right now, voting happens either on paper or on special computers that are running proprietary software. Voting on paper costs a lot of money, and electronic voting has security issues. In recent years, we've even seen countries move away from digital voting and adopting paper again, because they fear that electronic voting can be tampered with and influenced by hackers.

But instead of paper, we could use blockchains to cast and store votes. Such a system would be very transparent, as everyone could verify the voting count for themselves, and it would make tampering with it very difficult.

The Swiss company Agora is already working on such a system, and it's going to be completely open source, but there are many challenges. First, you have to be able to identify voters without compromising their privacy. Secondly, if you allow people to vote with their own computers or phones, you have to take into account that those might be infected with malware designed to tamper with the voting process.

A system like this also has to be able to withstand denial-of-service attacks, because that could render the whole thing unusable. Definitely a tough nut to crack, but if it becomes reality, it could make for a more transparent and practical voting system.

Let's move to yet another example, the food industry. They could use blockchain technologies to track their food products from the moment they are harvested to when they end up in the hands of customers. See, every year, almost half a million people die because of foodborne diseases, and that's partly because it takes too long to isolate the food that is causing harm.

Blockchains could help us to create a digital certificate for each piece of food, proving where it came from and where it has been. If a contamination is detected, we can trace it back to its roots, and instantly notify other people who bought the same batch of the bad food.

Walmart and IBM are currently working on such a system. It allowed them to trace the origin of a box of mangoes in just two seconds, compared to days or even weeks with a traditional system. A system like this could be applied to other industries as well.

We could use it to track regular products, and battle counterfeit goods by allowing anyone to verify whether or not the product comes from the manufacturer you think it does.

Another idea would be to track packages and shipments by using blockchain. That is something that IBM and container shipping giant Maersk are working on, a decentralised ledger to help with making global trade of goods a lot more efficient.

So far we've looked at ways blockchain can be used to keep track of information, and verify its integrity, but blockchains can be even more powerful when we add smart contracts to them. These contracts are tiny computer programmes that live on the blockchain, and can perform actions when certain conditions are met.

Insurance companies could use smart contracts to validate claims, and calculate a payout, or they could allow us to only pay for car insurance when we're driving.

But it goes even further. With smart contracts, we can secure our own data on a blockchain. It could, for instance, allow us to store our medical records on a blockchain, and only allow doctors to access them when we approve it with a digital signature.

In the same fashion, you could store your personal identity on there, and choose what data you want to reveal. Ordering alcohol in a bar, for instance, only requires you to prove that you're over the legal drinking age, and with smart contracts, you can deliver that proof without revealing anything else.

Or think about collecting royalties for artists. A future streaming service could set up two smart contracts; one where users sent a monthly subscription to, and one that keeps track of what the user has listened to. At the end of each month, the smart contract then automatically distributes this money to artists based on how many times their songs have been listened to.

So as you can see, blockchain technology can be used in so many different ways. This is just a brief overview of how they can be used, and it's by no means a complete list of all the applications.