Tuesday, May 22, 2018

BLOCKCHAIN INTERVIEW QUESTIONS PART 9 - What Is Hashing in Blockchain

What Are Addresses on Blockchains?
In the early days of Bitcoin, it was possible to send payments to an IP-address like 104.25.248.32 (which is blockgeeks.com). This was planned to be a convenient method to use Bitcoins without dealing with unhandy public keys and addresses. However, after the Bitcoin developers realized that this way of sending coins could be subject to serious man- in-the-middle-attacks, the option was disabled and did never come back.

The Public Key: Where the Blockchain Address Generation begins
After Pay to IP had been abandoned in Bitcoin, P2PKH became the new standard format for Bitcoin addresses.

It looks like this:
1K31KZXjcochXpRhjH9g5MxFFTHPi2zEXb

A standard P2PKH address has something like 34 signs and starts with a 1.
P2PKH is the abbreviation of “Pay To Public Key Hash.” This means that you pay to a hash of a public key.

Examples of cryptographic hash functions
  • MD 5: It produces a 128-bit hash. Collision resistance was broken after ~2^21 hashes.
  • SHA 1: Produces a 160-bit hash. Collision resistance broke after ~2^61 hashes.
  • SHA 256: Produces a 256-bit hash. This is currently being used by Bitcoin.
  • Keccak-256: Produces a 256-bit hash and is currently used by Ethereum.

So what is hashing?
In simple terms, hashing means taking an input string of any length and giving out an output of a fixed length.
In the context of cryptocurrencies like Bitcoin, the transactions are taken as an input and run through a hashing algorithm (Bitcoin uses SHA-256) which gives an output of a fixed length.
As you can see, in the case of SHA-256, no matter how big or small your input is, the output will always have a fixed 256-bits length.
This becomes critical when you are dealing with a huge amount of data and transactions. So basically, instead of remembering the input data which could be huge, you can just remember the hash and keep track.

Various properties of hashing functions and how they get implemented in the blockchain.
A cryptographic hash function is a special class of hash functions which has various properties making it ideal for cryptography. 

There are certain properties that a cryptographic hash function needs to have in order to be considered secure.
1.      Deterministic - This means that no matter how many times you parse through a particular input through a hash function you will always get the same result. 

2.      Quick Computation - The hash function should be capable of returning the hash of an input quickly. If the process isn’t fast enough then the system, simply won’t be efficient.

3.      Pre-Image Resistance - What pre-image resistance states is that given H(A) it is infeasible to determine A, where A is the input and H(A) is the output hash. 
Suppose you are rolling a dice and the output is the hash of the number that comes up from the dice. How will you be able to determine what the original number was? It’s simple all that you have to do is to find out the hashes of all numbers from 1-6 and compare. Since hash functions are deterministic, the hash of a particular input will always be the same, so you can simply compare the hashes and find out the original input.
But this only works when the given amount of data is very less. What happens when you have a huge amount of data? Suppose you are dealing with a 128-bit hash. The only method that you have to find the original input is by using the “brute-force method”. Brute-force method basically means that you have to pick up a random input, hash it and then compare the output with the target hash and repeat until you find a match.
So, while it is possible to break pre-image resistance via brute force method, it takes so long that it doesn’t matter.

4.      Small Changes in The Input Changes the Hash- Even if you make a small change in your input, the changes that will be reflected in the hash will be huge.

5.      Collision Resistant - Given two different inputs A and B where H(A) and H(B) are their respective hashes, it is infeasible for H(A) to be equal to H(B)



0 comments:

Post a Comment

Contact

Talk to us (+91-9738925800)