defi-amm-security

Reviews Solidity AMM contracts for reentrancy, oracle manipulation, and share-math vulnerabilities.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill defi-amm-security-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: defi-amm-security
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/defi-amm-security
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill defi-amm-security-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing or auditing Solidity AMM and liquidity-pool contracts exposes developers to subtle vulnerabilities like reentrancy, donation attacks, and flash-loan oracle manipulation that are easy to miss without a structured checklist. ## Core Features & Use Cases - Vulnerability Pattern Library: Side-by-side vulnerable and hardened Solidity implementations for reentrancy, CEI ordering, donation/inflation attacks, slippage, and admin controls. - Security Checklist: A concrete audit checklist covering share math, SafeERC20 usage, TWAP oracles, slippage deadlines, and overflow-safe reserve math. - Audit Tooling Guidance: Example commands for Slither static analysis, Echidna property testing, and Foundry fuzzing. - Use Case: While implementing a swap function for a new liquidity pool, use this Skill to verify the function enforces amountOutMin and deadline checks, uses nonReentrant, and avoids raw balanceOf-based share math. ## Quick Start Ask the AI to audit your Solidity AMM contract's deposit and swap functions against the DeFi AMM security checklist.

Frequently Asked Questions about defi-amm-security

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent reentrancy attacks in Solidity contracts?▼

Prevent reentrancy by following checks-effects-interactions ordering and applying OpenZeppelin's ReentrancyGuard nonReentrant modifier to external entrypoints. Update internal balances before transferring tokens, and use SafeERC20 for transfers instead of writing a custom guard.

What is a donation or inflation attack on liquidity pools?▼

A donation attack manipulates share math by sending tokens directly to the contract, inflating token.balanceOf(address(this)) used as the denominator. Mitigate it by tracking internal accounting state and measuring actual tokens received during deposits rather than reading raw balances.

How do I protect against oracle price manipulation in DeFi?▼

Protect against oracle manipulation by using a TWAP from Uniswap V3's observe function instead of spot prices, which are flash-loan manipulable. Query tick cumulatives over a window such as 30 minutes and derive the price from the time-weighted average tick.

Does this checklist cover slippage protection for swaps?▼

Yes, the checklist requires every swap path to accept caller-provided amountOutMin and deadline parameters. The swap must revert if the deadline has passed or if the calculated output falls below the minimum, protecting users from sandwich attacks and stale quotes.

What tools can I use to audit a Solidity AMM contract?▼

Use Slither for static analysis, Echidna for property-based testing, and Foundry's forge test with high fuzz runs for invariant checking. Run these only in a trusted checkout or sandbox, and never include private keys or RPC credentials in commands or reports.

When should I use FullMath mulDiv instead of plain multiplication?▼

Use Uniswap V3's FullMath.mulDiv for reserve math where naive a * b / c can overflow before the division. This applies to large reserve or share calculations in AMM contracts where intermediate products may exceed uint256 bounds.