· via dev.to (home feed)
ECDSA nonce reuse behind $10.4M USDC theft, rebuilt in 90 lines of Node.js
A trader's custom signing software reused ECDSA nonces, letting an attacker derive private keys from public signatures and drain 10.4M USDC from Lighter. A dev.to post shows the math and the audit that catches it.

What happened
On Monday, November 16, roughly 10.4 million USDC left the derivatives exchange Lighter through a single trader's API keys. Lighter's postmortem, as reported by Cointelegraph, attributes the compromise to the trader's own custom signing software reusing cryptographic nonces. Because the resulting signatures were public, the private keys could be calculated straight from them. Lighter says its protocol, contracts and official SDKs were untouched and that about $5 million was recovered for the trader.
A dev.to post walks through the algebra that makes this possible and ships a 90-line, dependency-free Node.js script that performs the key recovery against a deliberately broken signer, together with the small audit helper that would have caught the bug.
The algebra
An ECDSA signature over a message hash z with private key d begins with the signer choosing a nonce k — a value that must be unique per signature and never revealed. The signature is the pair (r, s), where r comes from the x-coordinate of k·G and s = k⁻¹(z + r·d) mod n, with n the curve order.
A single signature leaves an observer with one equation in two unknowns, k and d, which is not solvable. If the same k signs a second message, however, both signatures carry the same r and the equations can be combined. Subtracting one from the other cancels d and isolates k:
k = (z1 − z2) / (s1 − s2) mod n
The private key then falls out as:
d = (s1·k − z1) / r mod n
Anyone who can see the messages can hash them, and the signatures are public, so no secret material stands in the way.
The dev.to author flags one practical wrinkle: signers commonly canonicalise s into the lower half of the curve order, as Bitcoin and Ethereum do to prevent malleability, which effectively replaces s with n − s. A recovery routine has to try both candidates and check each derived key against the known public key.
The proof of concept
The script needs only Node 18 or newer, BigInt and node:crypto — no external packages. It implements secp256k1 point arithmetic from the raw curve constants, a textbook signer that accepts the nonce as an explicit argument so the mistake can be made on purpose, a verifier, the recovery routine and a helper that scans a signature log for repeated r values. The author notes the point multiplication was cross-checked against @noble/curves, though the script itself imports nothing.
In the demo, four API actions are signed, two of them with a fixed nonce. Every signature verifies, and the author identifies that as the reason such bugs sail through testing: nothing looks wrong until somebody puts two r values side by side. The script finds the duplicate pair, recovers a key from them, and confirms it matches the real one.
Detection and prevention
The most reusable piece is the audit helper. Since r is public anyway, any bot or custom signer can log the r of every signature it produces and alert on any duplicate under the same key. A repeated r means the key has already leaked; the only response is to rotate it and move funds immediately.
The stronger fix is not to choose nonces by hand at all. RFC 6979 derives k deterministically from the private key and the message hash, making an accidental collision between two different messages impossible. Mainstream libraries — the post names @noble/curves, libsecp256k1 and the Go and Rust secp256k1 crates — default to this behaviour.
The failure mode is not novel: the post recalls the 2010 PlayStation 3 signing key leak and the 2013 Android SecureRandom bug that exposed Bitcoin wallet keys, both rooted in nonces that were not unique.
Lighter's response
According to the postmortem as reported, Lighter now requires wallet signatures for transfers into public pools, has made API-key signatures non-public, and plans IP allowlists plus configurable permissions for API keys. Making signatures private blocks the route this attacker took, but as the author points out, a nonce-reusing signer still hands its key to anyone who can observe two of its signatures — the durable client-side fix is a vetted library that manages k itself.
Cointelegraph also reported that the same morning a Safe multisig lost roughly $6.45 million through a compromised role key combined with a permissions policy that permitted the transfer. A different mechanism, but the same neighbourhood: the code surrounding the contracts.
Why it matters
This incident is a clean demonstration that key compromise needs no malware or phishing — publishing two signatures from a buggy signer is enough, and no amount of exchange-side hardening can save a client that leaks its own key. It is also one of the cheapest vulnerability classes to prevent. Deterministic nonces have been standard in serious libraries for over a decade, and a few lines of logging turn a silent leak into a loud alarm. For anyone tempted to hand-roll signing code for trading bots or wallets, this is the cautionary tale: the attack math is simple enough to fit in 90 dependency-free lines, so the defence is to never hand an attacker the two equations in the first place.
- #cryptography
- #ecdsa
- #security
- #node-js
- #blockchain