Search code examples
blockchainethereumsoliditybitcoincryptocurrency

How hashes for blocks are created in ethereum?


So according to my understanding of bitcoin, we change the value of nonce to create new hashes for a block until we get a hash within the target.

But in case of ethereum "The nonce, a counter used to make sure each transaction can only be processed once" is incremented by one for each transaction according to my understanding, please correct me if I'm wrong.

My question is if we cannot use random values for nonce in ethereum block to change the hash values and get a value within target then what changes we make to the block data how do we change hash values to get a value within target?


Solution

  • The proof of work (PoW) algorithm works in the same way in bitcoin and ethereum. There is also nonce in ethereum block header. Official documentation, called yellow paper, in section 4.3 says:

    (...) The block header contains several pieces of information: (...)

    nonce: A 64-bit value which, combined with the mixhash, proves that a sufficient amount of computation has been carried out on this block; formally Hn.

    In the same document, in section 4.2, is explained nonce for transaction.

    Just to summarize: In ethereum nonce appears in 2 places, in transaction and in block header. In transaction nonce works in the way you've described. In block header nonce works like in PoW. Both nonces are independent of each other.