Why can blockchain be tamper proof?

Time:2021-2-16

As a senior siege lion, you must have a tree in your heart, because it can really improve the cognition of the bottom.

I hope everyone can have a tree in their heart and have a definite aim in the face of high-frequency interview questions.

01. Tree in blockchain


Experience: what impact will the tampering of transactions on the blockchain bring to the block?

Why can blockchain be tamper proof?

As shown in the figure, a block in the blockchain stores a batch of completed transaction information. In order to facilitate processing, the transaction information of the block is organized in the form of Merkle tree, and the block header stores the hash value of the previous block.

Suppose transaction 3 on the leaf node is tampered, then the hash value corresponding to transaction 3 will change, and the change will be passed up step by step until the corresponding parent node, which will eventually lead to the change of the root hash of the block, and then the change of the hash of the whole block.

in a word:Transaction tampering results in the hash change of the whole block.

Why can blockchain be tamper proof?

Due to the tampering of transaction 3, the hash of the whole block corresponding to transaction 3 will change, and then the hash of the previous block recorded on the next block will not match. Should we consider tampering with the following blocks? But the blocks behind the blocks should also be tampered with, and the children and grandchildren will be infinite.

In a word:__ The tampering of transactions will affect the whole body, and it needs to tamper with the whole chain before it can take effect. The difficulty can be imagined (the characteristics of blockchain that cannot be tampered with).

Feel it:How to verify the existence of transactions on a block?

Why can blockchain be tamper proof?

If it is necessary to verify whether transaction 3 really exists on the block, how should it be verified? In fact, we only need “hash 2” and “hash 01” to prove it. The verification steps are as follows.

Step 1: get the hash value of transaction 3, hash 3 = hash (transaction 3);

Step 2: get the hash value of the parent node through hash 2 and hash 3: hash 23 = hash (hash 2 + hash 3);

Step 3: get the hash value of the root node through the hash values of hash 01 and hash 23: root = hash (hash 01 + hash 23);

Step 4: compare the root hash value root obtained in the previous step with the Merkel root hash value in the block header. If it is the same, it is proved that transaction 3 exists in the block. Otherwise, it means that transaction 3 does not exist.

In a word:__ By introducing Merkel tree, bitcoin can complete transaction verification with a small amount of calculation and comparison.

Think about itHow to reclaim disk space?

With the passage of time, the chain is getting longer and longer, the data of the blockchain is growing day by day, the data level is getting larger and larger, and the storage requirements are getting higher and higher. In fact, once the latest transaction has been covered by enough blocks, the previous payment transaction can be discarded to save disk space.

Why can blockchain be tamper proof?

As shown in the figure above, the transaction is hashed into the Merkel tree, and only the root node is included in the hash value of the block. Then the old block can be compressed by pruning the branch, and the hash inside the branch does not need to be saved, which can save disk space without destroying the hash value of the block (perfect design).

In fact, the above designs of bitcoin are inseparable from the Merkel tree. What is the Merkel tree?

02. Master Merkel tree


When you learn any technology, don’t forget Gu Ge and Du Niang. Type “Merkle tree” in Google to search it. What you see is the explanation of Wikipedia.

Hash tree (Merkle tree) is a kind of tree data structure in cryptography and computer science. Each leaf node is labeled with the hash of the data block, while nodes other than leaf nodes are labeled with the encrypted hash of their child nodes. Hash tree can verify the content of large data structure efficiently and safely, and it is the extension of hash chain.

The concept of hash tree was patented by Raf murk in 1979, so it is also called Merkle tree.

By searching, we know two things.

1. The original Merkle tree is also called hash tree, because every leaf node of Merkle tree is labeled with the hash of data block, while nodes other than leaf nodes are labeled with the encrypted hash of their child nodes, so it is also called hash tree;

2. Merkle tree is translated into Merkel tree in Wikipedia and Merkel tree in Nakamoto’s paper. In fact, at this point, there is nothing to call it.

Why can blockchain be tamper proof?

We can see two things from this picture.

1. The top of the hash tree is top hash, also known as root hash or master hash;

2. Hash 0-0 and hash 0-1 are the hash values of data blocks L1 and L2 respectively, and hash 0 is the hash value obtained by connecting hash 0-0 and hash 0-1.

Main application scenarios.

1. The typical application scenario of Merkle tree is peer-to-peer network download.

First, get the top hash of the trusted Merkle tree from friends or websites; after getting the top hash, you can download the whole Merkle tree from untrusted sources in the P2P network; after downloading the Merkle tree, you can check it according to the trusted top hash to verify whether the data is complete and damaged;

2. Merkle tree can be used to quickly compare a large number of data, because when two Merkle trees have the same root, it means that the data they represent must be the same;

3. The blockchain scenario mentioned at the beginning.

03. Gossip


So much for Merkel tree. I hope you have a preliminary understanding of Merkel tree.

Most of the pictures in this article come from the paper of the founder of bitcoin, Nakamoto Tsung. Nakamoto Tsung’s paper suggests that we have time to read it. After all, it is subversive.

Ethereum, the representative technology of blockchain 2.0, is not a clone of bitcoin, but a completely independent design and implementation. It is suggested that we should learn about it when we have time.

Bitcoin: https://github.com/bitcoin

Nakamoto’s paper:

https://bitcoin.org/files/bit…_zh_cn.pdf

Ethereum: https://github.com/ethereum

Ethereum white paper:

https://github.com/ethereum/w…

Finally, no matter how cold the Internet winter is, please keep faith and don’t panic.

Welcome to WeChat official account, “one ape talk,” to learn more.