Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.
Sign up to join this communityAnybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
Asked
Viewed 47 times
For an exercise, I'm trying to find a sha256 hash with 11 leading zeroes.
For this reason, I wrote a Python script that basically tries all intergers from 1 to N and brute forces the hash. Now my N is at 16^11.
Am I mistaken or is there a problem with my code as there must be a nonce somewhere between 1 and 16^11 where the hash has 11 leading zeroes?
Thank you for your input!
Every attempted a hash has an independent probability of 1 in 1611 of having 11 leading zeroes.
That means a probability of not finding such a hash after n attempts is equal to the probability that n attempts are all unsuccesful: (1 - 16-11)n
That means the probability that you are successful increases with n, but never reaches 1:
- 1% chance after 176,807,378,144 attempts (~169.34).
- 5% chance after 902,361,177,698 attempts (~169.93).
- 20% chance after 3,925,582,869,332 attempts (~1610.46).
- 50% chance after 12,193,974,156,573 attempts (~1610.87).
- 80% chance after 28,313,531,182,477 attempts (~1611.17).
- 95% chance after 52,701,479,495,622 attempts (~1611.40).
- 99% chance after 81,015,010,678,098 attempts (~1611.55).
- 99.9% chance after 121,522,516,017,148 attempts (~1611.70).
- ...
No,the "nonce" could be alternate.Not limited in 1 to N. But the expect time of finding a target hash is 16^11,that meaning if u try 16^11 different "nonce" u are likely get a target.
there must be a nonce somewhere between 1 and 16^11 where the hash has 11 leading zeroes [in fixed-length hexadecimal encoding]?
You cannot assume this.
Bitcoin doesn't encode in hexadecimal and then test for number of leading zeroes. The test it uses is literally
if (hash <= hashTarget)
As you probably know, for current hashTarget
values, miners expect to exhaust all nonce values and vary other block values such as the so-called "extranonce" etc - and retry many many times.
See
you need difficulty * 248 / 65535 attempts.
Also note that's on average. You might never find one. The probability of finding a sufficiently small hash after n attempts is never 100% for any finite n.
You can get bonuses upto $100 FREE BONUS when you:
π° Install these recommended apps:
π² SocialGood - 100% Crypto Back on Everyday Shopping
π² xPortal - The DeFi For The Next Billion
π² CryptoTab Browser - Lightweight, fast, and ready to mine!
π° Register on these recommended exchanges:
π‘ Binanceπ‘ Bitfinexπ‘ Bitmartπ‘ Bittrexπ‘ Bitget
π‘ CoinExπ‘ Crypto.comπ‘ Gate.ioπ‘ Huobiπ‘ Kucoin.
Comments