Application of probability theory and mathematical statistics based on the textbooks by I. P. Matskevich, G. P. Svirid, and G. M. Buldyk “Higher Mathematics. Probability Theory and Mathematical Statistics” (1993)
and “Collection of Problems and Exercises…” (1996). The textbooks by I. P. Matskevich, G. P. Svirid, and G. M. Buldyk on probability theory and mathematical statistics provide not just an academic foundation, but a practical toolkit for real-world cryptanalysis. Their systematic presentation of random variables, hypothesis testing, correlation and regression analysis directly maps to the tasks of auditing cryptographic protocols.
The analysis shows that the security of Bitcoin’s ECDSA is critically dependent on the statistical properties of the nonce. Any deviation from perfect randomness—bias, correlation, recurrence—creates an exploitable vulnerability. The methods described in these textbooks allow:
- Detect anomalies in the nonce distribution using goodness-of-fit tests and nonparametric tests;
- Classify vulnerability types (short nonces, misaligned bits, linear and polynomial recurrences);
- Estimate the required number of signatures for a successful attack based on limit theorems;
- Recover private keys by reducing the problem to HNP and applying LLL/BKZ lattice algorithms.
The practical significance of this approach has been confirmed by numerous studies: from the recovery of 158 keys from early blockchain snapshots [reference:11] to the discovery of tens of thousands of vulnerable half-half nonce signatures [reference:12] and the development of tools like ecdsa-break [reference:13].
Thus, probability theory and mathematical statistics are not auxiliary, but rather core disciplines for a modern cryptanalyst working with blockchain data. Their application allows publicly available transaction information to be transformed into a means of recovering secret keys.
Content
- 1. Introduction
- 2. Theoretical Foundations of ECDSA and Nonce Vulnerability
- 3. Application of probability theory
- 4. Application of mathematical statistics
- 5. Hidden Number Problem (HNP) and Lattice Attacks
- 6. Practical implementation and examples
- 7. Conclusion
- 8. Directions for further research for cryptanalysis based on this area
1. Introduction
The Elliptic Curve Digital Signature Algorithm (ECDSA) is the cornerstone of Bitcoin transaction security. Its security is based on the computational difficulty of the Elliptic Curve Discrete Logarithm Problem (ECDLP). However, as practice shows, the security of ECDSA critically depends on the quality of the generation of the one-time secret number (nonce, k). Any deviation from a perfectly uniform and independent distribution of this parameter opens the door to cryptanalytic attacks that can recover the long-term private signature key.
Textbooks by I. P. Matskevich, G. P. Svirid, and G. M. Buldyk on probability theory and mathematical statistics provide a powerful and systematic mathematical framework for formalizing, detecting, and exploiting such vulnerabilities. This paper demonstrates how fundamental concepts—from statistical hypothesis testing to regression analysis—can be directly applied to real-world cryptanalytic problems related to blockchain auditing and key recovery.
2. Theoretical Foundations of ECDSA and Nonce Vulnerability
2.1. ECDSA Protocol
In the ECDSA scheme, the global parameters are an elliptic curve E over a finite field and a generating point G of prime order n . The signer’s private key is an integer d (mod n ), and the corresponding public key is the point Q = dG .
To sign a message with hash h, the signer generates a random nonce k (mod n ) and computes a point R = kG . The signature is a pair (r, s) , where r = R x (the x-coordinate of point R ), and
s = k −1 (h + r d) mod n
This equation is key to all nonce-based attacks. If the value of k is known for a single signature, the private key is calculated directly:
d = (s k − h) r −1 mod n
However, in practice, k is not published. The vulnerability arises when k is not a cryptographically strong random number, but has a statistically detectable structure or bias.
2.2. Classification of nonce vulnerabilities
| Vulnerability type | Description | Mathematical sign |
|---|---|---|
| Reuse | The same k for two different messages | Match r in two signatures |
| Short nonces | k has significantly less entropy than required by the order of the group | The distribution of k is concentrated in a small range |
| Shift of the most significant bits | The high-order bits k are predictable or fixed | Uneven distribution of k modulo n |
| Linear recurrence | k i+1 = a k i + b mod n | Affine dependence of consecutive nonces |
| Polynomial recurrence | Relationship of nonce through a polynomial of degree D ≥ 2 | Existence of a polynomial relation |
All of these types of vulnerabilities have been discovered in real Bitcoin transactions. A study by Breitner and Heninger (2019) found hundreds of Bitcoin private keys compromised due to misaligned nonces [reference:0]. More recent work has shown that in the Bitcoin blockchain alone, there are tens of thousands of signatures with nonces of the form k = h msb || d msb , where the high-order 128 bits of the nonce are formed from the high-order bits of the transaction hash and the private key [reference:1].
3. Application of probability theory
3.1. Model for generating nonce as a random variable
In an ideal ECDSA, nonce k is modeled as a random variable uniformly distributed over the set {1, 2, …, n−1} . In terms of probability theory, this means:
P(k = x) = 1/(n−1) for all x ∈ {1, …, n−1}
A vulnerability arises when the actual distribution of K real deviates from uniformity. Matskevich and Svirid introduce fundamental concepts of distribution functions, probability density functions, and numerical characteristics of random variables, which allow us to quantitatively describe this deviation.
3.2. Numerical characteristics of nonce
The mean and variance are the first indicators of anomalies. For a uniform distribution on {1, …, n−1} :
E[k] = n/2, Var(k) = (n² − 1)/12
If the sample mean k̄ for a set of signatures is significantly different from n/2 , or the sample variance s² is significantly smaller than the theoretical value, this indicates bias. For example, for short nonces (say, k < 2 64 ), the expected value will be on the order of 2 63 , which is many orders of magnitude smaller than n/2 ≈ 2 255 .
3.3 Bernoulli distribution and binomial distribution
Consider the most significant bit of a nonce. If k is uniformly distributed over {0, …, n−1} , then the probability that the most significant bit is 1 is approximately 1/2 . For m independent signatures, the number of 1s in the most significant bit follows a binomial distribution Bin(m, 1/2) . Deviation from this distribution is the first sign of a vulnerability.
A more subtle analysis: consider a sequence of nonces k 1 , k 2 , …, k m . If they are generated by a weak PRNG, autocorrelation may be observed. The Pearson correlation coefficient between k i and k i+1 should be statistically insignificant for a random sequence. The presence of a significant correlation indicates linear recurrence.
3.4 Limit theorems and estimation of the required number of signatures
The central limit theorem (CLT), discussed in detail in Matskevich and Svirid’s textbook, allows one to estimate how many signatures are needed to reliably detect bias. If the bias is a fraction ε of the nonce range, then detecting it with a given criterion power requires a sample size of the order of:
m ≈ (z α + z β )² · σ² / ε²
This directly links statistical theory to practical cryptanalysis: the weaker the bias, the more signatures need to be collected for an attack.
4. Application of mathematical statistics
4.1 Testing statistical hypotheses
Matskevich and Svirid devote significant attention to hypothesis testing—a method that is becoming the primary tool for blockchain auditing. Two hypotheses are formulated:
- H₀ (null hypothesis): nonce k are uniformly distributed on {1, …, n−1} .
- H₁ (alternative hypothesis): the distribution of k is biased (e.g. concentrated in the least significant bits).
Goodness-of-fit tests are used for testing, primarily the Pearson chi-square (χ²) test. The observed nonce values are grouped into intervals, and the statistic is calculated:
χ² = Σ (O i − E i )² / E i
where O i is the observed frequency of occurrence in the i -th interval, E i is the expected frequency under a uniform distribution. If χ² exceeds the critical value for a given significance level α , hypothesis H₀ is rejected.
A practical example. When analyzing 5 signatures with the same curve, it was found that 4 of the 5 nonces fall within the interval [1, n/4] —an 80% bias. The χ² test for such data yields a p-value < 0.001, allowing us to confidently reject the uniformity hypothesis [reference:2].
4.2. Series and autocorrelation criteria
To detect recurrent dependencies between consecutive nonces, nonparametric tests such as the Wald–Wolfowitz runs test are used. If the sequence of deviation signs k i − n/2 has abnormally long runs of identical signs or, conversely, alternates too frequently, this indicates a dependency.
Autocorrelation function (ACF) of the sample nonce sequence:
ρ(τ) = Σ i=1 m−τ (k i − k̄)(k i+τ − k̄) / Σ i=1 m (k i − k̄)²
Significant peaks in the ACF at τ = 1, 2, … indicate a linear or periodic relationship. This is a key step in detecting polynonce attacks [reference:3].
4.3 Regression analysis
Regression analysis is a powerful tool that Matskevich and Svirid discuss in the context of correlation and variance analysis. In ECDSA cryptanalysis, it is used to reconstruct linear relationships between nonces.
If the hypothesis of linear recurrence k i+1 = a k i + b exists , then the coefficients a and b can be estimated using the ordinary least squares (OLS) method based on the available data. However, in a real problem, k i is unknown. In this case, indirect regression is used: equations are constructed that exclude k .
From the equation s = k −1 (h + r d) it follows that k = s −1 (h + r d) . Substituting this expression into the linear relationship between the two nonces, we obtain a linear equation with respect to d :
s 2 −1 (h 2 + r 2 d) = a · s 1 −1 (h 1 + r 1 d) + b
From here, d is found algebraically. This approach underlies an attack on affinely related nonces, which allows the key to be recovered from just two signatures [reference:4].
4.4 Analysis of Variance (ANOVA)
Analysis of variance (ANOVA) allows us to test whether nonce distributions differ for different groups of transactions (e.g., for different time periods or different wallet types). If the F -statistic is significant, this may indicate that different wallet implementations or versions generate nonces with different biases. This analysis is useful for clustering vulnerable addresses and identifying specific software bugs.
5. Hidden Number Problem (HNP) and Lattice Attacks
5.1. HNP formulation
The Hidden Number Problem (HNP) is a computational challenge that arises when partial information about a nonce is available. It was introduced by Boneh and Wenston and is actively used in the cryptanalysis of ECDSA.
Let α be a secret number (in our case, the private key d ), and for each i we know that:
| (k i · β i − α) mod n | < n / 2 l+1
where β i are known constants and l is the number of known high-order bits of k i . The problem is to find α . In the context of ECDSA, β i = r i / s i , and α is related to d .
5.2 Lattice construction and the LLL algorithm
HNP reduces to the shortest vector problem (SVP) on a lattice. A basis matrix of size (m+2) × (m+2) is constructed :
M = [ n 0 … 0 0 0 ] [ 0 n … 0 0 0 ] [ … … … … … … ] [ 0 0 … n 0 0 ] [ β₁ β₂ … β_m B/n 0 ] [ t₁ t₂ … t_m 0 B ]
where t i are the known most significant bits, and B is the scaling parameter. After applying the Lenstra–Lenstra–Lovász (LLL) algorithm or its strengthened version BKZ, one of the reduced basis vectors will contain d as a coordinate [reference:5].
The LLL algorithm guarantees finding a “short enough” vector in polynomial time. Its effectiveness for ECDSA cryptanalysis has been repeatedly confirmed in practice: Breitner and Heninger recovered hundreds of Bitcoin keys using this approach [reference:6].
5.3. Required number of signatures
The number of signatures m required for a successful attack depends on the size of the leaked nonce information. If the l most significant bits of each k i are known , then recovering a 256-bit key requires approximately:
m ≈ 256 / l
For example, if 1 bit is leaked (only the most significant bit), approximately 256 signatures are required; if 4 bits are leaked, approximately 64 signatures are required. Experiments show that with 4 most significant bits and 5 signatures known, the LLL attack successfully recovers the key in seconds [reference:7].
6. Practical implementation and examples
6.1 Nonce Reuse Attack
This is the simplest and most destructive case. If two messages m 1 and m 2 are signed with the same k , then r 1 = r 2 = r . From the signature equations:
s 1 = k −1 (h 1 + r d) mod n
s 2 = k −1 (h 2 + r d) mod n
Subtracting one from the other:
s 1 − s 2 = k −1 (h 1 − h 2 ) mod n
k = (h 1 − h 2 ) / (s 1 − s 2 ) mod n
Once k is found, the private key is calculated as d = (s 1 k − h 1 ) / r mod n . Real-world studies have shown that thousands of Bitcoin keys have been compromised precisely due to nonce reuse [reference:8].
6.2. Attack on the shifted high-order bits (HNP + LLL)
Consider the scenario where the most significant l bits of each nonce are zero (or known). Then k i = ε i , where 0 ≤ ε i < 2 256−l . From the signature equation:
s i k i − r i d = h i mod n
This is a linear equation in k i and d . By collecting m such equations and applying LLL to the resulting lattice, one can simultaneously find all k i and d . This method was applied to the Bitcoin blockchain to recover keys associated with nonces with predictable high-order bits [reference:9].
6.3 Polynomial Recurrence
The Polynonce attack, discovered by Kudelski Security in 2023, generalizes linear recurrence to polynomials of arbitrary degree. If nonces satisfy the relation:
P(k 1 , k 2 , …, k m ) = 0 mod n
where P is a polynomial of degree D , then if there are N ≥ D + 3 signatures, one can eliminate unknown coefficients and find d as a root of a polynomial with known coefficients over a finite field [reference:10]. This demonstrates how powerful statistical analysis can be in revealing hidden dependencies.
6.4. Sample Code for Anomaly Detection
import numpy as np from scipy import stats def detect_nonce_bias(r_values, n): “”” Detect nonce bias from r values. r = the x-coordinate of kG, so the distribution of r mirrors the distribution of k. “”” # Convert r to the normalized range [0, 1] r_norm = np.array(r_values) / n # Chi-square test for uniformity observed, bins = np.histogram(r_norm, bins=10, range=(0, 1)) expected = len(r_values) / 10 chi2, p_value = stats.chisquare(observed, f_exp=expected) print(f»χ² = {chi2:.4f}, p-value = {p_value:.6f}”) if p_value < 0.01: print(“⚠️ Significant nonce bias detected!”) return True return False def autocorrelation_test(k_estimates): “”” Test the autocorrelation of a nonce sequence. “”” acf = np.correlate(k_estimates – np.mean(k_estimates), k_estimates – np.mean(k_estimates), mode=’full’) acf = acf / acf[len(acf)//2] # Checking peaks for significance threshold = 2 / np.sqrt(len(k_estimates)) significant_lags = [i for i in range(1, 10) if abs(acf[len(acf)//2 + i]) > threshold] if significant_lags: print(f”⚠️ Significant autocorrelation on lags: {significant_lags}”) return significant_lags
7. Conclusion
The textbooks by I. P. Matskevich, G. P. Svirid, and G. M. Buldyk on probability theory and mathematical statistics provide not just an academic foundation but also a practical toolkit for real-world cryptanalysis. Their systematic presentation of random variables, hypothesis testing, correlation and regression analysis directly relates to the tasks of auditing cryptographic protocols.
The analysis shows that the security of Bitcoin’s ECDSA is critically dependent on the statistical properties of the nonce. Any deviation from perfect randomness—bias, correlation, recurrence—creates an exploitable vulnerability. The methods described in these textbooks allow:
- Detect anomalies in the nonce distribution using goodness-of-fit tests and nonparametric tests;
- Classify vulnerability types (short nonces, misaligned bits, linear and polynomial recurrences);
- Estimate the required number of signatures for a successful attack based on limit theorems;
- Recover private keys by reducing the problem to HNP and applying LLL/BKZ lattice algorithms.
The practical significance of this approach has been confirmed by numerous studies: from the recovery of 158 keys from early blockchain snapshots [reference:11] to the discovery of tens of thousands of vulnerable half-half nonce signatures [reference:12] and the development of tools like ecdsa-break [reference:13].
Thus, probability theory and mathematical statistics are not auxiliary, but rather core disciplines for a modern cryptanalyst working with blockchain data. Their application allows publicly available transaction information to be transformed into a means of recovering secret keys.
8. Directions for further research for cryptanalysis based on this area
- Multivariate statistical analysis of nonlinear nonce dependencies. Development of principal component analysis (PCA) and factor analysis to identify hidden multivariate structures in nonce sequences. This will enable the detection of dependencies that cannot be reduced to simple linear or polynomial recurrences.
- Bayesian methods for estimating nonce distribution parameters. Using Bayesian inference to estimate the posterior distributions of nonce parameters (mean, variance, recurrence coefficients) given prior information about typical wallet implementations. This will enable the construction of probabilistic estimates of attack success.
- Spectral analysis and wavelet transforms. Using Fourier analysis and wavelet transforms to detect periodic and quasi-periodic components in nonce sequences. This is especially useful for detecting weak PRNGs with cyclic patterns.
- Hybrid statistical-lattice methods. Developing algorithms that, in the first stage, use statistical tests to select the most probable hypotheses about the nonce structure, and in the second stage, employ lattice methods to accurately recover the key. This will reduce the computational complexity of attacks.
- Adaptive signature count selection based on sequential analysis. Using sequential statistical analysis methods (e.g., the Wald test) to dynamically determine when the accumulated data is sufficient for a successful attack, while controlling for type I and type II errors.
- Nonce time series analysis. Modeling nonce sequences as time series (ARIMA, GARCH) to detect nonstationarity and heteroscedasticity. This can reveal vulnerabilities associated with changes in PRNG behavior over time or due to external factors.
- Clustering vulnerable addresses based on statistical features. Applying cluster analysis methods (k-means, DBSCAN, hierarchical clustering) to multidimensional vectors of statistical signature characteristics to automatically identify groups of addresses generated by the same vulnerable software.
- Using extreme value theory. Analyzing the tails of a nonce distribution using extreme value theory to detect rare but critical anomalies (e.g., nonces close to the range boundaries) that may provide disproportionately large amounts of information about the key.
- Developing statistical criteria for detecting “semi-deterministic” nonces (RFC 6979 with bugs). Even deterministic schemes, such as RFC 6979, can have vulnerabilities if implemented incorrectly. Statistical methods can identify deviations from expected deterministic behavior.
- Machine learning methods are used to predict nonces. Models (neural networks, gradient boosting) are trained on large datasets of signatures to predict future nonce values. While this approach is closely related to AI, statistical methods for assessing the quality of predictions (cross-validation, ROC analysis) play a key role.
The document was prepared on the basis of textbooks by I. P. Matskevich, G. P. Svirid, G. M. Buldyk
and modern research in the field of ECDSA cryptanalysis
