.claude/skills/solidity-guard/skills/defi-analyzer/SKILL.md
Analyzes DeFi-specific security patterns in Solidity contracts. Covers oracle manipulation, flash loan attacks, economic exploits, vault inflation, MEV, and protocol-specific vulnerabilities.
npx skillsauth add alt-research/solidityguard defi-analyzerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Detect economic and protocol-specific vulnerabilities unique to DeFi applications. These cause the largest financial losses but require semantic understanding beyond pattern matching.
Loss Example: Cream Finance $130M, Mango Markets $116M
// VULNERABLE — spot price, single source
uint256 price = pool.getReserves();
uint256 value = amount * price;
// SECURE — TWAP + multi-oracle + staleness
(, int256 price, , uint256 updatedAt, ) = chainlinkFeed.latestRoundData();
require(updatedAt > block.timestamp - MAX_STALENESS, "Stale oracle");
require(price > 0, "Invalid price");
// Cross-reference with TWAP
uint256 twapPrice = uniswapOracle.consult(token, TWAP_PERIOD);
require(abs(price - twapPrice) < MAX_DEVIATION, "Price deviation");
Loss Example: Beanstalk $182M, Harvest Finance $34M
// VULNERABLE — governance votes based on current balance
uint256 votingPower = token.balanceOf(msg.sender);
// SECURE — snapshot-based voting
uint256 votingPower = token.getPastVotes(msg.sender, proposalSnapshot);
Loss Example: Euler Finance $197M attack amplified by this
// VULNERABLE — first depositor can inflate share price
function deposit(uint256 assets) external returns (uint256 shares) {
shares = totalSupply == 0 ? assets : assets * totalSupply / totalAssets();
// Attacker: deposit 1 wei, donate 1M tokens, next depositor gets 0 shares
}
// SECURE — virtual offset (ERC-4626 recommendation)
function _convertToShares(uint256 assets) internal view returns (uint256) {
return assets.mulDiv(totalSupply() + 1, totalAssets() + 1); // Virtual offset
}
Attacker donates tokens directly to contract to manipulate share price or accounting.
// VULNERABLE — no slippage protection
function swap(uint amountIn) external {
uint amountOut = calculateOutput(amountIn);
token.transfer(msg.sender, amountOut);
}
// SECURE — user-specified minimum
function swap(uint amountIn, uint minAmountOut, uint deadline) external {
require(block.timestamp <= deadline, "Expired");
uint amountOut = calculateOutput(amountIn);
require(amountOut >= minAmountOut, "Slippage exceeded");
token.transfer(msg.sender, amountOut);
}
Loss Example: Cork Protocol $11M
// VULNERABLE — hook doesn't verify caller
function afterSwap(
address sender,
PoolKey calldata key,
IPoolManager.SwapParams calldata params,
BalanceDelta delta,
bytes calldata hookData
) external returns (bytes4, int128) {
// Anyone can call this directly!
_handleSwapLogic(key, delta, hookData);
}
// SECURE — verify msg.sender is PoolManager
function afterSwap(
address sender,
PoolKey calldata key,
IPoolManager.SwapParams calldata params,
BalanceDelta delta,
bytes calldata hookData
) external override poolManagerOnly returns (bytes4, int128) {
_handleSwapLogic(key, delta, hookData);
}
modifier poolManagerOnly() {
require(msg.sender == address(poolManager), "Not PoolManager");
_;
}
Attacker passes crafted hookData to manipulate hook behavior.
Loss Example: Yearn yETH $9M
// VULNERABLE — cached price becomes stale after external call
function rebalance() external {
uint256 price = oracle.getPrice(); // Cached
_swapTokens(tokenA, tokenB, amount); // External call changes state
uint256 value = balance * price; // Uses stale price!
}
// SECURE — re-read after external interaction
function rebalance() external {
_swapTokens(tokenA, tokenB, amount);
uint256 price = oracle.getPrice(); // Fresh read after interaction
uint256 value = balance * price;
}
msg.sender == poolManager (ETH-094)rg "swap|addLiquidity|removeLiquidity" contracts/ # AMM
rg "borrow|lend|liquidate|collateral" contracts/ # Lending
rg "deposit.*shares|withdraw.*assets|ERC4626" contracts/ # Vault
rg "propose|vote|execute|timelock" contracts/ # Governance
rg "IHooks|BaseHook|afterSwap|beforeSwap|afterModifyPosition" contracts/ # V4 hooks
rg "poolManager|PoolManager" contracts/ # Hook caller verification
rg "hookData" contracts/ # Data passed to hooks
| Exploit | Loss | Pattern | Lesson | |---------|------|---------|--------| | The DAO | $60M | ETH-001 | CEI pattern, ReentrancyGuard | | Cream Finance | $130M | ETH-024 | Multi-oracle, TWAP | | Beanstalk | $182M | ETH-025 | Snapshot voting, timelock | | Euler Finance | $197M | ETH-058 | Donation attack defense | | Ronin Bridge | $625M | ETH-006 | Multi-sig threshold | | Harvest Finance | $34M | ETH-024,025 | Flash loan oracle check | | Cork Protocol | $11M | ETH-094 | Verify hook msg.sender | | Yearn yETH | $9M | ETH-096 | Re-read state after calls | | GMX V1 | $42M | ETH-024 | Multi-oracle + TWAP | | Balancer V2 | $128M | ETH-004 | Reentrancy-aware view functions |
tools
Advanced Solidity/EVM smart contract security auditor with 104 vulnerability patterns, multi-tool integration, and professional report generation.
development
Comprehensive Solidity contract security scanner detecting 104 vulnerability patterns across reentrancy, access control, arithmetic, DeFi, proxy, and token categories. Integrates Slither, Aderyn, and Mythril with manual analysis.
testing
Analyzes storage layout, proxy patterns, and state variable security in Solidity contracts. Detects storage collisions, uninitialized pointers, and upgrade risks. Use when auditing proxy/upgradeable contracts.
development
Validates Solidity implementation against specification documents. Extracts behavior from docs (README, specs, NatSpec) and verifies code matches documented intent. Uses Trail of Bits methodology for divergence detection.