by dividuum · 10y ago · 0 comments
So the client does this:
from itertools import count
import hashlib
for i in count():
h = hashlib.md5("some-nonce:%d" % i).hexdigest()
if h.startswith("000000"):
print i
break
The value "some-nonce" is provided by the server. It also provides the difficulty by saying: I need you to find i which generates a hash that starts with 6 zeros.So the client calculates hashes for a while, and then submits the value 2652076 to the server. The server can the trivially check if the client did its work correctly:
$ echo -en "some-nonce:2652076" | md5sum
00000066adb2fb37a8460da553721c39 # ok, the first 6 digits are 0
The server can simply increase the difficulty by requiring the client to return more leading zeros. Or, if it should be more finegrained, a value below a certain threshold.The property of this proof of work is that the duration of the work is random.
How is it possible to know the average work time duration, without doing the measurement ? Is it possible to provide a work time limit so that if a client has really bad luck and can't find the solution in that period can he can issue another question ?
From the ur perspective, this varying work time duration may be an unpleasant experience.
To use your example, it must be 100% certain that a hash with 6 leading zeros is possible to generate with md5.
Also, I'm assuming you don't want clients spending too long on the problem, so it seems like you'd want to have a prediction of roughly how long it would take to compute the answer. Otherwise one client may get lucky after 10 iterations whist another may take 10 million. Are hashing functions predictable in that manner?
> The client has to create a hash that satisfies a certain condition
What you really want is to create a string whose hash matches the PoW challenge hash.