👨🏾💻 Dev corner: how reusing one random number can leak a private key
This week, perp DEX Lighter said an exploit hit unofficial signing code through nonce reuse. About 5M USDC was returned to an affected trader, withdrawals resumed, and the protocol said it was not affected (CoinGabbar, Nov 17).
What's a nonce here?
🔹 Crypto signatures (ECDSA, used by Bitcoin and Ethereum) need a fresh secret random number for every signature. That number is the nonce, often called k
🔹 It must be unique and unpredictable every single time
What goes wrong:
🔹 If the same k signs two different messages, anyone who sees both signatures can do some simple math and recover the private key
🔹 Weak randomness is almost as bad: a predictable k can be worked out too
🔹 This is not just theory. Old Android Bitcoin wallets and the PlayStation 3 were broken this way
How builders avoid it:
🔹 Use deterministic nonces (RFC 6979): k is derived from the key and the message, so it never repeats by accident
🔹 Use well-audited libraries, not hand-rolled or unofficial signing code
🔹 Never copy signing snippets from random repos
Don't confuse this with the Ethereum account nonce, which is just a transaction counter.
Did you know a signature could leak a key like this? 👇
📷 Photo: Mika Baumeister / Unsplash
This week, perp DEX Lighter said an exploit hit unofficial signing code through nonce reuse. About 5M USDC was returned to an affected trader, withdrawals resumed, and the protocol said it was not affected (CoinGabbar, Nov 17).
What's a nonce here?
🔹 Crypto signatures (ECDSA, used by Bitcoin and Ethereum) need a fresh secret random number for every signature. That number is the nonce, often called k
🔹 It must be unique and unpredictable every single time
What goes wrong:
🔹 If the same k signs two different messages, anyone who sees both signatures can do some simple math and recover the private key
🔹 Weak randomness is almost as bad: a predictable k can be worked out too
🔹 This is not just theory. Old Android Bitcoin wallets and the PlayStation 3 were broken this way
How builders avoid it:
🔹 Use deterministic nonces (RFC 6979): k is derived from the key and the message, so it never repeats by accident
🔹 Use well-audited libraries, not hand-rolled or unofficial signing code
🔹 Never copy signing snippets from random repos
Don't confuse this with the Ethereum account nonce, which is just a transaction counter.
Did you know a signature could leak a key like this? 👇
📷 Photo: Mika Baumeister / Unsplash
