Skip to content

fix(solidity): resolve ../ imports to the real file - #4985

Closed
rohit-jsfreaky wants to merge 1 commit into
Graphify-Labs:v8from
rohit-jsfreaky:fix/solidity-relative-imports
Closed

rohit-jsfreaky wants to merge 1 commit into
Graphify-Labs:v8from
rohit-jsfreaky:fix/solidity-relative-imports

Conversation

@rohit-jsfreaky

@rohit-jsfreaky rohit-jsfreaky commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #4984

What does this PR do?

While checking Solidity calls on OpenZeppelin I saw most imports going nowhere. The extractor joined the import path to the file's folder without normalising it, so import "../utils/Errors.sol" in contracts/proxy/Clones.sol pointed at contracts/proxy/utils/errors.sol, a stub that does not exist, and that stub's id even kept my checkout's absolute path.

The fix is one line: Path(os.path.normpath(path.parent / relative)), which is what the other extractors in extract.py already do. I added a regression test and bumped the AST cache schema (36 to 37) because Solidity output changes.

On OpenZeppelin Contracts v5.4.0 (319 files):

before after
imports that reach the real file 87 / 681 681 / 681
node ids with the checkout path in them 594 0

I also compared call links against the solc 0.8.28 AST before and after: same, inherited, super and modifier counts are identical, so nothing that worked before changed.

Not covered: remapped imports like @openzeppelin/contracts/... need the project's remappings, so I left them out.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: a Solidity imports_from edge targets the file the import names, using the same normalised path the file node is built from, so ids stay relative to the scan root. ./x.sol and http(s) imports behave as before.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

How was this tested?

uv run --frozen pytest -q tests/test_solidity_extractor.py      # 9 passed; the new test fails on v8 (fix stashed) and passes with it
uv run --frozen pytest -q <the 2 test files that mention solidity>   # 17 passed
uv run --frozen pytest -q tests/test_cache*.py                  # 1 failure, test_warm_cache_keeps_target_and_symlink_sources_distinct, same on v8 (Windows symlink)
uv run --frozen ruff check graphify/extractors/solidity.py tests/test_solidity_extractor.py   # clean
uv run --frozen pyright graphify/extractors/solidity.py         # 1 error, the same 1 as v8
graphify update . on OpenZeppelin v5.4.0, before and after      # numbers above

I did not run the full suite locally (low RAM on my laptop); CI runs it here.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (Not needed: no skill fragments changed.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

A Solidity import was joined to the importer's folder without normalising it,
so `import "../utils/Errors.sol"` from contracts/proxy/ pointed at a dangling
contracts/proxy/utils/errors.sol stub whose id kept the checkout's absolute path.
Normalise the joined path like the other extractors do (os.path.normpath).
OpenZeppelin Contracts v5.4.0: 87 -> 681 of 681 Solidity imports_from edges reach
a real file; no node ids carry the checkout path any more.

Co-Authored-By: Claude <[email protected]>
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Thanks for the pull request, @rohit-jsfreaky. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 3, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify reviewed this change.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 sampled, not proven).

Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.


Graphify review — findings

Fixes Solidity relative imports such as import "../x/Y.sol" so they resolve to the real file, instead of a dangling stub that kept the importer's own folder. The Solidity extractor also gets related edits to inherited-call and type-reference resolution, with tests covering enum values, free-function using sets and contract members and calls. Bumps _AST_CACHE_SCHEMA to 37, so cached Solidity extractions re-run once on the next build.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 3035 functions depend on the 126 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1116 callers, 66 callees

Verification — 3035 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 1538 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

501 of 501 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • tests/pi.test.ts — full-run-safety
  • tests/test_4874_jvm_resolution.py — full-run-safety
  • tests/test_4909_reference_binding_scale.py — full-run-safety
  • tests/test_affected_cli.py — full-run-safety
  • tests/test_affected_defines.py — full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_affected_overrides.py — full-run-safety
  • tests/test_affected_path_file_node.py — full-run-safety
  • tests/test_affected_seed_reference_forms.py — full-run-safety
  • tests/test_agents_platform.py — full-run-safety
  • tests/test_alias_folding.py — full-run-safety
  • tests/test_analyze.py — full-run-safety
  • tests/test_anthropic_custom_endpoint.py — full-run-safety
  • tests/test_antigravity_install.py — full-run-safety
  • tests/test_apm_fallback_version.py — full-run-safety
  • tests/test_architecture_doc.py — full-run-safety
  • tests/test_astro_extraction.py — full-run-safety
  • tests/test_astro_import_ids.py — full-run-safety
  • tests/test_atomic_canvas_export.py — full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — full-run-safety
  • tests/test_backend_env_isolation.py — full-run-safety
  • tests/test_backend_extras.py — full-run-safety
  • tests/test_backend_opt_in.py — full-run-safety
  • tests/test_benchmark.py — full-run-safety
  • tests/test_benchmark_raw_graph.py — full-run-safety
  • tests/test_benchmark_real_query.py — full-run-safety
  • tests/test_binary_media_words.py — impact, full-run-safety
  • tests/test_blade_extractor.py — full-run-safety
  • tests/test_build.py — full-run-safety
  • tests/test_build_located_semantic_identity.py — full-run-safety
  • tests/test_build_merge_dedup_scope.py — full-run-safety
  • tests/test_build_merge_hyperedges_and_prune.py — full-run-safety
  • tests/test_build_merge_shrink_guard.py — full-run-safety
  • tests/test_builtin_global_type_refs.py — full-run-safety
  • tests/test_c_include_resolution.py — full-run-safety
  • tests/test_cache.py — impact, full-run-safety
  • tests/test_cache_long_paths.py — impact, full-run-safety
  • tests/test_cache_stale_import_target.py — impact, full-run-safety
  • tests/test_cache_windows_case_4925.py — impact, full-run-safety
  • tests/test_callflow_html.py — full-run-safety
  • tests/test_cargo_introspect.py — full-run-safety
  • tests/test_cargo_missing_manifest.py — full-run-safety
  • tests/test_carried_hyperedge_remap.py — full-run-safety
  • tests/test_case_only_decl_ids_4904.py — full-run-safety
  • tests/test_case_sensitive_resolution.py — full-run-safety
  • tests/test_charmap_encoding.py — impact, full-run-safety
  • tests/test_chunking.py — impact, full-run-safety
  • tests/test_cjs_module_extension.py — full-run-safety
  • tests/test_claude_cli_backend.py — full-run-safety
  • … and 451 more

changed code file(s) with no mapped test (graphify/extractors/solidity.py) — a coverage gap or a missing link — running the full suite rather than only the selected tests

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

No difference found (not proven): No behavior difference found in extract\_solidity (not a proof).

The verifier ran both versions of extract\_solidity on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 1 more finding(s) on lines outside this diff (see the check run).

@safishamsi safishamsi closed this in 924be16 Nov 3, 2026
@safishamsi

Copy link
Copy Markdown
Member

Shipped in 0.9.102 (published to PyPI), with your authorship preserved. Fixes #4984. Thanks @rohit-jsfreaky.

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

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Solidity: an import with ../ points at a dangling stub instead of the real file

2 participants