agentleFS
iktok90-designiktok90-design/ai-smart-contract-auditor/skills/approval-issues/SKILL.md

approval-issues

Skill36 starsChanged 5 months agoMITView on GitHub

Detect ERC-20 approval pitfalls — approve race (front-run), missing safeApprove, infinite approvals, approval-without-revoke, Permit2 misuse, max-approval to untrusted contracts. Activate on `approve`, `safeApprove`, `permit`, `forceApprove`, `Permit2`, `IERC20.allowance`.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use forceApprove(spender, Y) (OZ ≥4.9), or decreaseAllowance / increaseAllowance, or zero-first.

    line 23
  2. Very specific:

    Always use OZ forceApprove for setting.

    line 75
  3. Very specific:

    After a router/exec call: safeApprove(target, 0) to reset.

    line 76

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Approval issues detection

When this applies

  • Any approve / safeApprove / forceApprove site
  • permit (EIP-2612, DAI-style, Permit2)
  • Routers / aggregators that hold persistent approvals
  • Vaults that approve strategies to pull funds
  • Bridges / cross-chain approvers

Detection patterns

The classic ERC-20 approve race (HIGH)

token.approve(spender, X);   // later
token.approve(spender, Y);   // ← spender can front-run and drain X+Y

Use forceApprove(spender, Y) (OZ ≥4.9), or decreaseAllowance / increaseAllowance, or zero-first.

approve instead of safeApprove on non-standard tokens (HIGH)

USDT requires approve-to-zero before approve-to-X. Use OZ forceApprove.

Infinite approval to mutable contract (HIGH)

token.approve(router, type(uint256).max);   // ← router is upgradeable, future impl can drain

Mitigate with allowance-per-action.

Per-pull infinite approval (HIGH)

Vault → strategy infinite approval; if strategy is upgradeable or has a bug, vault funds drainable.

Permit2 sig stolen / replayed (HIGH)

Permit2 signatures are bearer instruments — anyone with the sig can transfer. If the signed payload is logged or leaked, funds are drainable until the nonce is invalidated. Add a deadline.

permit then ignore failure (MEDIUM)

try IERC20Permit(token).permit(owner, spender, ...) {} catch {}
token.transferFrom(owner, ...);   // ← if permit fails, uses any stale allowance

Caller can grief by front-running permit. Acceptable IFF you then check the allowance is sufficient.

Approval to address(0) on revoke (LOW)

Some tokens treat approve(0, x) as a no-op or revert. Use the documented revoke method.

Allowance still set after action completes (HIGH for routers)

token.safeApprove(target, amount);
target.swap(...);
// ← allowance lingers; if `amount` was max, target keeps power

Set to 0 after each action, or use a single-tx wrapper.

Approve to factory / clone-deployer (HIGH)

Deployer can deploy attacker-controlled implementation that consumes the approval.

Severity rubric

PatternSeverity
Persistent infinite approval to upgradeable routerHigh
Approve race ignored, no forceApprove / increaseAllowanceHigh
USDT-style approve without zero-resetHigh
Vault → strategy infinite allowance with mutable strategyHigh
Permit2 with no deadlineHigh
Permit failure swallowed, allowance not re-checkedMedium
Lingering allowance after one-shot router actionHigh

Remediation patterns

  • Always use OZ forceApprove for setting; safeIncreaseAllowance for top-ups.
  • After a router/exec call: safeApprove(target, 0) to reset.
  • For vault→strategy: pull-only allowances and per-cycle resets.
  • Permit2: short deadlines (minutes), per-payload nonce, bind to specific recipient + amount.
  • For EOA users: surface the actual amount in the UI; never auto-approve max from the contract.

False-positive notes

  • Internal-only approve where source and spender are both controlled → Info.
  • WETH9-style approve returning bool always-true is well-known and safe.

Related

  • [[token-compatibility]]
  • [[signature-replay]] — Permit2 / EIP-2612
  • [[mev-frontrunning]] — approve race is an MEV pattern

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.