Cryptography in Bitcoin: Five characteristics of hash function and mining principle

Bitcoin is the world's first successful cryptocurrency, and previous attempts have not effectively solved various problems related to the currency like Bitcoin.

Bitcoin itself is a product of the development of cryptography. It is constructed by using two important techniques of cryptography, such as one-way hash function and digital signature. Today we focus on five important aspects of one-way hash function. The characteristics, as well as the technical principles related to Bitcoin mining.

Let's first talk about the characteristics of the hash function:

A one-way hash function , also known as a hash function.

The first feature: the input can be any length, the output is a fixed length

The hash function does not need to know what the input information represents, nor does it mean how long the information is long. As long as the input hash function comes out, it is a fixed-length bit value. For example, the very well-known SHA256 hash function, input any value is 256-bit 0 and 1. Enter a "Three Kingdoms" or just enter a letter a, all out are 256-bit length data.

The second feature: the calculation of the hash value is faster  

This is often overlooked by everyone. It seems that things that are commonplace are not taken care of. In fact, this is equally important, because the one-way hash calculation is very fast, and the speed of encryption or verification can be guaranteed.

The third feature, anti-collision characteristics (Collisionresistance )

X≠y, H(x)=H(y) The input space is much larger than the output space. For example, the 256-bit hash value means that the output space is 2^256, the input is infinite, and the output is fixed length. .

However, there is currently no good way to find out if an x ​​can get H(x) equal to the value on the right.

Traversing all the inputs may be able to find this value, called brute-force brute force cracking, which is the source of the so-called " hash collision " of the mining machine.

Hash anti-collision is to ensure that the data uploaded and downloaded is the same, that is, the result of a little change is much worse. For example, the information you entered is a "Dream of Red Mansions" (of course, the computer recognizes 0 and 1), then you change the comma to a period in the fifth sentence on page 100 of the Dream of Red Mansions, and then output the hash value. It's totally different. This is a very important feature of the hash function.

However, collision resistance does not currently have a mathematical proof that this collision will not occur. MD5 is the best example. It used to be very safe, but later found the crack method.

The fourth feature: Hiding or one-way

The calculation process of the hash function is one-way irreversible. x pushes H(x), but there is no way to reverse push (unidirectional), that is, the hash value does not reveal the information of the input x. That is to say, the information of x is hidden, which is hidden.

The input space should be large enough to be even, so it is difficult to brute force.

Using the third and fourth features can make a very interesting application scenario.

For example, predicting one thing. In the real world, predictions and results often have subtle relationships. For example, during the Three Kingdoms period, Cao Cao went to find the person's article expert Xu Wei at that time, let him see what material he was, and Xu Wei evaluated Cao Cao as "the power of governance." Chen, the chaos of the chaos, this is hard to say that his assessment is not accurate, perhaps because this comment has affected Cao Cao's psychology, he developed in this direction, it became a self-verification prophecy. Therefore, it is difficult to judge whether the prediction is really accurate.

A simpler example is an influential stock reviewer who predicts whether tomorrow's stock price will grow or not. If he publicly indicates the currency price, it may affect the currency price.

So how do you show that he is really accurate? Let him write the stock review information on paper, or save it to the computer, but the request is that after the opening of the next day, you can't secretly modify the content, so you don't have to worry about the forecast affecting the stock price. So what you need to do now is just one thing: make sure he hasn't tamper with what he has already written.

Then, you can use the hash algorithm, the predicted result (information) is x, the x hash function, the hash value is announced , and the x is released the next day. If you change the data yesterday, the hash changes. Everyone can use hash to compare this x with the hash value published yesterday.

In actual situations, the actual input space is not very large, the input is not random enough, and some people are worried about the combination of vocabulary statements such as rising and falling. Finding this x, in order to ensure security, a nonce random number is added, and the formula is expressed as follows.

H(x丨丨nonce) nonce is a random number

This means that the predicted result information x is followed by a random number, and the hash is obtained together.

Fifth point: puzzle friendly

That is to say, x does not know what H(x) is? This cannot be judged from the input data, and what the output looks like. That is to say, knowing the input information, you can't see at a glance what the hash value is. The puzzle-friendliness is worth it: you can't control the input value x to get the desired output value H(x).

Therefore, the characteristics of comprehensive concealment and puzzle friendliness, knowing the input information, do not know what the hash value is, can be calculated quickly, but can not be judged in advance; knowing the hash value can not know what the input value is, The calculation is very, very difficult and can only be violently cracked.

So if the value you want to output falls within a certain range, such as less than a certain value, the computer can only try to guess the answer one by one, to see which input the calculated output value falls within the range you want. .

You need to get a hash value before the K bit is 0. You can't know how to get the x that is so many 0 in front.

Mining is to find nonce, this is the random number.

H (block header + nonce )≤target

This is the basic principle of bitcoin mining, that is, the hash collision to find the nonce, let him be less than a target (such as 32 0 and so on). The block header (or block head) is the information included in the block header is all the information that all miners know (such as version, prehash, merkle root, ntimenbits, etc.), so everyone who competes first guesses the nonce.

Remarks: In the binary world, because each bit is 0 or 1, the specific size is the number of 0 above, the first 32 bits are 0, naturally less than the first 31 bits are 0 (the 32nd bit is 1) ), the so-called specific size of this target is a limited range, because the number of sha256 is a 256-bit binary number (the characteristics of the hash function output value is fixed), which is more convenient than the previous 0 The way the result value is in the area. There are a lot of people who ignore this point. It is actually a very basic mathematics knowledge, it is worth noting.

The basic idea of ​​mining is the information from the above. In the process of mining in Bitcoin, it is actually to find the nonce, that is, after determining the output range, to find the input value. H(block header + nonce)≤target

When the input value (various information + nonce) is hashed, the value obtained conforms to the target range. For example, the first 35 zeros are OK. The value you guessed is 40. The first 40 values ​​are zero. Then definitely meet the requirements, in fact, the first 35 zeros will meet the conditions.

Then you post this information, other miners see your nonce value, and also hash, and soon know that your nonce is suitable, can meet the target requirements. Here we use the fast calculation of the hash function (the second feature).

This paper summarizes the characteristics of the singular hash function, which is the hash function, which is the basis of many blockchain applications and the basic principles of bitcoin encryption mining. The article said at the beginning that in addition to function functions, the cryptography used by Bitcoin has a very important content: digital signature. We will talk about this soon.

At present, the so-called blockchain application in the world, in fact, sometimes uses the data structure of Bitcoin (Merkel tree, etc.), sometimes using the UTXO model to settle. Sometimes it is traceable, sometimes it is a contract. A lot of applications come out, no matter what kind of concept, most of them use the hash function, using some of the five characteristics of the hash function.

With the in-depth explanation of the article, about bitcoin, information about the industry is unfolding. Slowly everyone can understand why the hash function is the basis of the bitcoin and blockchain industries.

Author: village two old

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

Chainlink: Soaring High in the Crypto Sky!

Chainlink continues to be a top-performing altcoin, with its price surging up to 50% amidst the recent market boom.

Market

Magnificent Seven Stocks Take a Tumble: Is the Tech Space Headed for a Recession?

Crypto's top assets see substantial gains amid decline in Magnificent Seven tech stocks.

Blockchain

Blobs Launch on Gnosis Chain ahead of Ethereum's London Upgrade.

Gnosis Chain is taking a significant step in enhancing its ecosystem by integrating blobs. This strategic move also l...

Blockchain

Solana Mobile’s Chapter 2 Web3 Phone Surpasses Expectations with Impressive Pre-Orders

Solana Mobile's Chapter 2 has exceeded all expectations by receiving an incredible 25,000 pre-orders within just 24 h...

Blockchain

Sam Bankman-Fried: The King of Crypto Faces Judgment Day

Sam Bankman-Fried, the fashion entrepreneur accused of fraud and criminal conspiracy, has been convicted with all sev...

Bitcoin

Bitcoin: Riding High and Making a Splash in the Digital Ocean

Bitcoin (BTC) starts the week with a slight surge in trading while there has been a rise in activity on L1 chains.