Foundry is a fast, portable, modular smart contract development toolkit written in Rust, designed specifically for the Ethereum ecosystem. Unlike its predecessor Hardhat (JavaScript), Foundry lets developers write tests directly in Solidity — eliminating context-switching between languages. It consists of four primary tools: Forge (testing and building), Cast (command-line Ethereum interactions), Anvil (local Ethereum node/fork), and Chisel (Solidity REPL). Since its introduction in 2021, Foundry has rapidly become the preferred development environment for high-performance DeFi protocols, competitive auditors, and teams that prioritize test speed and correctness.
Components
The following sections cover this in detail.
Forge
- Solidity-native tests: Write and run tests in Solidity without JavaScript wrappers — test contracts directly test other contracts
- Speed: Runs thousands of tests in seconds (vs. Hardhat’s typical minutes for large suites)
- Fuzz testing: Built-in property-based fuzzing — automatically generates thousands of random inputs to find edge cases
- Invariant testing: Define protocol properties (invariants) that must always hold; Foundry tries to break them
- Symbolic execution integration: Works with tools like Halmos for formal verification
- Gas snapshots: Track precise gas costs per function via
.gas-snapshotfile (useful for gas optimization PRs)
“`solidity
// Example Forge test
contract VaultTest is Test {
Vault vault;
function setUp() public {
vault = new Vault();
}
function testDeposit(uint128 amount) public { // fuzz test — random amounts
vm.deal(address(this), amount);
vault.deposit{value: amount}();
assertEq(vault.balanceOf(address(this)), amount);
}
}
“`
Anvil
- Mainnet forking: Fork Ethereum mainnet (or any EVM chain) at any block
- Impersonate accounts, set balances, manipulate storage slots
- Very fast; frequently used in automated testing CI pipelines
- Compatible with any ethers.js/web3.js frontend tooling
Cast
- Call any contract:
cast call 0x...address... "balanceOf(address)(uint256)" 0x... - Send transactions, decode calldata, compute ABIs, query chain data
- Essential for quick debugging without writing full scripts
Chisel
- Evaluate Solidity snippets instantly in a local EVM environment
- Useful for quick calculations, testing expressions, exploring opcodes
Cheatcodes (vm.*)
| Cheatcode | Purpose |
|---|---|
vm.prank(addr) |
Execute next call as addr |
vm.warp(timestamp) |
Set block timestamp |
vm.roll(blockNum) |
Set block number |
vm.deal(addr, amount) |
Set ETH balance |
vm.expectRevert() |
Assert next call reverts |
vm.expectEmit() |
Assert specific event emitted |
vm.store(addr, slot, val) |
Overwrite contract storage directly |
vm.label(addr, "Name") |
Label addresses in debug output |
These cheatcodes allow precise simulation of any blockchain state in tests.
History
| Year | Events |
|---|---|
| 2021 | Georgios Konstantopoulos at Paradigm develops and open-sources Foundry (Forge) |
| 2021 | Initial community reception: shock that tests could be in Solidity; rapid adoption among DeFi devs |
| 2022 | Foundry becomes the go-to tool for Solidity auditors (Spearbit, Code4rena competitors); Anvil released |
| 2022 | Cast and Chisel mature; Foundry Book published as comprehensive documentation |
| 2023 | Invariant testing released — Foundry can now find bugs Hardhat tests miss by design |
| 2024 | Foundry used by the majority of new DeFi protocols (Aave v3 v4, Uniswap v4, Morpho, etc.) |
| 2025 | Standard for competitive auditing; Hardhat and Foundry often combined in the same project |
Common Misconceptions
“Foundry replaces Hardhat entirely”
Many production projects use both: Foundry for unit and fuzz testing (speed + coverage), Hardhat for deployment scripts and JavaScript-based integration tests. They are complementary tools, not strict replacements.
“Foundry is only for advanced users”
The Foundry Book provides excellent documentation for all skill levels. The Solidity-native approach can actually be easier for developers who know Solidity well but are uncomfortable with JavaScript.
Social Media Sentiment
Foundry is enthusiastically embraced by the DeFi development community. Paradigm’s backing gives it credibility. Security researchers and auditors strongly favor Foundry for its fuzz testing and invariant testing capabilities — finding bugs that manual tests miss. The speed improvement over Hardhat (often 10-100x faster) is consistently praised. The “tests in Solidity” design philosophy is considered elegant by experienced Solidity developers. Beginner tutorials still default to Hardhat due to ecosystem maturity; Foundry is considered more advanced but increasingly the standard for serious development.
Last updated: 2026-04
Related Terms
Sources
- Konstantopoulos, G. (2021). Introducing Foundry: Blazing Fast Testing for EVM Smart Contracts. Paradigm.xyz.
- Brock, E., et al. (2023). Foundry Book. Book.getfoundry.sh.
- Dragonfly Research. (2023). How We Use Invariant Testing at Morpho. Morpho.org.