HACKER Q&A
📣 0xhh

How does a blockchain server verifies the hash sent by a miner?


I'm sorry if this is not the right place to ask. I did not find any relevant subreddit on reddit to ask, so I came here.

I'm trying to follow some python tutorials on implementing a blockchain. I implemented the mining function, where it generates a hash based on previous hash, timestamp and some data. And this hash is verified by checking whether there are 4 zeros in the starting hash and is then added to an array called chain.

But, How does a server hosted somewhere on the cloud verifies this hash sent by a miner? should the server calculate the hash before the miner does and check whether they are equal?

Or will the server only checks for the starting zeros in the hash? In this case, miners can cheat right? just by sending a random string with 4 starting zeros?

Please enlighten me and explain me like I'm five. Thank you!


  👤 brudgers Accepted Answer ✓
Finding a new value that hashes to four leading zeros is computationally difficult. Because the hash function is designed so that very few values hash to four leading zeros.

But testing to see if a value hashes to zero is computationally simpler. Just take the value, hash it, and see if it has four leading zeros.

What is sent is the input value, not the output with four leading zeros.

The miner claims "if you hash this value, you will get four leading zeros."


👤 wmf
should the server calculate the hash before the miner does and check whether they are equal?

Yes, this is how it works.