Repository navigation
fix(solidity): keep _name and name apart in node ids - #5058
rohit-jsfreaky wants to merge 1 commit into
Conversation
make_id strips a leading `_` (and folds case), so in one contract `_grantRole(bytes32,address)` and `grantRole(bytes32,address)` minted ONE id. add_node kept the first declaration and dropped the second: the `_` function vanished from the graph, and every call it makes, and every call to it, landed on its public twin. OpenZeppelin v5.4.0 has 38 such pairs (`_grantRole`, `_transferOwnership`, `_safeTransferFrom`, ...), which made 104 of graphify's `calls` edges ones the compiler does not have. Apply the rule C# got in Graphify-Labs#4415 (and Python in Graphify-Labs#3302): group the members of a contract (functions, modifiers, events, errors, state variables, structs, enums), the file's free functions and the file's types by the id they would get, and run each through `_underscore_salted_nid`. The one public name keeps the plain id and every other spelling of the group is salted, so the outcome does not depend on declaration order. A name without a colliding sibling keeps its id, so only the `_` spelling of a clashing pair gets a new one. OpenZeppelin v5.4.0 (solc 0.8.28 AST as the answer key): 3907 -> 3945 nodes, 38 new ids (all salted `_` functions), 0 existing ids changed; wrong `calls` edges 104 -> 0; compiler-resolved calls found: same 803 -> 887, emit 119 -> 146, revert 403 -> 423, inherited 268 -> 279, super 173 -> 185, library 205 -> 209. solmate has no such pair and is unchanged. 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 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
Reworks Solidity extraction so inherited calls resolve in C3 linearization order, members get a stable identity (an _ member gets its own node and calls), and library calls bind from free functions, under negation and through whole-file imports. A library call fails closed when the name is ambiguous or isn't a type. Malformed tails, comments and strings no longer produce phantom nodes, enum values emit case_of instead of contains, and a missing Solidity parser reports an install hint. Tightens the semantic cache so entries are matched and saved by resolved source path, with item identity scoped per result, a grammar fingerprint, and id relativize/absolutize helpers. The AST cache schema goes to 40, so cached Solidity extractions re-run.
No blocking issues surfaced. 3 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3219 functions depend on the 154 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 1156 callers, 68 callees
Verification — 3219 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: 1594 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.
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).
#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 |
…de ids make_id strips a leading `_` and folds case, so in one Java class body `_testFoo()` / `testFoo()`, `getId()` / `getID()` and a constructor `HashCode()` / method `hashCode()` minted ONE id. add_node kept the first declaration and dropped the second: the method vanished, the calls it makes were credited to its twin, and calls to it landed on the twin (or, when the survivor's name no longer matched, fell back to a supertype's method or to another file's method). Apply the Python/C#/Solidity rule (Graphify-Labs#3302, Graphify-Labs#4415, Graphify-Labs#5058): group the methods and constructors of each class/interface/record/enum body by the id they would get and run each through `_underscore_salted_nid`. The one public name keeps the plain id, every other spelling is salted. Members that collide with nothing keep their ids; overloads share one name, so they are not a collision. Measured on jsoup, commons-lang, jackson-core, jackson-databind and guava: 160 colliding groups (131 of them `_x`/`x`), 160 methods that had no node on v8 now do, and 612 call edges that v8 credited to a differently-named method now hit the right one. No id changed outside a colliding group, and no edge away from those groups changed. Bump _AST_CACHE_SCHEMA to 44 so cached Java extractions re-run. Co-Authored-By: Claude <[email protected]>
…de ids make_id strips a leading `_` and folds case, so in one Java class body `_testFoo()` / `testFoo()`, `getId()` / `getID()` and a constructor `HashCode()` / method `hashCode()` minted ONE id. add_node kept the first declaration and dropped the second: the method vanished, the calls it makes were credited to its twin, and calls to it landed on the twin (or, when the survivor's name no longer matched, fell back to a supertype's method or to another file's method). Apply the Python/C#/Solidity rule (#3302, #4415, #5058): group the methods and constructors of each class/interface/record/enum body by the id they would get and run each through `_underscore_salted_nid`. The one public name keeps the plain id, every other spelling is salted. Members that collide with nothing keep their ids; overloads share one name, so they are not a collision. Measured on jsoup, commons-lang, jackson-core, jackson-databind and guava: 160 colliding groups (131 of them `_x`/`x`), 160 methods that had no node on v8 now do, and 612 call edges that v8 credited to a differently-named method now hit the right one. No id changed outside a colliding group, and no edge away from those groups changed. Bump _AST_CACHE_SCHEMA to 44 so cached Java extractions re-run. Co-Authored-By: Claude <[email protected]> (cherry picked from commit 8ca4806)
The Dart extractor scopes a function's id to its file (`stem_name`) and make_id strips a leading `_`, so the library-private `_dispose()` and `dispose()` of one file (in one class or two) minted ONE id. add_node kept the first and dropped the second: the function vanished and the Riverpod/Bloc references and navigation edges it makes were credited to its twin. Apply the Python/C#/Solidity/Java rule (#3302, #4415, #5058, #5151): group the function names of the file by the id they would get and run each through `_underscore_salted_nid`. The one public name keeps the plain id, every other spelling is salted; a name that collides with nothing keeps its id. A `_UpperCamel` match is a private type the pattern caught in a constructor call (`return _Page(`), so it joins no group. Measured on flutter/packages, riverpod and dart-lang/http: 69 colliding groups, 100 functions that had no node on v8 now do. The Dart extractor emits no plain `calls` edges, so no call edges moved; 104 reference, navigation and define edges now sit on the right function. One v8 id changed, inside a case-only group (`doit`/`doIt`). Bump _AST_CACHE_SCHEMA to 46 so cached Dart extractions re-run. Co-Authored-By: Claude <[email protected]> (cherry picked from commit efa38bf)
…node ids make_id strips a leading `_` and folds case, so the methods of one Kotlin class `` `_transaction works` `` / `` `transaction works` `` or `assumeOpenJSSE()` / `assumeOpenJsse()` minted ONE id. add_node kept the first declaration and dropped the second: the method vanished, the calls it makes were credited to its twin, and calls to it landed on the twin. Apply the Python/C#/Solidity/Java rule (#3302, #4415, #5058, #5151): a companion object's members take the class's id, so group the functions of the class body and its companion body by the id they would get and run each through `_underscore_salted_nid` (a backticked name is judged by its text). The one public name keeps the plain id, every other spelling is salted. Members that collide with nothing keep their ids; overloads share one name, so they are not a collision. Measured on ktor, okhttp, Exposed and kotlinx.coroutines: 10 colliding groups, 10 methods that had no node on v8 now do, and 50 call edges that v8 credited to a twin now hit the right method. Four v8 ids changed, all inside case-only groups where both names are public. Bump _AST_CACHE_SCHEMA to 46 so cached Kotlin extractions re-run. Co-Authored-By: Claude <[email protected]> (cherry picked from commit 0d28466)
…ode ids make_id strips a leading `_` and folds case, so the methods of one Swift type `_flatMap()` / `flatMap()` or `hexdumpDetailed()` / `hexDumpDetailed()` minted ONE id. add_node kept the first declaration and dropped the second: the method vanished, the calls it makes were credited to its twin, and calls to it landed on the twin. Apply the Python/C#/Solidity/Java rule (#3302, #4415, #5058, #5151): a type's id is its file stem plus its name, so its class body and every same-file `extension` share one id space; group the methods of all of them by the id they would get and run each through `_underscore_salted_nid`. The one public name keeps the plain id, every other spelling is salted. Members that collide with nothing keep their ids; overloads share one name, so they are not a collision. The cross-file member-call pass indexed methods by a folded key, so with both twins present `foo.bar()` from another file bound to whichever came last. It now binds the exact spelling first and falls back to the folded key only when the type has no member so named. Measured on Alamofire, swift-nio and swift-collections: 117 colliding groups, 137 methods that had no node on v8 now do, and 354 call edges that v8 credited to a twin now hit the right method. One v8 id changed, inside a case-only group where both names are public. The resolver change also re-points 7 test calls from `_append`/`_insert`/... to the public `append`/`insert`/... they name. Bump _AST_CACHE_SCHEMA to 46 so cached Swift extractions re-run. Co-Authored-By: Claude <[email protected]> (cherry picked from commit 2e1e871)
…apart in node ids make_id strips a leading or trailing `_` (and `~`) and folds case, so in one C++ class body `find()` / `find_()`, `_bar()` / `bar()`, `Rep()` / `rep()` and a constructor `Foo()` / destructor `~Foo()` minted ONE id. add_node kept the first declaration and dropped the second: the member vanished, the calls it makes were credited to its twin (a destructor's calls landed on the constructor), and the decl/def fold skipped the pair because one node carried two member records. Apply the Python/C#/Solidity/Java rule (#3302, #4415, #5058, #5151): group the member functions of each class body (inline definitions and the prototypes the walk turns into `.name()` nodes, also under `template`) by the id they would get and run each through `_underscore_salted_nid`, now with `~` as a private prefix and a trailing `_` as a private suffix. The one public name keeps the plain id, every other spelling is salted. Members that collide with nothing keep their ids; overloads share one name and operators are left alone. An out-of-line `Foo::_bar()` in the class's own file lands on the salted member. The cross-file member-call pass indexed methods by a folded key, so with both twins present `bar()` from a split .cpp bound to `bar_`. It now binds the exact spelling first and falls back to the folded key only when the type has no member so named. Measured on abseil-cpp and folly (classes graphify extracts): 471 colliding groups (452 constructor/destructor pairs, 18 `_x`/`x_` pairs, 1 case-only pair), 541 members that had no node on v8 now do, and 219 call edges that v8 credited to a twin now hit the right member. Seven v8 ids changed, all inside colliding groups (case-only pairs where both names are public, or file-prefixed ids that no longer need the prefix). test_cpp_member_declaration_identity listed `int Run(); int _Run();` as a case the fold must refuse: it only refused because the two shared one node carrying two records. They are separate members now, so that case moves to its own test: `Run` folds with its exact definition and `_Run` stays an unmerged declaration. The overload case still covers the more-than-one-record guard. Bump _AST_CACHE_SCHEMA to 46 so cached C++ extractions re-run. Co-Authored-By: Claude <[email protected]> (cherry picked from commit 73fd017)
make_id strips a leading `_` and folds case, so the methods of one Ruby class or module `_read_attribute` / `read_attribute` or `_where!` / `where!` minted ONE id. add_node kept the first declaration and dropped the second: the method vanished, the calls it makes were credited to its twin, and calls to it landed on the twin. Apply the Python/C#/Solidity/Java rule (#3302, #4415, #5058, #5151): group the methods of each class/module body (its own `def`s and those of a `class << self` in it) by the id they would get, after the #3077 suffix sanitizing, and run each through `_underscore_salted_nid`. The one public name keeps the plain id, every other spelling is salted. Members that collide with nothing keep their ids; an instance and a singleton method of one name are one name, so they are not a collision. Cross-file calls (`Foo.new._bar`, `Foo._make`) already bind by exact name and now reach the right twin. Measured on rails (activesupport + activerecord) and rubocop: 42 colliding groups, 42 methods that had no node on v8 now do, and 44 call edges that v8 credited to a twin now hit the right method. One v8 id changed, inside a group where both names are public (`Duration#==` / `===`). No edge away from those groups changed. Bump _AST_CACHE_SCHEMA to 49 so cached Ruby extractions re-run. Co-Authored-By: Claude <[email protected]> (cherry picked from commit f07ac34)
…art in node ids make_id strips a leading `_` and a trailing `_=` and folds case, so the methods of one Scala type `_enter` / `enter`, `forEach` / `foreach` or a getter `size` and its setter `size_=` minted ONE id. add_node kept the first declaration and dropped the second: the method vanished, the calls it makes were credited to its twin, and calls to it landed on the twin. Apply the Python/C#/Solidity/Java rule (#3302, #4415, #5058, #5151): a class and its companion object share one id, so group the methods of the type's body and of its same-named companions in the same scope by the id they would get and run each through `_underscore_salted_nid`, with `_=` counted as non-public so the getter keeps its id. The one public name keeps the plain id, every other spelling is salted. Members that collide with nothing keep their ids; overloads share one name, so they are not a collision. Measured on spark (core), pekko and scala/scala: 190 colliding groups, 203 of the 205 methods that had no node on v8 now do (the other two are not member twins: an anonymous `new { }` body, and a method named like a nested class), and 112 call edges that v8 credited to a twin now hit the right method. 49 v8 ids changed: 47 inside groups where no name is uniquely public (`forEach`/`foreach`, `unary_-`/`unary_+`, ...), and 2 nested objects (`object WARNING` / `ERROR`) that a colliding `def WARNING` / `def warning` pair had pushed onto a salted id and that now take the plain one. No edge away from those groups changed. Bump _AST_CACHE_SCHEMA to 49 so cached Scala extractions re-run. Co-Authored-By: Claude <[email protected]> (cherry picked from commit 09fae40)
…wins apart in node ids make_id strips `_`, `!` and `?` and folds case, so the defs of one Elixir module `__schema__` / `schema`, `get` / `get!`, `valid` / `valid?` or `sigil_c` / `sigil_C` minted ONE id. add_node kept the first def and dropped the second: the function vanished, the calls it makes were credited to its twin, and calls to it (`Repo.get!/2`) landed on the twin. Apply the Python/C#/Solidity/Java rule (#3302, #4415, #5058, #5151): group the defs of each module (or of the file, outside any module) by the id they would get and run each through `_underscore_salted_nid`, with a trailing `!`/`?` counted as non-public so the plain name keeps its id. Every other spelling is salted. Defs that collide with nothing keep their ids; clauses of one function share one name, so they are not a collision. Measured on phoenix, ecto and elixir-lang/elixir: 174 colliding groups, 178 defs that had no node on v8 now do, and 301 call edges that v8 credited to a twin now hit the right def. 10 v8 ids changed, all inside groups where no name is uniquely public (`sigil_c`/`sigil_C`, ...). No edge away from those groups changed. Bump _AST_CACHE_SCHEMA to 49 so cached Elixir extractions re-run. Co-Authored-By: Claude <[email protected]> (cherry picked from commit ac94937)
…n node make_id casefolds and strips leading and trailing underscores, and a method inside one @interface, @implementation or @protocol went straight through _make_id(container, name) with no collision check, unlike every other object oriented extractor (#3302, #4415, #5058, #5151, #5380). Two methods of one container differing only by a leading underscore or by case, such as setup and _setup, a common convention for a public method and its private helper, minted one node, the second declaration overwrote the first, and its own body's calls were credited to the first method instead. Pre scan each @interface, @implementation and @protocol's direct method names during a pass over the file, grouped by the id each name's own spelling would fold to, the same way file level items are grouped elsewhere in the codebase. A collision within one container's method set is then told apart from an unrelated collision in a different container that happens to share a selector name. The existing shared salting rule applies unchanged: the one public, non underscore prefixed name keeps the plain id when the group has exactly one such name, every other spelling is salted. (cherry picked from commit 6bababc)
Closes #5057
What does this PR do?
Solidity function ids drop the leading
_, so_grantRoleandgrantRolewith the same parameters share one node. I use the same helper C# uses for this (_underscore_salted_nid, #4415). The public spelling keeps its id, and only the clashing_namegets a salted id. Calls inside each function, and calls to it (direct, inherited, free functions), now land on the right node.No existing id changes. On OpenZeppelin v5.4.0 the graph goes from 3,907 to 3,945 nodes: 38 new ids, all salted
_functions. 0 v8 ids changed or disappeared. solmate has no such pair and is unchanged. AST cache schema 39 -> 40.Diff:
graphify/extractors/solidity.py,graphify/cache.py, 3 tests intests/test_solidity_extractor.py(+187 / -4).Numbers
OpenZeppelin Contracts v5.4.0, compared with the solc 0.8.28 AST (
referencedDeclaration):callsedges158 more compiler-resolved calls are linked, and all 104 wrong edges are gone. I also ran it on my laptop with my own key: calls whose caller had no node went from 214 to 46, and linked calls from 2,041 to 2,199.
Limitations
memory/calldata, which graphify's arity-based signature ignores, so they also merged on v8. They are split now too._bar()/bar()merge on v8. Python and Go don't. Java is not touched here.Type of change
Verification & Invariants
Invariant: a node id changes only when two declarations in one scope would otherwise share it, and then only the
_-spelled one moves.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