Application of paradoxes of probability theory and mathematical statistics of G. Szekely to the cryptanalysis of ECDSA in Bitcoin transactions

22.10.2026

Methodology for recovering a hidden number (nonce k) and a private key based on statistical anomalies in random variable generation

Field: Cryptanalysis, Probability Theory, Number Theory. Source Book: Szekely, G. “Paradoxes in Probability Theory and Mathematical Statistics.” Moscow: Mir, 1990. 240 p. Gabor Szekely’s book “Paradoxes in Probability Theory and Mathematical Statistics” (Moscow: Mir, 1990) is not just a collection of entertaining problems, but a methodological foundation for analyzing statistical anomalies in cryptographic systems. The paradoxes discussed there—birthday paradoxes, Monty Hall paradox, Simpson paradox, and sample mean paradox—describe precisely those situations where the intuitive understanding of randomness diverges from mathematical reality. In the context of Bitcoin’s ECDSA, these discrepancies become an attack vector.

Practical application of the approach includes:

  1. Statistical diagnostics  of nonce distribution using goodness-of-fit tests and spectral analysis.
  2. Formalization of the key recovery problem  as a Hidden Number Problem.
  3. Lattice methods  (LLL, BKZ) for solving HNP using partial nonce information.
  4. Verification of  the recovered key by checking its compliance with the public key.

Real-world attacks on the Bitcoin blockchain demonstrate that even minor deviations from perfect randomness (1-4 bit bias, nonce reuse, limited PRNG entropy) lead to complete compromise of private keys. Szekely’s book, written decades before

Content

  1. Introduction
  2. The Mathematical Foundations of ECDSA in Bitcoin
  3. Székely paradoxes and their relation to cryptanalysis
  4. Hidden Number in Signature: HNP Formulation
  5. Statistical analysis of the distribution of nonce k
  6. Lattice Attacks: LLL and BKZ
  7. Practical algorithm for key recovery
  8. Real-life attacks on the Bitcoin blockchain
  9. Conclusion
  10. Directions for further research for cryptanalysis based on this area

1. Introduction

The Elliptic Curve Digital Signature Algorithm (ECDSA) underlies the security of Bitcoin transactions. Each ECDSA signature uses a one-time secret number k (nonce), which is supposed to be chosen  uniformly at random  from the range [1, n−1], where n is the order of the elliptic curve secp256k1 point group. However, in practice, the generation of k often deviates from perfect uniformity due to bugs in the implementation of pseudorandom number generators (PRNGs), hardware glitches, or programming errors.

Hungarian mathematician Gabor Székely’s book “Paradoxes in Probability Theory and Mathematical Statistics” (Moscow: Mir, 1990) is a collection of unexpected conclusions and assertions from probability theory, mathematical statistics, and the theory of random processes.[reference:0] Although written long before the advent of Bitcoin, the book’s principles for analyzing statistical anomalies, paradoxes of sampling distributions, and intuitions about randomness are directly applicable to the cryptanalysis of ECDSA.

The key idea is that  if the distribution of nonce k deviates even slightly from uniformity, or if some information about k (even a few bits) becomes known, an attacker can recover the private key d using statistical and algebraic methods. Szekely’s book provides a methodological basis for identifying and quantifying such deviations.

2. Mathematical Foundations of ECDSA in Bitcoin

2.1. Secp256k1 Curve Parameters

Bitcoin uses a secp256k1 elliptic curve defined over a finite field F_p, where p = 2²⁵⁶ − 2³² − 977. The order of the point group n is a prime number close to 2²⁵⁶. The base point G has order n.

2.2. Signature process

To sign a message m with hash h = H(m) and private key d ∈ [1, n−1]:

1. Choose a random k ∈ [1, n−1] — a nonce.
2. Calculate the point R = kG = (x_R, y_R).
3. r = x_R mod n. If r = 0, return to step 1.
4. s = k⁻¹ (h + d r) mod n. If s = 0, return to step 1.
5. Signature: (r, s).

2.3. Equation relating nonce and private key

From step 4 follows the fundamental relationship:

s k ≡ h + d r (mod n)
⟹ k ≡ s⁻¹(h + d r) (mod n)

If the attacker knows k for at least one signature, the private key is calculated directly:

d = (s k − h) r⁻¹ mod n

However, k is secret. The problem of recovering d from signatures (r, s) without knowledge of k reduces to the discrete logarithm problem on an elliptic curve, which is computationally intractable given the correct nonce generation. The paradox is that  even partial leakage of information about k  or  statistical heterogeneity in its distribution  makes this problem tractable.

3. Székely paradoxes and their connection with cryptanalysis

Székely’s book contains numerous paradoxes, each of which illustrates the fundamental discrepancy between the intuitive understanding of randomness and its mathematical nature. Let’s consider the most relevant ones for ECDSA cryptanalysis.

3.1 The Birthday Paradox

A classic paradox: in a group of 23 people, the probability of matching birthdays exceeds 50%. In the context of ECDSA, this means that when generating a large number of nonces k, the probability of their repetition (collision) grows quadratically with the number of signatures. If the PRNG has a period smaller than n, or if the input entropy is bounded, repetition of k becomes virtually inevitable.

Practical consequence:  When using the same k repeatedly for two different messages m₁ and m₂:

s₁·k = h₁ + d·r (mod n)
s₂·k = h₂ + d·r (mod n)
⟹ k = (h₁ − h₂) · (s₁ − s₂)⁻¹ mod n
⟹ d = (s₁ · k − h₁) · r⁻¹ mod n

The private key can be recovered in O(1) operations.

3.2 The Monty Hall Paradox and Conditional Probabilities

The Monty Hall paradox demonstrates that the intuitive estimate of conditional probability can differ radically from the mathematically correct one. In ECDSA cryptanalysis, this is reflected in the fact that an attacker  aware  of bias in the nonce generator can use Bayesian inference to refine the distribution of k over observed signatures. Each new signature with a known bias increases the posterior probability of certain values ​​of k, allowing the HNP problem to be solved with fewer signatures than required in the absence of prior information.

3.3 Simpson’s paradox and sample aggregation

Simpson’s paradox suggests that a trend observed in individual subsets of data may disappear or reverse when these subsets are combined. In the context of ECDSA, this means that nonces that appear uniformly distributed when analyzed across the entire signature population may exhibit significant bias within certain subsets (e.g., signatures generated during specific time intervals, by specific wallet versions, or with specific hardware devices). Stratifying the sample by these characteristics allows for the identification of hidden biases.

3.4 The paradox of the sample mean and the law of large numbers

Székely examines in detail cases where the sample mean converges to the expected value more slowly than intuition suggests, or where the distribution of sample means is not normal even for large samples (e.g., for heavy-tailed distributions). In ECDSA cryptanalysis, this means that reliably detecting a small bias (e.g., 1–2 bits) may require significantly more signatures than predicted by a naive estimate based on the central limit theorem.

4. Hidden number in signature: HNP formulation

The problem of recovering an ECDSA private key given the nonce is formalized as  the Hidden Number Problem  (HNP), introduced by Boneh and Venkatesan to analyze the bit security of the Diffie–Hellman protocol[reference:1].

4.1. Statement of the problem

Let n be a prime number (the order of the group). Pairs (t_i, u_i) are known, where t_i ∈ Z_n and u_i is an approximation to α t_i mod n with an accuracy of n/2^ℓ:

|α·t_i − u_i|_n < n / 2^ℓ

where |·|_n denotes the distance modulo n, and α is a hidden number (in our case, a function of the private key d). The task is to recover α.

4.2. Reduction of ECDSA to HNP

From the signature equation:

s_i k_i ≡ h_i + d r_i (mod n)

Dividing both sides by s_i:

k_i ≡ s_i⁻¹·h_i + d·s_i⁻¹·r_i (mod n)

Denoting t_i = s_i⁻¹·r_i mod n and a_i = s_i⁻¹·h_i mod n, we obtain:

k_i ≡ a_i + d·t_i (mod n)

If the most significant ℓ bits of each k_i are known (or if k_i is known to lie in a certain interval), then we obtain u_i, an approximation to d t_i mod n with accuracy n/2^ℓ. This is exactly HNP with α = d.

5. Statistical analysis of the distribution of nonce k

5.1 Detecting Bias through Goodness-of-Fit Tests

The first stage of the attack is a statistical test of the hypothesis that k is uniformly distributed. This is accomplished by:

  • The χ² (chi-square) test  compares the empirical distribution of the most significant bits of k_i with a uniform distribution. A deviation from uniformity indicates the presence of bias.
  • Kolmogorov–Smirnov test:  testing the compliance of the empirical distribution function with the theoretical uniform one.
  • Fast Fourier Transform (FFT) analysis:  identifying periodicities in a nonce sequence characteristic of linear congruential generators (LCGs).
  • NIST SP 800-22 Test:  A suite of 15 statistical tests, including the frequency test, runs test, approximate entropy test, and others.

Result:  Research shows that 256-bit ECDSA becomes completely vulnerable with just a 4-bit offset in the nonce, even if the values ​​of the offset bits themselves are unknown[reference:2]. With 1–2 bits of offset, recovering the key may require hundreds to thousands of signatures.

5.2 Estimating the entropy of a nonce

The minimum entropy of a nonce is defined as:

H_min = −log₂( max_k P(k) )

If H_min < 256 bits, then an attack is fundamentally possible. In practice, many nonce generators in Bitcoin wallets had H_min values ​​in the 64–128 bit range due to limited system clock entropy, weak seed values, or implementation bugs.

5.3 Bayesian inference for refining the distribution of k

Given prior information about the nature of the bias (e.g., the most significant ℓ bits of the nonce are known to be fixed), one can construct a posterior distribution P(k | r, s, h, d) and use it to iteratively refine the estimate of d. This approach, based on Bayesian statistics, reduces the required number of signatures by 25–50% compared to purely lattice methods.

6. Lattice attacks: LLL and BKZ

6.1 Construction of the lattice for HNP

To solve the HNP, a lattice of dimension m+1 is constructed, where m is the number of known signatures. The basis vectors are formed as follows:

B = [ n 0 … 0 0 ]
[ 0 n … 0 0 ]
[ … … … … …]
[ 0 0 … n ​​0 ]
[ t₁ t₂ … t_m B/n ]

where B is a scaling parameter and t_i = s_i⁻¹ r_i mod n. The target vector containing information about d is a short vector in this lattice.

6.2. LLL Algorithm

The Lenstra–Lenstra–Lovász (LLL) algorithm finds approximately short vectors in a lattice in polynomial time. When applied to an HNP lattice, LLL allows one to extract a vector containing k_i − u_i and d·B/n, from which d is recovered [reference:3].

Key result:  Using LLL as a “black box” attack on ECDSA with a 4-bit nonce offset allows for private key recovery in minutes on commodity hardware[reference:4].

6.3. Post-processing BKZ

To improve accuracy and reduce the number of required signatures, the BKZ (Block Korkine–Zolotarev) algorithm is used. It provides better basis reduction than LLL, at the expense of increased computational complexity. Combining LLL with subsequent BKZ postprocessing enables an attack on HNP with a 1-bit bias using asymmetric lattice sifting [reference:5].

6.4 Software implementation

There are open-source libraries for implementing the attack in practice, such as  breaking-ecdsa-with-lll, which takes a CSV file with signatures and an offset parameter B (the number of known high-order bits) and returns private key candidates:

pip install breaking-ecdsa-with-lll

# Генерация слабых подписей (для тестирования)
gen-weak-sigs <secret_hex> 176 6 > nonces.csv

# Восстановление ключа
break-ecdsa nonces.csv 176 6

The tool uses LLL lattice reduction (optionally with BKZ) to solve HNP[reference:6].

7. Practical algorithm for key recovery

7.1 Step-by-step procedure

Step 1. Data collection.  Collect multiple signatures (r_i, s_i, h_i) for the same public key from the Bitcoin blockchain. You can use blockchain explorer APIs or a Bitcoin Core full node for this.

Step 2. Statistical analysis.  Apply goodness-of-fit tests (χ², KS test, spectral analysis) to the sequence of reconstructed values ​​t_i = s_i⁻¹ r_i mod n to identify deviations from uniformity.

Step 3. Estimating the bias parameters.  Determine the number ℓ of known/biased high-order bits of the nonce. If the exact value of ℓ is unknown, use an iterative approach: start with small ℓ and increase it until the lattice attack produces a stable result.

Step 4. Constructing the HNP lattice.  Create a lattice basis of dimension m+1 based on m signatures.

Step 5. Lattice reduction.  Apply LLL (and, if necessary, BKZ) to find a short vector containing information about d.

Step 6. Verification.  Verify the found candidate d by signing a test message and comparing the public key dG with the known public key of the victim.

7.2. Estimation of computational complexity

ParameterMeaning
Number of signatures mfrom 20 to 2000 (depending on ℓ)
Lattice dimensionm+1
Difficulty of LLLO(m⁵ · log³ n)
MemoryO(m²)
CPU timefrom minutes (LLL) to hours (BKZ)

8. Real attacks on the Bitcoin blockchain

8.1. Breitner–Heninger Study (2019)

In their paper “Biased Nonce Sense,” Joachim Breitner and Nadja Heninger computed hundreds of Bitcoin, Ethereum, Ripple, SSH, and HTTPS private keys through cryptanalytic attacks on digital signatures contained in public blockchains.[reference:7] Using a lattice algorithm to solve HNP, they recovered approximately 300 Bitcoin keys with 64-bit and 128-bit nonces.[reference:8] The total computational effort was approximately 40 CPU years.[reference:9]

8.2 Hash-Key Concatenation Vulnerability

In 2023, IACR researchers reported a new class of ECDSA vulnerability observed in the Bitcoin blockchain: a nonce was generated by concatenating half the bits of a message hash with half the bits of a private signature key.[reference:10] For such signatures, a lattice-based method for recovering the key from  a single  signature was developed. A scan of the entire blockchain identified hundreds of compromised Bitcoin addresses that had been used to empty wallets for years.[reference:11]

8.3 Nonce Reuse

Despite its well-known dangers, nonce reuse remains a recurring problem in the Bitcoin ecosystem. Research has shown that an attacker could steal 412.80 BTC (worth approximately $3.3 million at the time of analysis) by exploiting repeated nonces.[reference:12] Thousands of signatures were discovered using the same value k = (n−1)/2, which was apparently used to “dust” transactions.[reference:13]

8.4. CVE-2024-31497 (PuTTY) Vulnerability

In 2024, a vulnerability was discovered in the ECDSA implementation in PuTTY (and derivatives, including FileZilla) related to the predictable nonce generator for the NIST P-521 curve. By shifting the nonce, it was possible to recover the private key using methods similar to those described above [reference:14].

Conclusion.  Statistical anomalies in nonce generation are not a theoretical threat, but a real, exploitable vulnerability that leads to financial losses. A methodology based on Székely’s paradoxes allows for the systematic identification and exploitation of such anomalies.

9. Conclusion

Gábor Székely’s book “Paradoxes in Probability Theory and Mathematical Statistics” (Moscow: Mir, 1990) is not just a collection of entertaining problems, but a methodological foundation for analyzing statistical anomalies in cryptographic systems. The paradoxes discussed there—birthday paradoxes, Monty Hall paradox, Simpson paradox, and sample mean paradox—describe precisely those situations where the intuitive understanding of randomness diverges from mathematical reality. In the context of Bitcoin’s ECDSA, these discrepancies become an attack vector.

Practical application of the approach includes:

  1. Statistical diagnostics  of nonce distribution using goodness-of-fit tests and spectral analysis.
  2. Formalization of the key recovery problem  as a Hidden Number Problem.
  3. Lattice methods  (LLL, BKZ) for solving HNP using partial nonce information.
  4. Verification of  the recovered key by checking its compliance with the public key.

Real-world attacks on the Bitcoin blockchain demonstrate that even minor deviations from perfect randomness (1-4 bit bias, nonce reuse, limited PRNG entropy) lead to complete compromise of private keys. Szekely’s book, written decades before Bitcoin’s inception, remains a relevant guide for identifying and quantifying precisely these types of vulnerabilities.

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

This work opens several promising directions for further research at the intersection of probability theory, mathematical statistics and ECDSA cryptanalysis:

1. Applying Simpson’s Paradox to Stratified Blockchain Analysis.  Developing methods for automatic clustering of Bitcoin signatures based on temporal, hardware, and software characteristics to identify subgroups where nonce bias is more pronounced than in the overall population. This will allow attackers to attack keys that appear secure when analyzed across the entire sample.

2. Bayesian methods for real-time nonce entropy estimation.  The development of adaptive algorithms that refine the posterior distribution of k as new signatures are received and dynamically determine the optimal number of signatures required for a successful attack. This will reduce computational costs and improve the efficiency of cryptanalytic systems.

3. Detecting hidden periodicities in nonce sequences.  Applying spectral analysis and autocorrelation methods to t_i = s_i⁻¹ r_i mod n sequences to identify periodic components characteristic of linear congruential generators and other weak PRNGs. Developing statistical tests specifically targeted at cryptographic nonces.

4. Hybrid lattice-statistical attacks.  Combining lattice methods (LLL, BKZ) with Bayesian inference and Monte Carlo methods to attack HNP with erroneous nonce information (when known bits may be partially incorrect). This expands the class of attackable keys to include cases where information about k is obtained from unreliable sources (e.g., a noisy side-channel).

5. Analysis of nonce distribution in smart contracts and Layer-2 solutions.  Extension of the methodology to other blockchain platforms (Ethereum, Solana, Ripple) and protocols (Lightning Network, Taproot) where ECDSA or Schnorr signatures are used with other nonce generation mechanisms. Identification of platform-specific statistical anomalies.

6. Develop countermeasures based on Székely’s paradoxes.  Using the identified statistical anomalies to create improved nonce generators and monitoring systems that detect deviations from uniformity in real time and block signing until the problem is resolved. This will prevent attacks that exploit the weakness of PRNGs.

7. Formalizing the relationship between probability theory paradoxes and the complexity of HNP.  Building a theoretical model that links specific types of statistical anomalies (bias, correlation, periodicity) with the computational complexity of solving HNP. This will allow us to predict the vulnerability of specific ECDSA implementations based on a statistical analysis of their output sequences.

Sources:

  1. Szekely G. Paradoxes in probability theory and mathematical statistics. – Moscow: Mir, 1990. – 240 p. [reference:15]
  2. Breitner J., Heninger N. Biased Nonce Sense: Lattice Attacks against Weak ECDSA Signatures in Cryptocurrencies // IACR ePrint 2019/023.[reference:16]
  3. Rowe D., Breitner J., Heninger N. IACR News, 2023.[reference:17]
  4. Shi W., Jiang H., Ma Z. Solving HNP with One Bit Leakage // Entropy, 2022.[reference:18]
  5. Osaki S., Kunihiro N. Bias from Uniform Nonce: Revised Fourier Analysis-based Attack on ECDSA // SAC 2024.[reference:19]
  6. IEEE Xplore: Research on Elliptic Curve Crypto System with Bitcoin Curves.[reference:20]
  7. ecdsa-break: Breaking ECDSA with LLL // PyPI.[reference:21]