Skip to content

fix(solidity): link emit, revert and require to the event or error they name - #5001

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

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

Conversation

@rohit-jsfreaky

Copy link
Copy Markdown
Contributor

Closes #5000

What does this PR do?

While measuring Solidity calls against the compiler I found that no function is ever linked to the event or error it uses. emit E(..) and revert Err(..) are statements, not call_expressions, so the body walk in extract_solidity skipped them.

I link them as calls edges, the same way Python links raise Err() (a call of the class):

  1. Same contract: events and errors go into the same (name, arity) table as functions, so revert NotOwner(x) and emit Withdrawn(a, b) bind like a normal call. require(cond, Err(..)) is a plain call of the error, so it resolves too.
  2. Base contract: if the name is not declared in the caller's contract, it goes through the existing linearized-bases pass (resolve_solidity_inherited_calls), like an inherited call.
  3. Qualified, other file: revert Errors.InsufficientBalance(..) looks up Errors among the types the caller's file declares or imports directly (the same scope resolve_solidity_type_references uses), then the member by name and arity.

Every step fails closed: no edge when the name or the (name, arity) pair is ambiguous. Event and error nodes now carry metadata.arity. Node ids do not change. AST cache schema 37 -> 38 because Solidity output changes.

Diff: graphify/extractors/solidity.py +90 / -8, 3 new tests in tests/test_solidity_extractor.py.

Numbers

OpenZeppelin Contracts v5.4.0 (319 files), compared with the solc 0.8.28 AST (referencedDeclaration):

link kind compiler before after
revert Err() / require(c, Err()) -> error 403 0 401
emit E() -> event 119 0 119
same-contract / inherited / super / modifier calls 936 / 268 / 176 / 113 778 / 268 / 173 / 113 unchanged
all links 2,521 53% 73%

Limitations

  • A qualified error inside require(c, Errors.X()) still goes through the member-call path and is not linked (the 2 remaining revert misses).
  • Named arguments emit E({a: 1, b: 2}) count as one argument, like other calls. If an event has a one-argument overload, that could pick the wrong one.
  • About 41 new edges start from the wrong function because _grantRole and grantRole already share one node id (an existing id issue, not changed here).

Type of change

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

Verification & Invariants

Invariant: a link is added only when exactly one declaration matches by name and arity in a scope the caller can see (its contract, its linearized bases, or a type its file declares/imports). Nothing is guessed across scopes. Existing call, super and modifier resolution is untouched.

  • 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      # 11 passed; with v8's solidity.py the 3 new tests fail
uv run --frozen pytest tests -q                                  # 9983 passed; the only 11 failures were tests/test_skillgen.py in a shallow clone (pinned commit 47042be missing), they pass in a full clone
uv run --frozen ruff check graphify tests                        # 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

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.

🤖 Generated with Claude Code

…ey name

`emit E(..)` and `revert Err(..)` are statements, not call_expressions, so the
body walk skipped them and no function ever linked to the event or error it
uses. Bind them as calls by (name, arity): in the caller's own contract, through
the linearized bases (an interface's event, a base's error), or as `Lib.Err`
through a type the file declares or imports. Fail closed when ambiguous.
`require(c, Err(..))` is a plain call of the error and now resolves too.
OpenZeppelin v5.4.0 vs solc 0.8.28: revert 0 -> 386 of 403, emit 0 -> 116 of 119;
other call kinds unchanged.

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

github-actions Bot commented Nov 4, 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.

@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.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.

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: \_inherited\_call (unsupported), resolve\_solidity\_inherited\_calls (vacuous: never exercised).


Graphify review — findings

Adds Solidity emit E(..), revert Err(..) and require(c, Err(..)) as calls edges to the event or error they name, whether it lives in the same contract, a base contract, or behind a Lib.Err qualifier. Event and error nodes now carry metadata.arity, and inherited-call resolution gains a branch that binds these to base-contract members; removing events and errors from reference_targets risks dropping existing E.selector / Err.selector references, and named-argument emits and reverts get arity 1 and never bind. Bumps _AST_CACHE_SCHEMA to 38 so cached Solidity extractions re-run.

Worth a look

  • Events/errors removed from reference_targets, dropping E.selector / Err.selector references — graphify/extractors/solidity.py:572 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
  • New event/error contains branch may be unreachable behind an earlier contains branch — graphify/extractors/solidity.py:180 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 3165 functions depend on the 131 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1141 callers, 68 callees

Verification — 3165 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: 1566 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

518 of 518 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_ghost_fold_4955.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
  • … and 468 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

Could not verify: Could not verify \_inherited\_call.

The verifier did not have enough to check \_inherited\_call, 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 `node` 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

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

@rohit-jsfreaky

rohit-jsfreaky commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

I checked both bot findings:

  • E.selector / Err.selector references dropped: this doesn't happen. reference_targets is only read for a call_expression callee with no dot (Err(x)). Err.selector is a member access, not a call, so it never went through it. On v8 and on this branch, a contract with return (Err.selector, E.selector); gives the same edges: none.
  • contains branch unreachable: there is no earlier contains branch. The chain in resolve_solidity_inherited_calls is method / contains (event or error) / inherits. With that branch removed, 2 of the new tests fail (test_solidity_emit_and_revert_bind_events_and_errors_of_a_base_contract and test_solidity_qualified_revert_and_emit_bind_through_the_imported_type).

The bot also notes that named-argument emit E({a: 1, b: 2}) counts as arity 1. That's right and it's listed under Limitations. It fails closed unless a one-argument overload exists.

safishamsi added a commit that referenced this pull request Nov 5, 2026
…ractor fixes

#5003 (C# preprocessor blanking), #5005/#5001 (Solidity library + emit/revert/
require linking) and #4995 (YAML << merge precedence) each change per-file
extractor output; fold them into one schema-38 entry so warm caches re-run.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Closing in favour of #5005, which shipped in 0.9.103 and is a strict superset (it contains this emit/revert/require linking plus the Lib.f() library-call generalization). Same author, so no credit lost. 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: emit E() and revert Err() get no edge to the event / error they name

2 participants