Repository navigation
fix(solidity): link a call attached by using A for T to the function - #5062
rohit-jsfreaky wants to merge 2 commits into
Conversation
Read the declared type of `recv` in `recv.f(..)` and park the call as a
`member` raw call carrying that type, so a later pass can bind it through
the receiver's contract type or the `using` directives in scope. Nothing
binds `member` calls yet, so no edge changes.
A receiver is typed from a parameter, return variable or local of the
calling function (a name declared with two different types is ambiguous
and stays untyped), a state variable of the calling contract, an element
of a typed mapping or array, a field of a struct declared in the same
file, a conversion (`IERC20(a)`, `uint256(x)`, `payable(a)`) or a few
builtins (`msg.sender`, `keccak256(..)`, `abi.encode(..)`). The type is
normalized (`uint` -> `uint256`, whitespace) and a struct, enum or value
type declared in a contract is qualified with that contract's name, so
`Trace208` inside library Checkpoints and `Checkpoints.Trace208` in a
caller compare equal. A type name (`Lib.f()`) is not a typed receiver and
keeps its qualified-call path.
What only the cross-file pass can know is left to it: a state variable
node carries its `declared_type` and a function with one return value
its `returns` type, and `g(..).f()` records the call `g` it is the result
of. resolve_solidity_inherited_calls gains the helpers the binding passes
share: `receiver_types` (the extractor's reading, a base contract's state
variable, or the return type of `g`), `visible_types` (optionally through
re-exporting imports: `import {IERC20} from "./ERC20.sol"`) and a cached
`linearization`.
Co-Authored-By: Claude <[email protected]>
`using SafeCast for uint256; x.toUint48()` and `using EnumerableSet for
EnumerableSet.AddressSet; _set.add(a)` call the library function with
the receiver as its first argument, but the extractor parked
`x.toUint48` as a qualified call on a type named `x`, which never
exists, so no such call got an edge. On OpenZeppelin v5.4.0, 0 of the
228 calls solc resolves through a `using` directive were linked.
Record the directives in scope: a contract's own (`using` is not
inherited since 0.7), the file-level ones, and the `global` ones on a
type's declaration, as `using` metadata on the contract and file nodes,
and give library and free functions their `first_param_type`. The
resolver binds `recv.f(args)`, when the receiver's declared type is
known (the receiver typing of the previous commit, a base contract's
state variable or the return type of `g` in `g().f()`), to a function
`f` that a directive whose target is `*` or that type attaches, with
args + 1 parameters and the receiver's type as its first. The type must
match exactly, including user-defined value types and library structs
(`Trace208` inside Checkpoints reads as `Checkpoints.Trace208`, as a
caller writes it). An operator binding (`using {eq as ==} for T`)
attaches no member.
Fail closed: no edge when the receiver's type is unknown, a directive's
library name is ambiguous, or more than one function fits.
OpenZeppelin v5.4.0 (solc 0.8.28 AST as the answer key): using-for calls
0/228 -> 180/228; solmate: 0/10 -> 6/10. No other kind changes. Most of
the rest are chained calls (`slot.asBoolean().tload()`), calls written
inside a `?:` that tree-sitter parses as the member's object, and 7
calls made inside `_name` functions that share a node with their
`name` counterpart (the `_name` / `name` id merge), which land on that
merged node until the id merge is fixed.
Co-Authored-By: Claude <[email protected]>
|
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. |
There was a problem hiding this comment.
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 3 changed function(s) (1 sampled, not proven, 2 not verified).
Formal verification. PR-changed functions: 1/3 verified (0 proven, 1 may-equivalent, 0 distinguished) · 2 not verified (1 vacuous, 1 unsupported).
Not verified on this run: \_callee\_text (unsupported), resolve\_solidity\_inherited\_calls (vacuous: never exercised).
Graphify review — findings
Extends Solidity call resolution so a member call binds through the receiver's declared type, including state fields, array/mapping element types, and expressions typed on the fly. using {a, b} for T sets and using ... global directives now bind, and inherited calls, emit and revert resolve against the contract's linearized bases, so events and errors declared in a base contract link correctly. Resolution fails closed, emitting no edge when a library name is ambiguous or isn't a type, and bumps _AST_CACHE_SCHEMA to 40 so cached Solidity extractions re-run.
Review partial — this diff was larger than one review pass covers, so later files were not reviewed; some findings may be missing.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3240 functions depend on the 175 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 1154 callers, 68 callees - worse:
resolve_solidity_inherited_calls()— 1 callers, 6 callees
Verification — 3240 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: 1615 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
526 of 526 test file(s) selected (100%) via static blast radius.
Escalated to a full run for safety (
uncovered-code) — the selection is not trustworthy on its own (see below). CI should run the whole suite.
tests/pi.test.ts— full-run-safetytests/test_4874_jvm_resolution.py— full-run-safetytests/test_4909_reference_binding_scale.py— full-run-safetytests/test_4978_reconcile_cost.py— full-run-safetytests/test_4992_ts_import_types.py— full-run-safetytests/test_affected_cli.py— full-run-safetytests/test_affected_defines.py— full-run-safetytests/test_affected_member_seed.py— full-run-safetytests/test_affected_overrides.py— full-run-safetytests/test_affected_path_file_node.py— full-run-safetytests/test_affected_seed_reference_forms.py— full-run-safetytests/test_agents_platform.py— full-run-safetytests/test_alias_folding.py— full-run-safetytests/test_analyze.py— full-run-safetytests/test_anthropic_custom_endpoint.py— full-run-safetytests/test_antigravity_install.py— full-run-safetytests/test_apm_fallback_version.py— full-run-safetytests/test_architecture_doc.py— full-run-safetytests/test_astro_extraction.py— full-run-safetytests/test_astro_import_ids.py— full-run-safetytests/test_atomic_canvas_export.py— full-run-safetytests/test_atomic_version_stamp.py— full-run-safetytests/test_atomic_writes.py— full-run-safetytests/test_backend_env_isolation.py— full-run-safetytests/test_backend_extras.py— full-run-safetytests/test_backend_opt_in.py— full-run-safetytests/test_benchmark.py— full-run-safetytests/test_benchmark_raw_graph.py— full-run-safetytests/test_benchmark_real_query.py— full-run-safetytests/test_binary_media_words.py— impact, full-run-safetytests/test_blade_extractor.py— full-run-safetytests/test_build.py— full-run-safetytests/test_build_located_semantic_identity.py— full-run-safetytests/test_build_merge_dedup_scope.py— full-run-safetytests/test_build_merge_ghost_fold_4955.py— full-run-safetytests/test_build_merge_hyperedges_and_prune.py— full-run-safetytests/test_build_merge_shrink_guard.py— full-run-safetytests/test_builtin_global_type_refs.py— full-run-safetytests/test_c_include_resolution.py— full-run-safetytests/test_cache.py— impact, full-run-safetytests/test_cache_long_paths.py— impact, full-run-safetytests/test_cache_stale_import_target.py— impact, full-run-safetytests/test_cache_windows_case_4925.py— impact, full-run-safetytests/test_callflow_html.py— full-run-safetytests/test_cargo_introspect.py— full-run-safetytests/test_cargo_missing_manifest.py— full-run-safetytests/test_carried_hyperedge_remap.py— full-run-safetytests/test_case_only_decl_ids_4904.py— full-run-safetytests/test_case_sensitive_resolution.py— full-run-safetytests/test_charmap_encoding.py— impact, full-run-safety- … and 476 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.
Docs that may be stale (advisory)
CHANGELOG.md§ 0.9.92 (2026-10-16) (lines 270-295): references changed symbolslinearizationCHANGELOG.md§ 0.9.22 (2026-07-20) (lines 1223-1232): references changed symbolsreachable
Formal verification
Could not verify: Could not verify \_callee\_text.
The verifier did not have enough to check \_callee\_text, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: parameter `callee` is annotated `Node` — outside the synthesizable primitive/collection set
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.
Could not verify: Could not verify resolve\_solidity\_inherited\_calls.
The verifier did not have enough to check resolve\_solidity\_inherited\_calls, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous
· 2 more finding(s) on lines outside this diff (see the check run).
#5058, #5060, #5062, #5054 and #5056 each change per-file Solidity or C# extraction output and each bumped _AST_CACHE_SCHEMA to 40 on their own. Landed together in one release window they share a single bump; this folds their descriptions into one chained schema-40 comment over the prior 39 so a warm cache re-runs the affected Solidity and C# extractions exactly once. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed on |
Closes #5061
What does this PR do?
Calls attached with
using A for Tnow link to the library function:usingcan be: contract-level, file-level, andusing ... for T globalon the type's declaration.using A for *andusing {f, L.g} for T.x.f(args), whenx's declared type matchesT, it binds toA.fwith arityargs + 1. User-defined value types andLibrary.Structtypes match too.Contract and file nodes now carry
using, and library and free functions carryfirst_param_typeandarity. Node ids don't change. AST cache schema 39 -> 40.Diff: +779 / -34 in total (shared commit +417 / -30, fix +364 / -6), 5 new tests.
Numbers
Compared with the solc 0.8.28 AST. Every other kind is unchanged on both projects.
using forcallscallsedges, OZ / solmateThe 7 extra wrong edges on OZ are calls inside functions like
_setGrantDelay, which share a node with their public twin on v8 (#5058). With #5058 applied too,using foris 187/228 with 0 wrong edges. Most of the rest fail closed because types must match exactly (auint64value passed where the library takesuint256), plus chained calls.Limitations
slot.asBoolean().tload()are not typed.?:are not read (an existing parser gap).Type of change
Verification & Invariants
Invariant: a
usinglink is added only when ausing A for Tdirective is in scope, the receiver's declared type is exactlyT, and exactly oneA.ftakesargs + 1parameters.How was this tested?
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (Not needed: no skill fragments changed.)🤖 Generated with Claude Code