When we look at this block - what does the first number

Hash: 0xfe88c94d860f01a17f961bf4bdfb6e0c6cd10d3fda5cc861e805ca1240c58553

actually mean? How is it calculated?

"Nonce" is the value that is changed during mining, but what is hash?


The block header is the hash returned from generating a Merkle tree that is below the current difficulty target for the blocks data.

What's a hash?

In order to understand what the block header is you need to understand what a hashing function is. A hashing function is a one way(non invertible function) that maps a set of inputs to a set of outputs hash(s) -> p, where for our purposes s and p are both strings. For any string s we can find the hash by applying our hashing function, which will return a new string. This is a deterministic procedure in that given an s, the same hash() will produce the same p. There is no inverse of the hash operation, so you cannot go from output to input hash^-1(p) -> s. A hash function will ideally map the domain uniformly over the range such that any input that is in the domain will have a pretty even probability of being anywhere in the range vs more likely to be in a certain section.

You use hashing operations for many different applications from data storage and lookup to logging into any password protected environments. It is also used to verify the integrity of data. Lets say you have a large file F. You can take the hash of the file by converting it to a string and then taking the hash of it, hash(F) -> G. G will be a string representation of (in this case) a 5 digit hexadecimal number(hashes like sha give you 40 digit hex numbers), lets say 0x5a3b1. Now some interesting properties can be examined. First is data integrity, if you wanted to download a copy of the file, you would need a verified copy already to compare with to ensure that it was the same one and not tampered with to go through and make sure every byte is the same. With a hash we can do this much more easily. Since the hash of the original file always maps to the same G with the same hash function, the recipient can just take the hash of the file and compare it with a published hash of the file and see that they match. Changing even a single bit would change the value returned by the hash function.

So what's a merkle tree?

Blah blah, that's boring, what does any of this have to do with ethereum and blockchains? Well, the data in the blockchain can be "stored" by storing the hashes of data, such that you can at least verify that that's the datum whose hash was stored if you have the datum to hash yourself and check against the one in the blockchain. A Merkle tree is one way of doing this.

So to construct a Merkle tree you make a tree data structure with each of the leaf nodes containing the hash of a section of the data to be stored. From there you take the hash of the concatenation of the child nodes, and propagate the value up to the parent, continuing this process up the tree until a final hash is generated. A blocks header is the top hash of applying the Merkle procedure to a the data contained in the block. Thus even if a block has a large number of transactions all that is stored is the root hash of the Merkle tree.

enter image description here

Any changes to the source will be apparent if the same merkle procedure is applied to both files, small changes at the leaves propagate upwards and change the resultant hash.

enter image description here

An interesting lemma is that as a "storage" mechanism, hashes are "lossy" such that starting with a 2000 character file, and eventually getting a 40 digit hex number; The original encoding of 2000 characters with 78 possible characters(making bounds on this approximation) has 9.582e+3772 possible files that could be represented, while the hashing function can only map that range to 1.106e+47 outputs in the domain. That's still a large domain, so hash collisions (when two inputs map to the same output) would be extremely rare.

  • Thank you. So in practice, miner needs first to pick a Nonce and only after that he gets blocks hash (valid or not), because block's has contains nonce as input? So that leads to my other question. If blocks hash is The Final value, which needs to be below certain difficulty, why are the no zeroes in the beginning of ethereum blockchain hash as in Bitcoins hashes? – Matias Mar 17 '16 at 18:00
  • 2
  • I dont see why you could only generate a range of 1.106e+47 outputs from the hash input. a 40 digit hex number should be able to generate 16^40 = 1.4615016e+48 outputs. Am I missing any assumptions? – Validity Labs - Sebastian Apr 11 '16 at 15:24
  • Why cant we add all data and take a hash of it. Why does take 2 data and then take a hash and same till the top of tree? – Hacker May 14 '18 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.