Skip to content

Inconsistent behavior of compilation restrictions when using --extra-output-files flag #13057

@RayXpub

Description

@RayXpub

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge Version: 1.5.1-stable

What version of Foundryup are you on?

foundryup: 1.5.0

What command(s) is the bug in?

forge build --extra-output-files bin

Operating System

macOS (Apple Silicon)

Describe the bug

When using forge build --extra-output-files bin with contracts compiled by multiple profiles via additional_compiler_profiles and compilation_restrictions, Forge correctly generates multiple .json artifacts but only generates a single .bin file containing the bytecode from the additional profile, instead of generating a .bin file for each profile.

Steps to reproduce

  1. Clone the reproduction repository: https://github.com/RayXpub/foundry_compilation_restrictions_example/tree/main
  2. Build with extra output files:
forge build --extra-output-files bin
  1. Inspect the artifacts for Counter.sol

Expected behavior

Based on the Foundry documentation:

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.

I would expect that when using --extra-output-files bin, the same convention applies to .bin files. Since Counter.sol is compiled with:

  • Default profile (200 optimizer runs)
  • optimized-runs profile (100,000 optimizer runs)

The output should include:

  • Counter.json (default profile)
  • Counter.optimized-runs.json (optimized profile)
  • Invalid: Counter.bin (generated with optimized profile bytecode)
  • Missing: Counter.optimized-runs.bin (optimized profile bytecode)

Actual behavior

Only a single .bin file is generated:

out/Counter.sol/
├── Counter.bin                      # Contains optimized bytecode (100,000 runs)
├── Counter.json                     # Default profile artifact (200 runs)
└── Counter.optimized-runs.json      # Optimized profile artifact (100,000 runs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-bugType: bugT-needs-triageType: this issue needs to be labelled

    Type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions