4 ms·
The basic idea is: The client has to create a hash that satisfies a certain condition: Like the first n-digits must be 0, or maybe "the last bytes (when interpr
by dividuum 11y ago
The basic idea is: The client has to create a hash that satisfies a certain condition: Like the first n-digits must be 0, or maybe "the last bytes (when interpreted as a single 32 number) must be larger than x".
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.
- chmike 10y agoThank you very much. That was very clear. In the mean time I searched around on google. 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.
- wyldfire 11y agoYour explanation is fine but this summary will confuse people: > 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.
- hefty 11y agoMaybe I'm taking your example a bit far, but it seems like you'd have to choose the hashing function carefully, correct? 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?
- grenoire 11y agoReliable hash functions must be able to map to all combinations of 256, 512, or however many bits they are using.