Mathematical foundations, the covering set method, and practical applications for private key recovery in Bitcoin transactions. Riesel numbers, discovered by Hans Riesel in 1956, are a profound number-theoretic phenomenon that finds unexpected applications in cryptanalysis.
The covering set method, a key tool for proving properties of Riesel numbers, provides a structural foundation for the analysis of periodic sequences. In the context of ECDSA, this method allows:
- Formalize the problem of private key recovery as a system of linear comparisons;
- Reduce the infinite search space of nonces to a finite set of residue classes;
- Apply lattice methods (LLL/BKZ) to efficiently solve a hidden numerical problem.
Although modern cryptographic standards (RFC 6979, BIP-32) eliminate most practical vulnerabilities, the theoretical relationship between Riesel numbers and ECDSA remains important for understanding the underlying structures of cryptographic primitives. Cryptanalysis based on covering sets is a powerful tool for analyzing implementations that deviate from the standards.
1. Theoretical introduction: Riesel numbers
In 1956, the Swedish mathematician Hans Riesel proved a fundamental result in number theory: there exist infinitely many odd natural numbers k such that all numbers of the form k 2 n − 1 are composite for any natural number n. Such numbers are called Riesel numbers .
k 2 n − 1 ∈ ℤ composite ∀ n ∈ ℕ
The smallest known Riesel number is 509 203. Riesel showed that not only the number 509 203 itself has this property, but also any number of the form:
k = 509 203 + m 11 184 810, m ∈ ℕ
This means that the Riesel numbers form an arithmetic progression with difference equal to the product of prime numbers from the covering set [reference:0].
1.1. Covering Set Method
The key tool for proving that a number is a Riesel number is a covering set —a finite set of primes {p₁, p₂, …, p t } such that for every n, the number k · 2 n − 1 is divisible by at least one of these primes[reference:1].
For the number k = 509 203 the covering set has the form:
𝒞 = {3, 5, 7, 13, 17, 241}
The covering mechanism is based on the periodicity of the sequence 2 n mod p for each prime p in the covering set. For each p, there exists r p such that:
2 n ≡ r p (mod p) ⟹ k r p − 1 ≡ 0 (mod p)
This means that for any n there is a prime p ∈ 𝒞 such that p | (k 2 n − 1). Therefore, the number k 2 n − 1 can never be prime.
| Simple p | Period n mod (p−1) | Coverage condition |
|---|---|---|
| 3 | 2 | n ≡ 1 (mod 2) |
| 5 | 4 | n ≡ 3 (mod 4) |
| 7 | 3 | n ≡ 2 (mod 3) |
| 13 | 12 | n ≡ 11 (mod 12) |
| 17 | 8 | n ≡ 3 (mod 8) |
| 241 | 24 | n ≡ 15 (mod 24) |
The union of all residue classes n mod lcm(2,4,3,12,8,24) = 24 covers all natural numbers without exception. This is the essence of the covering set method[reference:2].
1.2 Riesel numbers and the prime number problem
Riesel numbers are closely related to the Sierpinski problem . A Sierpinski number k is an odd number such that k · 2 n + 1 is composite for all n. Riesel numbers use −1 instead of +1. There are numbers that are both Sierpinski numbers and Riesel numbers (the so-called Brier numbers ) [reference:3].
Important for cryptography: If a prime number p were of the form p = k · 2 n − 1 and k were a Riesel prime, then such a p could not exist. This directly affects the generation of cryptographic parameters that require prime numbers of a special type (for example, Mersenne or Proth primes).
2. ECDSA: architecture and vulnerabilities
2.1. ECDSA Algorithm
ECDSA (Elliptic Curve Digital Signature Algorithm) is a digital signature scheme whose security is based on the difficulty of the elliptic curve discrete logarithm problem (ECDLP)[reference:4].
The process of signing a message m with a private key d involves the following steps:
1. Choose an ephemeral nonce k ∈ [1, n−1]
2. Calculate the point R = k · G, where G is the generator of the group
3. r = R x mod n
4. s = k −1 · (H(m) + r · d) mod n
The pair (r, s) is a signature. It is critical that the nonce k be unique for each signature and unpredictable. If an attacker knows k for at least one signature, they can calculate the private key:
d = (s k − H(m)) r −1 mod n
Even partial knowledge of the nonce (e.g., the most significant or least significant bits) allows one to recover d using Hidden Number Problem (HNP) methods[reference:5].
2.2. Bitcoin transaction vulnerability
In the Bitcoin blockchain, all transactions and signatures are publicly available. If two different transactions use the same nonce k (or nonces related in a predictable way), the private key can be recovered. There have been real cases of such attacks on Bitcoin wallets [reference:6].
However, even without direct knowledge of the nonce, there are attacks based on the statistical properties of nonce generation and the structure of the modulus n. This is where Riesel numbers and the covering set method can find unexpected applications.
3. Application of Riesel numbers to ECDSA cryptanalysis
3.1 Conceptual connection
At first glance, Riesel numbers are a purely number-theoretic construct with no direct relation to elliptic curves. However, there is a deep structural analogy between the covering set method and the nonce recovery problem in ECDSA.
Consider the sequence k · 2 n − 1. The covering set method shows that for any n, the number is divisible by one of the primes p ∈ 𝒞. Similarly, in ECDSA, the sequence of nonces k₁, k₂, …, k N can be “covered” by a set of linear congruences if partial information about them is known.
Key idea: If the nonce generation structure has periodic properties similar to 2n mod p, then one can construct a “covering set” of comparisons that will allow one to recover the nonces and then the private key.
3.2. Formalization: Hidden Numerical Problem and Covering Sets
Let n be the order of the elliptic curve (a prime number). For each signature i, we have:
s i · k i ≡ H(m i ) + r i · d (mod n)
Let us assume that nonces are generated by a deterministic algorithm with period T:
k i = f(i mod T)
Then for each j ∈ {0, 1, …, T−1} we can write:
k j ≡ A j d + B j (mod n)
where A j = r j · s j −1 and B j = H(m j ) · s j −1 .
This reduces the problem to a system of linear congruences with respect to a single unknown d. If the number of signatures N ≥ T, the system becomes overdetermined, and d can be found using lattice methods (LLL, BKZ)[reference:7].
3.3. Private key recovery algorithm
Below is a conceptual algorithm that combines the covering set method with lattice cryptanalysis.
Step 1: Collect signatures
We collect N signatures (r i , s i , H(m i )) from the blockchain.
Step 2: Constructing a covering set of comparisons
For each possible period T (for example, T = 2 t ) we construct a set of comparisons:
𝒞 = { (A j , B j ) : j = 0, …, T−1 }
where A j = r j · s j −1 mod n, B j = H(m j ) · s j −1 mod n.
Step 3: Solving the system of comparisons
We are looking for d such that for all j:
k j = A j d + B j mod n ∈ [0, 2 m )
where m is a known bound on the size of the nonce (for example, if the nonce is generated as a 128-bit number).
Step 4: Lattice Attack
We construct a lattice of dimension T + 1 and apply the LLL algorithm to find a short vector corresponding to d[reference:8].
Step 5: Verification
We check that d · G = Q, where Q is the public key.
3.4 Practical implementation
"""
Концептуальная реализация восстановления приватного ключа ECDSA
на основе метода покрывающих множеств и решёточного анализа.
"""
import hashlib
import random
from math import gcd
# Параметры кривой secp256k1 (упрощённо)
n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
G = (0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798,
0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8)
def hash_message(msg: bytes) -> int:
"""SHA-256 хеш сообщения, приведённый по модулю n."""
h = hashlib.sha256(msg).digest()
return int.from_bytes(h, 'big') % n
def sign(msg: bytes, d: int, k: int) -> tuple:
"""Генерация подписи ECDSA с заданным нонсом."""
# Упрощённая реализация для демонстрации
h = hash_message(msg)
r = (k * G[0]) % n # Упрощение: используем только x-координату
s = (pow(k, -1, n) * (h + r * d)) % n
return (r, s, h)
def build_covering_set(signatures: list) -> list:
"""
Строит покрывающее множество сравнений.
Возвращает список кортежей (A_j, B_j), где:
k_j = A_j * d + B_j (mod n)
"""
covering_set = []
for (r, s, h) in signatures:
s_inv = pow(s, -1, n)
A = (r * s_inv) % n
B = (h * s_inv) % n
covering_set.append((A, B))
return covering_set
def lattice_attack(covering_set: list, bound: int) -> int:
"""
Концептуальный решёточный анализ для поиска d.
В реальной реализации здесь используется LLL/BKZ-редукция
решётки размерности len(covering_set) + 1.
"""
# Демонстрация: перебор для малых значений (только для тестирования)
T = len(covering_set)
# Строим систему: A_j * d + B_j = k_j (mod n), где k_j < bound
# Это система линейных сравнений, решаемая методом наименьших квадратов
# в решёточной постановке.
for d_candidate in range(1, bound):
valid = True
for j in range(T):
A_j, B_j = covering_set[j]
k_j = (A_j * d_candidate + B_j) % n
if k_j >= bound:
valid = False
break
if valid:
return d_candidate
return None
# === Демонстрация ===
if __name__ == "__main__":
# Приватный ключ (для теста)
d_true = 0x1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF % n
# Генерация подписей с детерминированными нонсами (период T=4)
T = 4
nonces = [random.randint(1, 2**32) for _ in range(T)]
signatures = []
for i in range(12): # 3 полных периода
msg = f"Transaction #{i}".encode()
k = nonces[i % T]
signatures.append(sign(msg, d_true, k))
# Строим покрывающее множество
covering = build_covering_set(signatures)
# Решёточная атака (демонстрация с малым bound)
bound = 2**40 # Реалистичный размер нонса
d_recovered = lattice_attack(covering, bound)
print(f"Истинный ключ: {d_true}")
print(f"Найденный ключ: {d_recovered}")
print(f"Совпадение: {d_true == d_recovered}")
Limitation: The code provided is a proof-of-concept demonstration. A real lattice attack requires the use of LLL/BKZ algorithms with a lattice dimension equal to the number of signatures and works only if the nonces actually have a periodic structure and their size is significantly smaller than n.
4. Mathematical reasons: why it works
4.1 Connection with the hidden number problem
The problem of recovering d from a system of congruences k j = A j · d + B j mod n subject to k j < 2 m is a classical Hidden Number Problem (HNP) introduced by Boneh and Venkatesan[reference:9].
For HNP, it is known that, given a sufficient number of signatures N and a sufficiently small m (the size of the nonce), a solution can be found in polynomial time using lattice methods. The critical condition is:
N (m − log₂ n) > log₂ n
This means that if the nonces are less than n by b bits, then approximately n / b signatures are needed to recover the key[reference:10].
4.2 Periodicity and covering sets
The covering set method from Riesel number theory provides structural regularity , which allows:
- Determine the minimum period T of nonce generation;
- Construct a system of comparisons covering all possible values of n;
- Reduce the problem to a lattice formulation with known dimension.
Without a covering set, we would have to consider all possible values of n without restrictions, making the problem computationally intractable. A covering set reduces the infinite search space to a finite set of residue classes .
4.3 Computational complexity
| Parameter | Meaning |
|---|---|
| Nonce size (bits) | 128 |
| Size n (secp256k1) | 256 |
| Information leak (bit) | 128 |
| Required number of signatures | ≈ 2–4 |
| LLL complexity (dimension 5) | Polynomial |
5. Practical aspects and limitations
5.1 When the attack is applicable
The attack based on Riesel numbers and covering sets is applicable when:
- Nonces are generated by a deterministic algorithm with a small period;
- There is a known upper limit on the size of nonces (for example, 128 or 160 bits instead of 256);
- A sufficient number of signatures are available (N ≥ T);
- The order of the curve n is a prime number (the standard case for secp256k1).
5.2. Limitations
Critical limitations:
- If the nonces are generated by a cryptographically strong generator (CSPRNG), there is no period and the attack does not work.
- If the nonces have size comparable to n, there is no information leakage and HNP is undecidable.
- Modern implementations of ECDSA (RFC 6979) use deterministic nonce generation based on HMAC, which eliminates periodicity.
- Bitcoin wallets that follow the BIP-32/BIP-39 standards use cryptographically strong nonces.
5.3. Real vulnerabilities
Despite the theoretical limitations, there are known real cases of ECDSA keys being compromised in the blockchain due to:
- Nonce reuse is a classic attack that allows one to recover a key from two signatures with the same k;
- Nonce bias – if the high-order bits of the nonce are always zero, HNP is solvable by lattice methods[reference:11];
- Faulty hardware generators – some hardware wallets had defects in random number generation.
6. Conclusion
Riesel numbers, discovered by Hans Riesel in 1956, are a deep number-theoretic phenomenon that finds unexpected applications in cryptanalysis.
The covering set method, a key tool for proving properties of Riesel numbers, provides a structural foundation for the analysis of periodic sequences. In the context of ECDSA, this method allows:
- Formalize the problem of private key recovery as a system of linear comparisons;
- Reduce the infinite search space of nonces to a finite set of residue classes;
- Apply lattice methods (LLL/BKZ) to efficiently solve a hidden numerical problem.
Although modern cryptographic standards (RFC 6979, BIP-32) eliminate most practical vulnerabilities, the theoretical relationship between Riesel numbers and ECDSA remains important for understanding the underlying structures of cryptographic primitives. Cryptanalysis based on covering sets is a powerful tool for analyzing implementations that deviate from the standards.
Ultimately, Riesel numbers remind us that even the most abstract mathematical constructs can find applications in the most unexpected areas—from number theory to blockchain security.
Directions for further research for cryptanalysis based on this area
- Generalized Covering Sets for Elliptic Curves. Investigation of the possibility of constructing covering sets directly in the group of points of an elliptic curve. If we can find a finite set of primes {p₁, …, p t } such that for any n, the dot product n · G has a coordinate divisible by one of the p i , this will yield a new class of attacks on ECDLP.
- Riesel primes and special primes in cryptography. Analysis of the influence of Riesel primes on the generation of Proth primes (p = k 2n + 1) and Mersenne primes. If k is a Riesel prime, then a prime of the form k 2n − 1 does not exist. This can be used to attack schemes that use such primes (e.g., some RSA implementations and Diffie-Hellman schemes).
- Lattice attacks on ECDSA with periodic nonces. Development of optimized LLL/BKZ algorithms for the case where nonces have a known periodic structure. Study of the dependence of attack complexity on the period length T and nonce size m.
- Application of Sierpinski and Brier numbers. Brier numbers (also known as Sierpinski and Riesel numbers) may have additional properties useful for cryptanalysis. A study of their application to constructing covering sets in pairing-based cryptography.
- Analysis of pseudorandom number generators for periodicity. Development of methods for detecting hidden periodicity in nonce generators used in cryptocurrency wallets. Application of spectral analysis and number theory methods (including covering set theory) to identify weak generators.
- Quantum aspects. Investigation of the relationship between Riesel numbers and Shor’s algorithm for factorization. Although Shor’s algorithm solves the factorization problem in polynomial time on a quantum computer, covering sets can provide additional constraints on the structure of factorable numbers, which can potentially be used for post-quantum cryptanalysis.
- Automated Covering Set Search. Development of machine learning algorithms for automatically searching for covering sets for given sequences. This can be applied to the analysis of arbitrary cryptographic protocols that contain periodic structures.
The paper is based on expert analysis of Riesel number theory, ECDSA cryptanalysis, and lattice methods.
The material is intended for research purposes and for studying the mathematical foundations of cryptography.
