Skip to content

slither-read-storage: auto-detect and accept solc Standard JSON input files - #3074

Open
Aravinds2511 wants to merge 1 commit into
crytic:masterfrom
Aravinds2511:fix-2777-read-storage-standard-json
Open

slither-read-storage: auto-detect and accept solc Standard JSON input files#3074
Aravinds2511 wants to merge 1 commit into
crytic:masterfrom
Aravinds2511:fix-2777-read-storage-standard-json

Conversation

@Aravinds2511

Copy link
Copy Markdown

Fixes #2777

Problem

slither-read-storage rejected any target that wasn't a .sol file or a
project directory. Feeding it a solc Standard JSON input file (as produced by
solc --standard-json, or hand-built, per the Standard JSON input
format
)
failed with:

slither.exceptions.SlitherError: Invalid compilation:
0424.json is not the expected format '.sol'

Root cause

The error comes from crytic-compile's Solc platform, which only accepts
.sol files. crytic-compile already ships a SolcStandardJson platform
(NAME = "Solc-json") that reads a Standard JSON input file directly, but
it's never auto-selected for .json targets — its is_supported() is
inherited unchanged from Solc (target.endswith(".sol")). The only way to
reach it today is the undocumented --compile-force-framework solc-json flag.

Fix

slither-read-storage's main() now checks whether the given target is a
.json file 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 to solc-json automatically. Detection
is safe on missing files, non-JSON files, and malformed JSON — it just
returns False and falls through to the original, clear error message.

Docs updated in docs/src/tools/ReadStorage.md to document the new
contract_source behavior 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 (valid
    Standard 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 real
    slither-read-storage CLI once against a .sol file and once against an
    equivalent Standard JSON file with no extra flags, and asserts the
    resulting storage layouts are identical.
$ pytest tests/tools/read-storage/test_read_storage.py -k "standard_json" -v

tests/tools/read-storage/test_read_storage.py::test_is_solc_standard_json[StorageLayout.sol-False] PASSED
tests/tools/read-storage/test_read_storage.py::test_is_solc_standard_json[not_standard.json-False] PASSED
tests/tools/read-storage/test_read_storage.py::test_is_solc_standard_json[standard_json_input.json-True] PASSED
tests/tools/read-storage/test_read_storage.py::test_read_storage_from_standard_json PASSED

4 passed, 2 deselected in 1.31s

Manual verification, reproducing the exact scenario from the issue:

$ uv run slither-read-storage 0424.json --contract-name TestVariables --json out.json

INFO:Slither-read-storage:
Contract 'TestVariables'
TestVariables.x with type uint256 is located at slot: 0

INFO:Slither-read-storage:
Name: x
Type: uint256
Slot: 0

INFO:Slither-read-storage:
Contract 'TestVariables'
TestVariables.owner with type address is located at slot: 1

INFO:Slither-read-storage:
Name: owner
Type: address
Slot: 1

INFO:Slither-read-storage:
Contract 'TestVariables'
TestVariables.paused with type bool is located at slot: 1

INFO:Slither-read-storage:
Name: paused
Type: bool
Slot: 1

$ cat out.json

{
    "x": {
        "name": "x",
        "type_string": "uint256",
        "slot": 0,
        "size": 256,
        "offset": 0,
        "value": null,
        "elems": {}
    },
    "owner": {
        "name": "owner",
        "type_string": "address",
        "slot": 1,
        "size": 160,
        "offset": 0,
        "value": null,
        "elems": {}
    },
    "paused": {
        "name": "paused",
        "type_string": "bool",
        "slot": 1,
        "size": 8,
        "offset": 160,
        "value": null,
        "elems": {}
    }
}

No extra flags required — matches the exact command from the issue report.

Scope note for maintainers

This fix is scoped to slither-read-storage only. A more general fix — giving
SolcStandardJson.is_supported() real content-based detection in
crytic-compile — would let every Slither tool accept Standard JSON targets
directly, not just read_storage. Happy to open a follow-up issue/PR there
if that's of interest.

@Aravinds2511
Aravinds2511 requested a review from smonicas as a code owner August 6, 2026 11:54
@CLAassistant

CLAassistant commented Aug 6, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

slither-read-storage should accept solc Standard JSON

2 participants