Knowing Bitcoin knows that mining is very power-hungry, which is due to the amount of work that Bitcoin uses.
Proof of workload refers to the work metrics that the system sets up to achieve a goal. The first is to use in the network attack and defense, greatly improve the attacker's computational capacity, the cost of attack went up.
The workload certificate needs to be completed by both the worker and the verifier. It has two meanings.
- 1. There must be a certain amount of work to be done by the worker, and this quantity is given by the validator.
- 2. The verifier can quickly check whether the workload is up to the standard, note that the test completed here must be simple.
Give a few examples
- A and B said, you give me to restore this Rubik's Cube, b to restore the Rubik's cube need a lot of time, and a verification is very fast, just need to see one eye.
- A and B say, you give me this 10 times equation, the process is very troublesome, but the results easy validation.
- A and B said, you give me to play this game clearance, B need a certain time, and a verification is very fast.
- The RSA algorithm is based on a very simple number theory fact: it is easy to multiply two large primes, but it is extremely difficult to factorization the product.
- ...
In a computer system, it is possible to design:
The validator given a random string s, the worker must find a number n, so that the random string to the number of n after the MD5 result of the previous several are 0.
That is, the results of MD5 (S+N) meet the requirements of the authenticator. Workers can only keep on trying to find a number n.
The Python code below.
Working Party:
#coding =utf-8from itertools Import countfrom hashlib Import md5msg = ' randomstring ' for I in Count (): Hashid = MD5 (msg+ STR (i)). Hexdigest () if Hashid.startswith (' 0000 '): print I,hashid break
Output 39496 00001c48020e444f58a297a0785df5cf, that is, the work party needs to MD5 () 39,496 times.
And the verifier only need to take the work party to come over N, do a MD5 can be verified.
That is, if MD5 (MSG+STR (n)). Hexdigest () [: 4] = = = ' 0000 '.
Since MD5 is represented in hexadecimal, the probability of each bit appearing is 16. So the workers to find the front 4 are 0 average need 16*16*16*16=65536 times.
The verifier can control the worker's workload according to the number of the previous 0. If you want to spend more power, add a few 0.
Demonstrate the workload with Python (proof of work)