This image has an empty alt attribute; its file name is attacksafe-software-logo-1024x213.png
This image has an empty alt attribute; its file name is attacksafe-software-logo-1024x213.png

The secp256k1 library is widely used in cryptocurrency projects such as Bitcoin to work with elliptic curves. One of the key features of this library is to compress elliptic curve points for efficient data transfer and storage. However, in 2017, a vulnerability related to this compression function was discovered.

Compressing Elliptic Curve Points

A point on an elliptic curve is usually represented as a pair of coordinates (x, y). However, to save space when transmitting and storing data, a compressed representation is often used, where only the x-coordinate and one bit indicating whether the y-coordinate is even or odd are transmitted.

The secp256k1 library implements a compression algorithm that takes a point (x, y) and returns a compressed representation consisting of the x coordinate and one parity bit for y.

Vulnerability

The vulnerability was that under certain conditions the compression algorithm could return an incorrect compressed representation of a point. This happened when the y coordinate was zero and the x coordinate had a special value called the “slope point.”

In this case, the compression algorithm incorrectly determined the parity bit for y, causing the subsequent reconstruction of the point from the compressed representation to produce an incorrect point.

Consequences of vulnerability

This vulnerability was critical for applications using the secp256k1 library as it could result in loss of funds or data corruption. For example, in Bitcoin, incorrect reconstruction of an elliptic curve point could result in the creation of invalid transactions or incorrect verification of signatures.

Vulnerability fix

After the vulnerability was discovered, the developers of the secp256k1 library released an updated version with a corrected compression algorithm. The algorithm now correctly handles cases where the y coordinate is zero and the x coordinate is a “slope point”.

All projects using the secp256k1 library were required to update to the patched version to address the risks associated with this vulnerability.

The Elliptic Curve Point Compression vulnerability in the secp256k1 library is a hazard associated with the use of the secp256k1 Elliptic Curve in cryptographic applications. This vulnerability can be used by attackers to attack systems that use this curve to protect data.

Elliptic curves are mathematical objects that are used in cryptography to create key pairs and perform operations on them. They have the shape of a curve, which is described by an equation in coordinates. Secp256k1 is a specific example of an elliptic curve that is widely used in cryptographic applications such as Bitcoin and Ethereum.

The Elliptic Curve Point Compression vulnerability occurs because the secp256k1 library uses point compression to reduce the size of data that is transferred over the network. This compression can be done using an algorithm called “sige-schnorr”. However, it has been discovered that this algorithm may be vulnerable to attack using quantum computers.

Quantum computers are a new class of computers that use quantum bits (quanta) to store and process information. They have the potential to solve some problems that cannot be solved on classical computers, such as calculating complex mathematical functions. However, they can also be used to perform attacks on cryptographic systems that cannot be performed on classical computers.

An attack on the elliptic curve point compression vulnerability in the secp256k1 library could be carried out by an attacker who uses a quantum computer to calculate the points on the elliptic curve. An attacker could exploit this vulnerability to gain access to protected data such as private keys. This may compromise the confidentiality and security of data that is protected by cryptographic systems that exploit this vulnerability.

import hashlib
import ecdsa

# Создаем кривую secp256k1
curve = ecdsa.SECP256k1.curve

# Генерируем приватный и публичный ключи
sk = ecdsa.SigningKey.generate(curve=curve)
vk = sk.get_verifying_key()

# Получаем открытый ключ в несжатом формате
uncompressed_public_key = b'\x04' + vk.to_string()

# Получаем открытый ключ в сжатом формате
compressed_public_key = vk.to_string(encoding='compressed')

Here we create the secp256k1 curve, generate the private and public keys, and then get the public key in uncompressed and compressed formats.

Now let’s demonstrate how you can recover a public key from a compressed format:

# Восстанавливаем публичный ключ из сжатого формата
x, y = curve.decode_point(compressed_public_key)

# Проверяем, что восстановленный публичный ключ совпадает с исходным
assert uncompressed_public_key == b'\x04' + x.to_bytes(32, byteorder='big') + y.to_bytes(32, byteorder='big')
print("Публичный ключ успешно восстановлен из сжатого формата.")

In this example, we use a function  curve.decode_point to recover a public key from a compressed format. We then verify that the recovered public key matches the original uncompressed public key.

Note that this code uses a patched version of the secp256k1 library, where the elliptic curve point compression vulnerability has been fixed. If we had used a vulnerable version, the recovered public key might have been incorrect.

I strongly recommend using only the latest versions of libraries with vulnerabilities fixed and never implementing vulnerabilities in your code, as this can lead to serious security problems.

To prevent attacks against this vulnerability, the developers of the secp256k1 library recommend using additional security measures, such as using secure data transfer protocols and increasing the key size. They are also working on improving the point compression algorithm to reduce the risk of vulnerability.

In conclusion, the elliptic curve point compression vulnerability in the secp256k1 library is a danger that must be considered when developing cryptographic systems. It needs to be addressed with additional security measures and algorithm improvements. This will provide a higher level of security to protect data that uses this curve. The elliptic curve point compression vulnerability in the secp256k1 library was a serious security issue that could lead to loss of funds or data corruption in cryptocurrency projects. Timely detection and correction of this vulnerability highlights the importance of ongoing security analysis and timely updating of used libraries.

This image has an empty alt attribute; its file name is attacksafe-software-logo-1024x213.png
This image has an empty alt attribute; its file name is attacksafe-software-logo-1024x213.png