> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://www.getfoundry.sh/api/mcp` to find what you need.
>
> **Have feedback?** Use `submit_feedback` on the same MCP server.

## Solidity compiler

Configuration related to the behavior of the Solidity compiler.

**Sections**

* [General](/config/reference/solidity-compiler#general)
* [Optimizer](/config/reference/solidity-compiler#optimizer)
* [Model Checker](/config/reference/solidity-compiler#model-checker)
* [Compilation Restrictions](/config/reference/solidity-compiler#compilation-restrictions)

### General

Configuration related to the behavior of the Solidity compiler.

#### `remappings`

* Type: array of string
* Default: `[]`
* Environment: `FOUNDRY_REMAPPINGS` or `DAPP_REMAPPINGS`

Import remappings used to resolve Solidity imports.

Each entry has the form `[<context>:]<name>=<target>`. An import path that starts with
`<name>` has that prefix replaced with `<target>`, a path relative to the project root. The
optional `<context>` limits the remapping to imports made by source units whose paths start
with it.

```toml
[profile.default]
remappings = [
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "lib/dep/:forge-std/=lib/dep/lib/forge-std/src/",
]
```

With the first entry, `import "@openzeppelin/contracts/utils/Context.sol";` resolves to
`lib/openzeppelin-contracts/contracts/utils/Context.sol`.

These entries are merged with remappings from `remappings.txt` in the project root, the
`FOUNDRY_REMAPPINGS` environment variable, `--remappings` on the command line, and those
detected automatically (see `auto_detect_remappings`). For the same name, command-line
remappings win over the environment, the environment over `remappings.txt`,
`remappings.txt` over this key, and all of them over auto-detected ones, including inside
dependencies. When two dependencies declare the same alias with different targets, each
declaration applies only within its own dependency; see [Dependency remapping
scope](https://www.getfoundry.sh/projects/dependencies#dependency-remapping-scope). Run
`forge remappings` to print the final list.

#### `auto_detect_remappings`

* Type: boolean
* Default: `true`
* Environment: `FOUNDRY_AUTO_DETECT_REMAPPINGS`, `DAPP_AUTO_DETECT_REMAPPINGS`, or `DAPP_TEST_AUTO_DETECT_REMAPPINGS`

Whether to detect remappings automatically by scanning the `libs` directories.

When enabled, Forge looks through each library directory for dependencies (including their
own `foundry.toml` and `remappings.txt` files) and generates remappings for them, including
contextual remappings for nested dependencies. Remappings you configure explicitly always
take precedence over detected ones. Dependency declarations that conflict with root paths
or other dependency mappings are scoped to their owner, with a configuration warning.
Unique aliases remain global. Dependencies with source directories outside their package
retain their existing declaration scope.

When disabled, only the remappings from `remappings`, `remappings.txt`, the
`FOUNDRY_REMAPPINGS` environment variable and `--remappings` are used.

#### `allow_paths`

* Type: array of string (path)
* Default: `[]`
* Environment: `FOUNDRY_ALLOW_PATHS`, `DAPP_ALLOW_PATHS`, or `DAPP_TEST_ALLOW_PATHS`

Additional directories that solc may read sources from, passed to `solc --allow-paths`.

Paths are relative to the project root. The project root and `libs` are always allowed, so
this is only needed for imports from outside the project, for example in workspaces managed
by pnpm or similar tools. See
[https://docs.soliditylang.org/en/latest/path-resolution.html#allowed-paths](https://docs.soliditylang.org/en/latest/path-resolution.html#allowed-paths).

#### `include_paths`

* Type: array of string (path)
* Default: `[]`
* Environment: `FOUNDRY_INCLUDE_PATHS`, `DAPP_INCLUDE_PATHS`, or `DAPP_TEST_INCLUDE_PATHS`

Additional source directories for import resolution, passed to `solc --include-path`.

Solc resolves imports against these directories in addition to its base path, which Foundry
sets to the project root. Use them to import contracts whose location is not fixed relative
to the project, such as packages installed by a package manager. Paths are relative to the
project root. See [solc path
resolution](https://docs.soliditylang.org/en/latest/path-resolution.html).

#### `libraries`

* Type: array of string
* Default: `[]`
* Environment: `DAPP_LIBRARIES` or `FOUNDRY_LIBRARIES`

Addresses of already deployed Solidity libraries to link against.

Each entry has the form `<file>:<library>:<address>`:

```toml
[profile.default]
libraries = ["src/MyLibrary.sol:MyLibrary:0xfD88CeE74f7D78697775aBDAE53f9Da1559728E4"]
```

Remappings apply to `<file>`. Contracts that call external functions of a listed library
are linked to the given address instead of having Forge deploy the library. These addresses
are also granted cheatcode access in tests and scripts (useful on forks), even when no
contract references them.

The `--libraries` flag and the `FOUNDRY_LIBRARIES` environment variable (a list, or a
single comma-separated string) set the same value. While `allow_linked_libraries` is
`false`, these addresses are withheld from solc; see that setting.

To link more than one library, add one entry per library:

```toml
libraries = [
    "src/MathLib.sol:MathLib:0xfD88CeE74f7D78697775aBDAE53f9Da1559728E4",
    "src/StringLib.sol:StringLib:0x4e59b44847b379578588920cA78FbF26c0B4956C",
]
```

On the command line, repeat `--libraries` once per library. A comma-separated list in a single `--libraries` flag is not supported.

```bash
$ forge build \
  --libraries src/MathLib.sol:MathLib:0xfD88CeE74f7D78697775aBDAE53f9Da1559728E4 \
  --libraries src/StringLib.sol:StringLib:0x4e59b44847b379578588920cA78FbF26c0B4956C
```

In the `FOUNDRY_LIBRARIES` environment variable, separate the entries with commas.

#### `allow_linked_libraries`

* Type: boolean
* Default: `true`
* Environment: `FOUNDRY_ALLOW_LINKED_LIBRARIES`, `DAPP_ALLOW_LINKED_LIBRARIES`, or `DAPP_TEST_ALLOW_LINKED_LIBRARIES`

Whether compiled contracts may depend on externally linked Solidity libraries.

Library functions declared `public` or `external` are called on a separately deployed
library, while `internal` ones are compiled into their callers. When set to `false`,
`forge build`, `forge test`, `forge script`, `forge create` and `forge coverage` fail if
the creation or runtime bytecode of any compiled contract requires an external library. The
check covers cached artifacts and the compilation used by mutation testing, and lists each
contract with the library it links. To fix a violation, make the called library functions
`internal`.

Internal libraries, unused public library functions and dynamic test linking remain
available. While disallowed, addresses configured in `libraries` are withheld from solc so
that actual dependencies stay visible in its link references; an unused address alone does
not fail the build.

The policy applies only to the artifacts selected for compilation, not to arbitrary
existing artifacts or code loaded at runtime through cheatcodes.
`--disallow-linked-libraries` enforces it for one invocation and overrides both the profile
and `FOUNDRY_ALLOW_LINKED_LIBRARIES`.

#### `solc`

* Type: string (version or path)
* Default: none
* Environment: `FOUNDRY_SOLC`, `DAPP_SOLC`, or `DAPP_TEST_SOLC`
* Aliases: `solc_version`

The Solidity compiler to use for the whole project, instead of detecting versions per file.

The value can be:

* an exact version, such as `"0.8.28"`, which is installed if it's missing (unless
  `offline` is set, in which case the build fails);
* `"solar:<version>"`, which pins an exact [Solar](https://github.com/paradigmxyz/solar)
  release, 0.2.0 or later without pre-release or build metadata;
* a path to a local compiler binary, or the name of an executable on `PATH`.

```toml
[profile.default]
solc = "0.8.28"
# solc = "solar:0.3.0"
# solc = "custom-solc"
```

Version requirements such as `"^0.8.0"` are not supported. When set, version auto-detection
is off and `auto_detect_solc` is ignored.

A Solar release is used from `~/.foundry/solar/<version>`. If it's missing, Forge downloads
it from the Solar GitHub release, checks it against the release's SHA-256 checksum file and
the version it reports, and installs it there. Releases are published for macOS, x86\_64
Linux, aarch64 Linux with glibc, and x86\_64 Windows; on other platforms, set `solc` to the
path of a `solar` binary instead.

The legacy key `solc_version` is still accepted and is used only when `solc` is not set.
For profiles that `foundry.toml` defines, the `FOUNDRY_SOLC_VERSION` (or
`DAPP_SOLC_VERSION`) environment variable overrides both. `--use` overrides it for one
invocation (accepting the same values, plus a `solc:` prefix).

#### `auto_detect_solc`

* Type: boolean
* Default: `true`
* Environment: `FOUNDRY_AUTO_DETECT_SOLC`, `DAPP_AUTO_DETECT_SOLC`, or `DAPP_TEST_AUTO_DETECT_SOLC`

Whether to detect the Solidity compiler versions to use from each file's `pragma solidity`.

With detection, Forge picks a compatible compiler version for each set of sources,
installing it if needed (unless `offline` is set). Setting `solc` turns detection off and
this key is then ignored.

`--no-auto-detect` sets this key to `false` for one invocation. Setting it to `false`
doesn't pin a compiler by itself: compilation still auto-detects when `solc` is unset, so
set `solc` to use a single version.

#### `offline`

* Type: boolean
* Default: `false`
* Environment: `FOUNDRY_OFFLINE`, `DAPP_OFFLINE`, or `DAPP_TEST_OFFLINE`

Whether to disallow network access for downloads and external lookups.

When enabled:

* missing solc versions and Solar releases are not installed; a build that needs one fails;
* traces don't look up contract names on Etherscan or function signatures in online
  signature databases;
* `forge script` skips verifying external contracts, and `--verify-external` fails.

With `auto_detect_solc` enabled, the required compiler versions are still detected, but
only installed ones are used. `--offline` enables it for one invocation.

#### `ignored_warnings_from`

* Type: array of string (path)
* Default: `[]`
* Environment: `FOUNDRY_IGNORED_WARNINGS_FROM`, `DAPP_IGNORED_WARNINGS_FROM`, or `DAPP_TEST_IGNORED_WARNINGS_FROM`

Paths whose compiler warnings are silenced.

Each entry is a file or directory path relative to the project root; a warning is silenced
when the file it points to starts with one of them. This hides known warnings from vendored
or generated code without affecting others:

```toml
[profile.default]
ignored_warnings_from = ["lib/legacy", "src/Generated.sol"]
```

Only warnings are silenced; errors are always reported. Silenced warnings don't fail the
build when `deny` is set. To silence only some codes, use `ignored_error_codes_from`.

#### `ignored_error_codes`

* Type: array of string or integer
* Default: `["license", "code-size", "init-code-size", "transient-storage", "transfer-deprecated", "natspec-memory-safe-assembly-deprecated", "code-size-amsterdam", "init-code-size-amsterdam"]`
* Environment: `FOUNDRY_IGNORED_ERROR_CODES`, `DAPP_IGNORED_ERROR_CODES`, or `DAPP_TEST_IGNORED_ERROR_CODES`

Solidity compiler warning codes to silence.

Each entry is a numeric code or one of these names:

* `license` (1878), `code-size` (5574), `init-code-size` (3860)
* `func-mutability` (2018), `unused-var` (2072), `unused-param` (5667), `unused-return`
  (9302)
* `virtual-interfaces` (5815), `missing-receive-ether` (3628), `shadowing` (2519)
* `same-varname` (8760), `unnamed-return` (6321), `unreachable` (5740)
* `pragma-solidity` (3420), `constructor-visibility` (2462), `transient-storage` (2394)
* `too-many-warnings` (4591), `transfer-deprecated` (9207)
* `natspec-memory-safe-assembly-deprecated` (2424)

```toml
[profile.default]
ignored_error_codes = ["license", "code-size", 2394]
```

Only warnings are silenced; errors are always reported. Silenced warnings don't fail the
build when `deny` is set. Setting this key replaces the default list. The SPDX license
(1878) and contract size (5574) warnings are always silenced in test files.
`--ignored-error-codes` replaces the list for one invocation. To silence codes only for
some paths, use `ignored_error_codes_from`.

The Amsterdam size warnings, `code-size-amsterdam` (5776) and `init-code-size-amsterdam` (7868), are included in nightlies with solc 0.8.39 support. Foundry v1.10.0 uses the first six defaults.

#### `deny_warnings`

* Type: boolean
* Default: none
* Deprecated: use `deny = "warnings"` instead

Whether to fail on warnings.

`deny_warnings = true` is read as `deny = "warnings"` and `false` as `deny = "never"`,
unless `deny` is also set in the same profile, in which case `deny` wins. The
`--deny-warnings` flag is deprecated in the same way in favor of `--deny warnings`. In the
environment, use `FOUNDRY_DENY=warnings`.

#### `evm_version`

* Type: string
* Default: `"osaka"`
* Environment: `FOUNDRY_EVM_VERSION`, `DAPP_EVM_VERSION`, or `DAPP_TEST_EVM_VERSION`

The EVM version to compile contracts for and, unless `hardfork` is set, to execute them
with.

The value is an Ethereum hardfork name: `homestead`, `tangerineWhistle`, `spuriousDragon`,
`byzantium`, `constantinople`, `petersburg`, `istanbul`, `berlin`, `london`, `paris`,
`shanghai`, `cancun`, `prague`, `osaka` or `amsterdam` (case-insensitive). It is passed to
the compiler and, when `hardfork` is unset and a fork doesn't determine the hardfork,
selects the EVM rules used by `forge test` and `forge script`.

If the selected compiler version doesn't support the configured EVM version, the newest one
it supports is used for compilation. Pin the version if you rely on it for compatibility,
since the default follows new hardforks:

```toml
[profile.default]
evm_version = "paris"
```

`--evm-version` overrides it for one invocation.

#### `revert_strings`

* Type: string
* Default: none
* Environment: `FOUNDRY_REVERT_STRINGS`, `DAPP_REVERT_STRINGS`, or `DAPP_TEST_REVERT_STRINGS`

How solc handles revert and require reason strings.

Valid values:

* `default`: keeps reason strings you write and doesn't add any generated by the compiler.
* `strip`: removes all reason strings where possible (when they are literals), keeping side
  effects.
* `debug`: adds strings for compiler-generated internal reverts (implemented for ABI
  encoders V1 and V2).
* `verboseDebug`: also appends further information to reason strings you write (not yet
  implemented by solc).

When unset, nothing is passed to solc and its default applies. `--revert-strings` overrides
it for one invocation.

#### `extra_output_files`

* Type: array of string
* Default: `[]`
* Environment: `FOUNDRY_EXTRA_OUTPUT_FILES`, `DAPP_EXTRA_OUTPUT_FILES`, or `DAPP_TEST_EXTRA_OUTPUT_FILES`

Compiler output to write as separate files next to each contract's artifact.

Supported values and the files they produce:

* `abi`: `<Contract>.abi.json`
* `metadata`: `<Contract>.metadata.json`
* `ir`: `<Contract>.ir`
* `irOptimized`: `<Contract>.iropt`
* `ewasm`: `<Contract>.ewasm`
* `evm.assembly`: `<Contract>.asm`
* `evm.legacyAssembly`: `<Contract>.legacyAssembly.json`
* `evm.bytecode.object`: `<Contract>.bin`
* `evm.deployedBytecode.object`: `<Contract>.deployed-bin`
* `evm.bytecode.sourceMap`: `<Contract>.sourcemap`
* `evm.bytecode.generatedSources`: `<Contract>.gensources`

```toml
[profile.default]
extra_output_files = ["metadata"]
```

`extra_output = ["metadata"]` puts the metadata in the contract's JSON artifact, while
`extra_output_files = ["metadata"]` writes it to its own file. See [Contract
Metadata](https://docs.soliditylang.org/en/latest/metadata.html). `--extra-output-files`
replaces it for one invocation.

#### `extra_output`

* Type: array of string
* Default: `[]`
* Environment: `FOUNDRY_EXTRA_OUTPUT`, `DAPP_EXTRA_OUTPUT`, or `DAPP_TEST_EXTRA_OUTPUT`

Additional compiler output to include in each contract's artifact.

Values are solc output selectors, such as `devdoc`, `userdoc`, `storageLayout`,
`transientStorageLayout`, `ir`, `irOptimized`, `irOptimizedAst`, `evm.assembly`,
`evm.legacyAssembly`, `evm.gasEstimates` or `ewasm.wasm`. See the [Solidity compiler
API](https://docs.soliditylang.org/en/latest/using-the-compiler.html#compiler-api) for the
full list.

Forge always requests what it needs, whatever this is set to: `abi`, the bytecode and
deployed bytecode objects, source maps and link references, immutable references, method
identifiers and `metadata`.

```toml
[profile.default]
extra_output = ["storageLayout", "devdoc"]
```

`--extra-output` replaces it for one invocation. To write output to separate files instead,
use `extra_output_files`.

#### `bytecode_hash`

* Type: string
* Default: `"ipfs"`
* Environment: `FOUNDRY_BYTECODE_HASH`, `DAPP_BYTECODE_HASH`, or `DAPP_TEST_BYTECODE_HASH`

The hash of the contract metadata that solc appends to the bytecode.

Valid values:

* `ipfs`: an IPFS hash of the metadata, as solc does by default.
* `bzzr1`: a Swarm hash of the metadata.
* `none`: no hash.

The hash depends on source contents, source paths and compiler settings, so the same
contract can produce different bytecode on different machines. Set `none` for bytecode that
doesn't depend on these, for example for deterministic deployments. This keeps the CBOR
metadata trailer; to omit it entirely, also set `cbor_metadata = false`, or pass
`--no-metadata` to do both. See [https://docs.soliditylang.org/en/latest/metadata.html](https://docs.soliditylang.org/en/latest/metadata.html).

#### `cbor_metadata`

* Type: boolean
* Default: `true`
* Environment: `FOUNDRY_CBOR_METADATA`, `DAPP_CBOR_METADATA`, or `DAPP_TEST_CBOR_METADATA`

Whether to append the CBOR-encoded metadata trailer to the bytecode.

The trailer holds the compiler version and the metadata hash chosen by `bytecode_hash`.
Because the hash is part of the trailer, also set `bytecode_hash = "none"` when disabling
it; `--no-metadata` does both. It requires solc 0.8.18 or later and is ignored for older
versions.

For reproducible CREATE2 addresses, pin the compiler version and settings as described in [Deterministic deployments with CREATE2](/guides/deterministic-deployments-using-create2).

#### `sparse_mode`

* Type: boolean
* Default: `false`
* Environment: `FOUNDRY_SPARSE_MODE`, `DAPP_SPARSE_MODE`, or `DAPP_TEST_SPARSE_MODE`

Has no effect; kept so that existing configuration files still load.

Sparse output selection, which asks solc only for the output of the contracts a command
needs, is applied automatically when `skip` patterns are set.

#### `external_compilers`

* Type: array of table
* Default: `[]`
* Environment: `FOUNDRY_EXTERNAL_COMPILERS`, `DAPP_EXTERNAL_COMPILERS`, or `DAPP_TEST_EXTERNAL_COMPILERS`

External compiler adapters that build compiler-native EVM projects as part of the build.

Adapters let Forge compile languages other than Solidity and Vyper through an executable
that speaks Foundry's adapter protocol. Each entry configures one adapter:

* `id` (required): a unique identifier that namespaces the adapter's artifacts and cache
  entries; ASCII letters, digits, `.`, `-` and `_`, but not `.` or `..`.
* `command` (required): the adapter executable, absolute or relative to the project root.
  It is run directly, without a shell or `PATH` lookup.
* `args`: arguments passed to the executable.
* `roots` (required): the compiler-native project roots, relative to the project root.
* `settings`: a table passed to the adapter as JSON, without interpretation.

```toml
[[profile.default.external_compilers]]
id = "contracts"
command = "/opt/toolchains/fe-foundry-adapter"
roots = ["contracts"]

[profile.default.external_compilers.settings]
compiler = "/opt/toolchains/fe"
```

Artifacts are written under `<out>/.external/<id>/` and compile results are cached under
`<cache_path>/external-compilers/`, so the contracts are available to `forge build`,
`forge test`, `forge script`, `forge inspect` and other commands.

**Warning:** a configured adapter runs with your privileges whenever Forge compiles. Forge
clears its environment and starts it in the project root, but this is not a sandbox.

### Optimizer

Configuration related to the Solidity optimizer.

#### `optimizer`

* Type: boolean
* Default: none
* Environment: `FOUNDRY_OPTIMIZER`, `DAPP_OPTIMIZER`, `DAPP_TEST_OPTIMIZER`, or `DAPP_BUILD_OPTIMIZE`

Whether to enable the Solidity optimizer.

When unset, the optimizer is enabled if `optimizer_runs` is set to a value greater than 0,
and disabled otherwise. Setting it explicitly always wins over that inference.
`optimizer_details` can switch individual optimizer components on or off independently of
this setting.

`--optimize` (or `--optimize=false`) overrides it for one invocation. `forge coverage`
disables the optimizer unless `--ir-minimum` is used.

#### `optimizer_runs`

* Type: integer
* Default: none
* Environment: `FOUNDRY_OPTIMIZER_RUNS`, `DAPP_OPTIMIZER_RUNS`, `DAPP_TEST_OPTIMIZER_RUNS`, or `DAPP_BUILD_OPTIMIZE_RUNS`

How many times each opcode of the deployed code is expected to run over the contract's
lifetime.

This is a trade-off between code size (deployment cost) and execution cost after
deployment. A value of `1` produces short but expensive code; larger values produce longer
but more gas-efficient code. The maximum is `2**32-1`; larger values are rejected.

It does not set how many times the optimizer runs: the optimizer always runs as many times
as it can still improve the code.

If `optimizer` is not set explicitly, a value greater than 0 enables the optimizer. When
neither is set, 200 is used. `--optimizer-runs` overrides it for one invocation.

#### `via_ir`

* Type: boolean
* Default: `false`
* Environment: `FOUNDRY_VIA_IR`, `DAPP_VIA_IR`, or `DAPP_TEST_VIA_IR`

Whether to compile through the Yul intermediate representation (IR) pipeline.

The IR pipeline can optimize across functions and avoid some "stack too deep" errors, but
compiles more slowly. It requires solc 0.7.5 or later and is ignored for older versions. It
is also enabled when `via_ssa_cfg` is set.

`--via-ir` enables it for one invocation. `forge coverage` disables it unless
`--ir-minimum` is used. Per-file overrides are possible with `additional_compiler_profiles`
and `compilation_restrictions`.

#### `use_literal_content`

* Type: boolean
* Default: `false`
* Environment: `FOUNDRY_USE_LITERAL_CONTENT`, `DAPP_USE_LITERAL_CONTENT`, or `DAPP_TEST_USE_LITERAL_CONTENT`

Whether to store the source code itself in the contract metadata instead of only
references.

When enabled, solc embeds the literal content of each source in the metadata instead of
URLs to it, so the metadata is self-contained. `--use-literal-content` enables it for one
invocation.

#### `optimizer_details`

* Type: table
* Default: none
* Environment: `FOUNDRY_OPTIMIZER_DETAILS`, `DAPP_OPTIMIZER_DETAILS`, or `DAPP_TEST_OPTIMIZER_DETAILS`

Switches individual Solidity optimizer components on or off.

The table is passed to solc as `settings.optimizer.details` and uses solc's camelCase key
names. Each key is a boolean; omitted keys keep solc's default:

* `peephole`: the peephole optimizer.
* `inliner`: the inliner (solc 0.8.5 or later).
* `jumpdestRemover`: removes unused jump destinations.
* `orderLiterals`: sometimes reorders literals in commutative operations.
* `deduplicate`: removes duplicate code blocks.
* `cse`: common subexpression elimination.
* `constantOptimizer`: optimizes the representation of literal numbers and strings.
* `yul`: the Yul optimizer, which mostly operates on ABI coder v2 code and inline assembly.
* `simpleCounterForLoopUncheckedIncrement`: unchecked increments of simple loop counters.

The `yulDetails` subtable tunes the Yul optimizer:

* `stackAllocation`: improves the allocation of stack slots by freeing them up earlier.
* `optimizerSteps`: the sequence of optimizer steps to apply.

```toml
[profile.default.optimizer_details]
constantOptimizer = true
yul = true

[profile.default.optimizer_details.yulDetails]
stackAllocation = true
optimizerSteps = "dhfoDgvulfnTUtnIf"
```

The details apply even when `optimizer` is unset. If compiling with `via_ir` fails, try
enabling `optimizer` and setting `optimizerSteps` to an empty string. See
[https://docs.soliditylang.org/en/latest/using-the-compiler.html#input-description](https://docs.soliditylang.org/en/latest/using-the-compiler.html#input-description) for the
defaults.

The `optimizer_details` table is used to tweak how the Solidity optimizer behaves. There are several configurable values in this section (each of them are booleans):

* `peephole`
* `inliner`
* `jumpdestRemover`
* `orderLiterals`
* `deduplicate`
* `cse`
* `constantOptimizer`
* `yul`

Refer to the Solidity [compiler input description](https://docs.soliditylang.org/en/latest/using-the-compiler.html#compiler-input-and-output-json-description) for the default values.

##### `[optimizer_details.yul_details]`

The Yul details subsection of the optimizer details section is used to tweak how the new IR optimizer behaves. There are two configuration values:

* `stack_allocation`: Tries to improve the allocation of stack slots by freeing them up earlier.
* `optimizer_steps`: Selects the optimizer steps to be applied.

Refer to the Solidity [compiler input description](https://docs.soliditylang.org/en/latest/using-the-compiler.html#compiler-input-and-output-json-description) for the default values.

> ℹ️ **Note**
> If you encounter compiler errors when using `via_ir`, explicitly enable the legacy `optimizer` and leave `optimizer_steps` as an empty string

### Model checker

The Solidity model checker is a built-in opt-in module that is available in Solidity compilers for OSX and Linux. Learn more about the model checker in the [Solidity compiler documentation](https://docs.soliditylang.org/en/latest/smtchecker.html#tutorial)

> ℹ️ **Note**
> The model checker requires `z3` version 4.8.8 or 4.8.14 on Linux.

The model checker settings are configured in the `[model_checker]` section of the configuration.

The model checker will run when `forge build` is invoked, and any findings will show up as warnings.

These are the recommended settings when using the model checker:

```toml
[profile.default.model_checker]
contracts = {'/path/to/project/src/Contract.sol' = ['Contract']}
engine = 'chc'
timeout = 10000
targets = ['assert']
```

Setting which contract should be verified is extremely important, otherwise all available contracts will be verified which may take a long time.

The recommended engine is `chc`, but `bmc` and `all` (which runs both) are also accepted.

It is also important to set a proper timeout (given in milliseconds), since the default time given to the underlying solver may not be enough.

If no verification targets are given, only assertions will be checked.

#### `model_checker`

* Type: table
* Default: none
* Environment: `FOUNDRY_MODEL_CHECKER`, `DAPP_MODEL_CHECKER`, or `DAPP_TEST_MODEL_CHECKER`

Settings for the Solidity SMTChecker, a formal verification module built into solc.

When set, the model checker runs during `forge build` and its findings are reported as
compiler warnings. It is available in solc 0.8.7 or later on macOS and Linux, and needs the
SMT solvers it uses (such as z3) to be installed.

The table uses solc's keys:

* `contracts`: the contracts to check, as a table from source path to contract names.
  Without it every contract is checked, which can take a long time.
* `engine`: `chc` (constrained Horn clauses, recommended), `bmc` (bounded model checker),
  `all` (both) or `none`. solc runs no engine unless one is set.
* `timeout`: the solver timeout per query, in milliseconds.
* `targets`: what to check: `assert`, `underflow`, `overflow`, `divByZero`,
  `constantCondition`, `popEmptyArray`, `outOfBounds` and `balance`. When omitted, Forge
  checks only `assert`, unlike solc, which checks all targets.
* `invariants`: invariants to report: `contract` and `reentrancy` (solc 0.8.10 or later).
* `solvers`: `cvc4`, `eld` (solc 0.8.18 or later), `smtlib2` and `z3`.
* `showUnproved`, `showUnsupported` and `showProvedSafe`: whether to report unproved
  targets, unsupported language features and targets proved safe (the last two need solc
  0.8.20).
* `divModWithSlacks`: whether to encode division and modulo with slack variables.

The `show*` and `divModWithSlacks` keys also accept snake\_case names.

```toml
[profile.default.model_checker]
contracts = { "src/Contract.sol" = ["Contract"] }
engine = "chc"
timeout = 10000
targets = ["assert"]
```

See the [SMTChecker documentation](https://docs.soliditylang.org/en/latest/smtchecker.html).

The following keys are available in the model checker section.

##### `model_checker.contracts`

* Type: table
* Default: all
* Environment: N/A

Specifies what contracts the model checker will analyze.

The key of the table is the path to a source file, and the value is an array of contract names to check.

For example:

```toml
[profile.default.model_checker]
contracts = { "src/MyContracts.sol" = ["ContractA", "ContractB"] }
```

##### `model_checker.div_mod_with_slacks`

* Type: boolean
* Default: false
* Environment: N/A

Sets how division and modulo operations should be encoded.

Refer to the [Solidity documentation](https://docs.soliditylang.org/en/latest/smtchecker.html#division-and-modulo-with-slack-variables) for more information.

##### `model_checker.engine`

* Type: string (see below)
* Default: all
* Environment: N/A

Specifies the model checker engine to run. Valid values are:

* `chc`: The constrained horn clauses engine
* `bmc`: The bounded model checker engine
* `all`: Runs both engines

Refer to the [Solidity documentation](https://docs.soliditylang.org/en/latest/smtchecker.html#model-checking-engines) for more information on the engines.

##### `model_checker.invariants`

* Type: array of strings
* Default: N/A
* Environment: N/A

Sets the model checker invariants. Valid values are:

* `contract`: Contract Invariants
* `reentrancy`: Reentrancy Properties

Refer to the [Solidity documentation](https://docs.soliditylang.org/en/latest/smtchecker.html#reported-inferred-inductive-invariants) for more information on the invariants.

##### `model_checker.show_unproved`

* Type: boolean
* Default: false
* Environment: N/A

Whether or not to output all unproved targets.

Refer to the [Solidity documentation](https://docs.soliditylang.org/en/latest/smtchecker.html#unproved-targets) for more information.

##### `model_checker.solvers`

* Type: array of strings
* Default: N/A
* Environment: N/A

Sets the model checker solvers. Valid values are:

* `cvc4`
* `eld`: introduced in v0.8.18
* `smtlib2`
* `z3`

Refer to the [Solidity documentation](https://docs.soliditylang.org/en/latest/smtchecker.html#smt-and-horn-solvers) for more information.

##### `model_checker.timeout`

* Type: number (milliseconds)
* Default: N/A
* Environment: N/A

Sets the timeout for the underlying model checker engines (in milliseconds).

##### `model_checker.targets`

* Type: array of strings
* Default: assert
* Environment: N/A

Sets the model checker targets. Valid values are:

* `assert`: Assertions
* `underflow`: Arithmetic underflow
* `overflow`: Arithmetic overflow
* `divByZero`: Division by zero
* `constantCondition`: Trivial conditions and unreachable code
* `popEmptyArray`: Popping an empty array
* `outOfBounds`: Out of bounds array/fixed bytes index access
* `default`: All of the above (note: not the default for Forge)

### Compilation Restrictions

Compilation restrictions allows configuration of how individual files or directories within projects are compiled.

> For a complex configuration of compiler profiles and compiler restrictions please refer to Uniswap [contracts monorepo](https://github.com/Uniswap/contracts/blob/4d80a9cfed9b920b83a394b168a95319606a0b73/foundry.toml#L27-L72).

For example, with configuration below, `Counter.sol` contract under `src` is compiled with `via-ir` option enabled while all other contracts (including tests) are compiled with the default profile.

```toml
# add via_ir profile
additional_compiler_profiles = [ { name = "via-ir", via_ir = true } ]

# enforce compiling tests without via_ir and only some heavy contract with via_ir
# note: it will only work if tests are using vm.deployCode to deploy contract
compilation_restrictions = [
    { paths = "test/**", via_ir = false },
    { paths = "src/Counter.sol", via_ir = true },
]
```

We can configure how individual files or directories are compiled by specifying the `compilation_restrictions` configuration (which applies to sources importing the restricted file as well).\
Once we have a set of restrictions we need to construct settings objects to satisfy them. This is done by adding `additional_compiler_profiles`, which is a mapping from profile name to settings overrides.

In the example above, we added a single profile named `via-ir` which uses default compilation settings but enables `via_ir` option, making it possible to compile the `Counter.sol` contract with `via_ir`, while all other contracts (including tests) with the default profile.\
When choosing compiler profile, first profile (starting with default one) satisfying restrictions of the source file and all of its imports will be used.

> If the same source file is compiled with several profiles, then an artifact is generated for each profile - if `Counter` is compiled with default and `v1` profile, `Counter.json` and `Counter.v1.json` artifacts are created.

#### `additional_compiler_profiles`

* Type: array of table
* Default: `[]`
* Environment: `FOUNDRY_ADDITIONAL_COMPILER_PROFILES`, `DAPP_ADDITIONAL_COMPILER_PROFILES`, or `DAPP_TEST_ADDITIONAL_COMPILER_PROFILES`

Extra compiler settings profiles that sources can be compiled with besides the main
settings.

Each entry starts from the active profile's compiler settings and overrides only the fields
it sets:

* `name` (required): the profile's name, used in artifact names.
* `via_ir`: whether to compile through the IR pipeline.
* `evm_version`: the target EVM version, also applied to Vyper sources.
* `optimizer`: whether to enable the optimizer.
* `optimizer_runs`: the optimizer runs; a value above `0` also enables the optimizer unless
  `optimizer` is set.
* `bytecode_hash`: the metadata hash method: `ipfs`, `bzzr1` or `none`.

For each source file Forge uses the first profile, starting with the main settings, that
satisfies the `compilation_restrictions` of the file and of all its imports. A file
compiled with several profiles gets one artifact per profile, such as `Counter.json` for
the main settings and `Counter.via-ir.json` for a profile named `via-ir`.

```toml
[profile.default]
additional_compiler_profiles = [{ name = "via-ir", via_ir = true }]
compilation_restrictions = [{ paths = "src/Heavy.sol", via_ir = true }]
```

Configures a mapping from profile name to settings overrides.

For example, an additional `via-ir` compiler profile that changes compilation pipeline to go through the new IR optimizer can be defined as:

```toml
additional_compiler_profiles = [ { name = "via-ir", via_ir = true } ]
```

There are several configurable values for a compiler profile:

* `name`
* `via_ir`
* `evm_version`
* `optimizer`
* `optimizer_runs`
* `bytecode_hash`

##### `additional_compiler_profile.name`

* Type: string

Additional compiler profile name.

##### `additional_compiler_profile.via_ir`

* Type: boolean
* Default: inherits `via_ir` from the active profile

Additional compiler profile [via\_ir](/config/reference/solidity-compiler#via_ir) setting.

##### `additional_compiler_profile.evm_version`

* Type: string
* Default: inherits `evm_version` from the active profile

Additional compiler profile [evm\_version](/config/reference/solidity-compiler#evm_version) setting.

##### `additional_compiler_profile.optimizer`

* Type: boolean
* Default: inherits `optimizer` from the active profile

Additional compiler profile [optimizer](/config/reference/solidity-compiler#optimizer) setting. Setting a positive `optimizer_runs` enables the optimizer unless this profile explicitly sets `optimizer`.

##### `additional_compiler_profile.optimizer_runs`

* Type: integer
* Default: inherits `optimizer_runs` from the active profile

Additional compiler profile [optimizer\_runs](/config/reference/solidity-compiler#optimizer_runs) setting.

##### `additional_compiler_profile.bytecode_hash`

* Type: string
* Default: inherits `bytecode_hash` from the active profile

Additional compiler profile [bytecode\_hash](/config/reference/solidity-compiler#bytecode_hash) setting.

#### `compilation_restrictions`

* Type: array of table
* Default: `[]`
* Environment: `FOUNDRY_COMPILATION_RESTRICTIONS`, `DAPP_COMPILATION_RESTRICTIONS`, or `DAPP_TEST_COMPILATION_RESTRICTIONS`

Restrictions on the compiler settings that matching source files may be compiled with.

A restriction applies to the files matched by `paths` and to every file that imports them.
Forge compiles each file with the first settings profile (the main settings, then
`additional_compiler_profiles` in order) that satisfies all restrictions that apply to it.
Fields:

* `paths` (required): a glob matched against source paths, absolute or relative to the
  project root, such as `src/Counter.sol`, `src/{Counter,Factory}.sol` or `src/v1/**`.
* `version`: a solc version requirement with an explicit operator, such as `=0.8.11`,
  `>=0.8.11` or `>=0.8.11 <0.9.0`; bare versions such as `0.8.11` are rejected.
* `via_ir`: the required `via_ir` setting.
* `bytecode_hash`: the required metadata hash method.
* `optimizer_runs`, or a range with `min_optimizer_runs` and/or `max_optimizer_runs`.
* `evm_version`, or a range with `min_evm_version` and/or `max_evm_version`.

An exact value cannot be combined with a minimum or maximum for the same setting. When
several entries match a file, their restrictions are merged; if they conflict, Forge warns
and keeps the first.

```toml
[profile.default]
additional_compiler_profiles = [{ name = "via-ir", via_ir = true }]
compilation_restrictions = [
    { paths = "test/**", via_ir = false },
    { paths = "src/Counter.sol", via_ir = true },
]
```

Because restrictions extend to importing files, a test that imports a restricted contract
must satisfy the same restrictions unless it deploys the contract without importing it, for
example with `vm.deployCode`.

##### `compilation_restriction.paths`

* Type: regex

Only applies compilation restrictions on files matching given paths.

For example:

* `src/contracts/Counter.sol` - apply restrictions for specific contract
* `src/contracts/{Counter,CounterFactory}.sol` - apply restrictions for multiple contracts, by name
* `src/v1/**` or `src/v3/**/libraries/**` - apply restrictions for all contracts in matching source path

There are several configurable values for an compilation restriction:

* `version`
* `via_ir`
* `bytecode_hash`
* `optimizer_runs`
* `min_optimizer_runs`
* `max_optimizer_runs`
* `evm_version`
* `min_evm_version`
* `max_evm_version`

##### `compilation_restriction.version`

* Type: string (semver)

Restrict compilation for a specific [`solc`](/config/reference/solidity-compiler#solc) version.

##### `compilation_restriction.via_ir`

* Type: boolean

Restrict compilation for specific [via\_ir](/config/reference/solidity-compiler#via_ir) setting.

##### `compilation_restriction.bytecode_hash`

* Type: string

Restrict compilation matching provided bytecode hash method.

##### `compilation_restriction.optimizer_runs`

* Type: integer

Restrict compilation for specific [optimizer\_runs](/config/reference/solidity-compiler#optimizer_runs) setting. Conflicts with `min_optimizer_runs` and `max_optimizer_runs` settings.

##### `compilation_restriction.min_optimizer_runs`

* Type: integer

Restrict compilation for min of [optimizer\_runs](/config/reference/solidity-compiler#optimizer_runs) setting. Conflicts with `optimizer_runs` setting, requires `max_optimizer_runs` setting.

##### `compilation_restriction.max_optimizer_runs`

* Type: integer

Restrict compilation for max of [optimizer\_runs](/config/reference/solidity-compiler#optimizer_runs) setting. Conflicts with `optimizer_runs` setting, requires `min_optimizer_runs` setting.

##### `compilation_restriction.evm_version`

* Type: string

Restrict compilation for specific [evm\_version](/config/reference/solidity-compiler#evm_version) setting. Conflicts with `min_evm_version` and `max_evm_version` settings.

##### `compilation_restriction.min_evm_version`

* Type: string

Restrict compilation for a min version of [evm\_version](/config/reference/solidity-compiler#evm_version) setting. Conflicts with `evm_version` setting, requires `max_evm_version` setting.

##### `compilation_restriction.max_evm_version`

* Type: string

Restrict compilation for a max version of [evm\_version](/config/reference/solidity-compiler#evm_version) setting. Conflicts with `evm_version` setting, requires `min_evm_version` setting.
