Research
Understanding ERC-20 approval risk before signing
Most token drains don’t start with a transfer. They start with a permission the owner signed, often for a reason that looked legitimate at the time. An approval moves nothing, so it’s easy to treat as harmless. Here’s what it actually grants, and what’s worth checking before signing one.
By CERQAVAPublished
What approve grants
EIP-20 defines approve(spender, value) as allowing spender to withdraw from your account multiple times, up to value. Calling it again overwrites the allowance. The spender withdraws with transferFrom(from, to, value), which the token checks against the allowance and, in most implementations, reduces it by the amount moved. Three things follow from that:
- It outlives the transaction. An allowance lasts until it’s spent or overwritten. It doesn’t expire. Many implementations, including OpenZeppelin’s, don’t even reduce an allowance set to the maximum value, so an unlimited allowance stays unlimited.
- It covers tokens you receive later. An allowance is a number, not a reservation of particular tokens. If your balance grows, the spender can take the new tokens too, up to whatever is left of the allowance.
- Whoever controls the spender controls the tokens. If the spender is an ordinary account, that’s whoever holds its key. If it’s a contract, it’s whatever the contract’s code lets callers do. And if the contract is upgradeable, it’s whatever its next implementation lets them do.
Reading the calldata
Here’s an unlimited approval as a wallet receives it, split into its parts. The spender address is fictional.
095ea7b3 approve(address,uint256)
0000000000000000000000003333333333333333333333333333333333333333 spender
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff amount: 2^256 − 1The first four bytes, 0x095ea7b3, are the selector: the start of the Keccak-256 hash of approve(address,uint256), as the Solidity ABI specification defines it. Two 32-byte words follow: the spender, padded with zeros, and the amount. An amount of all fs is 2256 − 1, the largest number a uint256 can hold. That’s how “unlimited” is usually written.
The token isn’t in the calldata at all. It’s the contract the transaction is sent to. So the token you’re approving is identified by that address, not by a symbol on screen: the symbol is whatever the contract chooses to call itself.
Approval versus transfer
Compare transfer(to, amount), with selector 0xa9059cbb. It moves amount now, once, and that’s all it does. An approval is the reverse: nothing moves now, and what moves later is up to someone else.
transfer | approve | |
|---|---|---|
| Tokens move in this transaction | Yes, the stated amount | No |
| Who decides what moves later | Nobody | The spender |
| How long the effect lasts | It happens once | Until the allowance is spent or overwritten |
| The most you can lose | The amount sent | Your whole balance of that token, now and later, up to the allowance |
This is also why a simulation alone undersells an approval. A simulated approve shows an Approval event and no change in balances. The exposure is in what the permission allows afterwards, and no simulation of this transaction can show that.
The spender is the risk
Many applications ask for an unlimited allowance, so that users don’t have to approve again before every trade. That’s a convenience trade-off, not an attack. An unlimited approval to the router of an exchange you’re actually using is common and usually intended. The same approval to an address you’ve never heard of is how many drains begin. The calldata looks the same in both cases. What differs is the spender, so the useful questions are about the spender:
- Is it the contract of the application you meant to use? Compare the address with the one the application publishes, not with a name shown on screen.
- Is it a contract at all? An approval to an ordinary account gives a person, not code, the right to move your tokens. There are few good reasons for that.
- Is it upgradeable? If so, it behaves however its next implementation does, and whoever controls upgrades decides what that is.
- Has anyone reported it? Threat-intelligence sources can confirm a known drainer. They can’t vouch for an address nobody has reported yet.
- Does it need this much? If the application accepts an exact amount, approving exactly that limits what a compromised spender could ever take.
One selector, two standards
ERC-721 has a function with the same signature, approve(address,uint256). There, the number is a token ID, and only that one NFT is approved. Calldata can’t tell the two apart. Some collections use hashes as token IDs, ENS names for example, and their IDs look like enormous allowances.
One way to resolve this is to ask the contract. ERC-165’s supportsInterface(0x80ac58cd) returns whether it claims to implement ERC-721. That’s a claim the contract makes about itself, not proof, but it’s evidence, and it narrows what an approval can mean. transferFrom has the same ambiguity, and so does setApprovalForAll, which ERC-721 and ERC-1155 share.
Approvals without a transaction
An allowance doesn’t always come from an approve transaction:
- EIP-2612 permits let the owner sign a message that grants an allowance. Anyone who holds the signature can submit it to the token. The owner never sends a transaction: the wallet shows a signing request instead.
- Permit2 holds allowances for any token that has been approved to it once, and lets applications use signed permits that carry an amount and an expiration. The exposure moves from the token’s allowance to Permit2’s, which a signature can grant.
setApprovalForAllgives an operator every NFT in a collection, including ones acquired later. It’s the NFT version of an unlimited allowance.
The questions about the spender stay the same. Only where the permission lives changes.
Changing and revoking an allowance
Setting an allowance to zero revokes it. EIP-20 also notes a race when you change an allowance from one non-zero value to another. A spender who sees the change coming can spend the old allowance first, and then the new one. The standard advises interfaces to set the allowance to zero before setting a new value for the same spender. Revoking allowances you no longer use limits what a compromised or malicious spender could take later.
How CERQAVA reports an approval
CERQAVA is in development, so this describes the engine being built, not a public service. It reports an unlimited or very large approval as a permission exposure. That makes the verdict review, not dangerous: it’s an exposure to understand, not evidence of an attack. The spender’s reputation is judged separately:
- if sources confirm the spender as malicious, with current evidence that no source disputes, the verdict is
dangerous; - if the spender has only been reported, the warning stays at
review.
When the token can be read, an approval on a contract that claims ERC-721 isn’t reported as an allowance. The report keeps that claim as evidence. EVM transaction decoding shows how the call is read.
An approval that isn’t flagged isn’t therefore safe to sign. The checks can only recognize what someone has already reported, as why “no risk detected” doesn’t mean safe explains.
Keep reading
- “No risk detected” isn’t safeWhy an approval that isn’t flagged isn’t therefore safe to sign.Read
- EVM transaction decodingWhich token, NFT and protocol calls CERQAVA decodes, and where it stops.Read
- Security modelHow findings, evidence and coverage become a verdict.Read
Private beta · waitlist open
We're opening CERQAVA to a small group of wallet and dApp teams first.