Getting started with blockchain | Read the hash function in a text

Hash function

Hash function: h=H(Data)

definition

The hash function H takes the variable size data Data as input and produces a fixed length h value.

A cryptographic hash function is a mathematical function. The characteristics of the hash function itself:

1, input arbitrariness: the input of the function can be any size of data;

2, output fixed: the output of the function is a fixed size of data;

3, can carry out effective calculation: that is, in a reasonable time, the input data can be calculated to obtain the output.

For blockchain technology and encrypted digital currency, to make the hash function password-safe, you also need to have the following characteristics:

1) Collision resistance

The concept of collision: If there are two different values ​​X, Y, H(X) = H(Y), then the hash function H is called a collision. Collision resistance means that two different values ​​X, Y cannot be found such that H(X) = H(Y).

From the interpretation of the collision resistance and the characteristics of the hash function, it is easy to conclude that the collision is an inevitable phenomenon. Because the input space of the hash function is data of any size, the output is a fixed size of data. This means that the input space is larger than the output space, so collisions are inevitable.

For example, if we define that the output of a hash function has only 0 and 1 results, then it is clear that collisions are very easy to happen.

Then a good hash function should look like this:

  • Any y, find x, make H(x) = y, very difficult
  • Given x1, find x2, making H(x1) == H(x2), very difficult
  • Find any x1, x2, making H(x1) == H(x2), very difficult

For example, for a 256-bit output hash function, the worst case is to perform 2256+1 hashes, and an average of 2128 hashes. This level is almost 10^27 years for a PC. Therefore, we can think that this is a collision resistance.

It is because of the collision resistance that there is a saying that the hash is on the chain. The so-called hash chaining is a typical deposit scenario: this scenario allows us to write the hash output as a message digest into the block structure of the blockchain. For example, if there is a very important file, the file is very large, and it is not feasible to write the file itself into the blockchain. Owner A hopes that the file will be safe and reliable in subsequent use, and there is no risk of being tampered with. Owner A then hashes the file and writes the hash value to the blockchain. In the subsequent use process, you only need to do a hash of the file to be used, and compare it with the hash value in the blockchain. If the hash values ​​are the same, the proof is not tampered with. If the hash values ​​are different, the proof is tampered with.

2) Unidirectional (secret)

Unidirectional (concealment) means that if we only know the output of the hash function h = H(X), there is no feasible algorithm to calculate the input value X.

Common hash algorithms are: MD5, SHA1, SHA224, SHA256, SHA384, SHA512, SM3

SHA-256 is a more efficient hash function used primarily by the Bitcoin world.

Hash pointers and data structures:

A hash pointer is a data structure that is a hash pointer to the data storage location and location data. When we learn C, we know that a normal pointer is an address that points to the location of the data store. But the hash pointer not only tells you where the data is stored, but also tells you if the data in this location has been tampered with. That is, a pointer that can clarify the hash value of the data under a certain timestamp.

A linked list constructed by a hash pointer is actually a blockchain.

As shown below:

Common linked list structure:

Common linked list structure

Blockchain structure:

Block linked list structure

Therefore, a typical application of blockchain is “tamper-proof”.

Merkle trees: A binary tree using a hash pointer is the Merkel tree. In the structure of the Merkel tree, all the data blocks are grouped in pairs, and the hash pointer of each two data blocks is stored in the parent nodes of the two data blocks, and the hash pointers of the two parent nodes are again They are stored in their parent node, and so on, reaching the root node of the Meck tree.

Its structure is as shown:

Merkel tree

The characteristics of the Merkel tree – the subordinate certificate

Suppose that if it is necessary to prove that a certain data block belongs to a certain Merkel tree, only the information of the data block and the block information of the data block leading to the root node of the tree can be verified. You can ignore other parts of the tree.

As shown in the figure below: If we want to verify whether D3 belongs to the ROOT tree, we only need to display the information of the nodes D3, N2, N5.

Affiliation

(Author: BitTribeLab Todd)

We will continue to update Blocking; if you have any questions or suggestions, please contact us!

Share:

Was this article helpful?

93 out of 132 found this helpful

Discover more

Blockchain

Cardano's ADA price is dropping towards $0.52. Is it time to buy the dip?

The value of Cardano (ADA) may decrease below $0.52 according to short-term forecasts, however long-term optimists re...

Market

Is Bitcoin’s Uptrend at Risk? Analyst Issues Witty Warning as Altcoins Surge

The future of BTC price is uncertain due to the decline in crypto market dominance. A major reversal for Bitcoin is p...

Market

$100 Million Trading Volume Fuels Cardano's 3% Surge Is it the Beginning of a New Bull Market?

Fashionista Alert Cardano (ADA) on the Rise – Breaking Resistance Level May Indicate Bull Market, But Poor Fundamenta...

Market

Cardano Is it Going to Zero? ADA Price Slips Amidst Crypto Market Rally – Will This Mining Protocol Go Viral?

Will Cardano's Growth in Valuation Lead to a Collapse or a Surge? Expert Predicts ADA Price in Light of Record-Breaki...

Market

Cardano Price Prediction: ADA Set for Spectacular Gains Post-Bitcoin Halving – Future Millionaire Maker?

Cardano gains 4% in 24 hours, reaching $0.383747 amidst a 2.5% marketwide increase.

Market

Analysis and Commentary: The Fate of Bitcoin ETFs and Cryptocurrency Performance

After a period of significant growth in the crypto market, traders were briefly shaken by a report causing a halt in ...