Skip on-disk filename verification for standard json sources#686
Skip on-disk filename verification for standard json sources#686arpitjain099 wants to merge 1 commit into
Conversation
Standard json source paths are virtual keys that can be provided inline via content, so they need not exist on disk. parse_standard_json_output called convert_filename, which ran _verify_filename_existence and raised InvalidCompilation for absent files. Add an opt-in skip_filename_verification parameter to convert_filename and pass it on the standard json path. Default behavior is unchanged for all other platforms. The previous skip_filename branches were dead code (both arms identical) and are removed. Fixes crytic#495 Signed-off-by: Arpit Jain <[email protected]>
|
Hi! Do you have any real-life examples (eg foundry project or similar) where these virtual files are used? I'm trying to understand why is this change needed. Typically the files exist on disk, as you need them for foundry et al to compile your project. |
|
Good question. The case where the source files never exist on disk is standard-json input whose sources are provided inline through the
In all of these the compiler is given the sources via |
Fixes #495
Problem
When compiling a solc standard json input,
parse_standard_json_outputcallsconvert_filenamefor every source path.convert_filenameruns_verify_filename_existence, which requires the path to exist on disk. For standard json, the source keys are virtual: the sources can be provided inline viacontent, so they often do not map to real files. As a result, a valid standard json compilation raisesInvalidCompilation: Unknown file: ....The issue reporter hits this directly:
parse_standard_json_outputalready carried askip_filenameflag, but itsif/elsebranches were identical, so it had no effect.Fix
convert_filenamegains an opt-inskip_filename_verification: bool = Falseparameter. When True it bypasses the on-disk_verify_filename_existencecheck and keeps the rest of the path normalization unchanged. Default behavior is untouched, so every other platform (solc, hardhat, foundry, etc.) keeps verifying filenames exactly as before.parse_standard_json_outputnow passesskip_filename_verification=Truefor both thesourcesandcontractspaths, and the dead identical branches are removed.Before / after
Reproduction (mocking the solc invocation so no solc binary is needed), source
main.solprovided inline and absent from disk:Before:
After:
Tests
tests/test_solc_standard_json.py::test_standard_json_does_not_verify_virtual_filenames: end-to-end regression test throughCryticCompile(SolcStandardJson(...))with the solc call mocked. Fails on the currentmasterwithInvalidCompilation: Unknown file: main.sol, passes with the fix.tests/test_naming.py: two unit tests forconvert_filename, one assertingskip_filename_verification=Truereturns aFilenamefor a path absent on disk, one asserting the default still raisesInvalidCompilationfor a missing file (guards the non-standard-json paths that rely on verification).All previously passing tests continue to pass. The tests that fail in my environment fail identically on pristine
masterbecause they require a realsolcbinary or network access.