0

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!

4
  • Why must there be? And are you sure you really did 17 trillion SHA256 hashes? What do you mean by "brute forces the hash"? Commented Jul 23, 2022 at 9:19
  • @DavidSchwartz I did 1.1 Trillion and found no 10. But I guess there is a flaw in this logic the longer I think about it.
    – Howdy
    Commented Jul 23, 2022 at 9:45
  • 11 leading zeros in binary or hexadecimal?
    – bordalix
    Commented Jul 24, 2022 at 7:35
  • @bordalix hexadecimal
    – Howdy
    Commented Jul 24, 2022 at 7:56

3 Answers 3

1

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).
  • ...
0
0

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.

0

there must be a nonce somewhere between 1 and 16^11 where the hash has 11 leading zeroes [in fixed-length hexadecimal encoding]?

  1. You cannot assume this.

  2. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.