Tech, business, and useful tricks.
Vheüel Insight Network

Classical Attacks on Bitcoin Keys: Nonce Reuse, Weak Entropy, xpub Leaks

•11 min read

Breaking secp256k1 head-on takes a quantum computer, but real Bitcoin keys fall to classical attacks today: nonce reuse, weak entropy, and xpub leaks.

Vheüel

Vheüel

Author

Classical Attacks on Bitcoin Keys: Nonce Reuse, Weak Entropy, xpub Leaks

Breaking Bitcoin's secp256k1 curve head-on, by recovering a private key from its public key through the discrete logarithm, requires a Cryptographically Relevant Quantum Computer (CRQC). But that is not how keys get stolen today. When an implementation breaks the mathematical assumptions behind ECDSA/Schnorr signatures or BIP32 key derivation, standard hardware can recover private keys in milliseconds to minutes.

Understanding where classical cryptography stands firm, and where it collapses instantly, comes down to the difference between solving a one-way trapdoor function and exploiting leaked algebraic relationships.

Why Classical Hardware Hits a Wall on secp256k1

On secp256k1, a private key d is a random 256-bit integer, and its corresponding public key P is a curve point (x, y) produced by scalar multiplication over a large finite field modulo the prime p = 2^256 - 2^32 - 977:

P = d · G

This equation behaves as a strict one-way trapdoor function on classical processors:

  • Forward computation is trivial: Calculating P from d via the double-and-add algorithm takes at most 256 point doublings and additions. A modern smartphone finishes the calculation in microseconds.
  • Reverse computation has no division operation: Recovering d from P, known as the Elliptic Curve Discrete Logarithm Problem (ECDLP), cannot be solved by dividing P by generator point G, because modular arithmetic scatters resulting points pseudo-randomly across the curve.
  • Classical algorithms hit an exponential ceiling: The fastest known classical ECDLP attacks, such as Pollard's rho and Baby-step Giant-step, still require roughly √n ≈ 2^128 elliptic curve operations.

For scale, the entire Bitcoin mining network (roughly 800 EH/s) executes around 2^69 SHA-256 hashes per second. Even if one elliptic curve point operation cost the same as one hash (it costs far more, and mining ASICs cannot compute it at all), 2^128 operations would take on the order of the age of the universe.

How Quantum Computers Bypass the Exponential Wall

Classical computers must evaluate candidate values individually because they cannot observe the global cyclic structure of the elliptic curve group. A fault-tolerant quantum computer running Shor's algorithm changes the complexity class entirely:

  1. State superposition: Qubit registers hold all possible scalar combinations (a, b) simultaneously to evaluate a · G + b · P in a single quantum state.
  2. Periodicity detection: Elliptic curve arithmetic over a finite field contains hidden periodic structure. Applying the Quantum Fourier Transform (QFT) amplifies the probability amplitude of that period through quantum interference while canceling out wrong answers.
  3. Complexity collapse: Once measurement reveals the period, classical modular arithmetic computes d immediately. Attack cost drops from exponential O(√n) to polynomial in the key size. Published resource estimates for a 256-bit curve vary widely with the construction and what is counted: roughly 10^11 Toffoli gates and about 2,300 logical qubits in Roetteler et al. (2017), down to about 5 · 10^7 Toffoli gates in Litinski (2023). Actual runtime depends on physical qubit count and error-correction overhead.

Classical vs. Quantum Attack Profile on secp256k1

  • Best Algorithm: Pollard's rho / Baby-step Giant-step (Classical) vs. Shor's Algorithm with QFT (Quantum).
  • Time Complexity: Exponential O(√n) (Classical) vs. polynomial in key size (Quantum).
  • Operation Count: Approximately 2^128 curve operations (Classical) vs. roughly 10^7 - 10^11 Toffoli gates depending on the estimate (Quantum).
  • Estimated Runtime: Longer than the age of the universe (Classical) vs. minutes to hours on a large fault-tolerant machine, which does not exist yet (Quantum).

None of this is how real keys are lost today. A fault-tolerant machine of that size does not exist, while the three implementation failures below are exploited on classical hardware right now.

1. Nonce Reuse and Partial Nonce Bias

Every digital signature in ECDSA and Schnorr depends on a unique, unpredictable ephemeral nonce k chosen from [1, n - 1]. That nonce generates the public point R = k · G, whose x-coordinate r = R_x mod n is published inside the signature.

If the same private key d signs two different message hashes (z_1 ≠ z_2) using the exact same nonce k, both signatures share an identical r value on-chain or in the mempool. Any observer spotting that collision can extract d using elementary modular algebra. This is not hypothetical: a 2013 flaw in Android's SecureRandom produced repeated ECDSA nonces in Bitcoin wallets.

ECDSA Private Key Recovery

Given two ECDSA signatures (r, s_1) and (r, s_2) over message hashes z_1 and z_2, subtracting the signature equations cancels out the r · d term and isolates k:

s_1 = k⁻¹ · (z_1 + r · d) mod n
s_2 = k⁻¹ · (z_2 + r · d) mod n

k = (z_1 - z_2) · (s_1 - s_2)⁻¹ mod n
d = r⁻¹ · (s_1 · k - z_1) mod n

Once k is computed, substituting it back into either equation yields the private key d in under a millisecond.

Schnorr (Taproot / BIP 340) Private Key Recovery

BIP 340 Schnorr signatures follow the linear equation s = (k + e · d) mod n, where e = H(R_x ∥ P_x ∥ m) (BIP 340's even-y normalization only flips the sign of k or d, which does not change the attack). When k repeats across two distinct challenges (e_1 ≠ e_2), an attacker does not even need to solve for k first:

s_1 - s_2 ≡ (e_1 - e_2) · d (mod n)
d = (s_1 - s_2) · (e_1 - e_2)⁻¹ mod n

Partial Nonce Bias: Nonces do not need to be 100% identical to break a key. If a defective random number generator leaves even a few leading bits predictable across enough signatures (the required number depends on how many bits leak), classical lattice reduction algorithms such as LLL and BKZ can reconstruct d. Deterministic nonce derivation (RFC 6979 for ECDSA; BIP 340 defines its own scheme with optional auxiliary randomness) removes the dependence on a good RNG, which closes the most common cause. It does not cover fault-injection attacks, implementation bugs, or nonce handling in multi-party signing protocols.

2. Weak Entropy and Predictable Seeds

The 128-bit classical security margin of secp256k1 holds only if d is sampled uniformly across the entire keyspace of n ≈ 2^256 (approximately 1.15 · 10^77 possible keys). When key generation relies on low-entropy inputs or flawed generators, the search space collapses to a range that commodity GPUs can exhaust rapidly:

  1. Brainwallets: Generating a private key by hashing a human-chosen passphrase, lyric, or quote (d = SHA256("passphrase")) provides only about 1 to 2 bits of entropy per character. Automated GPU clusters test tens of billions of SHA-256 candidates per second against dictionaries and leaked password corpora, routinely sweeping brainwallet deposits seconds after confirmation.
  2. Non-Cryptographic PRNGs and Narrow Seeds: Wallets built with general-purpose functions like Math.random(), rand(), or Mersenne Twister (MT19937) rather than a cryptographically secure generator (CSPRNG) fail whenever the initial seed is small. Seeding with a 32-bit UNIX timestamp or Process ID shrinks the keyspace from 2^256 down to 2^32 (~4.29 billion possibilities). A real-world incident is the libbitcoin Milk Sad vulnerability (32-bit MT19937 seed).
  3. Static Bit Patterns and Sequential Keys: Development keys generated from small integers (d = 1, 2, 3, ..., 2^40) or zero-padded ASCII strings are continuously monitored by automated blockchain sweepers looking for exposed test funds on mainnet.

3. BIP32 xpub Leak Combined with One Non-Hardened Child Private Key

Even when every individual key is generated with strong entropy and safe nonces, Hierarchical Deterministic (HD) wallets defined under BIP32 contain a deterministic algebraic bridge between parent and child keys. If an attacker obtains a parent extended public key (xpub) alongside just one non-hardened child private key, classical subtraction recovers the entire parent private key. Note that this is an escalation: the attacker already holds one private key and uses the xpub to reach every other key under the same parent.

An xpub carries two essential pieces of data: the 33-byte parent compressed public key (K_parent) and the 32-byte parent chain code (c_parent). When deriving a non-hardened child key at index i < 2^31 (paths without the ' or h hardened suffix), BIP32 computes a 64-byte HMAC-SHA512 digest strictly from public inputs:

I = HMAC-SHA512(Key = c_parent, Data = K_parent ∥ ser_32(i))

The output I splits into two 32-byte halves: I_L (the left 32 bytes) and I_R (the right 32 bytes, which becomes the child chain code c_child). BIP32 then computes the child private key k_child by adding I_L to the parent private key k_parent modulo the curve order n:

k_child = (k_parent + I_L) mod n

Notice that I_L does not depend on k_parent at all: anyone holding the xpub and child index i can compute I_L directly. Consequently, if an attacker leaks an xpub (for example, from a watch-only wallet, accounting export, or payment processor) and compromises a single non-hardened child private key k_child (such as a hot-wallet key exposed in server logs or memory), reversing the equation requires one trivial subtraction:

k_parent = (k_child - I_L) mod n

Recovering k_parent gives the attacker the complete parent extended private key (xpriv, since the chain code is already in the xpub), enabling them to derive every sibling address and descendant branch under that parent node, including its hardened children.

In a standard path such as m/84'/0'/0'/0/i, the xpub is usually exported at the account level (m/84'/0'/0') and the address keys below it are non-hardened, so this attack compromises the whole account. Hardened derivation at the account boundary (i ≥ 2^31) does not prevent that; it limits the blast radius. Because the account key is derived from its parent with HMAC-SHA512(c_parent, 0x00 ∥ ser_256(k_parent) ∥ ser_32(i)), which uses the parent private key instead of K_parent, the leak cannot climb to the purpose, coin-type, or master keys. Within the account, the defense is to treat every xpub as a sensitive credential rather than harmless public metadata, and to avoid keeping it in the same breach domain as any signing key.

Where Public Keys Get Exposed: The Quantum Angle

The three failures above do not depend on how a public key is exposed. Exposure matters for the quantum threat, because Shor's algorithm needs a public key to attack:

  • Legacy (P2PKH) and SegWit v0 (P2WPKH / P2WSH): The on-chain ScriptPubKey stores only a cryptographic hash of the public key (HASH160(P)) or script. As long as funds remain unspent at rest without address reuse, P stays shielded behind one-way SHA-256 and RIPEMD-160 hashes. Exposure begins when the owner broadcasts a spending transaction to the mempool, revealing P in the scriptSig or Witness during the ~10-minute confirmation window, which creates a race condition where an attacker with a CRQC could attempt Replace-By-Fee (RBF) front-running.
  • Pay-to-Public-Key (P2PK): Early outputs (mostly from Bitcoin's first years) store P directly in the ScriptPubKey, so the public key is exposed at rest from the moment the output is created.
  • Taproot (P2TR, BIP 341): To optimize transaction size and privacy, Taproot removes the hashing layer from ScriptPubKey and embeds a 32-byte x-only tweaked public key Q directly on-chain from the moment the UTXO is funded. Constructed from internal key P = d · G and Merkle root m via t = tagged_hash("TapTweak", P_x ∥ m), the on-chain key equals Q = P + t · G = (d + t) · G (with d negated first if P has an odd y-coordinate). Because Q sits exposed at rest, an attacker faces no mempool time pressure, and recovering the tweaked private key d' = (d + t) mod n allows spending via the key path while bypassing every hidden MAST script-path condition, including multisig rules, timelocks (CLTV/CSV), and hashlocks.

Quantum computers threaten the long-term hardness of elliptic curve discrete logarithms, particularly for outputs whose raw public keys rest permanently on-chain, such as Taproot key-path UTXOs and legacy P2PK outputs. Until fault-tolerant quantum machines arrive, however, real-world key compromises remain overwhelmingly classical, driven by reused nonces, predictable randomness, and leaked xpub hierarchies paired with exposed child keys.

Join Bybit