slither-read-storage: auto-detect and accept solc Standard JSON input files - #3074
Open
Aravinds2511 wants to merge 1 commit into
Open
slither-read-storage: auto-detect and accept solc Standard JSON input files#3074Aravinds2511 wants to merge 1 commit into
Aravinds2511 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2777
Problem
slither-read-storagerejected any target that wasn't a.solfile or aproject directory. Feeding it a solc Standard JSON input file (as produced by
solc --standard-json, or hand-built, per the Standard JSON inputformat)
failed with:
Root cause
The error comes from crytic-compile's
Solcplatform, which only accepts.solfiles. crytic-compile already ships aSolcStandardJsonplatform(
NAME = "Solc-json") that reads a Standard JSON input file directly, butit's never auto-selected for
.jsontargets — itsis_supported()isinherited unchanged from
Solc(target.endswith(".sol")). The only way toreach it today is the undocumented
--compile-force-framework solc-jsonflag.Fix
slither-read-storage'smain()now checks whether the given target is a.jsonfile containing the two keys that define a solc Standard JSON input(
"language","sources"). If so, and the user hasn't already passed--compile-force-framework, it's set tosolc-jsonautomatically. Detectionis safe on missing files, non-JSON files, and malformed JSON — it just
returns
Falseand falls through to the original, clear error message.Docs updated in
docs/src/tools/ReadStorage.mdto document the newcontract_sourcebehavior and add a usage example.Testing
Added to
tests/tools/read-storage/test_read_storage.py:test_is_solc_standard_json— unit tests of the detection helper (validStandard JSON, non-standard JSON, non-JSON file, missing file, malformed
JSON syntax).
test_read_storage_from_standard_json— end-to-end test that runs the realslither-read-storageCLI once against a.solfile and once against anequivalent Standard JSON file with no extra flags, and asserts the
resulting storage layouts are identical.
Manual verification, reproducing the exact scenario from the issue:
No extra flags required — matches the exact command from the issue report.
Scope note for maintainers
This fix is scoped to
slither-read-storageonly. A more general fix — givingSolcStandardJson.is_supported()real content-based detection incrytic-compile— would let every Slither tool accept Standard JSON targetsdirectly, not just
read_storage. Happy to open a follow-up issue/PR thereif that's of interest.