How Is Blockchain Immutable?

In episode 5 of The Building Blocks of Blockchain, we explained in detail how the mechanics of blockchain work. We didn’t really show how all of that makes blockchain immutable, though. Because immutability is one of the crucial features that makes blockchain interesting for application in the energy industry, I thought it worth explaining in more detail.

Immutable is just a fancy way of saying a blockchain’s contents cannot be changed. Let’s see what happens if Bugs Bunny attempts to change the contents of a block.

Source: Giphy

Let’s take the same block we used in the “Putting It All Together” post:

1. Daffy Duck receives 12.5 Bitcoins
2. Yosemite Sam gives Wile E. Coyote 4 Bitcoins
3. Porky Pig gives Pepé Le Pew 3 Bitcoins
4. Bugs Bunny gives Marvin the Martian 1 Bitcoin
5. Wile E. Coyote gives Elmer Fudd 2 Bitcoins
6. Elmer Fudd gives Porky Pig 7 Bitcoins
---
previous_block: 00bc30f8fae8f8b3ca113390fb4cfa16fd01084189fe285805a43c22bd81c739
nonce: 117
hash: 00639a07198476c9436cbbe1836ca8ca23c6a4792f8ebcba68732b56e9b81fae

And let’s say this is block number 5 in the blockchain.

Bugs’ first idea is to just change transaction number 2 in the block:

2. Yosemite Sam gives Wile E. Coyote 4 Bitcoins

so that he becomes the recipient instead:

2. Yosemite Sam gives Bugs Bunny 4 Bitcoins

He quickly realises this won’t work, because Yosemite Sam’s digital signature will not check out any more, and he can’t create a valid signature without knowing Sam’s private key.

He then figures he could just remove the transaction in which he gave Marvin his Bitcoin, essentially stealing it back. Now block number 5 looks like this:

1. Daffy Duck receives 25 Bitcoins
2. Yosemite Sam gives Wile E. Coyote 4 Bitcoins
3. Porky Pig gives Pepé Le Pew 3 Bitcoins
4. Wile E. Coyote gives Elmer Fudd 2 Bitcoins
5. Elmer Fudd gives Porky Pig 7 Bitcoins
---
previous_block: 00bc30f8fae8f8b3ca113390fb4cfa16fd01084189fe285805a43c22bd81c739
nonce: 127
hash: 0091ba2887d8a267c462c8d6f0a538e87188748308e15c644e25e81e479eeaf6

However, removing the transaction changes the hash of the block:

Bugs Bunny removes a transaction from the block, causing its hash to change

The above calculation was made using this online hash calculator. The new hash is:

1f2d89d4cb8ed12233ea4a4c9578b64ff5071dfd2a1213eadf99f2d92e587bae

which no longer matches the hash declared above. What’s more, it no longer provides a valid solution to the puzzle, as the new hash does not start with 2 zeroes! That means Bugs Bunny needs to solve the puzzle all over again!

That’s still not enough setback for Bugs Bunny to give up, so he goes about solving the puzzle. It takes him quite a while, but he manages to solve it eventually. He finds that the nonce 398 results in the following hash for his updated block number 5:

00be3133fa9810016c39305eb0dffc206ab98871b39fceec1b7d7c35911cb356

Now he has a valid-looking block which he could start spreading around. However, while he was solving the puzzle, there were several new blocks added to the blockchain! The next block, number 6, contains the old hash of block number 5 in its previous_block field. If Bugs Bunny were to update the previous_block field in block 6, its hash would change, which means he would need to solve a puzzle again, and then again for block 7, and 8, and each subsequent block.

Any change to a block makes the hash of that block and all subsequent blocks invalid.

Just call it a day, Bugs.

Source: Giphy