Theoretical foundations, practical implementation, and analysis of real-world vulnerabilities. The Pohlig-Hellman algorithm is a powerful cryptanalytic tool, but its direct application to ECDLP on a curve secp256k1 is impossible due to the simple order of the group. However, in the context of Bitcoin’s ECDSA, this algorithm finds application in hybrid attacks targeting nonce-related vulnerabilities.
Cryptanalysis of ECDSA/secp256k1 Discrete Logarithm
Content
- Introduction: Statement of the Problem
- The Pohlig-Hellman Algorithm: Essence and Mathematical Foundations
- ECDSA and Bitcoin’s signature structure
- Nonce Vulnerability: The Key to the Attack
- Using Pohlig-Hellman: From Nonce to Private Key
- Features of the secp256k1 curve and applicability of the algorithm
- Practical implementation: code and examples
- Actual incidents and the scale of the threat
- Countermeasures and protection
- Conclusion
1. Introduction: statement of the problem
Recovering a Bitcoin private key from publicly available data is a problem that at first glance appears computationally intractable. It reduces to solving the elliptic curve discrete logarithm problem (ECDLP) . For the curve secp256k1used in Bitcoin, the group order is prime n ≈ 2256 , making direct solution of the ECDLP using methods like Pollard’s ρ computationally infeasible with current technology.
However, there are scenarios in which the problem ceases to be “unsolvable.” A key one is the reuse or predictability of the hidden number (nonce) in ECDSA signatures. In such cases, the cryptanalyst gains additional information that allows them to apply specialized algorithms, including the Pohlig-Hellman (Silver-Pohlig-Hellman) algorithm , to recover the secret scalar.
The purpose of this paper is to show how the Pohlig-Hellman algorithm is applied in the context of Bitcoin’s ECDSA, what mathematical assumptions make it possible, and what the full attack chain looks like in practice: from two signatures with the same nonce to private key recovery.
Key idea
The Pohlig-Hellman algorithm is efficient when the order of the group factorizes into small prime numbers (is a “smooth” number). In the context of Bitcoin’s ECDSA, it is applied not directly to the curve group (its order is a large prime number), but to the discrete logarithm subproblem that arises when recovering a nonce if that nonce has bounded entropy or a known structure.
2. The Pohlig-Hellman algorithm: essence and mathematical foundations
2.1 General formulation
The Pohlig–Hellman algorithm (also called the Silver–Pohlig–Hellman algorithm) is a deterministic algorithm for taking discrete logarithms in a finite Abelian group whose order is a smooth number.[reference:0] It was invented by Roland Silver and independently published by Stephen Pohlig and Martin Hellman in 1978.[reference:1]
Problem statement: Given a cyclic group G of order n , a generator element g and an element h ∈ G , it is required to find x such that g x = h .
2.2. The idea of the algorithm
If the order of a group n is factorizable into prime factors:
n = p 1 e 1 · p 2 e 2 · … · p k e k
then the discrete logarithm problem is reduced to solving k subproblems of lower dimension—computing x modulo each p i e i . The solution is then reconstructed using the Chinese remainder theorem (CRT) [reference:2].
The complexity of the algorithm is O(∑ e i √p i ) , which is significantly faster than exhaustive search if all p i are small[reference:3].
2.3 Algorithm for prime-power order groups
Let us consider an important special case when the group order is n = p e for a prime p . The algorithm works iteratively, reconstructing the digits of x to the base p :
- Initialization: x 0 = 0 .
- Calculate γ = g pe−1 — the element of order p .
- For each k = 0, 1, …, e−1 :
- We calculate h k = (g −x k · h) pe−1−k — an element of the subgroup of order p .
- The discrete logarithm problem γ d k = h k in a subgroup of order p is solved (for example, using the baby-step giant-step method).
- It is specified that x k+1 = x k + p k · d k .
- Returns x e .
In general, for n = ∏ p i e i , the algorithm is applied to each primary component separately, and the results are combined using CRT[reference:4].
2.4. Condition of applicability
Critical
The Pohlig-Hellman algorithm fails for groups whose order has a large prime divisor. This is why a curve secp256k1 with order n ≈ 2256 (a prime number) is resistant to a direct Pohlig-Hellman attack [reference:5].
3. ECDSA and Bitcoin’s signature structure
3.1 ECDSA Signature Algorithm
ECDSA (Elliptic Curve Digital Signature Algorithm) is a digital signature algorithm that underlies Bitcoin transaction security. The signature generation process involves the following steps:
- A random number k ∈ [1, n−1] is selected — nonce (hidden number).
- The point R = k · G is calculated , where G is the base point of the curve.
- Calculate r = R x mod n — the x-coordinate of point R.
- Calculate s = k −1 · (e + r · d) mod n , where e = H(m) is the message hash and d is the private key.
The signature is a pair (r, s) . The public key is Q = d · G .
3.2. Private key recovery formula
From the equation for s we can express k :
k = s −1 (e + r d) mod n
If k is known (or recovered), the private key is calculated as:
d = (s k − e) r −1 mod n
This formula is fundamental to all nonce discovery or reuse attacks[reference:6].
Key vulnerability
If two messages are signed using the same nonce k , then knowing both signatures (r, s 1 ) and (r, s 2 ) and the corresponding hashes e 1 and e 2 , one can recover k , and then d .
4. Nonce Vulnerability: The Key to the Attack
4.1 Nonce reuse
The classic case: Let two signatures use the same k :
s 1 = k −1 (e 1 + r d) mod n
s 2 = k −1 (e 2 + r d) mod n
Subtracting one equation from the other and eliminating d , we get:
k = (e 1 − e 2 ) (s 1 − s 2 ) −1 mod n
After k is recovered, the private key is calculated using a standard formula. This method is well known and widely used in cryptanalysis [reference:7].
4.2. Weak or limited nonce
A more subtle case: the nonce is non-repeating but has limited entropy —for example, it is generated by an RNG with errors, has a bias in the high- or low-order bits, or its partial structure is known. In such cases, the Hidden Number Problem (HNP) is used , which can be solved using lattice analysis methods (LLL/BKZ) [reference:8].
The Pohlig-Hellman algorithm plays a supporting role in this scheme: it allows one to efficiently solve the discrete logarithm subproblem for recovering the least significant bits of a nonce if its structure is known.
4.3 Nonce with known structure
If nonce k has the form k = k 0 + 2 t · k’ , where k 0 is known (or small) and k’ is the unknown part, then the problem reduces to a discrete logarithm in a subgroup of lower order. This is where the Pohlig-Hellman algorithm is applied.
5. Using Pohlig-Hellman: From Nonce to Private Key
5.1. Complete attack chain
Consider a scenario in which an attacker has two ECDSA signatures generated with a nonce k of known, bounded structure. The attack chain looks like this:
- Data collection: transactions with signatures (r, s 1 , e 1 ) and (r, s 2 , e 2 ) are extracted from the blockchain .
- Vulnerability detection: checks whether signatures use the same r (a sign of a repeated nonce) or whether an anomalous structure is observed (for example, a nonce with a small number of bits).
- Recovering nonce:
- When reused, it is a direct algebraic formula.
- With bounded entropy, the HNP solution is solved by lattice methods, where the discrete logarithm subproblem is solved by the Pohlig-Hellman algorithm.
- Calculation of the private key: according to the formula d = (s · k − e) · r −1 mod n .
5.2. The Role of Pohlig-Hellman in Nonce Recovery
Suppose the nonce is of the form k = k 0 + 2 t · k’ , where k 0 is known and k’ is an unknown scalar. Then the signature equation takes the form:
s (k 0 + 2 t k’) = e + r d mod n
Rearranging, we get:
2 t · s · k’ ≡ e + r · d − s · k 0 mod n
This equation can be solved for k’ and d using congruence systems methods. If 2t has small prime factors, the Pohlig-Hellman algorithm allows one to efficiently recover k ‘ modulo each of these factors, and then combine the results using the CRT.
5.3. Example: nonce with a small number of bits
Let k < 2 64 be a nonce generated with an error by the RNG. Then k can be recovered by solving the discrete logarithm problem k · G = R in the subgroup of order 2 64 . The Pohlig–Hellman algorithm is applicable since the order of the subgroup 2 64 is a smooth number (a power of two).
Breitner and Heninger (2019) show that bounded-entropy nonces are found in real Bitcoin transactions, and lattice methods in combination with the Pohlig-Hellman algorithm are used to recover them[reference:9].
6. Features of the secp256k1 curve and applicability of the algorithm
6.1 Curve parameters
Bitcoin uses an elliptic curve secp256k1 with the following parameters:
| Parameter | Meaning |
|---|---|
| Equation | y 2 = x 3 + 7 over GF(p) |
| Order of group n | ≈ 2,256 (prime number) |
| Base point order | n |
| Cofactor | 1 |
6.2 Why a direct Pohlig-Hellman attack is impossible
The order of a group n for secp256k1 is a prime number. This means that factoring n is trivial: n = n (one prime factor). The Pohlig–Hellman algorithm in this case degenerates into a baby-step giant-step algorithm for a group of order √n ≈ 2 128 , which is computationally infeasible [reference:10].
Conclusion
Direct application of the Pohlig-Hellman algorithm to ECDLP is secp256k1 not possible . Bitcoin’s security is based precisely on this fact.
6.3. When is Polyga-Hellman still applicable?
The algorithm becomes applicable in the following cases:
- Vulnerable implementations with composite order: if the system uses an elliptic curve whose order has small prime divisors (e.g., in test or custom implementations).
- Nonce recovery with bounded entropy: when the nonce has a structure that reduces the problem to a discrete logarithm in a subgroup of small order.
- Hybrid attacks: Polyga-Hellman is used as a subroutine in lattice attacks on HNP.
7. Practical implementation: code and examples
7.1 Recovering a private key when a nonce is duplicated (Python)
from ecdsa import SigningKey, SECP256k1
import hashlib
n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
def recover_private_key(r, s1, s2, e1, e2):
"""
Восстановление приватного ключа при повторном использовании nonce.
Аргументы:
r : общая r-компонента двух подписей
s1 : s-компонента первой подписи
s2 : s-компонента второй подписи
e1 : хеш первого сообщения
e2 : хеш второго сообщения
Возвращает:
d : приватный ключ
k : восстановленный nonce
"""
# Восстановление nonce: k = (e1 - e2) / (s1 - s2) mod n
k = ((e1 - e2) * pow(s1 - s2, -1, n)) % n
# Восстановление приватного ключа: d = (s1 * k - e1) / r mod n
d = ((s1 * k - e1) * pow(r, -1, n)) % n
return d, k
# Пример использования (тестовые данные)
r = 0x678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb6
s1 = 0x496bc3f4cef38c4f35504e5ec112de5c384df7ba0b8d578a4c702b6bf1d5f
s2 = 0x9a5f1c75...
e1 = 0x4b1eab...
e2 = 0x7c3d2e...
d, k = recover_private_key(r, s1, s2, e1, e2)
print(f"Восстановленный nonce: {hex(k)}")
print(f"Приватный ключ: {hex(d)}")
7.2. Implementation of the Pohlig-Hellman algorithm (SageMath)
def pohlig_hellman_ec(E, P, Q):
"""
Алгоритм Полига — Хеллмана для решения ECDLP Q = k * P
на эллиптической кривой E с гладким порядком группы.
Аргументы:
E : эллиптическая кривая (SageMath)
P : базовая точка
Q : целевая точка
Возвращает:
k : дискретный логарифм
"""
n = P.order()
factors = factor(n)
residues = []
moduli = []
for p, e in factors:
# Примарная компонента: p^e
pe = p^e
# Проекция в подгруппу порядка p^e
P_e = (n // pe) * P
Q_e = (n // pe) * Q
# Решение DLP в подгруппе порядка pe
k_e = discrete_log_rho(Q_e, P_e, pe)
residues.append(k_e)
moduli.append(pe)
# Восстановление по китайской теореме об остатках
k = CRT_list(residues, moduli)
return k
# Пример для демонстрационной кривой с гладким порядком
p = 13827821670227353601
E = EllipticCurve(GF(p), [0, 7])
G = E.gens()[0]
k_secret = 123456789
Q = k_secret * G
k_recovered = pohlig_hellman_ec(E, G, Q)
print(f"Восстановленный ключ: {k_recovered}")
7.3. Hybrid Attack: Poliga – Hellman + LLL
# Псевдокод гибридной атаки на HNP с использованием Полига — Хеллмана
#
# 1. Собрать множество подписей (r_i, s_i, e_i) с biased nonces.
# 2. Построить решётку HNP.
# 3. Применить LLL/BKZ для поиска приближения nonce.
# 4. Для каждого кандидата k_i решить DLP в подгруппе малого порядка,
# используя алгоритм Полига — Хеллмана.
# 5. Объединить результаты по CRT и вычислить приватный ключ.
from fpylll import IntegerMatrix, LLL, BKZ
def build_hnp_lattice(signatures, B):
"""Построение матрицы для решения HNP."""
# ... (реализация зависит от конкретной постановки)
pass
def solve_hnp(lattice_matrix):
"""Решение HNP с помощью LLL/BKZ."""
LLL.reduction(lattice_matrix)
# BKZ для повышения качества
BKZ.reduction(lattice_matrix, BKZ.Param(block_size=20))
return lattice_matrix
def recover_with_pohlig_hellman(signatures):
"""Полная цепочка: HNP -> Полига — Хеллман -> приватный ключ."""
# Построение решётки
lattice = build_hnp_lattice(signatures, B=176)
reduced = solve_hnp(lattice)
# Извлечение кандидатов nonce
candidates = extract_nonce_candidates(reduced)
# Решение DLP для каждого кандидата
for k_candidate in candidates:
# Проверка через алгоритм Полига — Хеллмана
# (если порядок подгруппы гладкий)
if is_smooth_order(k_candidate):
k = pohlig_hellman_ec(E, G, k_candidate * G)
d = (s1 * k - e1) * pow(r, -1, n) % n
return d
return None
8. Real incidents and the scale of the threat
8.1. Sony PlayStation 3 Hack (2010)
The hacker group fail0verflow discovered that Sony was using the same nonce for all ECDSA signatures on PlayStation 3 software. This allowed them to extract the private key used to sign applications and gain the ability to run any code on the console.[reference:11]
8.2. Android SecureRandom Vulnerability (2013)
A bug in Android’s random number generator caused nonce repetition in Bitcoin wallets. Attackers exploited this to steal funds: numerous wallets were compromised, with potential losses estimated at 412.80 BTC (worth ~$3.3 million at the time)[reference:12].
8.3. Research by Breitner and Heninger (2019)
In the paper “Biased Nonce Sense,” the authors scanned the Bitcoin and other cryptocurrency blockchains using lattice attacks on HNP. The results are impressive:
- About 300 Bitcoin private keys have been recovered .
- Dozens of Ethereum, Ripple, SSH and HTTPS keys recovered .
- 1,296 private keys were discovered due to nonce reuse[reference:13][reference:14].
The scale of the problem
The study found that nonce-related vulnerabilities are widespread in real-world cryptocurrency systems and are actively exploited.
8.4. The case of nonce = 3307 in early Bitcoin blocks
There are claims that early Bitcoin blocks (including those mined by Satoshi Nakamoto) used a predictable nonce k = 3307 . Substituting this value into the ECDSA formula allows one to recover the private keys associated with these blocks [reference:15]. While this claim remains controversial, it demonstrates the fundamental possibility of an attack with a known nonce.
9. Countermeasures and protection
9.1 Deterministic Nonce Generation (RFC 6979)
RFC 6979 describes deterministic nonce generation based on a message hash and a private key. This completely eliminates the possibility of nonce reuse or predictability:
k = HMAC_DRBG(d, H(m))
Modern Bitcoin wallets (Bitcoin Core, Electrum) use RFC 6979 by default[reference:16].
9.2 Using cryptographically strong RNGs
If the nonce is generated randomly, it is necessary to use proven cryptographically strong pseudorandom number generators (CSPRNGs) such as /dev/urandom or getrandom().
9.3 Checking the order of a curve
When implementing ECDSA on custom curves, it is necessary to ensure that the group order is not a smooth number. secp256k1 This condition is satisfied.
9.4. Audit and monitoring
Regular auditing of cryptographic implementations and monitoring of the blockchain for duplicate r -component signatures allows for the timely detection of vulnerabilities.
Recommendation
For new projects, use RFC 6979 and secp256k1 without modification. For existing systems, audit nonce generators and check the signature history for duplicates.
10. Conclusion
The Pohlig-Hellman algorithm is a powerful cryptanalytic tool, but its direct application to ECDLP on a curve secp256k1 is impossible due to the simple order of the group. However, in the context of Bitcoin’s ECDSA, this algorithm finds application in hybrid attacks targeting nonce-related vulnerabilities:
- When reusing a nonce, the private key is recovered directly algebraically.
- With bounded nonce entropy, the Pohlig-Hellman algorithm is used as a subroutine to solve DLP in small-order subgroups.
- In lattice attacks on HNP, the Pohlig-Hellman algorithm allows one to efficiently recover the least significant bits of the nonce.
The practical significance of these attacks has been confirmed by real-world incidents, ranging from PS3 hacking to Bitcoin theft due to Android RNG bugs. The only reliable defense is strict adherence to standards (RFC 6979) and the use of proven cryptographic libraries.
Result
The security of Bitcoin’s ECDSA isn’t limited to just the strength of the curve secp256k1. Equally critical is the correct implementation of nonce generation. The Pohlig-Hellman algorithm is a tool that turns a nonce generation error into a completely compromised private key.
This document is based on open sources on ECDSA cryptanalysis and security. All formulas and methods are provided for educational purposes.
Key sources: Pohlig & Hellman (1978), Breitner & Heninger (2019), IACR ePrint, PS3 vulnerabilities and Android SecureRandom materials.
