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!
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."
Yes, this is how it works.