Every signature check answers two questions: who signed? and is that who I trust? The bugs in this guide each delete one of those answers.
This guide covers two closely related bugs. In the first, a permit never asks the second question. In the second, a wallet lets the attacker supply the answer.
The bug in one sentence
ecrecover is a calculator, not an authenticator. For a well-formed (v, r, s) it returns some address, and address(0) when recovery fails. So a check that stops at “not zero”, or compares against an expected signer the attacker picked, accepts signatures nobody ever made.
A real case: Lixir vault tokens (Ethereum, June 2026)
Lixir’s vault tokens shipped a hand-written permit, the ERC-2612 approve-by-signature flow. The correct version, as in OpenZeppelin’s ERC20Permit, ends with two conditions:
address recovered = ecrecover(digest, v, r, s);
require(recovered != address(0)); // reject failed recovery
require(recovered == owner); // and bind it to the actual owner
Lixir’s version kept only the first line. Any well-formed signature, made with no private key at all, recovered to some address, passed the non-zero check, and granted a max allowance over any holder’s tokens.
The attacker reused one constant signature across 82 holders. They forged allowances everywhere, then burned vault shares through the vault’s own withdraw functions to take the underlying: about 2.6 ETH, 4,478 USDC, 3,610 USDT and 24,183 LIX.
The habit this teaches: at every ecrecover call, read the next five lines and look for the == owner comparison. If it isn’t there, that’s the whole bug.
The math: one signature, many victims
Forging costs nothing extra per victim. You pick one signature once. The payoff grows with the number of holders:
profit = Σ over holders ( min(balance, forged allowance) ) − gas
There’s no per-victim work, no private key and no flash loan. The same bytes are reused because nothing ties them to anyone.
The attack, step by step
| Step | What happens | What the check sees |
|---|---|---|
| 1 | Pick a constant (v, r, s). Sign nothing. |
— |
| 2 | Call permit(holder, attacker, max, ..., v, r, s) for each holder |
recovered != 0 passes |
| 3 | An Approval(holder → attacker, max) event fires |
No == owner check stops it |
| 4 | Withdraw from each holder’s position using the forged allowance | Forged allowance, real balance |
| 5 | Repeat across every holder | Same bytes every time |
Why it worked: three facts
- Authority comes from recovery. The permit grants spending power based on
ecrecover’s output. - No identity binding. It checks for non-zero only, never
recovered == owner. - The grant can be spent. The forged allowance reaches withdraw paths that move real value.
Fact 2 is a one-clause bug. require(recovered != address(0) && recovered == owner) would have stopped every call in this incident. That’s why reading a few lines past every recovery site pays off.
Two patterns in one family
Pattern A, the missing owner check (Lixir). Signature-based authority, a comparison that stops at the zero sentinel, and an authorization that moves value.
Pattern B, the attacker-named verifier (Sodium, Lumi, Mure, below). The signer’s address travels inside the caller’s bytes and gets “verified” with EIP-1271 against a contract the attacker controls. Secondary checks compare one attacker-supplied value with another. The real proof only runs later, after billing has already happened.
Here the comparison exists. Its expected signer is just attacker-chosen. So it’s not enough to find a comparison. You have to ask where the expected signer comes from.
How to hunt for it
- List every place a signature becomes authority.
bash grep -rnE "ecrecover|ECDSA\.recover|tryRecover|isValidSignature|permit\(" src/At each one: after recovery, must the result equal the account whose authority is being used, not just be non-zero? - Where does the expected signer come from? Stored ownership, or an address carried in the input? Byte slicing like
_signature[1:21]followed byisValidSignatureNow(signer, ...)is the giveaway. - EIP-1271 support. Must the verifying contract be registered on-chain first? An unregistered verifier taken from the input is Pattern B.
- Self-referential checks. After validation, are the remaining checks independent of attacker input? Flag comparisons between two input-derived values, such as
sessionKey == signer. - Account-abstraction wallets. Compare what’s checked in validation with what’s checked in execution. Anything authorization-related that only runs in execution, while validation success is billable, is a candidate finding.
- The extras. Is
srange-checked, and isv27 or 28? Those make things worse but aren’t the core bug. Can the expected signer ever be zero? (See LegendaryMoneyMonNft below.)
Lookalikes that are safe, and why
- OpenZeppelin
ERC20Permitor Solmate ERC2612. The full chain of checks (non-zero,== owner,srange) comes from audited code. Confirm the contract actually inherits it and doesn’t reimplement it alongside. - Registered EIP-1271 verifiers. Contract signatures from Safe or similar wallets are fine when the verifier is a stored owner or module. The defect is only the unregistered, input-derived address.
- The proof checked during validation. If the real check runs in the validation hook, forged operations revert before any billing.
- Gas-capped forgery. Wallets that cap
maxFeePerGasnear the base fee, or have gas paid by a paymaster, leave Pattern B almost nothing to earn even with a weak check. Billing math is part of the audit.
Fixes that work
- Always compare to the owner (Pattern A).
recovered == owner, plus the zero check and thesrange check. This fails if the comparison targets the wrong party (msg.senderinstead ofowner) or the expected signer can be zero or set by the attacker. - Get verifiers from storage, never from input (Pattern B). The signer must be a stored owner, a live session key or a registered module. This fails if registration itself is open.
- Verify the real proof during validation. Anything that gates value or billing must run before success is reported.
- Bound the billing. Cap
maxFeePerGasagainst the base fee, use nonces and expire digests. A bypassed check then earns dust. - Prefer vetted libraries. Use the standard OpenZeppelin or Solmate permit with an EIP-712 domain separator, nonce and deadline. Then audit every recovery site, because a hand-written parallel path can still bypass the standard one.
The same bug in other clothes
- Sodium smart wallets (Arbitrum). One signature branch read the signer from the signature bytes and validated it with EIP-1271 against a contract the attacker deployed, which always returned “valid”. The session branch reduced to
sessionKey == signer, two attacker values agreeing with each other. The real proof only ran in execution. Hundreds of forged operations passed validation and were billed at a high gas price, with the attacker as beneficiary, even though execution always failed. Passing validation was the payout. - LegendaryMoneyMonNft (BNB Chain). The check was
recoverSigner(...) == admin, so the comparison was there. Butadminhad been set toaddress(0), and the zero result was never rejected. A malformed signature recovered toaddress(0),0 == 0passed, and the reward function (spelledcliamRewredin the contract) paid out the whole balance. The missing property wasn’t the comparison. It was a live, non-zero expected signer. - Lumi and Mure. Lumi’s accounts, from the same family as Sodium, let forged operations actually execute: max approvals through the EntryPoint, then a
transferFromdrain per account. Mure’s distribution contract read its trusted signer from a caller-suppliedsourcecontract, admitted by an interface check the contract itself claimed to pass. That’s the same shape outside the wallet family.
Test yourself
- A hand-written permit checks only that the recovered address is non-zero. Verdict? Critical. One constant signature forges every holder’s allowance.
- The comparison is there:
recovered == admin. Safe? Not until you’ve checkedadmincan’t be zero or attacker-set. - A wallet verifies EIP-1271 against input-named signers but caps gas at the base fee. Severity? Reduced, not cleared. The cap closes the billing channel, but forged execution, as with Lumi, is unaffected.
- The digest skips the nonce and deadline but binds owner and amount. Which bug is this? Not this one. That’s replay (part 6 of this series): a genuine signature with too broad a scope. Keep the two apart: who signed versus what the signature covers.
Recap
- Recovery isn’t authentication.
ecrecovercomputes. Only== owner, plus range checks and a live signer, authenticates. - Where the expected signer comes from decides everything: stored owner (safe), input-named verifier (Pattern B), or zero admin.
- Passing validation can itself be valuable when billing rides on it. Audit the billing math, not just the auth math.
- The reflex: at every recovery site, read five lines forward, then ask where the expected value came from.