Foundry
repository·master·Indexed 11 days ago
https://github.com/foundry-rs/foundryA portable and modular toolkit for Ethereum application development written in Rust, providing tools for building, testing, and interacting with smart contracts.
What's inside Foundry
- The Foundry Linter is a Solidity linter designed to identify potential errors, vulnerabilities, gas optimizations, and style guide violations. It is used to enforce best practices and improve code quality within Foundry projects by scanning Solidity source code for various issues ranging from high-severity security risks to low-severity style inconsistencies.
Overview of Foundry components
masterFoundry is a modular toolkit for Ethereum development consisting of four primary tools:
- Forge: Used to build, test, fuzz, debug, and deploy Solidity contracts.
- Cast: A CLI tool for interacting with EVM smart contracts, sending transactions, and retrieving chain data.
- Anvil: A fast local Ethereum development node.
- Chisel: A fast and verbose Solidity REPL (Read-Eval-Print Loop).
Overview of foundry-common utilities
masterThefoundry-commoncrate provides a collection of shared utilities designed to assist in the development and operation of various Foundry tools. It serves as a foundational layer for building and using the broader Foundry ecosystem.Overview of Tempo Foundry
masterTempo Foundry is a high-performance, portable, and modular toolkit for Ethereum application development written in Rust. It primarily consists of two core tools:
- Forge: An Ethereum testing framework designed to replace tools like Truffle, Hardhat, and DappTools.
- Cast: A versatile CLI tool (Swiss army knife) used for interacting with EVM smart contracts, sending transactions, and retrieving chain data.
Overview of forge-doc
masterOverview of the Foundry toolkit
masterFoundry is a high-performance, modular toolkit for Ethereum application development written in Rust. It consists of four primary tools:
- Forge: An Ethereum testing framework (comparable to Truffle, Hardhat, or DappTools).
- Cast: A command-line utility for interacting with EVM smart contracts, sending transactions, and retrieving chain data.
- Anvil: A local Ethereum node (comparable to Ganache or Hardhat Network).
- Chisel: A fast and verbose Solidity REPL (Read-Eval Print Loop).
Understand the `arbitrary-send-erc20-permit` lint rule
masterThe
arbitrary-send-erc20-permitlint rule (Severity:High) detects a dangerous pattern where a contract callspermiton a token and subsequently callstransferFromusing an arbitraryfromaddress that is not proven to bemsg.senderoraddress(this).Why this is dangerous
This pattern is dangerous when used with tokens that do not actually implement
permitbut have a fallback function (e.g., WETH). In such cases, thepermitcall might silently succeed without actually granting an allowance. If the subsequenttransferFromuses an attacker-suppliedfromaddress, the contract might inadvertently drain funds from a user who had previously granted an allowance to the contract, because the contract incorrectly assumes thepermitcall authorized the transfer.Understand the `inline-assembly` lint
masterThe
inline-assemblylint (Severity:Info, ID:inline-assembly) flags everyassembly { ... }block in your Solidity code. Because inline assembly bypasses Solidity's safety features (type checks, overflow checks, and memory layout invariants), it is a common source of high-impact bugs.This lint reports all assembly blocks, including those using the
"evmasm"dialect or the("memory-safe")flag. For blocks marked as memory-safe, the lint provides a softer message acknowledging the developer's attestation, shifting the review focus from memory layout to business logic and side effects.Understand the `write-after-write` lint rule
masterThe
write-after-writelint rule (Severity:Gas, ID:write-after-write) identifies instances where a state variable is written to consecutively without the first value ever being read. The first write is considered dead code because it incurs anSSTOREgas cost but its value is immediately discarded by the subsequent write.What is detected:
- Plain
=assignments. deleteoperations on bare state variable identifiers.- Tuple/destructuring assignments (e.g.,
(x, y) = (1, 2)), where each component is tracked individually. - Pre/post increment and decrement operators (e.g.,
++x,x--), as the write they produce can be immediately overwritten.
What is excluded (to avoid false positives):
- Compound assignments (e.g.,
+=,|=). - Index or member writes (e.g.,
mapping[k],struct.field). - Conditional boundaries like
&&,||, or ternary operators are handled conservatively to prevent false positives across short-circuit paths.
- Plain
Understand the Right-to-left override (rtlo) lint rule
masterThe
rtlolint rule flags the presence of Unicode bidirectional override characters in source code. These characters (such as the right-to-left override codepointU+202E) can be used to create "Trojan Source" attacks, where code is rendered visually in a different order than how the compiler actually reads it. This allows malicious behavior to be hidden during visual code reviews.This rule detects these characters when they are embedded in:
- Identifiers
- Strings
- Comments
Severity:
High
ID:rtloHow custom EVM networks work in Foundry
masterTheevm-networkscrate provides a mechanism for defining and sharing custom network features across Foundry's core tools, includinganvil,forge, andcast. Currently, this system is used to implement custom precompiles, with future support planned for custom transaction types. Custom network features can be toggled via CLI flags, configuration infoundry.toml, or automatically enabled based on the detectedchain_id.How comment handling works in the formatter
masterThe formatter preserves developer intent by categorizing comments into
Isolated,Mixed, orTrailingtypes.- Vertical Spacing: Blank lines are treated as
BlankLinecomments. The formatter preserves vertical spacing between logical blocks but collapses multiple consecutive blank lines into a single blank line to maintain a clean rhythm. - Integration: During AST traversal, the formatter inserts
Breaktokens around comments to ensure correct spacing. For blank lines, it emits one or twohardbreaks to maintain the original vertical rhythm.
- Vertical Spacing: Blank lines are treated as