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)

GalloDaSballo and others added 2 commits January 20, 2026 11:10
- Move shutil import to top of file
- Update clean() to skip when foundry_no_force is set
- Update help text to clarify the flag's behavior

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@dguido dguido force-pushed the experimental-skip-foundry-full branch from 6104232 to 2e4114f Compare January 20, 2026 16:17
Copy link
Member

@elopez elopez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently have a skip clean flag, maybe it should be harmonized with the foundry implementation to drop the force in that case.

Comment on lines +117 to +123
if no_force:
compile_all = True
out_dir = foundry_config.out_path if foundry_config else "out"
build_info_dir = Path(self._project_root, out_dir, "build-info")
if build_info_dir.exists():
shutil.rmtree(build_info_dir)
LOGGER.info("Cleaned %s for fresh build-info generation", build_info_dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this goes against the objective described on the PR.

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.

3 participants