ERC-20 Approval Race Condition Explained in Detail
The ERC-20 approval race condition appears when a token owner changes a spender's allowance from one non-zero value to another. The spender may spend the old allowance before the new approval lands, then use the new allowance afterward.
The risk comes from transaction ordering and allowance semantics.
Transaction example
-
Current: Alice approved a spender for 100 tokens.
-
Change: Alice submits a transaction to change approval to 50.
-
Race: The spender sees the pending transaction and spends 100 first.
-
After: Alice's approval to 50 executes, leaving more allowance available.
ERC-20 Approval Race Condition in Auditing
Allowance bugs affect routers, vaults, bridges, aggregators, and protocols that manage user approvals. They connect directly to front-running, Permit2, and signature-based approvals such as ERC-20 Permit. The broader front-running attack guide covers the transaction-ordering mechanics behind the race.
Red flags in code
-
Non-zero allowance changed directly to another non-zero value.
-
Protocol asks users for unlimited approvals without clear need.
-
Spender can redirect
transferFromoutput. -
Permit or Permit2 integration omits spender, token, amount, nonce, or deadline checks.
-
UI suggests allowance is reduced before the transaction is final.
How to test or review it
-
Test allowance changes under adversarial transaction ordering.
-
Prefer setting allowance to zero before setting a new non-zero value when using classic
approve. -
Review
increaseAllowance,decreaseAllowance, permit, and Permit2 flows separately. -
Verify the spender cannot use approval for a different action than the user intended.
-
Check whether protocol accounting handles fee-on-transfer and non-standard tokens.
Keep learning this topic
Front-Running
Front-running is a transaction-ordering attack where an attacker observes a pending transaction and submits their own transaction so it executes first.
Permit2
Permit2 is Uniswap's shared approval and signature transfer system that lets users authorize token spends through structured signatures or managed allowances.
EIP-712
EIP-712 is a standard for signing typed structured data so a signature is bound to a specific message type and domain.
Frontrunning & Sandwich Attacks
Frontrunning and sandwich attacks in Solidity: how MEV bots extract value from DeFi traders, real examples, and slippage-based protections.
Replay Attacks
See how this vulnerability appears in real smart contract audits.
Smart Contract Audit Checklist
Use this SCH tool to turn the concept into practical audit work.
Practice this in real audit scenarios
Definitions help, but auditors need reps. SCH turns concepts like ERC-20 Approval Race Condition into exploit labs, code review habits, and report-writing practice.
Start the free trial or see the full smart contract auditing course.