Loading...
Loading...
[AUTO-INVOKE] MUST be invoked BEFORE deploying DeFi contracts (DEX, lending, staking, LP, token). Covers anti-whale, anti-MEV, flash loan protection, launch checklists, and emergency response. Trigger: any deployment or security review of DeFi-related contracts.
npx skill4agent add 0xlayerghost/solidity-agent-kit defi-securityScope: Only applicable to DeFi projects (DEX, lending, staking, LP, yield). Non-DeFi projects can ignore this skill.
| Threat | Required Protection |
|---|---|
| Whale manipulation | Daily transaction caps + per-tx amount limits + cooldown window |
| MEV / sandwich attack | EOA-only checks ( |
| Arbitrage | Referral binding + liquidity distribution + fixed yield model + lock period |
| Reentrancy | |
| Flash loan attack | Check |
| Price manipulation | Chainlink oracle or TWAP — never rely on spot AMM reserves for pricing |
| Approval exploit | Use |
| Governance attack | Voting requires snapshot + minimum token holding period; timelock ≥ 48h on proposal execution |
| ERC4626 inflation attack | First deposit must enforce minimum amount or use virtual shares to prevent share dilution via rounding |
onlyOwnermapping(address => mapping(uint256 => uint256))block.timestampblock.numberonlyOwnerPausablepause()unpause()forge test --fuzz-runs 10000| Step | Action |
|---|---|
| 1. Detect | Monitor alerts trigger (on-chain monitoring, community reports) |
| 2. Pause | Designated address calls |
| 3. Assess | Technical lead analyzes root cause, estimates fund impact |
| 4. Communicate | Post incident notice to community channels (Discord, Twitter, Telegram) |
| 5. Fix | Deploy fix or prepare recovery plan |
| 6. Resume | Call |
| 7. Post-mortem | Publish detailed incident report within 48 hours |
# Fuzz test fund flows with high iterations
forge test --match-contract StakingTest --fuzz-runs 10000
# Fork mainnet to test against real state
forge test --fork-url $MAINNET_RPC -vvvv
# Simulate whale transaction on fork
cast call <CONTRACT> "stake(uint256)" 1000000000000000000000000 \
--rpc-url $FORK_RPC --from <WHALE_ADDRESS>