Cointime

Download App
iOS & Android

Uncovering the Twist Attack Vulnerability: Was This a Failed Scam by Ronin exploiter?

On March 13th, 2023, Euler Finance, a DeFi project on the Ethereum blockchain, fell victim to a security breach, leading to a staggering loss of approximately $200 million US dollars to the attacker.

To complicate the investigation and evade detection, the Euler hacker transferred 100 ETH to Lazarus, the hacker group who had previously stolen over $625 million from Ronin. Lazarus then seized the opportunity to send a coded message on-chain to the Euler hacker, accompanied by a 2 ETH gift.

The message content was a hint for the Euler Exploiter to decrypt the message using eth-ecies.

Disclosure

In theory, if the Ronin Exploiter just wanted to encrypt communication in a public environment, using public-key encryption would be the simplest solution.

  • Public-key encryption: C = {rG, M + rQ} = {C1, C2}
  • Private key decryption: M = M + r(dG) − d(rG) = C2 − d(C1)

The protocol is very simple, where the ciphertext C, public key Q, private key d, random number r, and message M are used. The encryption process does not require the private key, so there is no path for private key leakage.

Was the use of eth-ecies for encryption for convenience or was there another purpose? Soon after, someone pointed out that there is a security vulnerability in eth-ecies, and the Ronin Exploiter may want to steal the private key of the Euler Exploiter.

Was this the real reason behind the message? Let us first analyze the type of vulnerability that exists in eth-ecies.

Twist Attack Vulnerability

Upon analysis, it has been discovered that the JavaScript elliptic curve library “elliptic”: “⁶.4.0” used by eth-ecies, is vulnerable to multiple security threats, including the twisted curve attack vulnerability (twist attacks). This vulnerability arises due to the failure of verifying whether the other party’s public key is on the curve when calculating the ECDH shared key. This allows attackers to construct a public key on a small subgroup curve and trick the victim into computing the shared key, ultimately leading to the compromise of the victim’s private key.

However, the exploit difficulty of this vulnerability is high and requires a very specific scenario to launch an attack. Did the Ronin Exploiter have the opportunity to launch a twist attack?

Risks with the ECDH Algorithm

ECDH algorithm is a key exchange algorithm based on elliptic curve cryptography. Similar to the traditional Diffie-Hellman (DH) algorithm, it uses mathematical operations on elliptic curves to achieve key exchange, thus providing higher security.

The steps of the ECDH algorithm are as follows:

  1. Generate an elliptic curve: Before initiating the key exchange, both parties must agree on a suitable elliptic curve that satisfies certain mathematical properties, such as the discrete logarithm problem.
  2. Generate private and public keys: Each party needs to generate a pair of private and public keys. The private key is a random number used to calculate the public key. The public key is a point on the elliptic curve, calculated from the private key.
  3. Exchange public keys: The two parties exchange their public keys.
  4. Calculate shared key: The two parties use the other party’s public key and their own private key to calculate a shared key. This shared key can be used to encrypt data in communication, ensuring the confidentiality of the communication.

For ease of description, let’s assume that Alice and Bob represent the two parties mentioned above, and G is the base point. Suppose:

Alice’s private key is a, so Alice’s public key is A = aG.

Bob’s private key is b, so Bob’s public key is B = bG.

The key to ECDH algorithm lies in the method of calculating the shared key. Using the commutative law of group multiplication, the parties can calculate the shared key as long as they have the other party’s public key.

S = aB = a(bG) = b(aG) = bA

If Alice wants to obtain Bob’s private key, she can select a curve point H with a very small order q (very few points), which is not the public key corresponding to any specific private key (but Bob does not know this). As the group is a cyclic group, when Bob calculates S’ = bH, the resulting S’ will be within this small point group. Alice does not know Bob’s private key b, but can obtain x that satisfies S’ = xH through brute force, and then b ≡ x mod q. Clearly, x is very small, at most q.

Knowing only one congruence is not enough to determine the private key, as the private key is a very large number, up to

, and a congruence in this range can have many solutions. Therefore, multiple such twisted points H need to be given to Bob for computation, so that a unique solution can be obtained through computation.

How many twisted points are needed? This depends on the order q chosen each time. The product of the orders needs to exceed the maximum value of the private key, that is, satisfy:

If a larger q is choosen each time, the number of interactions required n can be reduced, but the larger q means that the difficulty of exhaustive search increases. Therefore, a trade-off needs to be made based on Alice’s computational performance.

Event Analysis

Above, we analyzed the risks and attack principles of the ECDH algorithm. Let’s return to the eth-ecies library. In fact, it uses an algorithm similar to ECDH. It uses a temporary key when constructing the shared private key, and does not require the private key of the encryption party, so it does not pose a risk to the encryption party.

It is possible that the Ronin Exploiter may try to use social engineering tactics to guide the Euler Exploiter to use other vulnerable tools, such as the well-known PGP encryption protocol.

Coincidentally, we discovered that the widely used open-source library openpgpjs still uses a lower version of “@openpgp/elliptic”: “⁶.5.1” in its latest version, v5.7.0. What’s even more surprising is that it supports ECDH protocol based on Curve25519. The story seemed to have reached its climax, but upon analysis, we found that the ECDH protocol of openpgpjs introduces temporary keys, similar to the Ecies protocol. Even if the encryption party introduces the private key, it is only used for message signing and will not be used to construct shared keys.

With the story coming to an end, it seems unlikely that the Ronin Exploiter utilized the vulnerability in the older version of elliptic to covertly steal the Euler Explorer’s private key. As for the on-chain message, it may have genuinely been for the purpose of collaborating on a plan. Any further malicious intentions would require more advanced social engineering techniques. However, the Euler Exploiter is already aware of the situation and is staying vigilant.

Additional Information

Above, we mentioned the principles of twist attacks. However, there are still several problems that need to be solved in the actual implementation:

  1. How to construct twisted points?
  2. When Bob uses the shared key S’ to encrypt messages, he does not transmit S’ to Alice because, according to the protocol, Bob believes that Alice already knows the key. So, how can Alice obtain S’?
  3. Assuming the worst-case scenario, Alice eventually obtains a series of shared keys

What method can she use to recover Bob’s private key?

Taking the Curve25519 curve as an example, its curve equation is:

If we arbitrarily change one of the parameters, we get a new curve, such as:

We can use the sagemath mathematical software to represent it:

Then we calculate its order and factorize it:

End result:

We choose the moderately size number 19442993 and create a subgroup with 19442993 elements using the Chinese Remainder Theorem:

So here we have obtained the first twisted point, which we send to Bob as the public key, and Bob can calculate the first shared secret key:

Bob encrypted a message M using

and sent it to Alice. Alice does not know

or the message M, but she knows that M is definitely human-readable natural language. So she starts to enumerate

:

Using

, Alice decrypts the ciphertext, and if the resulting plaintext is natural language, then

=

,

.

Using the same method as above, we can obtain

. In my experiment, I used the following curves:

The final result can be represented as:

The private key b can be calculated using the Chinese Remainder Theorem:

Summary

In this article, we delved into the twisted curve attack in elliptic curve encryption algorithms through an unconventional dialogue. We analyzed the underlying cause of this vulnerability and although its exploit scenarios are limited, it is still a valuable vulnerability to be aware of. We hope our exploration inspires further learning and research in this field.

Lastly, we extend our gratitude to Safeheron, a leading one-stop digital asset self-custody service provider, for their invaluable technical guidance.

Read more: https://slowmist.medium.com/uncovering-the-twist-attack-vulnerability-was-this-a-failed-scam-by-ronin-exploiter-539111187aa6

Comments

All Comments

Recommended for you

  • Putin: Russia "supports" Harris, calls her smile "contagious"

    According to foreign media such as TASS and Russia's Sputnik News, Jinse Finance reported that on the afternoon of September 5th local time, Russian President Putin said at the plenary session of the Eastern Economic Forum 2024 that Russia will "support" the US Democratic Party presidential candidate and vice president Harris as recommended by the US President Biden in the upcoming US presidential election. When asked how he viewed the 2024 US election, Putin said it was the choice of the American people. The new US president will be elected by the American people, and Russia will respect the choice of the American people. Putin also said that just as Biden suggested his supporters to support Harris, "we will do the same, we will support her." The report said that Putin also joked that Harris' laughter is "expressive and infectious," which shows that "she is doing everything well." He added that this may mean that she will avoid further sanctions against Russia.

  • An ETH whale repurchased 5,153 ETH with 12.23 million USDT 20 minutes ago

    A certain high-frequency trading ETH whale monitored by on-chain analyst Yu Jin bought 5,153 ETH with 12.23 million USDT 20 minutes ago.

  • CFTC: Uniswap Labs has actively cooperated with the investigation and only needs to pay a fine of US$175,000

    The CFTC has filed a lawsuit against Uniswap Labs and reached a settlement. It was found that Uniswap Labs illegally provided leveraged or margined retail commodity transactions of digital assets through a decentralized digital asset trading protocol. Uniswap Labs was required to pay a civil penalty of $175,000 and cease violations of the Commodity Exchange Act (CEA). The CFTC acknowledged that Uniswap Labs actively cooperated with law enforcement agencies in the investigation and reduced the civil penalty.

  • Federal Reserve Beige Book: Respondents generally expect economic activity to remain stable or improve

    The Federal Reserve's Beige Book pointed out that economic activity in three regions has slightly increased, while the number of regions reporting flat or declining economic activity has increased from five in the previous quarter to nine in this quarter. Overall employment levels remain stable, although some reports indicate that companies are only filling necessary positions, reducing working hours and shifts, or reducing overall employment levels through natural attrition. However, reports of layoffs are still rare. Generally speaking, wage growth is moderate, and the growth rate of labor input costs and sales prices ranges from slight to moderate. Consumer spending has declined in most regions, while in the previous reporting period, consumer spending remained stable overall.

  • Puffpaw Completes $6 Million Seed Round with Lemniscap Ventures as Participant

    Puffpaw has announced the completion of a $6 million seed round of financing, with participation from Lemniscap Ventures. The Puffpaw project plans to launch a blockchain-enabled electronic cigarette aimed at helping users reduce nicotine intake through token incentives. The project encourages users to quit smoking by recording their smoking habits and rewarding them with tokens. Puffpaw's token economics aims to cover 30% of the cost of users' first month of using their product and provide social rewards. The project also considers possible system abuse, but the issue of users potentially reporting smoking habits dishonestly is not yet clear.

  • Affected by Ethervista and others, Ethereum Gas temporarily rose to 33gwei

    According to Etherscan, due to the influence of contracts such as Ethervista, Ethereum Gas has temporarily risen to 33gwei, with the top three being EthervistaRouter, UniswapRouter, and BananaGun.

  • The probability of the Fed cutting interest rates by 25 basis points in September is 55%.

    The probability of the Federal Reserve cutting interest rates by 25 basis points in September is 55.0%, while the probability of a 50 basis point cut is 45.0%. The probability of the Federal Reserve cutting interest rates by a cumulative 50 basis points by November is 32.1%, by 75 basis points is 49.2%, and by 100 basis points is 18.8%.

  • Nvidia: No subpoena received from the US Department of Justice

    Nvidia (NVDA.O) stated that it has not received a subpoena from the US Department of Justice.

  • US SEC again postpones decision on environmentally friendly Bitcoin ETF listing application

    The US Securities and Exchange Commission (SEC) has once again postponed its final decision on the New York Stock Exchange (NYSE) Arca's application for a carbon offset Bitcoin ETF. According to a document dated September 4th, the decision has been extended to November 21st. The ETF aims to provide a Bitcoin investment exposure in an environmentally friendly way by offsetting carbon emissions, tracking an investment portfolio composed of 80% Bitcoin and 20% carbon credit futures. Tidal Investments submitted the fund registration application in December 2023, while NYSE Arca submitted the initial application in March. Concerns have been raised about the environmental impact of Bitcoin mining, with the International Monetary Fund (IMF) reporting that cryptocurrency mining accounts for 1% of global greenhouse gas emissions. The delay in this decision also includes the postponement of approval for the Nasdaq One-Stop Cryptocurrency Investment Portfolio ETF.

  • Japanese regulator calls for lower cryptocurrency tax rates by 2025

    On September 4th, it was announced that Japan's financial regulatory agency has released a comprehensive tax reform plan for the fiscal year 2025, which includes regulations on cryptocurrency to lower its tax rate.