Why is bitcoin mining difficult if hashing is easy?
TL:DR - Why is bitcoin mining actually difficult when hashing is inherently an easy computational task?When researching what bitcoin miners are hashing I always end up with the same result:
Miners take the blocks header, tx data, nonce and guess a hash with a specific amount of zeroes in front of a hash according to a predetermined difficulty. The result is proof that work has been spent to get the hash to prove there was no cheating.
But from experience, I know that hashing data is inherently a fairly easy computing process. You can do it on literally any device (even with pen and paper), you just open any command line, take any piece of data and apply a SHA-256 algorithm and you get a hash. Many do this daily to check open source software for tampering when comparing a publicly provided hash to your local hash. And the hash is supposed to be always the same for the same piece of data which verifies for tampering.
I've been trying to figure something out for a while but can't seem to get my finger on it. Why is hash guessing actually difficult if miners are simply taking the data from the block and deriving the hash from it?
The few reasons I can come up with are if the miners are guessing a hash for a block that is still in the process of being filled, hence the hash is still unclear due to changing data, so are the miners hashing into the future until the block fills up and one of the hashes turns out to be correct?
Or is the nonce not known to the miner and along with the hash the miners have to also guess the correct nonce as well to achieve the necessary amount of zeroes? How can the nonce be unknown initially?
What is the correct answer here?
Posted Sep 14, 2022, 6:13 AM UTC
Let's pretend you're rolling dice. Yes, a roll of the dice is very easy to do!
But to get snake eyes? That's trickier. You need to roll and roll and roll and roll again, and never quite sure when you'll get snake eyes.
Likewise, it is easy to hash, but to get exactly the right hash? That's much trickier.
So you've got to do lots and lots and lots of hashing, until with a bit of luck you get the right hash. (and obviously, the greater the hash power you have, the more "lucky" you'll be!)
This is also why there are mining pools. If you're rolling dice by yourself, it might take a long time until you get to be first in getting snake eyes. But if you're rolling dice with all your friends together (and you agree to split the prize, no matter who wins), then you improve your odds for each new block, and smooth out the variability in the long run.