Applying SAT/SMT, bit constraints, truncated rounds, and mixed logic to the ECDSA nonce recovery problem represents a powerful, albeit unconventional, approach. It is particularly effective in scenarios where classical lattice methods are inapplicable or insufficient: with arbitrary partial knowledge of the nonce, when combining multiple constraint types, and when analyzing nonstandard implementations.
1. Introduction: ECDSA and the Critical Role of Nonces
The ECDSA (Elliptic Curve Digital Signature Algorithm) algorithm underlies transaction authentication in the Bitcoin network. When signing a message (transaction hash) h, the signer generates an ephemeral secret parameter k— a nonce . This parameter is used to calculate a point R = kG on the elliptic curve secp256k1, which then forms a pair (r, s), where:
r = x(R) mod n
s = k−1 (h + r·d) mod n
Here G is the generator point, n is the curve order, d is the long-term private key.
The security of ECDSA depends critically on the fact that k is chosen uniformly at random and never repeats. However, in practice, there are implementations where the nonce is generated with insufficient entropy, has a biased distribution, or is partially leaked through side channels. In such cases, the problem arises of recovering the hidden number k (or the private key d) from known signatures (r, s) and message hashes h.
The classical approach to solving this problem is based on reduction to the Hidden Number Problem (HNP) and the use of lattice algorithms (LLL, BKZ). However, there is an alternative, less well-known, but extremely powerful approach based on SAT/SMT solvers and bit constraints . This is the focus of this paper.
Important: This is not about “bypassing a full uniform key.” SAT/SMT methods are effective only when partial information about the nonce exists (for example, the high- or low-order bits are known, or the nonce is shorter than expected) or when multiple signatures use nonces related by a known relationship. A completely random, uniform 256-bit nonce cannot be attacked using such methods—it would require trying 2,256 possible combinations.
2. Theoretical Foundations: SAT, SMT, and Bit Constraints
2.1. SAT (Boolean Satisfiability Problem)
The SAT problem is formulated as follows: given a Boolean formula in conjunctive normal form (CNF), the task is to find a set of variable values for which the formula is true. Modern SAT solvers (MiniSat, Glucose, CaDiCaL) are capable of processing formulas with millions of variables and clauses using the CDCL (Conflict-Driven Clause Learning) architecture.
2.2. SMT (Satisfiability Modulo Theories)
SMT extends SAT by adding support for theories such as integer arithmetic, bit vectors, arrays, real numbers, and others. Bit vector theory (BV) is of particular interest for cryptanalysis, as ECDSA operations (addition, modulo multiplication, bitwise shifts) are naturally expressed in terms of fixed-length bit vectors.
Popular SMT solvers include Z3 (Microsoft Research), CVC5 , Boolector , and STP . They allow constraints to be formulated as follows:
; SMT-LIB example for Z3 (declare-const k (_ BitVec 256)) (assert (= (bvmul k #x... ) #x...)) (assert (bvult k #x...)) (check-sat) (get-model)
2.3. Bit Limits
Bit constraints are restrictions placed on individual bits of variables. For example, knowing that the top four bits of a nonce are zero is written as:
(k >> 252) = 0 ⇔ k & 0xF000…000 = 0
Such restrictions dramatically reduce the search space and make the problem solvable for SAT/SMT solvers even with 256-bit variables.
3. Formalization of the nonce recovery problem
Let there be m ECDSA signatures: (r i , s i ) for messages with hashes h i . For each signature, the following holds:
s i ≡ k i −1 (h i + r i · d) (mod n)
Multiplying both sides by k i and rearranging:
k i · s i − r i · d ≡ h i (mod n)
This is a linear comparison with respect to the unknowns k i and d. If all k i were known, d could be found from a single equation. If only some bits of each k i are known , the problem becomes partially determined.
Let us introduce for each nonce a representation in the form of a bit vector of length 256:
k i = (b i,255 , b i,254 , …, b i,0 ) 2
Then the known bits are fixed as constants, and the unknown bits remain free variables. The private key d is represented similarly.
The problem is reduced to finding a set of bits {b i,j } and d such that all m comparisons are performed modulo n.
Key idea: Modular arithmetic modulo n (for secp256k1, n ≈ 1.158 × 10 77 ) can be encoded in SAT/SMT using bit vector operations using multiplication and comparison . This is significantly more complex than pure Boolean circuits, but modern SMT solvers with BV support can handle such problems under sufficient constraints.
4. Encoding ECDSA equations in SAT/SMT
4.1 Signature equation as a constraint
For each signature i we write:
(k i · s i ) mod n = (h i + r i · d) mod n
In SMT-LIB (Z3) it looks like this:
; Variable declaration (declare-const k_i (_ BitVec 256)) (declare-const d (_ BitVec 256)) ; Constraint: (k_i * s_i) mod n == (h_i + r_i * d) mod n (assert (= (bvsmod (bvmul k_i s_i) n) (bvsmod (bvadd h_i (bvmul r_i d)) n)))
Here bvmul, is the multiplication of bit vectors, bvsmodand is the modulo (signed) remainder. For secp256k1 n, this is a specific 256-bit constant.
4.2 Adding constraints on nonce bits
If it is known that, for example, the senior 8 bits of nonce are equal to zero, we add:
; k_i < 2^248 ⇔ the most significant 8 bits are zero ( assert (bvult k_i # x0 #x00000000000000000000000000000000000000000000000000000000000000000))
Similarly, any known bits (not necessarily the most significant ones) can be fixed.
4.3. Relationship of nonce to private key
In some scenarios (for example, a side-channel leak), the functional dependence k i = f(d, h i ) is known. The corresponding equations are then added to the model. A classic example is a nonce of the form k = h msb ‖ d msb , where the high-order half of the nonce is equal to the high-order half of the hash, and the low-order half is equal to the high-order half of the private key. This is expressed through bitwise operations of concatenation and subvector extraction.
4.4 Modular Arithmetic: The Carry Problem
The biggest challenge in encoding ECDSA in SAT is the modulo operation. Direct encoding bvsmodin SAT requires introducing auxiliary variables to track carries during multiplication and subtraction. Modern SMT solvers do this automatically, but the resulting SAT formula can be quite large.
To improve efficiency, a reduction technique to HNP is used : instead of directly encoding the modular equation, an approximate equality without the modulus is introduced, using the fact that k i s i − r i d − h i = q i n for some integer q i . Then:
k i · s i − r i · d − h i − q i · n = 0
Here q i is a new unknown, but its range is limited (approximately 0 … 2256 ). This equation no longer contains the mod operation, but only multiplication and addition, which is much simpler for SAT/SMT.
5. Shortened rounds and mixed logic
5.1. Reduced Rounds
The term “truncated rounds” is typically applied to the analysis of symmetric cryptographic primitives (e.g., SHA-256, used in Bitcoin for transaction hashing). In the context of ECDSA nonces, this technique can be used indirectly: if the nonce is generated deterministically via a hash function (e.g., RFC 6979), then the attack can target the internal state of the generator rather than the nonce itself. However, for “pure” ECDSA, truncated rounds have no direct bearing on the recovery of k.
However, if in a specific implementation the nonce is calculated as the result of a truncated version of the hash function (e.g., due to a coding error), the SAT/SMT model can include a description of this hash function with fewer rounds, significantly simplifying the problem. This already falls within the scope of SAT-based cryptanalysis of hash functions , and such methods are well studied.
5.2. Mixed Logic
“Mixed logic” refers to the combination of various theories within a single SMT solver: Boolean logic, bit vectors, integer arithmetic, and arrays. For ECDSA, this means we can simultaneously impose:
- Boolean constraints on flags (e.g. “nonce even”);
- bit limits on specific bits;
- arithmetic constraints on ranges of values (0 < k < n);
- constraints on modulo equality.
Mixed logic allows for natural expression of complex dependencies, such as “nonce k is such that its least significant 4 bits are 0, and k s − r d ≡ h (mod n)”. The solver itself chooses the optimal search strategy by combining bit propagation, linear equation resolution, and CDCL.
Practical Tip: When using Z3 for ECDSA problems, it is recommended to use the qfbv(Quantifier-Free Bit-Vectors) and tactics smt, and to enable the smt.bv.enable_int2bvand options smt.arith.solver=6for better performance.
6. Practical implementation and examples
6.1 Python example using Z3
Let’s look at a simplified example: there’s a single signature, and the high-order 8 bits of the nonce are known to be zero. We need to find k and d.
from z3 import *
# secp256k1 parameters (simplified)
n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
G = ... # generator point (not needed for algebraic model)
# Known values from signature
r = 0x... # 256-bit number
s = 0x...
h = 0x... # message hash
# Create bit vectors of length 256
k = BitVec('k', 256)
d = BitVec('d', 256)
q = BitVec('q', 256) # auxiliary variable for the module
# Limitation: k * s - r * d - h = q * n
solver = Solver()
solver.add(k * s - r * d - h == q * n)
# Limitation: The high 8 bits of k are zero
solver.add((k & 0xFF00000000000000000000000000000000000000000000000000000000000000000000) == 0)
# Constraint: d in range [1, n-1]
solver.add(d >= 1, d < n)
# Constraint: k in range [1, n-1]
solver.add(k >= 1, k < n)
# Run solver
if solver.check() == sat:
model = solver.model()
k_val = model[k].as_long()
d_val = model[d].as_long()
print(f"Found nonce k = {hex(k_val)}")
print(f"Found private key d = {hex(d_val)}")
else:
print("No solution found")
In practice, for 256-bit numbers, such a query may prove too complex for the standard Z3 without additional constraints. However, if, for example, the 32 most significant bits of the nonce are known (as in the attack on the Bitcoin blockchain described by Breitner & Heninger), the problem becomes solvable in seconds.
6.2 Multiple signatures
With m signatures with partially known nonces, the system of equations becomes highly overdetermined. Each additional signature adds an equation and a new unknown k i , but if even a small fraction of the bits of each k i are known , the combined information quickly makes the system decidable.
Example for m = 2:
k1 = BitVec('k1', 256)
k2 = BitVec('k2', 256)
d = BitVec('d', 256)
q1 = BitVec('q1', 256)
q2 = BitVec('q2', 256) solver.add(k1 * s1 - r1 * d - h1 == q1 * n)
solver.add(k2 * s2 - r2 * d - h2 == q2 * n)
We know that the least significant 4 bits of both nonces are 0
solver.add((k1 & 0xF) == 0)
solver.add((k2 & 0xF) == 0)
6.3 Performance Comparison
| Method | Required nonce information | Number of signatures | Time (order) |
|---|---|---|---|
| Direct calculation | Full nonce | 1 | instantly |
| Reusing a nonce | k1 = k2 | 2 | instantly |
| Lattice attacks (LLL/BKZ) | High bits (≥ 4 bits) | 32–64 | seconds–minutes |
| SAT/SMT (Z3) | Partial bits (≥ 8 bits) | 1–10 | seconds–hours |
| Fourier analysis (Bleichenbacher) | < 1 bit (probabilistically) | millions | days-weeks |
7. Limitations, comparison with lattice attacks and countermeasures
7.1 Limitations of the SAT/SMT approach
- Combinatorial explosion: For small numbers of known bits (less than 4-8 per nonce), the search space remains huge and a SAT solver may not be able to solve it in a reasonable amount of time.
- Complexity of modular arithmetic: Coding
bvsmodfor 256-bit numbers produces cumbersome formulas with a large number of auxiliary variables. - No guarantees: SAT solvers do not provide a polynomial running time guarantee; in the worst case, the search may drag on indefinitely.
- Sensitivity to formulation: A small change in constraints (such as adding an extra variable) can dramatically impact performance.
7.2 Comparison with Lattice Attacks
Lattice attacks (LLL, BKZ) on the HNP problem are the de facto standard for recovering ECDSA keys with partial nonce leakage. They scale well, have theoretical complexity bounds, and are effectively implemented in tools such as fplll[ NTL[ … [[ ecdsa-break[ [[[ [[ [[ [ [[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [
The SAT/SMT approach, by contrast, is more flexible with respect to arbitrary constraints: it allows combining knowledge about any bits, imposing logical conditions, and modeling nonstandard dependencies between nonces. This makes it a powerful tool for analyzing nonstandard vulnerabilities that don’t fit into the classical HNP model.
7.3. Countermeasures
- RFC 6979: Deterministic Nonce Generation Based on HMAC-DRBG Eliminates Bias and Replay.
- Constant execution time: Protects against timing attacks that could leak nonce bits.
- Entropy Audit: Using Cryptographically Strong Random Number Generators (CSPRNGs).
- Nonce checking: Rejection of “suspicious” nonces (too short, with abnormal bit distribution).
8. Conclusion
Applying SAT/SMT, bit constraints, truncated rounds, and mixed logic to the ECDSA nonce recovery problem represents a powerful, albeit unconventional, approach. It is particularly effective in scenarios where classical lattice methods are inapplicable or insufficient: with arbitrary partial knowledge of the nonce, when combining multiple constraint types, and when analyzing nonstandard implementations.
Key advantages of the SAT/SMT approach:
- Flexibility in formulating restrictions;
- Ability to work with incomplete and heterogeneous information;
- Automatic proof of unfeasibility (if there is no solution);
- Direct modeling of cryptographic primitives.
However, it’s important to remember that this method isn’t a “silver bullet.” It doesn’t bypass the fundamental security of ECDSA when generating nonces correctly. It’s purely an exploitation of implementation errors that lead to partial leakage or bias of the hidden number. Therefore, the primary focus should be on preventing such errors, not exploiting them.
Ethical note: All described methods should be used exclusively for legitimate purposes: auditing one’s own systems, scientific research, and penetration testing with the express permission of the owner. Using them to steal cryptocurrency or compromise someone else’s keys is a criminal offense.
References and sources
- Breitner, J., Heninger, N. «Biased Nonce Sense: Lattice Attacks against Weak ECDSA Signatures in Cryptocurrencies». IACR ePrint 2019/023. [reference:0]
- Rowe, D., Breitner, J., Heninger, N. «A new class of ECDSA signature vulnerability observed in the wild on the Bitcoin blockchain». IACR ePrint 2023/841. [reference:1]
- Aranha, D. F., et al. «LadderLeak: Breaking ECDSA With Less Than One Bit Of Nonce Leakage». IACR ePrint 2020/615. [reference:2]
- Nguyen, P. Q., Shparlinski, I. E. «The Insecurity of the Digital Signature Algorithm with Partially Known Nonces». Journal of Cryptology, 2002.
- Howgrave-Graham, N., Smart, N. P. «Lattice Attacks on Digital Signature Schemes». Designs, Codes and Cryptography, 2001. [reference:3]
- De Moura, L., Bjørner, N. «Z3: An Efficient SMT Solver». TACAS 2008.
- Barrett, C., et al. «Handbook of Satisfiability». IOS Press, 2009.
- «Extracting the Secret Key with Known Nonce Bits». University of Texas at Austin, репозиторий. [reference:4]
This document has been prepared for educational and research purposes. The author assumes no liability for any unauthorized use of the materials presented.
