The Solovay–Strassen Test and Its Application to Bitcoin ECDSA Cryptanalysis

21.10.2026

Experimental results:  with a bias of just 1 bit and 1000 signatures, the probability of successful key recovery exceeds 90%[reference:15]. The Solovay-Strassen test allows for a reduction in the required number of signatures due to more accurate bias detection.

The Solovay-Strassen test, originally developed as a tool for checking primality, finds effective application in ECDSA cryptanalysis. Its key advantage—resistance to Carmichael numbers—makes it indispensable for analyzing nonces generated by flawed randomness sources. Combined with lattice methods (LLL/BKZ) and the hidden number problem, the test allows for the recovery of Bitcoin private keys even with minor biases in signature generation.

The practical significance of this approach is confirmed by real-world attacks on blockchain transactions: thousands of keys were compromised due to weak nonce generators. Using the Solovey-Strassen test in a cryptanalyst’s arsenal allows for a more systematic search for vulnerabilities and increases the effectiveness of attacks.

Content

1. Introduction

The Solovay–Strassen test is a probabilistic primality test proposed in 1977 by Robert Solovay and Volker Strassen.[reference:0] It was one of the first algorithms to demonstrate that primality testing can be performed in polynomial time with a controlled error probability. The test is based on the distinction between Legendre and Jacobi symbols: for a prime number,  n the Jacobi symbol  (a/n) coincides with the Legendre symbol and obeys Euler’s criterion, whereas for a composite number, this equality may be violated.[reference:1]

The key advantage of the Solovay–Strassen test over the Fermat test is that it  recognizes Carmichael numbers as composite . Carmichael numbers (e.g., 561 = 3 × 11 × 17) pass the Fermat test for all bases coprime to  n, but fail the Solovay–Strassen test with probability at least 1/2 for a randomly chosen base [reference:2].

In the context of Bitcoin cryptanalysis, the Solovay-Strassen test finds an unexpected application: it is used as a tool  for statistically analyzing the structure of the hidden number  (nonce) in ECDSA signatures. If the nonce is generated with deviations from a uniform distribution, the Solovay-Strassen test can detect anomalies in its bit structure, which, when combined with lattice methods, allows for the recovery of the private key [reference:3].

2. Mathematical foundations of the Solovey-Strassen test

2.1. Legendre and Jacobi symbols

The Legendre symbol (a/p)  is defined for the prime  p and the integer  a:

(a/p) = 0 if p | a;
(a/p) = 1 if a is a quadratic residue modulo p;
(a/p) = −1 if a is a quadratic non-residue modulo p.

The Jacobi symbol (a/n)  generalizes the Legendre symbol to composite odd  n. If  n = p₁·p₂·…·pₖ, then:

(a/n) = (a/p₁) · (a/p₂) · … · (a/pₖ).

The Jacobi symbol can be calculated in  O(log n) operations without factorization  nusing the law of quadratic reciprocity[reference:4].

2.2. Euler’s criterion

For a prime  p and an integer  anot divisible by  p, the following holds:

a (p−1)/2  ≡ (a/p) (mod p).

This criterion is the basis of the Solovey-Strassen test: for a simple  n comparison, the comparison   is always performed, but for a composite   comparison, it is violated for at least half of the bases  [reference:5].a(n−1)/2 ≡ (a/n) (mod n)na

2.3. Test algorithm

Вход: нечётное n ≥ 3, параметр надёжности t.
Выход: "простое" или "составное".

1. Для i = 1 до t:
   a. Выбрать случайное a ∈ {2, …, n−1}.
   b. Вычислить x = (a/n) — символ Якоби.
   c. Если x = 0 или a^((n−1)/2) mod n ≠ x mod n:
         вернуть "составное".
2. Вернуть "простое".

The probability of error (recognizing a composite number as prime) does not exceed  . For practical applications,  [reference:6] is sufficient.2−tt = 20–50

3. Carmichael numbers and test advantage

A number  n is called  a Carmichael number if it is composite, but for all  acoprime to  n,  . The smallest such number is 561 = 3 × 11 × 17[reference:7].an−1 ≡ 1 (mod n)

Fermat’s test is unable to distinguish Carmichael numbers from prime numbers, since they pass the test for all bases. The Solovay–Strassen test solves this problem: for a Carmichael number  n and a random  a number, the probability that  , does not exceed 1/2. Thus, even for ,   the error probability is less than  [reference:8].a(n−1)/2 ≡ (a/n) (mod n)t = 2010−6

Important:  Unlike the Fermat test, the Solovay–Strassen test does not have a Carmichael number equivalent that passes the test for all bases. This makes it fundamentally more secure for cryptographic applications [reference:9].

4. ECDSA and the Hidden Number Problem

4.1 ECDSA Scheme

The ECDSA (Elliptic Curve Digital Signature Algorithm) algorithm over the curve  secp256k1used in Bitcoin works as follows. Let be  d the private key,  Q = d·G and be the public key. To sign a message with a hash  z:

  1. A random nonce is selected  k ∈ [1, n−1].
  2. The point is calculated  R = k·G, and  .r = Rx mod n
  3. Calculated  .s = k−1(z + r·d) mod n
  4. Signature – pair  (r, s).

From the signature equation it follows:

k ≡ s −1 (z + r d) (mod n).

If the nonce  k is known in whole or in part, the private key  d can be calculated. However, in real systems,  k it is considered secret and is generated randomly. The problem arises when the random number generator produces  biased  values  k.

4.2 Hidden Number Problem (HNP)

Let’s assume for  ℓ signatures  (rᵢ, sᵢ) with hashes  zᵢ that the nonce  kᵢ has an offset: the most significant  m bits are zero or known. Then:

kᵢ = kᵢ’ + 2 m  · bᵢ, where 0 ≤ kᵢ’ < 2 m  is the unknown minor part,
bᵢ is the known bias.

Substituting this into the equation of the signature, we obtain a system of linear comparisons with respect to  d and unknowns  kᵢ':

sᵢ −1 (zᵢ + rᵢ·d) ≡ kᵢ’ + 2 m ·bᵢ (mod n).

This system reduces to the problem of finding a short vector in a lattice (lattice), which is solved by the LLL (Lenstra-Lenstra-Lovász) algorithm or its improved versions (BKZ)[reference:10][reference:11].

4.3. The Role of the Solovey-Strassen Test

The Solovay-Strassen test is used to  detect bias  in the nonce sequence. If the random number generator is flawed, the bit distribution  kᵢ may deviate from uniformity. The Solovay-Strassen test, by checking the primality of the numbers formed by nonce fragments, allows for the statistical detection of such anomalies [reference:12].

Moreover, in some ECDSA implementations, the nonce can be generated using prime numbers or numbers close to prime. The Solovay-Strassen test allows for the rapid elimination of composite candidates, narrowing the search space and increasing the effectiveness of the lattice attack.

5. Application of the Solovey–Strassen test to ECDSA cryptanalysis

5.1 General attack scheme

An attack on ECDSA using the Solovay-Strassen test involves the following steps:

  1. Signature collection.ℓ  Signatures   are collected  (rᵢ, sᵢ) for messages with known hashes  zᵢcreated by a single private key  d.
  2. Nonce analysis.  For each signature, is calculated  . Since   is unknown,   intermediate values ​​depending on are analyzed  instead .kᵢ ≡ sᵢ−1(zᵢ + rᵢ·d) (mod n)dkᵢkᵢ
  3. Applying the Solovey-Strassen test.  Fragments of the nonce (e.g., the least significant or most significant bits) are checked for primality. If the nonce generator had a prime-related flaw, the test reveals statistical patterns.
  4. Lattice construction.  Based on the detected bias, a lattice of dimension is constructed  ℓ + 2, in which a short vector corresponding to the true value is sought  d.
  5. Key recovery.  Using LLL/BKZ reduction, a vector is found from which the private key is extracted  d.

5.2 Mathematical justification

Let’s consider  ℓ signatures with a known offset  m of the high-order bits of the nonce. Then:

kᵢ = 2 m bᵢ + kᵢ’, 0 ≤ kᵢ’ < 2 m .

Substituting the signatures into the equation:

sᵢ −1 (zᵢ + rᵢ·d) ≡ 2 m ·bᵢ + kᵢ’ (mod n).

Multiplying by  sᵢ and regrouping:

rᵢ·d − sᵢ·2 m ·bᵢ ≡ sᵢ·kᵢ’ − zᵢ (mod n).

Let us introduce the notations   and  . Then:Aᵢ = rᵢ·sᵢ−1 mod nBᵢ = (2m·bᵢ − zᵢ·sᵢ−1) mod n

Aᵢ·d + Bᵢ ≡ kᵢ’ (mod n), |kᵢ’| < 2m .

This is the classic formulation of HNP. To solve it, a lattice  L with the following basis is constructed:

B = [ n 0 0 … 0 0 ]
[ 0 n 0 … 0 0 ]
[ … … … … … … ]
[ A₁ A₂ A₃ … A_ℓ 1/2 m  ]

The short vector in this lattice corresponds to the desired vector  d. The LLL algorithm finds it in polynomial time in the lattice dimension [reference:13].

5.3 Why the Solovey-Strassen test?

The use of the Solovey-Strassen test, rather than the Fermat or Miller-Rabin test, is due to two reasons:

  • Resistance to Carmichael numbers.  If the nonce generator produces numbers that could be Carmichael numbers (for example, when using composite moduli), the Fermat test will yield a false positive. The Solovay–Strassen test reliably filters out such cases.
  • Relationship with quadratic residues.  The Jacobian symbol used in the test is closely related to the distribution of quadratic residues modulo  n. This allows for the detection of subtle correlations in the nonce bit structure that are not visible with other tests.

6. Practical implementation: Bitcoin private key recovery

6.1. Python Implementation of the Solovay–Strassen Test

import random

def jacobi_symbol(a, n):
    """Вычисление символа Якоби (a/n) для нечётного n > 0."""
    if n <= 0 or n % 2 == 0:
        raise ValueError("n должно быть положительным нечётным числом")
    a = a % n
    result = 1
    while a != 0:
        while a % 2 == 0:
            a //= 2
            if n % 8 in (3, 5):
                result = -result
        a, n = n, a
        if a % 4 == 3 and n % 4 == 3:
            result = -result
        a = a % n
    return result if n == 1 else 0


def solovay_strassen(n, t=20):
    """Вероятностный тест простоты Соловея — Штрассена."""
    if n < 2:
        return False
    if n == 2 or n == 3:
        return True
    if n % 2 == 0:
        return False

    for _ in range(t):
        a = random.randint(2, n - 2)
        x = jacobi_symbol(a, n)
        if x == 0:
            return False
        y = pow(a, (n - 1) // 2, n)
        if y != x % n:
            return False
    return True

6.2 Nonce Analysis and Lattice Construction

from fpylll import IntegerMatrix, LLL
import hashlib

def recover_private_key(signatures, curve_order, known_msb_bits=4):
    """
    signatures: список кортежей (r, s, z)
    curve_order: порядок кривой secp256k1 (n)
    known_msb_bits: количество известных старших бит nonce
    """
    n = curve_order
    l = len(signatures)
    m = known_msb_bits

    # Построение матрицы для HNP
    # Размерность: (l + 2) x (l + 2)
    B = IntegerMatrix(l + 2, l + 2)

    # Заполнение диагонали n
    for i in range(l):
        B[i, i] = n

    # Заполнение последней строки
    for i in range(l):
        r, s, z = signatures[i]
        s_inv = pow(s, -1, n)
        A_i = (r * s_inv) % n
        B[l, i] = A_i

    # Масштабирующий коэффициент для известных битов
    scale = 1 << (256 - m)  # для secp256k1
    B[l, l] = 1
    B[l + 1, l + 1] = scale

    # LLL-редукция
    LLL.reduction(B)

    # Поиск короткого вектора
    # ... извлечение d из редуцированной матрицы
    # (детали зависят от конкретной реализации)

    return d  # восстановленный приватный ключ

6.3. Example with real data

Consider a scenario in which the nonce generator was biased by 4 high-order bits. By collecting 50 signatures from the Bitcoin blockchain, a 52-dimensional lattice can be constructed and LLL reduction applied. In the paper “Biased Nonce Sense,” the authors demonstrated the recovery  of hundreds of Bitcoin private keys  using precisely this method [reference:14].

Experimental results:  with a bias of just 1 bit and 1000 signatures, the probability of successful key recovery exceeds 90%[reference:15]. The Solovay-Strassen test allows for a reduction in the required number of signatures due to more accurate bias detection.

Conclusion

The Solovay-Strassen test, originally developed as a tool for checking primality, finds effective application in ECDSA cryptanalysis. Its key advantage—resistance to Carmichael numbers—makes it indispensable for analyzing nonces generated by flawed randomness sources. Combined with lattice methods (LLL/BKZ) and the hidden number problem, the test allows for the recovery of Bitcoin private keys even with minor biases in signature generation.

The practical significance of this approach is confirmed by real-world attacks on blockchain transactions: thousands of keys were compromised due to weak nonce generators. Using the Solovey-Strassen test in a cryptanalyst’s arsenal allows for a more systematic search for vulnerabilities and increases the effectiveness of attacks.

Directions for further research for cryptanalysis based on this area

  1. Hybrid primality tests for nonce analysis.  Combining the Solovay-Strassen test with the Miller-Rabin test and the Bailey-PSV test for more accurate detection of structured nonces. A study of which classes of composite numbers (Carmichael numbers, Euler pseudoprimes) are most common in real-world nonce generators.
  2. Statistical analysis of the distribution of Jacobian symbols in nonce sequences.(kᵢ/n) Development of methods for  recovering information about the random number generator and predicting future nonce values  ​​from a Jacobian symbol sequence  .
  3. Optimizing lattice attacks using the Solovey-Strassen test.  Using information about the primality properties of nonce fragments to reduce the lattice dimension and the number of required signatures.
  4. Attacks on Deterministic Nonce Generation Schemes (RFC 6979).  Investigation of the feasibility of using the Solovay-Strassen test for analyzing deterministic nonces, where  k = H(d ‖ z). Although such schemes are considered resistant to lattice attacks, the statistical properties of hash functions can create exploitable anomalies [reference:16].
  5. Quantum Algorithms for the Solovay-Strassen Test in the Context of ECDSA.  An exploration of how quantum computing can accelerate nonce primality verification and improve the efficiency of ECDSA cryptanalysis in the post-quantum era.
  6. Applying the Solovay–Strassen test to other cryptographic primitives.  An analysis of the feasibility of using the test for cryptanalysis of RSA schemes, where prime numbers  p are  q generated with defects, and Diffie–Hellman schemes on elliptic curves.
  7. Developing security measures based on the identified patterns.  Creating recommendations for developers of cryptographic libraries for generating nonces that are resistant to statistical analysis using the Solovey-Strassen test.

This document is based on an analysis of scientific publications on cryptography, number theory, and blockchain security.
All mathematical calculations and code examples are intended for educational purposes.