Skip to content

#environment setup with bypass_prevrandao propagation #148

@Dargon789

Description

@Dargon789

Reviewer's Guide

This PR enhances the formatting command to properly exclude libraries during recursive runs, introduces a new bypass_prevrandao configuration option for networks, and refactors environment setup to propagate network settings (including the new flag) across EVM and CLI components. Workspace and test updates ensure defaults and dependencies align with these changes.

Sequence diagram for environment setup with bypass_prevrandao propagation

sequenceDiagram
    participant "CLI/Forge/Cast/Anvil"
    participant "EVM Core"
    participant "NetworkConfigs"
    participant "EnvMut"
    participant "BlockResponse"
    "CLI/Forge/Cast/Anvil"->>"EVM Core": Call environment(..., configs)
    "EVM Core"->>"NetworkConfigs": Pass configs to apply_chain_and_block_specific_env_changes
    "EVM Core"->>"EnvMut": Apply chain and block specific changes
    "EVM Core"->>"NetworkConfigs": Call bypass_prevrandao(chain_id)
    "NetworkConfigs"-->>"EVM Core": Return true/false
    "EVM Core"->>"EnvMut": Set prevrandao if bypass required
    "EVM Core"->>"EnvMut": Finalize environment setup
Loading

Entity relationship diagram for NetworkConfigs and chain types

erDiagram
    NETWORKCONFIGS {
        bool bypass_prevrandao
    }
    NAMEDCHAIN {
        chain_id u64
    }
    NETWORKCONFIGS ||--o| NAMEDCHAIN : "uses chain_id for bypass_prevrandao logic"
Loading

Class diagram for updated NetworkConfigs struct and related methods

classDiagram
    class NetworkConfigs {
        +bool optimism
        +bool celo
        +bool bypass_prevrandao
        +bypass_prevrandao(chain_id: u64) bool
        +is_optimism() bool
        +is_celo() bool
    }
    NetworkConfigs <|-- AnyNetwork
    class AnyNetwork {
        // Inherits network config logic
    }
Loading

Class diagram for FmtArgs filtering logic update

classDiagram
    class FmtArgs {
        +run() Result
        -is_under_ignored_dir(file_path: &Path, include_libs: bool) bool
    }
    FmtArgs --> Input
    class Input {
        +Paths(Vec<PathBuf>)
    }
Loading

File-Level Changes

Change Details Files
Exclude library paths when recursing in the fmt command
  • Expand lib globs separately and canonicalize paths
  • Add is_under_ignored_dir helper to combine ignored and lib checks
  • Update project_paths and directory recursion filters to skip libs
  • Add CLI test verifying lib exclusion in fmt recursion
crates/forge/src/cmd/fmt.rs
crates/forge/tests/cli/fmt.rs
Add bypass_prevrandao flag to network configuration
  • Introduce bypass_prevrandao field with serde and clap attributes
  • Implement bypass_prevrandao() method honoring named chains or user flag
  • Add default bypass_prevrandao entry to CLI config test
crates/evm/networks/src/lib.rs
crates/forge/tests/cli/config.rs
Refactor environment initialization to consume network configs
  • Remove hardcoded Moonbeam-specific randomization in apply_chain_and_block_specific_env_changes
  • Add NetworkConfigs parameter to apply_chain_and_block_specific_env_changes, configure_env_block, and environment()
  • Update call sites in anvil, cast, verify, evm-core/fork/init.rs, evm-core/src/utils.rs, evm-core/src/opts.rs to pass network configs
crates/evm/core/src/utils.rs
crates/anvil/src/config.rs
crates/cast/src/cmd/run.rs
crates/verify/src/bytecode.rs
crates/verify/src/utils.rs
crates/evm/core/src/fork/init.rs
crates/evm/core/src/opts.rs
Update verify workspace dependency
  • Add foundry-evm-networks to the workspace members in verify/Cargo.toml
crates/verify/Cargo.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Originally posted by @sourcery-ai[bot] in #147 (comment)

Metadata

Metadata

Assignees

Labels

P-highT-bugbugSomething isn't workingdependenciesPull requests that update a dependency filedocumentationImprovements or additions to documentationduplicateThis issue or pull request already existsenhancementNew feature or requestgithub_actionsPull requests that update GitHub Actions codegood first issueGood for newcomersinvalidThis doesn't seem rightquestionFurther information is requestedrustPull requests that update rust codewontfixThis will not be worked on

Projects

Status

Backlog

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions