Skip to content

Conversation

@GalloDaSballo
Copy link

@GalloDaSballo GalloDaSballo commented Oct 28, 2025

Executive Summary

We use --foundry-compile-all at all times
We want to use differential compilation (recompile only what's necessary)

Test

Change medusa.json[compilation] to:

  "compilation": {
    "platform": "crytic-compile",
    "platformConfig": {
      "target": ".",
      "solcVersion": "",
      "exportDirectory": "",
      "args": [
        "--skip-clean",
        "--foundry-no-force"
      ]
    }
  },

It seems to work as intended and is faster, I have to test it on a bigger codebase.

I also don't believe you should use this push, but likely this will help get it done fairly easily.

NOTE: For some reason (maybe tied to slither), you need to compile all the first time or medusa will crash.

Below comment from Claude

Incremental Compilation Patch for CryticCompile + Medusa

Problem

CryticCompile calls forge clean (deletes out/ folder) and uses --force flag on every compilation, causing full rebuilds even when only minor changes are made. This is slow for iterative fuzzing workflows.

Root Causes

  1. forge clean removes both out/ (artifacts) and cache/ directories
  2. --force flag tells Forge to ignore its cache and recompile everything
  3. Default behavior skips test files (--skip */test/**), so test changes aren't detected
  4. Forge's incremental compilation creates multiple build-info/*.json files, causing CryticCompile to generate multiple compilation units instead of single combined_solc.json that Medusa expects

Solution

Added --foundry-no-force flag that:

  1. Skips forge clean (preserves out/ and cache/)
  2. Removes --force flag (enables Forge's incremental compilation)
  3. Forces compilation of ALL files including tests (ensures test changes detected)
  4. Cleans only out/build-info/ before compilation (prevents multiple compilation units)

Files Changed

  • crytic_compile/cryticparser/defaults.py - Added flag default
  • crytic_compile/cryticparser/cryticparser.py - Added CLI argument
  • crytic_compile/platform/foundry.py - Core implementation

Usage

// medusa.json
{
  "compilation": {
    "platformConfig": {
      "args": ["--skip-clean", "--foundry-no-force"]
    }
  }
}

Result

  • Forge recompiles only changed files (11/45 files on subsequent runs)
  • Properly detects changes in both source and test files
  • Generates single combined_solc.json as expected by Medusa
  • Maintains full compatibility with existing workflows (flags are opt-in)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant