Role of Hash in blockchain

When you are thinking of blockchain, you imagine chain of blocks. However, do you already know how these blocks are connected with each…

Role of Hash in blockchain

When you are thinking of blockchain, you imagine chain of blocks. However, do you already know how these blocks are connected with each other?

The answer is… by hash.


Agenda:

  • introduction,
  • What is hash?
  • Hash properties,
  • Hash use case in blockchain,
  • Hash algorithm,
  • Hashing process,
  • Hashing algorithms examples,
  • Security.

What is hash?

Hash is the mathematical function which takes as arguments different kind of data, numbers, strings, timestamps and as a result, generates encrypted output with precised length.


Properties

Hash has to fulfill six fundamental properties, it should be:

  • Deterministic,
  • Quick computation,
  • Pre-image resistance,
  • A small change in inputs changes the output entirely,
  • Collision resistance,
  • Puzzle friendly.

Hash is unique, always the same length and can not be “mathematically reversed”. To better describe, if you cook eggs, you can not get the primary ones by reverse-cooking. You can not put egg scramble back into eggs.

Moreover, there should not be possible to get hash output from many different variations of inputs. However, certain inputs should always generate the same output.


Hash use case in blockchain

Blockchain without hashes practically do not exist. Hash is the key of decentralization. From my previous thread, it is known that block is built from a header and the body.

Header mainly consists data like: previous hash, nonce, timestamp… Body includes transactions. Hash is used to “connect” blocks in chain. Block information about the previous hash indicates to which block is added, by finding this mentioned “number”.

Finding a new hash is the fundamental part of mining process, by nonce the target number is precised, so that miners can start solving the algorithm and seek hash below this level. Nonce indicates the difficulty level of adding new block.


Hash algorithm

All hash algorithms are:

  • Mathematical,
  • Uniform,
  • Consistent,
  • One way.

But how it works?


The process which hashing algorithm follows:

  • create the message, user determines what to hash
  • Choose the type of algorithm
  • User enters the message
  • Start of hashing function
  • Storing and saving the hash

Hashing algorithms examples:

  • MD-5,
  • Ripemd-160,
  • SHA,
  • Whirlpool.

Worth of mentioning is that bitcoin network uses SHA-256 algorithm, which output is a 256 bit hash.


Security

Hash makes blockchain extremely secure, adding next block requires computing the block header into hash. It makes practically impossible to change data in existing block, because output hash will not be equal to the previous hash data in next block.

Join my web3 challenge and follow new content:

twitter: https://twitter.com/kacperhernacki

Instagram: https://www.instagram.com/kacper.hernacki/

LinkedIn: https://pl.linkedin.com/in/kacper-hernacki-965161203

Github: https://github.com/Kacper-Hernacki