Every signature hides a secret dice-roll
To spend Bitcoin you sign a transaction with ECDSA. Each signature needs a fresh, secret, random number called the nonce k. A signature is a pair (r, s):
where d is your private key, z is the message hash, and G, n are public curve constants. The k never leaves your wallet — it's thrown away after signing. As long as every k is unique and unpredictable, the signature reveals nothing about d.
Sign twice with the same k, and d falls out
Suppose a buggy wallet reuses the same k for two different transactions. Then both signatures share the same r (because r depends only on k·G). An attacker who sees both signatures on the blockchain now has:
That's it. Two signatures, four subtractions and two modular inverses, and the "unbreakable" key is in the attacker's hands. The curve was never touched.
Proof you can run yourself (on a key we make here)
This demo generates its own victim key, signs two messages with a deliberately reused nonce, then recovers the key from only the public signatures — nothing real is touched:
# pip install ecdsa ; secp256k1 order n, generator G import secrets, hashlib from ecdsa import SECP256k1 from ecdsa.numbertheory import inverse_mod n = SECP256k1.order; G = SECP256k1.generator H = lambda m: int.from_bytes(hashlib.sha256(m).digest(),"big") % n d = secrets.randbelow(n-1)+1 # the victim's secret (we made it) k = secrets.randbelow(n-1)+1 # a nonce the buggy RNG will REUSE def sign(msg): z = H(msg); r = (k*G).x() % n s = (inverse_mod(k,n)*(z + r*d)) % n return r, s, z r1,s1,z1 = sign(b"Pay Alice 1 BTC") r2,s2,z2 = sign(b"Pay Bob 2 BTC") # different message, SAME k — the bug k_rec = ((z1-z2) * inverse_mod((s1-s2) % n, n)) % n d_rec = ((s1*k_rec - z1) * inverse_mod(r1, n)) % n print("recovered == victim?", d_rec == d) # → True
This isn't hypothetical
It has happened, repeatedly, with real losses:
• 2010 — Sony PlayStation 3. Sony signed firmware with a constant nonce. The fail0verflow team recovered the master signing key and the console was permanently jailbroken.
• 2013 — Android SecureRandom. A flaw made some Android wallets generate repeated nonces. Attackers scanned the chain for reused r values and swept the affected wallets. Real Bitcoin was stolen.
• It still surfaces today whenever a hardware wallet, library, or hastily-written signer botches its RNG.
The lesson (and the fix)
A private key is only as strong as the randomness around it. secp256k1 and SHA-256 are fine — the failure is always broken randomness. The modern fix is deterministic nonces (RFC 6979): derive k from the private key and the message hash, so it's unique per message and never depends on a flaky RNG. Every serious wallet uses it now.