Skip to content

Optional Chain Sections + Skip Flags in Foundry Script Config #13119

@S0mt0

Description

@S0mt0

Component

Config

Describe the feature you would like

Foundry’s current Config loader (used by _loadConfig and _loadConfigAndForks) attempts to parse every configured chain section in a TOML file and will error if a section is present but effectively empty or missing expected keys. This makes multi-chain workflows harder when some chains intentionally lack certain config values.

Example config:

[sepolia]
endpoint_url = "${SEPOLIA_RPC_URL}"

[anvil]
endpoint_url = "http://127.0.0.1:8545"
[anvil.bool]
use_mocks = true

[anvil.uint]
mock_decimals = 8
mock_initial_price = 2000e8

In this file:

sepolia does not define mocks — and that’s fine.

anvil does not define price_feed — also fine.

But Foundry currently will throw when trying to load or parse these mismatched sections as if all chains must have all keys present.

Proposal

  1. Skip Empty Chain Sections with Warning

Treat a chain section as optional:

If a top-level chain section has no keys, skip it with a detailed warning:

Warning: Skipped config section for chain `<chain>` — no values found.
  1. Add a Skip Flag

Add a new loader option to make this behavior explicitly opt-in:

_skipEmptySections = true

This flag would be passed alongside _loadConfig or _loadConfigAndForks, e.g.:

_loadConfig("./deployments.toml", true, ConfigOpts.skipEmptySections);

Or via a global config option at the top of the TOML:

[_config]
skip_empty_sections = true
  1. Verbose Warnings for Missing Keys

When a chain section has some keys but is missing others seen in other chains, emit a verbose warning:

Warning: chain `sepolia` missing key `use_mocks`; only defined under `anvil`.

This helps developers see mismatches in multi-chain configs.

  1. Key Lookup Behavior (Unchanged)

Only throw at runtime when a script explicitly calls config.get(...) for a missing key.

Missing keys do not cause load errors with the skip option enabled.

Summary of Desired Behavior

Behavior With Skip Flag (_skipEmptySections = true)
Empty chain section Skipped with a detailed warning (no values found for that chain)
Missing key under a chain No load error; only errors if script explicitly calls config.get(...)
Cross-chain mismatches Emit verbose warnings showing which keys are missing under which chains
Backwards compatibility Default behavior unchanged; skip flag is opt-in

This feature will significantly improve ergonomics for multi-chain workflows where not every chain has every config value defined.

Additional context

As shown below, Patrick Collins (of Cyfrin) highlights the failure case when blank chain sections are present:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-featureType: featureT-needs-triageType: this issue needs to be labelled

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions