Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 21, 2020 09:34 pm GMT

Proof Of Work : Explained

If you have been following the blockchain space you have probably heard of the term proof of work.

In this article I will try to explain the concept in a way that at the end of this article you can have a grasp of what POW really is both theoretically and in practical or technical aspect.

Understanding Hash Functions

To understand POW, one has to learn about hash function, you can skip this part if you already know about hash functions.

Simply put a hash function is a family of functions that take an input data, this data can be a string of text, an array of bytes, etc, ... and then the function returns a fixed length value can be 128 bits, 250 bits, 512 bits, etc, ...

Note that there are hundreds of hundred functions currently in use, and the most widely used in the blockchain space is the SHA256

In the example below we will use 2 hash functions RIPEMD128 and SHA256

> RIPEMD128_Of("Eddy")> bb8535858fed3f9f979367cc0de9f7f6 # RIPEMD128> SHA256_Of("Eddy")> 29b566345fb23ef6e9097cb2100ba8724d8253a39f0cfee35ca0c8480588449e# Since it's function we can even call it twice on the same value f(f(x))> SHA256_Of(SHA256_Of("Eddy")) # Double hashing> 00693c845afdfccde0eeffbe9ad149028f019a1c48e139e52ab46d1beea903ea

Online hash calculator : https://md5calc.com/hash

How is POW computed

The first step of POW computation is concatenating or adding together different pieces of the block header data. [1]
The result is a piece of data on which we can perform hash functions.
One important piece of the header data is called nonce which is a 32 bits integer

NOTE : I won't be detailing on block header components in this piece, the rabbit hole goes so deep that those can be an articles on their own.

Once we have the block header data, the work can finally start.
The way it works is start by :

  • Double hashing the data with SHA256 hash function,
  • Extract a number from the 256 bits output and
  • Compare the result number against the target, if it's bigger than the target, the process is repeated again.With the current network difficulty level, this process can be done in extremely large number of sequences.

The current network hash rate is ~ 90 quintillions ( 10^18) of hashes every second, this led to development of ASIC miners , which are hardware devices solely optimized for hash algorithm computation.

POW Steps In Pseudocode

# Concatenate header data.0 : HeaderData = version + prevBlockHash + rootHash + time + targetNumber +nonce# We hash twice the header data1 : DoubleHash  =  SHA256_Of(SHA256_Of( HeaderData )) # We convert the 256 bits output to a large integer value2 : ResultNumber =  Number.from(DoubleHash) # Compare the result number3 : IF ResultNumber < targetNumber   We have found the right hash, POW is completed.    Else : We increment the nonce integer and go back again to Step 0 Until we find a result number that is smaller than the target.

REFERENCES

[1] https://en.bitcoin.it/wiki/Block_hashing_algorithm


Original Link: https://dev.to/eddy_wm/proof-of-work-explained-531

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To