Foundry
Fast, portable Ethereum development framework written in Rust, featuring advanced testing and debugging capabilities.
Foundry is a blazingly fast, portable toolkit for Ethereum application development written in Rust. Created by Georgios Konstantopoulos and maintained by Paradigm, Foundry has become the preferred development framework for security-conscious teams and competitive auditors. The framework consists of three core tools: Forge for testing and deploying contracts, Cast for interacting with the blockchain via command-line, and Anvil for running a local Ethereum node.
Foundry's distinguishing characteristic is performance—tests execute orders of magnitude faster than JavaScript-based frameworks like Hardhat because Foundry compiles directly to native code rather than running through a JavaScript VM. This speed enables development workflows that were previously impractical, such as comprehensive fuzzing campaigns that execute millions of test cases or property-based invariant testing that explores vast state spaces. The article's discussion of the competitive audit demonstrates how Foundry's speed and powerful debugging features enable auditors to rapidly iterate on vulnerability hypotheses.
Core Components and Capabilities
Forge is Foundry's smart contract testing and deployment tool. Tests are written in Solidity itself rather than JavaScript, removing context switching and allowing auditors to work in a single language throughout the codebase. Forge provides an extensive cheatcode library (vm.* functions) that enables precise control over the testing environment. The vm.prank cheatcode simulates calls from any address, enabling multi-user scenarios. The vm.warp and vm.roll cheatcodes manipulate block timestamp and number, critical for testing time-dependent logic.
Forge's execution tracing capabilities, accessed via verbosity flags (-v, -vv, -vvv, -vvvv), provide increasingly detailed output about test execution. The article describes using -vvvv (maximum verbosity) to identify the "Zero Tax Exploitation" vulnerability, where the trace revealed that a calculated tax was never actually subtracted from the withdrawal amount. This level of introspection—seeing every state change, variable assignment, and internal function call—transforms auditing from static code analysis into dynamic execution analysis.
Cast is Foundry's command-line tool for blockchain interaction. It provides utilities for ABI encoding/decoding, transaction building, calldata analysis, and storage inspection. Cast enables auditors to decode complex transaction data, query historical state, and interact with deployed contracts without writing any code. The tool integrates seamlessly with Unix pipes and scripts, making it invaluable for automation and investigation workflows.
Anvil is Foundry's local Ethereum node, providing a fast development blockchain that can fork mainnet state at specific blocks. Forking capabilities enable testing against real production contract deployments with actual state, which is critical for integration testing and investigating potential exploits against live protocols. Anvil's instant mining and flexible RPC interface make it ideal for iterative development and testing workflows.
Advanced Testing Techniques
Fuzzing in Foundry automatically generates random inputs to test functions, searching for inputs that cause failures. Unlike JavaScript-based fuzzing which is limited by performance, Forge can execute hundreds of thousands of fuzz runs per second. Fuzz testing is declared by using function parameters in test functions—Forge automatically provides randomized values for these parameters across multiple runs. The article mentions using LLMs to generate initial test stubs, which auditors then enhance with fuzzing to explore edge cases.
Property-based invariant testing defines conditions that should always hold true regardless of contract state or function call sequence. Forge then attempts to violate these invariants by executing random sequences of contract interactions. For ERC-4626 vaults, critical invariants include "total shares minted minus shares burned equals total supply" and "sum of all user claims never exceeds vault assets." Invariant testing is particularly powerful for finding inflation attacks and other economic exploits that emerge from valid but unexpected state combinations.
Differential testing compares two implementations of the same functionality to find discrepancies. When auditing a new ERC-4626 implementation, auditors can write tests that compare its behavior against OpenZeppelin's reference implementation. Any divergence in share calculations, rounding behavior, or edge case handling indicates either a bug in the new implementation or potentially an issue with the reference.
Gas profiling with Forge's --gas-report flag provides detailed analysis of gas consumption per function. This helps identify optimization opportunities and potential denial-of-service vectors where expensive operations could be exploited. Forge can snapshot gas usage and alert when changes increase gas costs beyond acceptable thresholds, preventing performance regressions.
Cheatcodes and Debugging Workflows
Foundry's cheatcode library provides unprecedented control over the testing environment. Storage manipulation via vm.store and vm.load enables direct reading and writing of contract storage slots, allowing auditors to construct specific state scenarios that would be difficult to reach through normal function calls. This is invaluable for testing edge cases involving unusual storage states.
Expectation cheatcodes (vm.expectRevert, vm.expectEmit, vm.expectCall) enable precise assertions about contract behavior. Rather than just checking final state, tests can verify that specific events were emitted, particular functions were called, or expected reverts occurred. This catches bugs where contracts fail silently or emit incorrect events while appearing to work correctly.
Snapshot and revert functionality (vm.snapshot and vm.revertTo) enables tests to save blockchain state and reset to that point. This is crucial for testing multiple paths from the same starting state without expensive setup duplication. The article's workflow of using LLMs to generate test stubs benefits from snapshots—auditors can quickly explore many hypothetical scenarios branching from a common setup.
Transaction manipulation through vm.broadcast and vm.startBroadcast enables scripts to send real transactions to testnets or mainnet from within Solidity scripts. This unifies the development workflow—deployment scripts are written in the same language as tests and contracts, reducing errors from translation between JavaScript deployment code and Solidity contract logic.
Integration with Auditing Workflows
The competitive audit experience described in the article demonstrates Foundry's role in professional security research. Auditors use Foundry to rapidly test vulnerability hypotheses—when code review suggests a potential exploit, writing a Foundry test to demonstrate the issue takes minutes rather than hours. This rapid iteration cycle is critical in competitive audits where time pressure is intense.
Forking production state enables auditors to test potential exploits against actual deployed contracts. If auditing an upgrade to an existing protocol, Forge can fork mainnet at the current block, deploy the new version, and test whether the upgrade introduces vulnerabilities or whether existing state can be exploited. The article's finding of the inflation attack could have been validated against a mainnet fork if the underlying vault was already deployed.
Collaborative auditing benefits from Foundry's plain-text Solidity tests that integrate naturally with git workflows. Teams can share test suites, review test cases in pull requests, and build comprehensive test coverage collaboratively. The speed of Foundry tests means CI/CD pipelines can run extensive test suites on every commit without timeout issues that plague slower frameworks.
Proof-of-concept development for vulnerability reports is straightforward with Foundry. Rather than explaining a vulnerability with pseudocode or written descriptions, auditors provide runnable Foundry tests that demonstrate exploitation. This removes ambiguity—protocol teams can execute the PoC themselves, observe the exact state changes, and verify the severity.
Ecosystem and Adoption
Foundry has achieved widespread adoption among security-focused teams and competitive auditors. Major audit competitions on platforms like Sherlock and Code4rena increasingly use Foundry as the standard testing framework for protocol contests. The article's description of the Burve Protocol audit exemplifies this trend—competitive auditors rely on Foundry's speed and power to maximize findings within limited contest timelines.
Open-source protocols increasingly adopt Foundry as their primary development framework. Projects like Uniswap V4, Optimism, and numerous other major protocols have migrated to Foundry, citing faster development cycles, better test coverage, and improved developer experience. This migration trend means auditors must master Foundry to effectively work with modern protocol codebases.
Educational resources for Foundry include the Foundry Book, an extensive online documentation covering all features. The Foundry GitHub repository contains numerous example projects and test patterns. Security-focused tutorials and workshops increasingly use Foundry, training the next generation of auditors on the framework.
Understanding Foundry is essential for anyone involved in Ethereum security research or development. The framework's speed enables testing approaches that were previously impractical—comprehensive fuzzing, exhaustive invariant checking, and rapid PoC development. The article's competitive audit success story demonstrates that mastering Foundry's advanced features—particularly high-verbosity tracing and systematic testing—provides competitive advantages in finding vulnerabilities. As the ecosystem continues adopting Foundry as the standard development framework, proficiency with its testing and debugging capabilities becomes a prerequisite for effective security auditing.
Articles Using This Term
Learn more about Foundry in these articles:
Need expert guidance on Foundry?
Our team at Zealynx has deep expertise in blockchain security and DeFi protocols. Whether you need an audit or consultation, we're here to help.
Get a Quote

