HomeCryptoBitcoinBitcoin: what is the hash function?

Bitcoin: what is the hash function?

The Bitcoin protocol makes extensive use of the so-called hash function for adding new blocks to the blockchain through the mining process.

Generally, from a technical point of view, a hash function is an algorithm that, starting from data of arbitrary length, produces a hash of fixed length. This hash is a hexadecimal code that represents the original data package used to generate it and is generally much shorter in length. 

The main use of this function is to create a synthetic, relatively short code that represents a much larger data package. Considering that this process, if done in this way, inevitably involves a certain loss of data, it is de facto irreversible: the hash cannot be traced back to the data packet used to generate it. 

The algorithm used by Bitcoin for the hash function is SHA-256, which produces a 256-bit hash and requires a predictable amount of processing power from the computer. 

To add a new block to the Bitcoin blockchain, a data packet of queued transactions in the mempool waiting to be confirmed is used as input to the hash function. 

The miner’s job, though, is not just to produce the hash of this input, but to produce a hash that starts with a number of additional zeros, and that matches the input data packet. 

In fact, although the hash cannot be traced back to the data that generated it, it is always possible to repeat the operation to verify that it was done correctly. This way, since all transaction data entered in the block is public, anyone can verify using SHA-256 that the hash produced by the miner is correct. Only if it is correct will the hash actually be added to the blockchain, and the miner will receive the reward. 

Hash function and difficulty of mining

The number of additional zeros is changed every two weeks or so and corresponds to the so-called difficulty: the more zeros are needed, the harder it will be to find the hash, the longer it will take. 

In order to find the hash with the additional zeros, the miner can only proceed by trial and error, which is why computing power plays a key role in the mining process. 

Since each block can be mined by a single miner, and since the reward is given only to the miner who can find the hash that confirms the block, this generates a competition in which the miner with the most computing power has the most advantage. 

In addition, even the smallest change to the input data produces a completely different hash, so the only way to proceed is to process as many hashes as possible in the shortest possible time, running the hash function many times per second. 

For example, a hashrate of 130 Ehash/s means that machines that are trying to mine Bitcoin blocks all over the world perform a total of 130 Exa hash functions per second, or 130 million million million (or 130 billion billion). 

The Bitcoin protocol also uses the hash function to generate the hash of a transaction, which is the unique identifier used to identify each individual transaction. 

 

Marco Cavicchioli
Marco Cavicchioli
Born in 1975, Marco has been the first to talk about Bitcoin on YouTube in Italy. He founded ilBitcoin.news and the Facebook group" Bitcoin Italia (open and without scam) ".
RELATED ARTICLES

MOST POPULARS

GoldBrick