What is a fork? Why is it dangerous?

Often a blockchain can have some flaws, bugs or it just needs improvements. To fix those vulnerabilities the blockchain has to be forked.
A fork rewrites the rules which a full node must follow in order to consider a block valid. A full node can decide either to accept the new rule (updating its software) or reject it.

If some nodes choose to support the fork while others choose not to do so, then a blockchain fork might happen: in this case the blockchain splits up in two different branches.
The two blockchains share the same chunk of chain from the genesis block to a certain block before the divergence.

There are two kinds of fork: hard fork and soft fork. Both hard and soft forks can cause a blockchain fork.

When a fork happens, the choice made by the community is crucial because it can weaken the blockchain. When the community of the full nodes split then each branch of the blockchain created by the split will have less hashpower: so both blockchains become weak to a 51% attack.
If the community cannot make a strong decision about the fork, then also the community itself can become weak; this could lead to bad consequences regarding the trust on the platform: the reliability of the platform will decrease and the interest of investors and developers will move away.

Let’s take some real examples.
Before August 2017, the bitcoin community was discussing how to improve the bitcoin transaction performance (aka scalability). The community had two different opinions:

  • to increase the block size to 8MB
  • to store the data within a block with a method called SegWit [1]

In August 2017 the bitcoin blockchain split up in two branches: Bitcoin Cash [2] with an increased block size to 8M and Bitcoin that uses SegWit.

Another example.
In 2016 an attacker managed to use the vulnerability of ethereum security for his own good and many people lost their investments [3]. Within the ethereum community there were two ways to solve this problem:

  • to revert the transactions due to the flaw
  • not to make any changes, keeping the original protocol

In July 2016 the ethereum blockchain forked into Ethereum (with the flaw fixed) and Ethereum Classic (original protocol) [3].

What is the difference between hard fork and soft fork?

Soft fork: a block created with a new rule is considered valid also by the old rule; this means a soft fork is forward compatible (in other words the blocks created with the new rule are compatible with the blocks created with the old rule but not the other way around).
Example: you have a blockchain where each block has a maximum size of 2MB; then you apply a soft fork to reduce the maximum size of the block to 1MB. The old rule will consider the blocks created with the new rule valid since they do not exceed the 2MB maximum size.

Hard fork: blocks created with the new rule are not considered valid by the old rule; this means that a hard fork is not forward compatible (the blocks created with the new rule are not compatible with the blocks created with the old rule).
Example: a blockchain has the block size limit of 1MB; then a hard fork is applied in order to increase the block size limit to 3MB. The blocks created with the hard fork rule are not compatible with the old rule since the 3MB limit exceeded the 1MB limit but the old blocks are still compatible with the new rule.

SOFT FORK: how does the blockchain fork happen?

If the hashpower of the full nodes that accepted the soft fork is 51% or more, then there will be no blockchain fork.

If less than 51% of the hashpower comes from the full nodes which do not support the soft fork then the blockchain will split: a branch of blocks will be created by the nodes following the old rule (since the old rule is not compatible with the new rule) and another branch of blocks by the nodes following the new rule.

If the full nodes start upgrading their software to the soft fork and the hashing power supporting the soft fork is more than 51%, then all the network (both supporting and not supporting the fork) will consider the blockchain branch created with the soft fork rule as true.
This is possible because the branch created with the soft fork became longer than the other branch; since the soft fork branch is compatible with the old rule, all the network will consider the longer branch valid and there will be one single branch.

HARD FORK: how does the blockchain fork happen?

Here we have to consider two cases.

Case 1: 51% of the hashpower of the network do not update their software to the hard fork.
Since the blocks created with the old rule are compatible with the hard fork and the blockchain branch supported by the old rule grow faster (because it has more hashpower), then the blockchain branch supported by the old rule is considered valid and there is no blockchain split.

Case 2: 51% of the full nodes update their software to the hard fork but a smaller percentage is still using the old rule.
In this case the blockchain will split: since the blocks created with the hard fork rule are not compatible with the old rule then there will be a branch supported by the nodes following the old rule and a branch supported by the nodes following the hard fork.

Obviously in case when 100% of the community supports or does not support the hard fork there will be no blockchain split.


[1] Bitcoin Cash – Wikipedia

[2] SegWit Protocol – CoinDesk

[3] The stolen ether and the birth of Ethereum Classic:

[4] 51% Attack



Blockchain Fork – Wikipedia

Guide to Forks: Everything You Need to Know About Forks, Hard Fork and Soft Fork

What is a soft fork?

The differences between a hard fork, a soft fork, and a chain split, and what they mean for the future of bitcoin


Read the original article at www.danielefavi.com

Where is the blockchain revolution?

A friend of mine asked me: bitcoin was invented 10 years ago, why has not anyone come up with a real product yet? Has anything been disrupted by blockchain?

His disappointment is quite understandable.
Everyone is talking about blockchain as a revolutionary technology, they say it will change how we approach the life, make transactions cheaper and free us from the middle man.
Many times I heard how Air B&B and Amazon will be wiped out by blockchain technology and how blockchain will protect our privacy from Facebook and Google.

Nowadays there are many products based on blockchain but none of them have been revolutionary, none of them changed our approach to life like the first PC, the first iPhone or Facebook.

Where is the claimed disruption?

Enthusiasts are claiming that blockchain will disrupt many industries in the future, but what about now?
No revolution happened yet, lots of good words, speculation and euphoria; even Bitcoin is failing its purpose as a means of payment [1].

The blinding light of making easy money on bitcoin hooked many people; it seduced not just investors and cyber-nerds but also normal people, everyone is hunting for a new business opportunity. If this euphoria does not match with a real solution it will soon turn into disappointment (as I am already reading around).

And the euphoria is a close friend of speculation, not just on bitcoin’s economy but also on the blockchain as term itself; for instance a tea company changed its name from Long Island Iced Tea to Long Blockchain and it got +500% increase on its shares [2]. Isn’t it crazy?

So what’s the state of work right now?

Let’s be realistic: blockchain is a new technology and it is still in development, experimentation and testing. Bitcoin blockchain is still fighting on performance (like transaction speed and fees).
Perhaps in 10 years blockchain will revolutionize our life, or it may fail as well.

Internet was invented in the 1950s but it boomed forty years later in the 1990s [3]. The artificial intelligence was invented in the 1950s but it boomed in 2015 [4].
Bitcoin’s white paper came out in 2008 [5] and now, ten years later, what has been accomplished by blockchain technology?

A lot.

No revolutionary products have been invented yet but many new blockchain platforms were born (like Ripple, Ethereum, Hyperledger or Iota): remember that blockchain is a new world to discover and it is still in development. When the foundation is ready new blockchain products will come out.

Many big tech corporations (like IBM or Microsoft) as well as banks are investing a lot in it.
I’m investing my free time in studying blockchain development and I personally think blockchain will help the humankind technology evolution.
Now it is the right time to invest in this technology if you want to be in the forefront in a close future. Be aware that blockchain might fail as well but no investment comes without risk.

The history of blockchain just started. Don’t let the mass euphoria, disappointment or skepticism blind you, stay calm and keep yourself informed instead.



[1] Why bitcoin is failing its purpose as a means of payment:

[2] Tea company that chaged its name: https://techcrunch.com/2017/12/21/long-island-iced-tea-shares-went-gangbusters-after-changing-its-name-to-long-blockchain/

[3] History of the internet: https://en.wikipedia.org/wiki/History_of_the_Internet

[4] History of AI: https://en.wikipedia.org/wiki/History_of_artificial_intelligence

[5] History of Bitcoin: https://en.wikipedia.org/wiki/History_of_bitcoin


Read the original article at www.danielefavi.com

How a blockchain works… Let’s make one!

Have you ever wondered why the blocks on the blockchain are stored one after another?
In this article we are going to talk about the basic blockchain concepts; these concepts will be fundamental to grasp how the proof-of-work works, why the mining requires lots of computational power and how the blocks become immutable.

The blockchain technology uses a mathematical function called Hash which turns data into a 64 character long code. The hash code identifies the block in the blockchain and protects its content.

What is the hash?

The hash is a mathematical function that turns every type of data (like text or file) into a string of 64 characters. The output code never changes for the same input. The hash is a one way function: it is easy to generate a code but starting from a hash code it is impossible to get the original data.

Let’s take an example: this is the link to my website where you can find the hash calculator https://www.danielefavi.com/sha256-hash-calculator/.
Let’s type “test” in the text field and then press the button Calculate SHA256 hash. The generated code is:

Now let’s type “test.” (add only a full stop) in the text field Data and press again the button Calculate SHA256 hash. The generated hash is:

Adding a full stop makes a difference, the code of “test” is totally different from the code of “test.” Even the addition of a space or a blank line or change a letter to the capital letter can change completely the hash of the output code.

It is easy to calculate the hash, but it is very difficult to get back the starting data from the hash. For example try to find the word that matches with the following hash:
You can search for a starting word doing lots of random attempts until you will find the corresponding word (this method is called brute-force).

Let’s create a simple blockchain to understand what the hash is for.

Our blockchain contains simple information: a list of people with their names and ages; the name and the age are separated by a dash:

  • Block 1: Natalia-28
  • Block 2: John-45
  • Block 3: Paul-21
  • Block 4: Claire-67

Every block must have an identification code: this code will be calculated with the hash.
In order to build a chain of blocks you must link each block to its previous one: so a block must contains the identification code of the previous block.

For a better understanding let’s build our blockchain.

Let’s start with the first block: since the block 1 has no previous blocks we can choose zero: 0-natalia-28.
Now go to the hash calculator and calculate the hash of 0-natalia-28; the hash is:

Let’s take only the first 5 digits of this code (to make our life easy) and put them at the beginning of the second block: 51831-john-45.
Go back to the hash calculator and calculate the hash of 51831-john-45; the generated hash is:

Again, take only the first 5 digits and put them at the beginning of the third block, obtaining 4e942-paul-21.
Repeat the same process for the blocks #3 and #4; the chain that you have built is:

Let’s tamper with the blockchain!

For our friend Natalia, from the first block, let’s change the age from 28 to 25. So, changing the content of the block will result in the change of the hash of the block too.
The new content of the first block is 0-natalia-25 and the first 5 digits of the new hash are 07698.

Since the identification code of the first block changed (before it was 51831 and now it is 07698) we must update the hash code inside the second block that refers to the first block. With this update the content of the second block changes (now it is 07698-john-45) so we have to calculate again the hash of the second block: the first 5 digits of the hash code of 07698-john-45 are 43339.

The hash code of the block #2 is changed, as well as the content of the block #3. The content of the block #3 is 77e83-paul-21.
As you have already guessed, since the content of the block #3 is changed, we must calculate again its hash, which will cause the change of the content and the hash of the block #4.

The change of the content of the block not only invalidates the block itself but causes the invalidation of all the following blocks.

This article showed us how a blockchain is structured. In the next article we will see how to prevent a blockchain from being tampered.


Read the original article at www.danielefavi.com

What is the mining? Who is the miner?

The mining is the process where the data is collected in a block and then the block is appended to the blockchain. This process is done by the miner.

Before digging into the process of mining, I suggest you read the following articles:

Who is the miner? Why does a person decide to start mining?

The miner is a special node in the network that gives its computational power to the network. You could be a miner too, all you need to do is to download a free software and run it.
The miner earns 12.5 bitcoins for each block created (called coinbase) as well as the transaction fee.

If it’s so easy I’ll quit my job and I’m going to be a miner!

Wait! It’s not so easy! In order to secure the data on the blockchain, it has been made intentionally difficult to create a block.
During the mining process, the miner calculates a code which will identify the block within the blockchain. This calculation must comply with the criteria of complexity that increases with the hashing power of the network. This difficult puzzle is called proof-of-work (I will talk about it in the next article).
The miners are racing with each other to solve the puzzle and the winner will earn the coinbase and the transaction fees.
Nowadays, there are miners with warehouses full of special computers that are working 24/7 only for mining; so if you want to start the career as a miner, your nerd computer is not enough!

What is the proof-of-work for? Why do miners spend so much effort on mining?

The proof-of-work is a mechanism for reaching global consensus on the valid blockchain: since all nodes have a copy of the blockchain, each node must agree on the conditions that prove how much effort a node has spent on verifying transactions.
In other words: if the content of the blockchain is easy to change then everyone can tamper with it; instead, if each block is calculated with complex mathematical functions then it takes a lot of effort to tamper with the blockchain.

If everyone can be a miner, is there any risk that someone can create a fake block?

Of course. A bad miner can create an invalid block; but remember that before appending a block to the blockchain, a miner must check if the block is valid. Hence if the block received by the miner is not valid, it will be rejected.
Moreover, the identifier hash code links each block together in a chain (that’s why the name is the blockchain); if I tamper with a block, I will invalidate not only that block, but also all the following blocks!


Coinbase value: https://blockchain.info/stats (you can calculate it dividing Bitcoins Mined by Blocks Mined)

Hash: wikipedia or you can wait for the next article!

Difficulty of proof-of-work: https://blockchain.info/it/charts/hash-rate?timespan=all


Read the original article at www.danielefavi.com

Bitcoin transaction: how does it work?

In the previous article we had a quick introduction to the blockchain technology. In this article we are going to see what’s happening behind a bitcoin transaction.

Let’s take a simple example: Robert and his friends went to the Bit&Beer pub where bitcoin payments are accepted. After the whole night of drinking and having fun it’s time to pay the bill!
The waiter takes out a smartphone and shows the QR code to Robert for the payment of the bill. Robert takes out his smartphone as well, opens his bitcon app, scans the QR code, checks if the payment details are correct and presses the PAY button.

The QR code is a kind of a bar code but more complex, it contains several types of information, like:

  • the ewallet of the receiver (in our case Bit&Beer)
  • bitcoin amount to transfer
  • general information (like the name of the receiver)

When Robert presses the PAY button he creates a new transaction which contains the sender’s ewallet (Robert) and the receiver’s ewallet (Bit&Beer) details, the amount of bitcoins and a small fee. The fee however is not mandatory: the sender can decide whether or not to include the fee (transactions with a higher fee have a higher priority).

What is happening behind the scene?

The transaction is propagated in the bitcoin network (phase #1 of the scheme); the waiter of Bit&Beer can see Robert’s payment on his phone almost instantly, the status however is NOT CONFIRMED.

Who decides whether a transaction is valid or not?

The transaction is considered valid when special nodes in the network (called Miner) will append this transaction into a block in the blockchain.
This process is called Mining (phase #2 of the chart) and it has the following purposes:

  • to validate the transaction (referring to consensus protocol) or to reject an invalid transaction.
  • to create new bitcoins.

The process of Mining is the essential phase where the transactions are stored in the blockchain. In this step the transaction is being included inside a new block and this block is appended to the blockchain.
It is not simple at all to create a new block. Mining a block requires complex operations using a lot of computational power; this operation is called proof-of-work and it verifies the data on the blockchain and makes it immutable.

Miners are racing with each other to create a block: the first one that creates a block which satisfies the requirements earns some bitcoins and the fee within the transactions (phase #3 of the chart).

A new block is propagated on the network (phase #4 of the chart); other miners which received a new block, are going to check if the block is valid first and then include the new block in the blockchain.
Finally, the waiter of Bit&Beer can see in his ewallet that the payment has been confirmed. All this process is about 10 minutes long.


Read the original at www.danielefavi.com