0xlayerghost/solidity-agent-kit/token-antiflash
Claude Code and agent skill by 0xlayerghost/solidity-agent-kit
- community
Checking that the SKILL.md file is still in the repository.
[AUTO-INVOKE] MUST be invoked when designing or reviewing ERC20 token contracts that need flash loan protection. Covers token-level defense design patterns: cost tracking, same-block cooldown, progressive sell tax, minimum balance retention, EIP-7702 aware address checks, front-run protection, and referral binding. Trigger: any ERC20 token with anti-flash-loan, anti-bot, or tokenomics security design requirements.
Install
npx vskill@latest install 0xlayerghost/solidity-agent-kit/token-antiflashSKILL.md
The same SKILL.md was published earlier as 0xlayerghost/solidity-agent-kit/token-antiflash.
Token-Level Flash Loan Prevention Design Patterns
Language Rule
- Always respond in the same language the user is using. If the user asks in Chinese, respond in Chinese. If in English, respond in English.
Scope: Applicable to ERC20 token contracts that need protection against flash loan attacks at the token contract level. Complements thedefi-securityskill (protocol-level) with token-internal defense mechanisms. All parameters mentioned below are design references — actual values should be determined based on project requirements, tokenomics, and market conditions.
Workflow Rule
When this skill is triggered, DO NOT directly implement all strategies. Follow this workflow:
- Assess: Identify the project's threat model — what type of token (meme, community, DeFi ecosystem), what value at stake, what attack vectors are realistic
- Present: Show the developer the Strategy Decision Matrix and Combination Guide. Clearly explain the trade-offs of each strategy (gas cost, UX friction, implementation complexity)
- Let the developer choose: Ask the developer which protection level (Basic / Standard / Advanced / Maximum) or which specific strategies they want. Do NOT assume a protection level
- Confirm parameters: For each chosen strategy, confirm key design parameters with the developer (e.g., tax tiers, volume limit percentages, cooldown granularity) before writing code
- Implement: Only after developer confirmation, implement the selected strategies with the agreed parameters
Exception: If the developer explicitly says "implement all" or "maximum protection", skip steps 2-4 and implement the Maximum combination. If the developer specifies exact strategies by number, skip to step 4 for those strategies.
Toolchain Baseline
Use solc 0.8.24 with OpenZeppelin Contracts 5.0.2. Override _update(address from, address to, uint256 amount) for ERC20 transfer customization. State whether each check requires pre-transfer balances or post-transfer balances, and call super._update exactly where that ordering requires.
Core Design Principle
Flash loan attacks rely on atomic execution within a single transaction: borrow → manipulate → profit → repay. Token-level defense breaks this atomicity by introducing cost, time, and identity barriers inside the token contract itself.
Strategy Decision Matrix
When designing a token with flash loan protection, evaluate which strategies to apply based on the threat model:
| Threat Vector | Recommended Strategies | Priority | |
|---|---|---|---|
| Single-block buy→sell arbitrage | Same-block cooldown + Contract address check | High | |
| Zero-cost token exploitation (airdrop/exploit) | Cost tracking + Progressive sell tax | High | |
| Large-volume manipulation | Per-address volume limits + Base trade fee | Medium | |
| Multi-address Sybil bypass | Referral binding + State propagation on transfer | Medium | |
| Bot front-running / sandwich | Front-run sell protection + Dynamic fee | Situational |
Strategy 1: Cost Tracking
Design Idea: Track the acquisition cost basis of tokens per address. Limit realized profit to a configurable multiplier of the cost. Tokens acquired at zero cost (airdrop, exploit, flash loan) have zero cost basis, meaning profit is capped at zero or the tokens are burned on sell.
Key Design Points:
- Maintain per-address cost basis state, updated on every
_transfer/_update - On transfer: cost follows the token — propagate cost from sender to receiver proportionally
- Zero-cost tokens should be flagged and handled separately (burn or restrict sell)
- Profit cap multiplier should be a configurable owner parameter with a reasonable upper bound
- Consider gas cost of maintaining the extra mapping — measure impact on transfer gas
Why It Works Against Flash Loans: Flash-borrowed tokens inherently have zero cost basis. With profit capped relative to cost, there is no economic incentive to execute the attack.
Implementation:
Strategy 2: Contract Address Check (EIP-7702 Aware)
Design Idea: Block interactions from smart contracts (which flash loan contracts are) while properly handling EIP-7702 delegated EOAs.
Key Design Points:
- EIP-7702 delegation designator has a specific code length (23 bytes:
0xef0100+ 20-byte address) - Allow addresses with this exact code length (they are delegated EOAs, not contracts)
- Block addresses with other non-zero code lengths (regular smart contracts)
- Consider also checking
msg.sender == tx.originas a secondary guard - Whitelist necessary contracts: LP pair, router, staking contracts
Why It Works Against Flash Loans: Flash loan execution happens inside a contract call chain. Blocking contract callers forces interaction through EOAs, breaking atomic execution.
Implementation:
Strategy 3: Same-Block Cooldown
Design Idea: Prevent buying and selling (or receiving and selling) within the same block. This is the most direct defense against flash loans since they must complete within one transaction (one block).
Key Design Points:
- Track the block number of last incoming transfer per address
- On sell (transfer to LP pair): require that the tracked block number is strictly less than current
block.number - Critical: Also handle the transfer bypass — prevent
A buys → A transfers to B → B sellsin the same block - On wallet-to-wallet transfer: propagate the block restriction using
max(lastBlock[to], lastBlock[from])to prevent state laundering - Do NOT use `block.timestamp` for same-block tracking —
block.numberis the correct metric
Why It Works Against Flash Loans: Flash loans execute and repay within a single transaction (single block). Same-block cooldown completely prevents the buy→sell cycle.
_update Integration Hub
All strategy state propagation must be wired together in a single _update override. This is the most commonly missed vulnerability — partial wiring leaves transfer bypass paths open.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/token-antiflash/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/0xlayerghost/solidity-agent-kit/token-antiflash)