
Auditing Foundry Smart Contract Security
FreeEnsure your Solidity contracts are secure before deployment.
Free · Opens the source repo
What Auditing Foundry Smart Contract Security does
The Auditing Foundry Smart Contract Security skill provides a comprehensive pre-deployment security audit for Solidity smart contracts within a Foundry project. Given the immutable nature of deployed smart contracts, this skill is designed to identify and mitigate potential vulnerabilities that could lead to significant financial losses. It employs a multi-layered approach that combines static analysis, symbolic execution, property-based testing, and manual review to ensure robust security practices are followed.
At the core of this skill are four distinct techniques. First, static analysis tools like Slither and Aderyn quickly scan the abstract syntax tree (AST) and intermediate representation (IR) of the contracts to detect known anti-patterns. Next, symbolic execution with Mythril allows for deeper analysis of critical contracts, exploring execution paths to uncover complex bugs. Property-based testing using Forge enables fuzz testing and invariant verification, ensuring that the contract behaves as expected across a wide range of scenarios. Finally, a structured manual review process, supplemented by a checklist, ensures that all critical security aspects are covered, including key management practices to prevent plaintext key exposure.
This skill is particularly useful for developers and auditors working on DeFi applications, dApps, or any project that involves handling tokens or other valuable assets. By integrating this skill into your development workflow, you can catch vulnerabilities early in the process, leading to safer deployments and increased confidence in your smart contracts. Whether you are writing new contracts, reviewing existing ones, or preparing for deployment, this skill provides the necessary tools to enhance your security posture and protect against common exploits.
When to use it
Use this skill before deploying any Solidity contract to a testnet or mainnet EVM chain, especially when handling value or integrating with external systems.
When not to use it
This skill may not be necessary for simple contracts that do not handle significant value or for projects where security is not a primary concern.
What you can build with it
Pre-deployment Audit
Run this skill before deploying any Solidity contract to ensure it is free of critical vulnerabilities.
Integration with DeFi Protocols
Use this skill when developing contracts that handle tokens or interact with DeFi protocols to catch common security issues.
Manual Review Assistance
Leverage the structured checklist provided to assist in manual reviews of smart contracts, ensuring comprehensive security coverage.
How to install Auditing Foundry Smart Contract Security
View source1. Install with the skills CLI
npx skills add mukul975/anthropic-cybersecurity-skills/auditing-foundry-smart-contract-security --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by mukul975Auditing Foundry Smart Contract Security
Overview
Deployed smart contracts are immutable and custody real funds, so a bug shipped to mainnet cannot be patched — it can only be exploited. Most catastrophic DeFi losses come from a small set of recurring classes: reentrancy, broken access control, oracle/price manipulation, and unchecked arithmetic or external calls.
This skill runs a defense-in-depth, pre-deployment audit of a Foundry project, layering four independent techniques that each catch what the others miss:
- Static analysis —
slither(90+ detectors) andaderyn(Cyfrin, Rust) scan the AST/IR in seconds for known anti-patterns. - Symbolic execution —
mythril(optional, slow) explores execution paths and SMT-solves for deep arithmetic/reentrancy bugs. - Property-based testing —
forge testwith fuzzing (testFuzz_*) and invariant tests (invariant_*+ handler contracts with ghost variables) proves protocol-level properties hold across millions of random sequences. - Manual review + key hygiene — a structured checklist (see
references/vulnerability-checklist.md) and a secrets/keystore audit so no private key ever lives in plaintext and deployment goes through an encryptedcastkeystore (seereferences/secure-deployment-and-keys.md).
The skill is dev-side and pre-deployment — it is run by the engineer building the contract, not by a SOC after an incident. Findings gate the deploy: any high/critical static finding, failing test, leaked key, or low coverage = FAIL.
When to Use
- Before deploying any Solidity contract to a testnet or mainnet EVM chain.
- When writing or reviewing a Foundry project (
foundry.toml,src/,test/,script/). - When a contract handles value: tokens (ERC-20/721/1155), vaults, staking, AMMs, bridges, governance.
- When adding fuzz or invariant tests, or when coverage of value-moving functions is unknown.
- When wiring deployment scripts — to verify keys are in an encrypted keystore, not
.envplaintext. - When integrating a price oracle, external call,
delegatecall, or upgradeable proxy. - When triaging a Slither/Aderyn report and needing to separate real bugs from false positives.
Prerequisites
- Foundry installed (
forge,cast,anvil):curl -L https://foundry.paradigm.xyz | bash && foundryup - Slither + solc:
pip install slither-analyzerandsolc-select install <ver> && solc-select use <ver> - Aderyn (recommended):
cargo install aderyn(ornpm i -g @cyfrin/aderyn) - Mythril (optional, slow symbolic exec):
pip install mythril - gitleaks (key-leak scan): see the companion
implementing-secret-scanning-with-gitleaksskill - A Foundry project that compiles (
forge buildsucceeds) — analyzers need build artifacts. - Solidity ^0.8.x is assumed (built-in overflow checks); pre-0.8 contracts need extra SafeMath review.
Install the Python tools in a virtualenv (recommended on externally-managed distros). Never run analysis against untrusted contract source on a machine with funded wallets unlocked.
Steps
Step 1: Build and sanity-check the project
forge build # analyzers require fresh artifacts
forge fmt --check # style gate (optional)
cat foundry.toml # note solc version, optimizer, remappings, evm_version
Step 2: Static analysis (fast, run every time)
# Slither — full project (uses foundry.toml + remappings automatically)
slither . --json slither-report.json
# Aderyn — Cyfrin Rust analyzer, complementary detectors
aderyn . -o aderyn-report.json
Or run the bundled orchestrator that runs both, deduplicates, and gates the result:
python3 scripts/agent.py --project . --output audit-report.json
Step 3: Symbolic execution on critical contracts (optional, slow)
# Only on the highest-value contract(s) — Mythril is path-explosive
myth analyze src/Vault.sol --solc-json mythril.config.json --execution-timeout 300 -o json
# or: python3 scripts/agent.py --project . --mythril src/Vault.sol
Step 4: Property-based testing — fuzz + invariants
forge test -vvv # unit + fuzz tests
forge coverage --report summary # coverage of value-moving code
forge test --match-test invariant_ -vvv # invariant suite (handler-based)
Every value-moving contract should have invariant tests with a handler (bounded
inputs, ghost variables, targetContract(handler)) — not just unit tests. See
references/api-reference.md for the handler pattern, and write a
test_RevertWhen_* (with vm.expectRevert) for each access-control guard.
Step 5: Manual review against the checklist
Walk references/vulnerability-checklist.md for every contract: reentrancy
(checks-effects-interactions / nonReentrant), access control, oracle manipulation,
delegatecall/proxy storage layout, unchecked return values, tx.origin, weak
randomness, DoS, front-running/MEV, and ERC-specific pitfalls (approve race,
fee-on-transfer, rebasing).
Step 6: Key hygiene & secure deploy
gitleaks detect --no-banner # no private keys / mnemonics / .env committed
git ls-files | grep -E '\.env$|keystore' && echo "WARN: secrets tracked by git"
# Import the deploy key ONCE into an encrypted keystore — never a plaintext PRIVATE_KEY env
cast wallet import deployer --interactive
# Deploy via the keystore account (testnet first), simulate before --broadcast
forge script script/Deploy.s.sol --account deployer --rpc-url <testnet> --broadcast --verify
See references/secure-deployment-and-keys.md for the full hardening rules
(MetaMask hygiene, hardware wallet for mainnet, RPC trust, post-deploy verification).
Step 7: Triage and report
Combine Slither + Aderyn + Mythril + test results, deduplicate by (file, line),
drop confirmed false positives, rank by exploitability × financial impact, and map
each to its SWC id. The orchestrator emits audit-report.json with a PASS/FAIL gate.
Expected Output
A JSON audit report listing findings with SWC identifiers, severity, tool source, affected contract/function/line, and remediation; plus the test/coverage summary and a single PASS / FAIL deploy gate. FAIL on any high/critical static finding, failing test, leaked secret, or coverage below the configured threshold on value-moving code.
Frequently asked questions about Auditing Foundry Smart Contract Security
Similar skills
CodeQL Code Scanning
Streamline CodeQL setup and configuration for security analysis.
Security Review
AI-powered codebase security scanner for vulnerabilities.
Integrating SAST into GitHub Actions
Automate SAST scanning in GitHub Actions workflows.
Implementing Semgrep for Custom SAST Rules
Enhance code security with custom Semgrep rules.
Infrastructure as Code Security Scanning
Automate security checks for your IaC deployments.
Implementing GitHub Advanced Security
Automate code scanning and vulnerability detection at scale.
