Applying statistical methods to cryptanalysis of Bitcoin’s ECDSA

23.10.2026

Based on the textbook: Khamitov G.P., Vedernikova T.I.
“Probabilities and Statistics”. – Irkutsk: BSUEL, 2006. – 270 p.

Abstract.  This paper presents a practical guide to applying the statistical methods outlined in G.P. Khamitov and T.I. Vedernikova’s textbook “Probability and Statistics” to the problem of recovering a private key for the Elliptic Curve Digital Signature Algorithm (ECDSA) used in the Bitcoin blockchain. Statistical tests for detecting biased nonces, methods for testing hypotheses about the uniformity of distributions, correlation and regression analysis, and a transition from statistical anomalies to algebraic key recovery via the Hidden Number Problem (HNP) and lattice attacks (LLL/BKZ) are considered. Practical algorithms, code examples, and computational complexity estimates are provided.

The textbook “Probability and Statistics” by G.P. Khamitov and T.I. Vedernikova provides a complete and systematic presentation of the apparatus necessary for  the first, critical stage  of ECDSA cryptanalysis—statistical exploration of biases in nonce generation. Key sections of the textbook—statistical hypothesis testing, the χ² test, the Kolmogorov–Smirnov test, correlation and regression analysis—find direct application in the following problems:

  1. Detecting nonce reuse  through frequency analysis  r .
  2. Detection of bias of the most significant bits of nonce  using the χ² test and the binomial test for normalized values  .ti(d')
  3. Detection of linear dependencies  between consecutive nonces through correlation analysis and regression models.
  4. Testing hypotheses about the nature of the bias  (uniform vs. biased) using p-values ​​and critical regions.

Once statistical analysis confirms the presence of bias, the problem is reduced to  a hidden number problem  (HNP), solvable using lattice reduction methods (LLL/BKZ). A combination of statistical and algebraic methods allows ECDSA private keys to be recovered with only 4–8 bits of bias in the nonce and several hundred signatures.

The practical significance of this approach is confirmed by large-scale studies of the Bitcoin blockchain, which discovered and recovered hundreds of private keys vulnerable to statistical attacks on nonces. This underscores the importance of  cryptographically secure random number generation  and regular statistical auditing of cryptographic implementations.

1. Introduction

The ECDSA algorithm, which underlies Bitcoin transaction signing, critically depends on the quality of the generated  k nonce. According to the SECP256k1 standard, the nonce must be uniformly distributed over the interval  [1, n−1], where  n is the order of the elliptic curve base point. Any deviation from uniformity (shifting of high-order bits, reuse, linear dependencies between consecutive nonces) creates a statistically detectable anomaly that can be used to recover the long-term private key  d.

Khamitov and Vedernikova’s textbook systematically presents the framework of probability theory and mathematical statistics: from the classical and statistical definitions of probability to statistical hypothesis testing, the χ² criterion, correlation and regression analysis. This framework constitutes  the first stage of any attack on ECDSA—the statistical reconnaissance  stage   , which identifies anomalies in nonce sequences.

The key idea is that  ECDSA is not a “statistically secure” algorithm, meaning that even a small bias in the nonce distribution accumulates with the number of signatures, leading to a linear leakage of private key information. Statistical methods can  detect  this bias, and algebraic methods (lattices, HNP) can  exploit  it.

2. Theoretical foundations from the Khamitov-Vedernikova manual

2.1 Probability space and random variables

The manual introduces the classical definition of probability as the ratio of the number of favorable outcomes to the total number of equally likely outcomes. For ECDSA, this means that with  perfect  nonce generation, the probability of  k falling within any fixed interval of length  mis  m/n.

However, in practice, pseudorandom number generators (PRNGs) can produce a distribution that is not uniform. In the textbook’s terms, this corresponds to a deviation of the empirical distribution function   from the theoretical one  .Fn(x)F(x)

2.2. Statistical definition of probability and the law of large numbers

The statistical definition of probability outlined in the textbook relates the probability of an event to the relative frequency of its occurrence over a large number of trials. The law of large numbers (Bernoulli’s theorem) guarantees that as the number of signatures increases,  N the empirical frequency of occurrence of a nonce with a certain property (for example, with a zero high-order bit) converges to the theoretical probability of that event.

P(|ν n /n − p| < ε) → 1 as n → ∞

This fundamental principle allows us to use  frequency analysis  to estimate the parameters of a nonce generator: if the relative frequency of occurrence of nonces with a zero high-order bit is significantly different from  1/2, the generator is biased.

2.3. Testing statistical hypotheses

The manual examines in detail the procedure for testing statistical hypotheses: the formulation of the main ( H₀) and alternative ( H₁) hypotheses, the choice of the significance level  α, the calculation of the criterion statistics and decision-making based on the critical region.

In relation to ECDSA:

  • H₀:  nonces are distributed uniformly on  [1, n−1].
  • H₁:  The nonce distribution is skewed (e.g., the high-order bits are more often zero).
  • Significance level:  usually  α = 0.01 or  α = 0.05.

If  p-value it turns out to be less than  α, the hypothesis  H₀ is rejected, and we obtain statistical evidence in favor of the existence of a bias – the first step to recovering the key.

2.4. Chi-square (χ²) goodness-of-fit test

Pearson’s χ² test, discussed in detail in the textbook, allows you to test whether the empirical distribution of a nonce is consistent with the theoretical uniform distribution. We divide the range of values  [1, n−1] ​​into  r intervals (bins) of equal length. Let   χ be the observed number of nonces in  the ith bin,   and χ be the expected number. Then the test statistic is:OiiEi = N/r

χ² = Σ i=1 r  (O i  − E i )² / E i

If true,  H₀ this statistic is asymptotically distributed as a χ² distribution with  r−1 degrees of freedom. The critical value   is found from χ² distribution tables.χ²кр(α, r−1)

Important:  To apply the χ² test, the expected frequencies must   be at least 5. When analyzing ECDSA nonces (256-bit values), the number of bins   should be chosen wisely—for example,   or  , to cover the distribution of the most significant bits.Eirr = 256r = 1024

2.5. Kolmogorov–Smirnov criterion

Unlike the χ² test, the Kolmogorov–Smirnov (K–S) test does not require binning and works with continuous distributions. The K–S statistic has the form:

D n  = sup x  |F n (x) − F(x)|

where   is the empirical distribution function,   is the theoretical one (uniform   after normalization). Critical values   ​​for the significance level   are determined by the formula  .Fn(x)F(x)[0,1]DnαDкр ≈ √(−ln(α/2) / (2n))

If  , the uniformity hypothesis is rejected. The K–S test is particularly effective for detecting  local  biases in the nonce distribution.Dn > Dкр

2.6. Correlation and regression analysis

The manual devotes considerable attention to correlation analysis. In the context of ECDSA, this means testing for a statistical relationship between:

  • nonce values ​​in successive signatures;
  • nonce and message hash  h(m);
  • nonce and signature generation time.

The Pearson correlation coefficient   is calculated using the standard formula. If   it differs significantly from zero (significance testing using  the α-statistic), this indicates a linear relationship between the variables, which significantly reduces the nonce entropy.rxy|rxy|t

Regression analysis allows us to construct a model of the following type:

k i  = β₀ + β₁ t i  + ε i

where   is the timestamp or serial number of the signature. If the coefficient of determination   is high, this means that a significant portion of the nonce variation is explained by the linear model, meaning that the nonces  are predictable .tiR²

3. The ECDSA mathematical model and the role of nonce

3.1 Signature Equation

Let be  d the private key,  Q = dG be the public key,  G and be the base point of the SECP256k1 curve of order  n. For a message with a hash,  h the signature  (r, s) is calculated as follows:

k ← random from [1, n−1]
R = kG; r = R x  mod n
s = k −1 (h + r d) mod n

From the second equation we express nonce:

k = s −1 (h + r d) mod n

If  k known for one signature, the private key is calculated directly:

d = r −1 (k s − h) mod n

However, in practice,  k it is unknown. It is precisely statistical methods that allow us to obtain  partial  information about  k (for example, that the most significant bits are zero), which is sufficient for recovery  d.

3.2 Nonce Reuse

If two messages  h₁, h₂ are signed with the same  k, then  r₁ = r₂, and the system of equations:

s₁ = k −1 (h₁ + r d)
s₂ = k −1 (h₂ + r d)

is solved relatively  k and  d elementarily:

k = (h₁ − h₂) / (s₁ − s₂) mod n
d = r −1 (k s₁ − h₁) mod n

However, nonce reuse is only  a special case  of a more general problem:  nonce bias  . Statistical methods can detect more subtle forms of bias.

4. Statistical Analysis of Nonces: Practical Methodology

4.1. Data collection

For statistical analysis, a sample of ECDSA signatures extracted from the Bitcoin blockchain is required. Each signature contains:

  • r — x-coordinate of the point  R = kG;
  • s — the meaning of the signature;
  • h — hash of the signed message (transaction);
  • public key  Q (from scriptPubKey).

Data collection can be accomplished through Bitcoin full nodes (Bitcoin Core), public blockchain explorer APIs, or specialized datasets. A sample size of at least 10,000 signatures is recommended for statistical significance.

4.2 Extraction of nonce-dependent values

Although the nonce itself  k is unknown, from the signature equation one can express a quantity that depends linearly on  k and  d:

z i  = s i −1 h i  + s i −1 r i ·d ≡ k i  (mod n)

This equation relates the observables   to the unknowns   and  . If we assume that   have a bias in the most significant bits, then the quantities:(ri, si, hi)kidki

t i  = (s i −1 h i  + s i −1 r i ·d) mod n

will also have a bias, which  is linearly dependent on d . This key observation underlies statistical attacks.

4.3 Testing the Uniformity of Distribution of t i

At the first stage, we don’t know  d, but we can test the hypothesis that the distribution is uniform   for  a hypothetical  value  . If   the distribution   turns out to be significantly uneven for some (for example, the most significant bits are more often zero), this indicates a bias in the nonce and simultaneously provides an estimate of  .tiddtid

Formally, for each candidate  d' we calculate:

t i (d’) = (s i −1 h i  + s i −1 r i d’) mod n

and apply the χ² test or the K–S test to the sample  . The value  at which the test statistic is maximal (the p-value is minimal) is the best estimate of the private key.{ti(d')}d'

Note:  A straightforward enumeration of all  d' ∈ [1, n−1] the nonces is computationally infeasible (256-bit space). However, the statistical approach is combined with lattice methods: first, a χ² test is applied to  the projections  of the nonce onto the least significant bits, which allows us to narrow the search space.

4.4 Analysis of the high-order bits of the nonce

The most common type of bias is  short nonces  , where the high-order bits  k are zero. If   for some   (for example,  ), then the probability of such an event under uniform distribution is  . With bias, this probability is significantly higher.k < 2256−ℓℓℓ = 8, 16, 322−ℓ

To detect short nonces, the following statistical test can be used:

  1. For each candidate,  d' calculate  .ti(d')
  2. Calculate the fraction  of which the most significant   bits are zero.ti(d')ℓ
  3. Compare this proportion with the expected one   using the binomial test or χ².2−ℓ

If for some  d' the proportion of short nonces is statistically significantly greater than  , this indicates a bias and yields a candidate for the private keys.2−ℓ

4.5. Correlation analysis of consecutive nonces

Another class of attacks is based on the correlation between consecutive nonces. If the generator has “memory” (e.g., a linear congruential generator), then it   can be linearly related to  :ki+1ki

k i+1  = a k i  + b mod n

In this case, the quantities   will also exhibit a linear correlation. The Pearson correlation coefficient between   and   will be significantly different from zero if is correct  . This provides an additional criterion for key identification.titi(d')ti+1(d')d'

5. From Statistics to Algebra: The Hidden Number Problem (HNP)

5.1. HNP setting

Once statistical analysis has confirmed the presence of nonce bias (e.g., the most significant  ℓ bits are zero), the key recovery problem reduces to  the Hidden Number Problem  (HNP), first formulated by Boneh and Venkatesan.

Let be   nonce,  ,  . Then:kiai = si−1ri mod nbi = si−1hi mod n

k i  = a i ·d + b i  mod n

If   are small (e.g.,  ), then the  set-based  recovery problem   is an instance of HNP.kiki < 2256−ℓd(ai, bi)

5.2 Solution of HNP via Lattice

The standard approach to solving HNP is to construct a lattice of dimension  m+1, where  m is the number of signatures, and apply the Lenstra–Lenstra–Lovász (LLL) algorithm or its improved versions (BKZ). The lattice matrix has the form:

M = [ n 0 0 … 0 0 ]
[ 0 n 0 … 0 0 ]
[ … ]
[ 0 0 0 … n ​​0 ]
[ a₁ a₂ a₃ … a_m B/n ]

where   is a parameter controlling the balance between coordinates. After the lattice basis reduction, one of the short vectors contains information about  .B = 2ℓd

5.3. Practical assessments

Number of known nonce bitsNumber of signatures (m)Difficulty (approximately)
ℓ = 1 bit~10,000–40,000High (LLL dimension 10⁴)
ℓ = 4 bits~1,000–2,000Average
ℓ = 8 bits~100–300Low
ℓ = 16 bits~10–30Very low
ℓ = 32 bits~4–8Trivial

As the table shows, even a shift of 4–8 high-order bits in the nonce makes the attack entirely feasible. Statistical methods can detect such a shift, and lattice methods can exploit it.

6. Practical implementation: step-by-step algorithm

6.1. Step 1: Data collection and preprocessing

import requests
import json
from ecdsa import VerifyingKey, SECP256k1

def collect_signatures(address, limit=10000):
    """Collecting ECDSA signatures for a given address."""
    signatures = []
    # Using the Blockchain Explorer API
    url = f"https://blockchain.info/rawaddr/{address}?limit={limit}"
    response = requests.get(url)
    data = response.json()
    
    for tx in data.get('txs', []):
        for inp in tx.get('inputs', []):
            script = inp.get('script', '')
            if script and 'sig' in inp:
                # Extracting r, s, h from a script (simplified)
                r = int(inp['sig'][:64], 16)
                s = int(inp['sig'][64:128], 16)
                h = int(tx['hash'], 16) % SECP256k1.order
                signatures.append((r, s, h))
    return signatures

6.2 Step 2: Statistical Analysis of Bias

import numpy as np
from scipy import stats

def chi_square_test(signatures, d_candidate, num_bins=256):
    """
    Testing the hypothesis about the uniformity of distribution of t_i(d').
    
    signatures: list (r, s, h)
    d_candidate: private key candidate
    num_bins: number of bins for the χ² test
    """
    n = SECP256k1.order
    t_values ​​= []
    
    for r, s, h in signatures:
        s_inv = pow(s, -1, n)
        t = (s_inv * h + s_inv * r * d_candidate) % n
        t_values.append(t / n) # normalize to [0, 1)
    
    # χ² test
    observed, _ = np.histogram(t_values, bins=num_bins, range=(0, 1))
    expected = len(t_values) / num_bins
    chi2_stat = np.sum((observed - expected)**2 / expected)
    p_value = 1 - stats.chi2.cdf(chi2_stat, df=num_bins - 1)
    
    return chi2_stat, p_value

def ks_test(signatures, d_candidate):
    """Kolmogorov–Smirnov criterion."""
    n = SECP256k1.order
    t_values ​​= []
    
    for r, s, h in signatures:
        s_inv = pow(s, -1, n)
        t = (s_inv * h + s_inv * r * d_candidate) % n
        t_values.append(t / n)
    
    ks_stat, p_value = stats.kstest(t_values, 'uniform')
    return ks_stat, p_value

6.3. Step 3: Finding Candidates and Refining

def find_key_candidates(signatures, num_candidates=100):
    """
    Finding private key candidates based on statistical anomalies.
    """
    n = SECP256k1.order
    candidates = []
    
    # Strategy: Analyze the least significant bits of t_i to narrow the space
    # (a complete enumeration of 2^256 is impossible, but statistics allow
    # identify candidate clusters)
    
    # Example: Testing the hypothesis about short nonces for random d'
    for _ in range(num_candidates):
        d_prime = np.random.randint(1, n)
        short_count = 0
        
        for r, s, h in signatures:
            s_inv = pow(s, -1, n)
            t = (s_inv * h + s_inv * r * d_prime) % n
            # Check: Are the most significant 8 bits zero?
            if t < 2**248:
                short_count += 1
        
        # Expected number of short nonces under uniform distribution
        expected = len(signatures) * 2**(-8)
        
        # Binomial test
        p_value = stats.binom_test(short_count, len(signatures),
                                   2**(-8), alternative='greater')
        
        if p_value < 0.001:
            candidates.append((d_prime, short_count, p_value))
    
    return sorted(candidates, key=lambda x: x[2])

6.4 Step 4: Lattice Attack (LLL)

from fpylll import IntegerMatrix, LLL

def lattice_attack(signatures, known_bits=8):
    """
    Lattice attack on ECDSA with known high-order bits of nonce.
    
    signatures: list (r, s, h)
    known_bits: The number of known high-order bits of the nonce (equal to zero)
    """
    n = SECP256k1.order
    m = len(signatures)
    
    # Construction of the lattice matrix
    B = IntegerMatrix(m + 1, m + 1)
    
    for i in range(m):
        B[i, i] = n
        s_inv = pow(signatures[i][1], -1, n)
        a_i = (s_inv * signatures[i][0]) % n
        b_i = (s_inv * signatures[i][2]) % n
        B[m, i] = a_i
        B[i, m] = 0
    
    B[m, m] = 2**known_bits
    
    # Basis reduction
    LLL.reduction(B)
    
    # Extract candidate d from short vectors
    for i in range(m + 1):
        row = [B[i, j] for j in range(m + 1)]
        if abs(row[m]) == 2**known_bits:
            d_candidate = abs(row[m - 1]) % n
            return d_candidate
    
    return None

7. Example: High-Bit Shift Attack

Let’s consider a hypothetical scenario. Suppose we have  N = 500 ECDSA signatures generated using a nonce whose most significant 8 bits are zero (i.e.,  ). Such a bias could arise, for example, when using a 248-bit PRNG instead of a 256-bit one, or due to an implementation error where the generator returns a value that doesn’t fill the most significant bytes.k < 2248

Step 1.  Apply the χ² test to the normalized values   ​​for random  . For most ,   the p-value will be high (the distribution is close to uniform). However, with correct ,   the distribution   will be concentrated in the lower part of the range  , yielding an abnormally low p-value.ti(d')d'd'dti[0, 2248/n)

Step 2.  We use the “short nonce” method: for each,  d' we calculate the proportion  . If correct,   this proportion will be close to 1; if incorrect, it will be close to  . Threshold: if the proportion exceeds 0.5,   the candidate is considered a candidate.ti(d') < 2248d2−8 = 0.0039d'

Step 3.  Once the candidate  d' is found to within a few least significant bits, we apply the lattice attack (LLL) to recover it exactly  d.

Result.  Breitner and Heninger (2019) demonstrated that, given a bias of 4–8 high-order bits of the nonce and several hundred signatures, a private key can be recovered in minutes on a standard CPU using open-source libraries (fpylll, SageMath). In total, approximately 300 keys vulnerable to such attacks have been discovered in the Bitcoin blockchain.

8. Computational complexity and limitations

StageComplexityRestrictions
Collection of signaturesO(N)Blockchain or API access required; N ≥ 1000 for statistical significance
χ² test for one d’O(N)It is impossible to enumerate all d’; it is used in combination with other methods
Candidate search (binomial test)O(N · C), C is the number of candidatesEffective for offset ≥ 4 bits
LLL-reductionO(m³ · log² B)m is the number of signatures; for m = 1000, ~10⁹ operations are required
BKZ post-processingHigher than LLLRequired for large m or small displacements

Limitation:  If nonces are generated uniformly (a perfect PRNG), statistical tests will reveal no anomalies, and the attack is impossible. Therefore, statistical cryptanalysis of ECDSA  does not break  the algorithm in the mathematical sense, but rather exploits  implementation flaws  in the nonce generator.

9. Conclusion

The textbook “Probability and Statistics” by G.P. Khamitov and T.I. Vedernikova provides a complete and systematic presentation of the apparatus necessary for  the first, critical stage  of ECDSA cryptanalysis—statistical exploration of biases in nonce generation. Key sections of the textbook—statistical hypothesis testing, the χ² test, the Kolmogorov–Smirnov test, correlation and regression analysis—find direct application in the following problems:

  1. Detecting nonce reuse  through frequency analysis  r .
  2. Detection of bias of the most significant bits of nonce  using the χ² test and the binomial test for normalized values  .ti(d')
  3. Detection of linear dependencies  between consecutive nonces through correlation analysis and regression models.
  4. Testing hypotheses about the nature of the bias  (uniform vs. biased) using p-values ​​and critical regions.

Once statistical analysis confirms the presence of bias, the problem is reduced to  a hidden number problem  (HNP), solvable using lattice reduction methods (LLL/BKZ). A combination of statistical and algebraic methods allows ECDSA private keys to be recovered with only 4–8 bits of bias in the nonce and several hundred signatures.

The practical significance of this approach is confirmed by large-scale studies of the Bitcoin blockchain, which discovered and recovered hundreds of private keys vulnerable to statistical attacks on nonces. This underscores the importance of  cryptographically secure random number generation  and regular statistical auditing of cryptographic implementations.

10. Directions for further research for cryptanalysis based on this area

  1. Multivariate statistical analysis of nonces.  Application of multivariate tests (Hotelling’s T², MANOVA) to simultaneously analyze multiple nonce bit layers and identify complex, nonlinear biases that are not detectable by univariate tests.
  2. Bayesian methods for private key estimation.  Construction of a posterior distribution  d based on statistical evidence (p-value, test statistics) using MCMC (Markov Chain Monte Carlo) methods for point estimation and construction of confidence intervals.
  3. Machine learning methods applied.  Neural networks (LSTM, transformers) are used to detect hidden patterns in nonce sequences that are not captured by classical statistical tests. Supervised learning is performed on synthetic data with known bias for subsequent application to real blockchain data.
  4. Nonce time series analysis.  Using spectral analysis (FFT, wavelet transform) to detect periodicities and autocorrelations in nonce sequences, which may indicate the use of a PRNG with a fixed seed or a linear congruential generator.
  5. Robust statistical tests for incomplete data.  Developing methods that are robust to missing data (e.g., when the public key is not available for all transactions) and outliers, using rank statistics and bootstrap procedures.
  6. Combining statistical and lattice methods into a single automated system.  Creating a pipeline that automatically collects signatures, applies a set of statistical tests, identifies anomalies, and launches a corresponding lattice attack with optimized parameters (lattice dimension, signature selection, preprocessing).
  7. Cross-blockchain correlation analysis.  A study of nonce reuse across different blockchains (Bitcoin, Ethereum, Litecoin, etc.) using statistical methods to identify common sources of entropy and vulnerabilities in key generation libraries.
  8. Statistical analysis of side-channel leakage.  Applying hypothesis testing and correlation analysis to power consumption or electromagnetic radiation data to detect relationships between nonces and device physical characteristics.
  9. Developing statistical tests for new signature schemes.  Adapting the methodology outlined in this guide to modern schemes (Schnorr, BLS, post-quantum signatures) to assess the resilience of their nonce generators to statistical attacks.
  10. A study of the limits of statistical detectability of biases.  A theoretical analysis of the minimum number of signatures required to detect a bias of a given magnitude, using information theory (mutual information, entropy) and asymptotic statistics.

The document has been prepared on the basis of the textbook: Khamitov G.P., Vedernikova T.I. “Probabilities and Statistics”. – Irkutsk: Publishing house of BSUEL, 2006. – 270 p. ISBN 978-5-7253-1504-2.

Statistical analysis of ECDSA nonces: methods, implementation, cryptanalytic applications.