Application of probability theory (Akhtyamov A. M., 2016) to the calculation of a hidden number in the signature of an ECDSA Bitcoin transaction for the purpose of recovering a private key

25.10.2026

Abstract.  This paper explores the applicability of probabilistic and statistical methods outlined in A. M. Akhtyamova’s textbook “Probability Theory for Socio-Economic Specialties” (Moscow: Fizmatlit, 2016) to the cryptanalysis of the Elliptic Curve Digital Signature Algorithm (ECDSA) protocol used in the Bitcoin blockchain. It is shown that statistical criteria, probability distributions, and parameter estimation methods are directly applicable to detecting anomalies in nonce (hidden number  k) generation, which ultimately allows for the recovery of the private signature key. This paper demonstrates that the classical apparatus of probability theory outlined in A. M. Akhtyamova’s textbook finds direct and effective application in ECDSA cryptanalysis. Key findings:

  1. Nonce as a random variable.  The hidden number  k in ECDSA is a discrete random variable. Deviation from its uniform distribution is a key source of vulnerability.
  2. Statistical tests.  The χ² and Kolmogorov-Smirnov tests allow us to detect nonce bias using publicly available blockchain data.
  3. Bayesian approach.  Posterior distribution estimation  k significantly narrows the search space and improves the attack’s effectiveness.
  4. Hidden Number Problem (HNP).  Key recovery with partial knowledge of the nonce reduces to the HNP, which is solved using lattice methods and the Fourier transform.
  5. Practical feasibility.  Even a leak of 3-4 bits of nonce information is sufficient to recover a 256-bit private key. Hundreds of vulnerable keys have been discovered in real blockchains.

The results demonstrate a profound connection between classical probability theory and modern cryptography. Methods developed for analyzing socioeconomic processes are proving useful in solving problems related to ensuring the security of blockchain systems.

Content

  1. Introduction
  2. Theoretical foundations
  3. Application of probability theory to ECDSA cryptanalysis
  4. Practical methods for calculating hidden numbers
  5. Practical implementation
  6. Example: Recovering a key from 6 signatures
  7. Conclusion
  8. Directions for further research for cryptanalysis based on this area

1. Introduction

The ECDSA (Elliptic Curve Digital Signature Algorithm) protocol is the cornerstone of Bitcoin blockchain security. Each transaction is signed using a private key  d and an ephemeral secret number  kcalled a nonce (number used once). The security of ECDSA depends critically on the fact that the value  k must be chosen uniformly randomly from the range  [1, n−1], where  n is the order of the elliptic curve secp256k1, and  must never repeat [reference:0].

Violating these conditions—reusing it  k, shifting its bits, using short values, or leaking some information about it—causes the private key recovery problem to be reduced to  the Hidden Number  Problem (HNP), first formulated by Boneh and Venkatesan and adapted to (EC)DSA by Haugrave-Graham and Smart[reference:1][reference:2].

The purpose of this work is to show that the classical apparatus of probability theory, presented in the textbook by A. M. Akhtyamova [reference:3], includes:

  • laws of distribution of discrete random variables;
  • statistical criteria for hypothesis testing;
  • Bayesian approach to parameter estimation;
  • limit theorems and asymptotic estimates;
  • elements of the theory of random processes,

finds direct and effective application in ECDSA vulnerability analysis and hidden number calculation  k with subsequent private key recovery.

2. Theoretical foundations

2.1 Probabilistic Models Applicable to Cryptanalysis

Akhtyamova’s manual [reference:4] systematically presents the following probabilistic constructions, which are in demand in the cryptanalysis of ECDSA:

Section of probability theoryApplication in ECDSA cryptanalysis
Discrete distributions (uniform, binomial, geometric)Modeling the nonce distribution  k; testing the uniformity hypothesis
Statistical criteria of goodness of fit (χ², Kolmogorov-Smirnov)Detection of statistically significant deviations in generation k
Bayesian estimation methodsA posteriori estimate of the probability that  k belongs to a certain interval
Law of large numbers and limit theoremsJustification of the convergence of statistics when accumulating a large number of signatures
Theory of random processesModeling a nonce sequence as a random process with Memory
Estimation of distribution parametersDefining offset parameters (e.g., length of the zero prefix)

The key idea is that  nonce generation in real cryptographic libraries is far from always perfectly uniform . Various implementation flaws—poor PRNGs, errors in modular arithmetic, side-channel attacks—lead to  statistically detectable  deviations from a uniform distribution [reference:5]. It is these deviations that allow the application of probabilistic tools.

2.2 Mathematical structure of ECDSA

Let’s recall the basic equations of the ECDSA protocol. Let  n be the order of the elliptic curve base point  G secp256k1,  d be the private key,  k and be the nonce. For a message with a hash,  z the signature  (r, s) is calculated as follows:

R = k · G (a point on an elliptic curve)
r = R x  mod n (the x-coordinate of the point R)
s = k −1  · (z + r · d) mod n

From here we obtain the basic equation connecting the known quantities  (r, s, z) with the unknowns  k and  d:

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

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

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

The task of cryptanalysis thus boils down to  calculating the hidden number k . This is where probability theory comes in.

2.3. Hidden number (nonce) as a random variable

From a probability theory perspective  k , it is a discrete random variable taking values ​​in  {1, 2, …, n−1}. In an ideal implementation, the distribution  k should be uniform:

P(k = t) = 1/(n−1), t = 1, 2, …, n−1

However, in practice, due to generation defects, the distribution may have one of the following types:

  • Most significant bit bias (MSB bias).  The most significant  l bits  k are zero. Mathematically:  [reference:6].0 ≤ k < 2256−l
  • Least significant bit bias (LSB bias).  The least significant  l bits  k are zero:  , where   is the smaller number[reference:7].k = 2l · k'k'
  • Truncated nonce. k  Takes values ​​from some subrange  , where  [reference:8].[1, 2m−1]m < 256
  • Reuse   for two different signatures  [reference:9].ki = kji ≠ j

Each of these deviations can be detected  by statistical methods  and used for restoration  k.

3. Application of probability theory to ECDSA cryptanalysis

3.1 Statistical analysis of nonce distribution

The first step for a cryptanalyst is  to collect a set of signatures  corresponding to the same private key  . Such signatures can be extracted from the public Bitcoin blockchain: all transactions originating from a single address are signed by the same key[reference:10].(ri, si, zi)d

Chi-square test

To test the hypothesis of uniform distribution,  k Pearson’s goodness-of-fit test can be used. However, this  k is not directly known. Instead, the statistic derived from is analyzed  (r, s, z).

From equation (1) we express  k:

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

Since  d is unknown, direct calculation  k is impossible. However,  the distribution of the most significant bits of the quantity can be investigated :

w i  = s i −1  · z i  mod n

If   the MSB is biased, the value   will also exhibit an anomalous distribution. Breitner and Heninger [reference:11] demonstrated that this strategy can detect hundreds of vulnerable keys in the Bitcoin blockchain.kisi−1 · ri · d

Kolmogorov-Smirnov criterion

To test the hypothesis that the empirical distribution function  k corresponds to the theoretical one (uniform or biased), statistics are used:

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

For large  n values,  the value  has a Kolmogorov distribution, which allows one to construct a goodness-of-fit criterion.√n · Dn

3.2. Bayesian approach to hidden number estimation

The Bayesian approach outlined in Akhtyamova’s textbook allows one to formally estimate the posterior distribution  k given the observed data. Let be   a vector of unknown parameters. The posterior density is:θ = (d, k1, …, km)

p(θ | r, s, z) ∝ p(r, s, z | θ) p(θ)

If the prior distribution  k is known (for example, if it is biased toward small values), this allows for a significant narrowing of the search space. The following prior models are used in practice:

  • Uniform distribution  on   with truncated nonce;[1, 2m]
  • Binomial model  for the number of leading zero bits;
  • Geometric distribution  for the length of the zero prefix.

Key takeaway:  The Bayesian approach allows us to move from the problem of exhaustive enumeration   of options   to a statistical estimation problem with significantly reduced variance.2256k

3.3 Probabilistic Nature of the Hidden Number Problem (HNP)

The Hidden Number Problem (HNP) is formulated as follows. Let be   a secret. Given pairs  , where:α ∈ Zn(ti, ai)

a i  = ⌊α · t i ⌋ n  + e i    (mod n)

Here   are the errors (noise), which are assumed to be small. It is necessary to restore  .eiα

In the context of ECDSA,  α the private key plays  a role d, and the values   ​​are related to the nonce  . It is  the probabilistic distribution of errors  that determines the difficulty of the problem and the success of the attack.aiki ei

According to Boneh and Venkatesan’s results, if the errors   are bounded in absolute value and their distribution has sufficiently light tails, HNP can be solved in polynomial time. In the context of ECDSA, this means that  even a small nonce bias makes the key recovery problem computationally feasible [reference:12].ei

3.4 Probability Analysis Based on the Fourier Transform

Bleichenbacher’s approach to solving HNP is based on Fourier analysis. We define the function:

f(x) = E[exp(2πi · x · k / n)]

If the distribution  k is biased, then  f(x) is not equal to zero at  x ≠ 0. This allows us to construct a recovery algorithm  d by searching for the maximum of |f(x)|.

Osaka and Kunihiro [reference:13] showed that even if  less than one bit of  nonce information is leaked (for example, the most significant bit is known with probability  < 1), the Fourier transform can be used to recover the key. The number of required signatures is reduced by a  factor of 2  when one bit is leaked, and by  a factor of 4  when two or more bits are leaked [reference:14].

Practical result:  For 256-bit ECDSA,  3–4 bits of nonce leakage are sufficient to recover the private key in a few minutes of computation [reference:15].

4. Practical methods for calculating the hidden number

4.1 Nonce Reuse Detection

The simplest and most destructive scenario is  reusing the same signature k  to sign two different messages. Let’s say   signatures are obtained  for messages with hashes  and   with   the same signature  .z1z2(r, s1)(r, s2)k

Then from equation (1):

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

Subtracting, we get:

k ≡ (z 1  − z 2 ) (s 1  − s 2 ) −1    (mod n)

After calculation,  k the private key is found using formula (2). This is  a deterministic attack that does not require probabilistic analysis.

To detect reuse  k in a blockchain, it’s enough to find two transactions with the same value  r. Blockchain scanners (such as  reused-r-scanner[[ …

4.2. Lattice attacks based on HNP

Lattice attacks, first proposed by Haugrave-Graham and Smart for (EC)DSA[reference:17], are the most powerful key recovery tool given  partial knowledge of the nonce .

The idea of ​​the method is as follows. Suppose that  the most significant  bits of each  m signature are known  . Then:lki

k i  = 2 256−l  · a i  + b i , where 0 ≤ b i  < 2 256−l

Substituting into (1) and excluding  d, we obtain a system of linear equations for   and  . This system reduces to the nearest vector in a lattice problem (CVP), which is solved by the LLL (Lenstra-Lenstra-Lovasz) algorithm or its generalization BKZ[reference:18].aid

The probabilistic analysis of the success of a lattice attack is based on:

  • distribution of errors   (usually uniform over the interval);bi
  • estimation of the norm of the target vector in the lattice;
  • Gaussian heuristic for predicting shortest vectors.

According to the results, for 256-bit ECDSA,  3-4 bits of known high-order nonce bits  and  several dozen signatures are sufficient to recover the key with high probability[reference:19].

4.3. Attacks on displaced nonces

Even if the exact values ​​of the nonce bits are unknown, but they are known to be  statistically biased , probabilistic methods can be applied. For example:

  • MSB offset:  ;P(k < 2256−l) ≈ 1
  • LSB offset:  ;P(k ≡ 0 mod 2l) ≈ 1
  • Non-uniform distribution: k  takes values ​​from some subset with probability different from 1/|S|.

Breitner and Heninger [reference:20] showed that  any statistically significant deviation from uniformity  can be exploited to recover a key given a sufficient number of signatures. The authors calculated  approximately 300 Bitcoin private keys using the described methods [reference:21].

5. Practical implementation

Below is a general algorithm for recovering an ECDSA private key based on probabilistic nonce analysis.

Step 1: Data Collection

All transactions originating from the target address are extracted from the Bitcoin blockchain. For each transaction, the following information is stored:

  • message hash  ;zi
  • signature components  ,  ;risi
  • public key  Q = d · G (known from the lock script).

Step 2. Statistical analysis

The following statistics are calculated for the set   :{(ri, si, zi)}

  • distribution of the most significant bits of the value  ;wi = si−1 · zi mod n
  • χ² test for uniformity;
  • autocorrelation function for periodicity detection.

Step 3. Building the lattice

If a bias is detected (e.g.  ), the lattice matrix is ​​constructed:ki < 2256−l

L = 
[ n    0    0   ...  0    0  ]
[ 0    n    0   ...  0    0  ]
[ ...                         ]
[ t₁   t₂   t₃  ...  tₘ   B/n ]

where  ,   is the scaling parameter (usually  ).ti = si−1 · ri mod nB2256−l

Step 4. Lattice reduction

The LLL or BKZ algorithm is used to find short vectors. The target vector contains information about  d and  .ki

Step 5. Verification

The found key  d is verified against the public key:  d · G = Q. If a match is achieved, the key is recovered.

Software implementation.  There are ready-made libraries for performing such attacks:  ecdsa-break in Python, implementing LLL/BKZ reduction [reference:22], and also  lattice-attack (Sage) [reference:23].

6. Example: restoring a key from 6 signatures

Let’s look at a demonstration example. Let’s say an attacker has collected six ECDSA signatures generated with a private key whose nonce has a 176-bit offset (that is,  ).k < 280

Using the library  ecdsa-break, the attack is performed with the following command:

pip install breaking-ecdsa-with-lll
break-ecdsa nonces.csv 176 6

The input file  nonces.csv contains lines of the form:

hash, r, s, pubkey
e3b0c442..., 79be667e..., 483ada77..., 04a34b99...
...

After executing the command, the program outputs the recovered private key in hex format[reference:24].

Important:  This example is for educational purposes only. Unauthorized access to cryptocurrency funds is a criminal offense.

7. Conclusion

This paper demonstrates that the classical apparatus of probability theory, as presented in A. M. Akhtyamova’s textbook, finds direct and effective application in ECDSA cryptanalysis. Key findings:

  1. Nonce as a random variable.  The hidden number  k in ECDSA is a discrete random variable. Deviation from its uniform distribution is a key source of vulnerability.
  2. Statistical tests.  The χ² and Kolmogorov-Smirnov tests allow us to detect nonce bias using publicly available blockchain data.
  3. Bayesian approach.  Posterior distribution estimation  k significantly narrows the search space and improves the attack’s effectiveness.
  4. Hidden Number Problem (HNP).  Key recovery with partial knowledge of the nonce reduces to the HNP, which is solved using lattice methods and the Fourier transform.
  5. Practical feasibility.  Even a leak of 3-4 bits of nonce information is sufficient to recover a 256-bit private key. Hundreds of vulnerable keys have been discovered in real blockchains.

The results demonstrate a profound connection between classical probability theory and modern cryptography. Methods developed for analyzing socioeconomic processes are proving useful in solving problems related to ensuring the security of blockchain systems.

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

  1. Developing adaptive statistical tests to detect hidden nonce biases. Existing tests (χ², Kolmogorov-Smirnov) are focused on detecting obvious biases. A promising direction is the development of  adaptive  tests capable of detecting weak but systematic biases in large samples. In particular, Wald sequential analysis methods and Bayesian criteria with uninformative prior distributions can be used.
  2. Applying random process theory to modeling nonce sequences. Nonces in real-world implementations can be correlated over time (for example, due to the use of a linear congruential generator). Modeling the sequence   as a random process with Memory (Markov chains, autoregressive models) will allow for the detection of more subtle dependencies and improve the effectiveness of attacks.{ki}
  3. Probabilistic analysis of the robustness of lattice attacks to noise. In real-world settings, nonce information may contain errors (e.g., during side-channel attacks). A rigorous probabilistic analysis of how the error distribution affects the success rate of LLL/BKZ reduction is necessary. This will allow us to determine  the leakage thresholds  at which the attack becomes infeasible.
  4. Using Bayesian networks for joint estimation  d of and  .ki The joint posterior distribution   can be approximated using Markov Chain Monte Carlo (MCMC) methods. This opens the way to the creation of  probabilistic  key recovery algorithms that operate under incomplete information.p(d, k1, …, km | r, s, z)
  5. Analysis of nonce distribution in hardware wallets and HSMs. Hardware random number generators can have specific flaws (e.g., correlations with temperature, supply voltage, and electromagnetic radiation). Applying probabilistic methods to the analysis of output sequences from such devices is a promising area.
  6. Developing countermeasures based on statistical analysis. A symmetrical task is to develop methods  for detecting  attacks at the signature generation stage. Probabilistic models make it possible to build early warning systems that detect anomalies in the nonce distribution and block signing until the threat is eliminated.
  7. Applying large deviation theory to estimating the attack’s success probability. For large  m numbers of signatures, the probability of successful key recovery can be estimated using large deviation theory. This yields asymptotic formulas relating the leak length, the number of signatures, and the computational cost.
  8. A study of the resilience of ECDSA with deterministic nonces (RFC 6979). RFC 6979 proposes deterministic nonce generation, eliminating the bias problem. However, the question remains: does the vulnerability persist even if the private key or hash function is compromised? Probabilistic analysis of deterministic schemes is an important area of ​​research.

Conclusion.  Probability theory provides a powerful and flexible toolkit for ECDSA cryptanalysis. Further development in this field requires a synthesis of probabilistic, algebraic, and computational methods, opening new horizons for both attackers and defenders of blockchain systems.


This document is based on A. M. Akhtyamova’s textbook “Probability Theory for Socio-Economic Specialties” (Moscow: Fizmatlit, 2016) and modern research in the field of ECDSA cryptanalysis.
This material is for educational purposes only.