Foundry

repository·master·Indexed 11 days ago

https://github.com/foundry-rs/foundry

A portable and modular toolkit for Ethereum application development written in Rust, providing tools for building, testing, and interacting with smart contracts.

Tokens
148.8K
Snippets
474
Records
649
Agent score
95%

What's inside Foundry

  1. Overview of the Foundry Linter (`lint`)

    master
    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.
  2. Overview of Foundry components

    master

    Foundry 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).
  3. Overview of Tempo Foundry

    master

    Tempo 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.
  4. Overview of the Foundry toolkit

    master

    Foundry 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).
  5. Understand the `arbitrary-send-erc20-permit` lint rule

    master

    The arbitrary-send-erc20-permit lint rule (Severity: High) detects a dangerous pattern where a contract calls permit on a token and subsequently calls transferFrom using an arbitrary from address that is not proven to be msg.sender or address(this).

    Why this is dangerous

    This pattern is dangerous when used with tokens that do not actually implement permit but have a fallback function (e.g., WETH). In such cases, the permit call might silently succeed without actually granting an allowance. If the subsequent transferFrom uses an attacker-supplied from address, the contract might inadvertently drain funds from a user who had previously granted an allowance to the contract, because the contract incorrectly assumes the permit call authorized the transfer.

  6. Understand the `inline-assembly` lint

    master

    The inline-assembly lint (Severity: Info, ID: inline-assembly) flags every assembly { ... } 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.

  7. Understand the `write-after-write` lint rule

    master

    The write-after-write lint 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 an SSTORE gas cost but its value is immediately discarded by the subsequent write.

    What is detected:

    • Plain = assignments.
    • delete operations 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.
  8. Understand the Right-to-left override (rtlo) lint rule

    master

    The rtlo lint rule flags the presence of Unicode bidirectional override characters in source code. These characters (such as the right-to-left override codepoint U+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: rtlo

  9. How custom EVM networks work in Foundry

    master
    The evm-networks crate provides a mechanism for defining and sharing custom network features across Foundry's core tools, including anvil, forge, and cast. 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 in foundry.toml, or automatically enabled based on the detected chain_id.
  10. How comment handling works in the formatter

    master

    The formatter preserves developer intent by categorizing comments into Isolated, Mixed, or Trailing types.

    • Vertical Spacing: Blank lines are treated as BlankLine comments. 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 Break tokens around comments to ensure correct spacing. For blank lines, it emits one or two hardbreaks to maintain the original vertical rhythm.