chikaku

且听风吟

永远是深夜有多好。
github
email

Time-lock puzzle

Recently, there have been fewer things to do at work, so I have been browsing interesting things while slacking off. When I was looking for VDF-related information, I came across a question: how to design a puzzle that can only be solved after a specified time TT? I thought about it for a while but couldn't figure out how to quantify the abstract concept of time in a puzzle. 🤔

Then I came across this referenced paper Time-lock puzzles and timed-release Crypto.

After reading the article, I realized that this problem can actually be equivalent to designing an algorithm that can only produce the correct result after PP calculations, and the calculation process of this algorithm cannot be accelerated by parallel computing. This means that only one machine can be used for decryption. Assuming its maximum computing power per second is SS, it will take T=P/ST = P / S seconds to obtain the correct result, achieving the goal of time-lock.

The article introduces two implementations of time-lock puzzles.

Design of the first type of time-lock puzzle#

Assuming Alice has a message MM to be transmitted to Bob, but it needs to be encrypted (locked) for TT seconds. (Here, one prerequisite is that Alice needs to know Bob's computing power in advance)

Encryption#

Step 1: Randomly select two large prime numbers pp and qq, and multiply them to get n=pqn = p*q. At the same time, calculate ϕ(n)=(p1)(q1)\phi(n) = (p-1)*(q-1).

Step 2: Calculate t=TSt = T*S, where SS is the number of times Bob's single machine can perform modular exponentiation of nn per second (also known as computing power).

Step 3: Randomly generate a sufficiently secure key KK for encryption, and an encryption algorithm such as RC5.

Step 4: Use the key and encryption algorithm to encrypt the original message to obtain Cm=RC5(K,M)C_m = RC5(K, M).

Step 5: Choose a random number a (1<a<n)a\ (1 < a < n) and encrypt KK to obtain Ck=a2t (mod n)C_k = a^{2^{t}}\ (mod\ n).

This step can be accelerated through the following steps: first calculate e=2t (mod ϕ(n))e = 2^{t}\ (mod\ \phi(n) ), and then calculate b=ae (mod n)b = a^{e}\ (mod\ n).

Finally, Alice publishes (n,a,t,Ck,Cm)(n, a, t, C_k, C_m) to Bob.

Decryption#

For Bob to obtain MM, he needs to decrypt CmC_m using the key KK. However, during encryption, it has been ensured that KK itself is sufficiently secure. Bob can only calculate K=Cka2t (mod n)K = C_k - a^{2^{t}}\ (mod\ n) using CkC_k.

At this point, only tt remains as an unknown variable. For Bob, there is no better way to find the correct KK other than brute-forcing all possible values of tt.

Thus, it is necessary to perform calculations for a sequence of a2,a4,a8,a16,...ax(t=1,2,3,...) a^{2}, a^{4}, a^{8},a^{16},...a^{x} (t = 1,2,3,...). It can be observed that in this sequence, each calculation depends on the previous calculation result a4=(a2)2,a8=(a4)2,...a^{4} = (a^{2})^{2}, a^{8} = (a^{4})^{2}, .... This means that the values of the later terms cannot be calculated in advance, and the calculation cannot be accelerated in parallel. The result can only be obtained through tt calculations. According to the previously set t=TSt = T*S, the required calculation time is T=t/ST = t/S, which achieves Alice's goal of locking the message for TT time.

(As for how Bob determines that he has found the correct KK, it is not part of this algorithm. One way is for the encryptor to provide sha256(K)sha256(K) for Bob to verify.)

Design of the second type of time-lock puzzle#

I didn't read the second part carefully. I directly uploaded the paper to Claude2 and asked AI to summarize it for me (highly recommended to use Claude2 when GPT-4 is not available).

ME: Please introduce the second method.

The second method proposed in the article using trusted proxies is roughly as follows:

  1. Set multiple trusted proxies, each proxy regularly publishes a key.
  2. The user encrypts the message with a random key to obtain the ciphertext.
  3. The user divides this random key into multiple parts using a key sharing scheme and gives each part to a different proxy.
  4. Each proxy encrypts the part of the key they hold using the key published at time t in the future.
  5. At time t, a sufficient number of proxies have published their keys at that time.
  6. The user can decrypt the parts of the key using these keys and reconstruct the original random key.
  7. Finally, use this random key to decrypt the original message.

The security of this method depends on the trusted proxies not leaking future keys in advance. At the same time, setting multiple proxies can achieve a certain degree of fault tolerance through key sharing and threshold verification. Even if individual proxies are compromised or fail, as long as there are enough proxies still functioning properly, the information can still be decrypted at the predetermined time.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.