Skip to content

feat: detect reentrancy through token hooks and receiver callbacks - #1415

Open
p3ris0n wants to merge 1 commit into
MDTechLabs:mainfrom
p3ris0n:feat/detect-reentrancy-token-callbacks-1362
Open

p3ris0n wants to merge 1 commit into
MDTechLabs:mainfrom
p3ris0n:feat/detect-reentrancy-token-callbacks-1362

Conversation

@p3ris0n

@p3ris0n p3ris0n commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

feat(analyzer): callback-reentrancy and unsafe-catch detectors, post-mortem benchmark suite, rule-pack compatibility checks

Closes #1362
Closes #1364
Closes #1336
Closes #1335

Summary

This PR adds two security detectors to the control-flow and call-safety workstream, plus two reliability features for the analyzer pipeline.

Issue Change Type
#1362 Reentrancy detection through ERC-777 hooks and ERC-721/ERC-1155 receiver callbacks New detector
#1364 Detection of try/catch handlers that silently swallow failures from critical calls New detector
#1336 Benchmark suite built from public post-mortem vulnerability cases Test and benchmark infrastructure
#1335 Rule compatibility checks that gate rule-pack releases Release tooling

All findings use the existing normalized finding schema and run inside the existing analyzer pipeline. The analyzer never executes repository code, package scripts or build hooks from the project under analysis.

Supported scope and assumptions

  • Solidity versions: [e.g. >=0.6.0 <0.9.x]
  • Compiler settings and AST/IR: [e.g. solc-JSON AST, default optimizer settings; IR assumptions]
  • Toolchain versions are pinned and recorded in analysis output so results are reproducible: [solc / parser / dependency versions]
  • Explicitly unsupported (reported as diagnostics, not silently skipped):
    • [e.g. inline-assembly external calls]
    • [e.g. unresolved dynamic dispatch / cross-contract calls to unknown targets]
    • [e.g. unsupported syntax or compiler versions]

Changes

#1362: Reentrancy through token hooks and receiver callbacks

Rule ID: [GG-XXX-NNN]

  • Models callback-capable token operations as external control transfers that can re-enter the contract:
    • ERC-777: tokensReceived / tokensToSend hooks, as triggered by send and operatorSend
    • ERC-721: onERC721Received, as triggered by safeTransferFrom and _safeMint
    • ERC-1155: onERC1155Received / onERC1155BatchReceived, as triggered by safeTransferFrom, safeBatchTransferFrom and _mint
  • Tracks shared state across callback-reachable entry points. A finding is raised when state is read or written after the callback-capable call and another reachable entry point depends on the same state.
  • Recognizes guarded and intentionally callback-safe designs:
    • Reentrancy guards (nonReentrant and equivalents) [list recognized patterns]
    • Checks-effects-interactions ordering
    • [other callback-safe patterns handled]
  • Each finding includes call-chain evidence (entry point → callback-capable call → re-enterable function → shared state) with source locations.
  • Severity rationale: [why this severity]
  • Confidence evidence: [how confidence is derived]
  • Remediation: [e.g. apply a reentrancy guard, reorder to checks-effects-interactions, ...]

#1364: Unsafe try/catch that ignores failed calls

Rule ID: [GG-XXX-NNN]

  • Classifies caught external calls by downstream state impact: critical (token, oracle, bridge, accounting) versus best-effort (e.g. telemetry).
  • Reports empty or ineffective catch branches that neither restore invariants, revert, bubble the error, nor surface the failure through an event or return value.
  • Distinguishes intentional best-effort handling from critical state transitions to limit false positives.
  • Findings include call-site context: the caught call, the catch clause, and the state affected after the failure.
  • Severity rationale: [...] Confidence evidence: [...] Remediation: [...]
  • Behaviors covered by tests: revert bubbling, fallback behavior, and explicit recovery paths.

#1336: Benchmark suite from public post-mortem cases

  • Adds a benchmark suite built from public post-mortem vulnerability cases: [N cases, location, e.g. benchmarks/postmortem/].
  • Each case records its source (post-mortem reference), pinned compiler and toolchain versions, deterministic inputs, and the expected normalized findings.
  • Runs reproducibly and without network access, production credentials or unpinned external state.
  • Reports precision and recall per rule and per case. Unsupported cases are listed explicitly instead of being counted as passes.
  • Runs under resource limits and isolation, so untrusted fixtures cannot exhaust worker resources.

#1335: Rule compatibility checks before rule-pack release

  • Adds a pre-release gate that validates each rule in a pack before release:
    • Stable rule identifiers are present and not reused or silently changed
    • Declared supported Solidity versions are consistent with the analyzer
    • The normalized finding schema is compatible
    • [other compatibility dimensions checked]
  • A failing check blocks the release and reports which rule failed and why.
  • Runs in CI with pinned inputs and no production credentials.

Security and robustness

  • No execution of untrusted code: repository-provided scripts, package scripts and build hooks are never run by default, and project configuration is validated before use.
  • Fail-safe handling: malformed source and unsupported syntax produce a diagnostic and a partial result, not a crash, and the rest of the scan continues.
  • Resource limits: [time / memory / file-size / recursion limits and where they are enforced]
  • Logging: repository contents, credentials and analyzer subprocess output are kept out of logs.
  • Determinism: findings are ordered deterministically and carry stable identifiers and precise source locations.

Testing

Each detector has fixtures for the cases below. Fixtures live in [path].

Category #1362 #1364
Vulnerable example [fixture] [fixture]
Safe counterexample [fixture] [fixture]
Boundary cases [e.g. guard on only one entry point, batch callbacks, inherited hooks] [e.g. nested try/catch, catch with a revert, telemetry-only call]
Regression [fixture] [fixture]
Malformed or unsupported input [fixture] [fixture]

Coverage also includes inheritance, modifiers, libraries, proxies and compiler-version differences where relevant: [confirm].

Verification evidence

  • Unit tests: [link / result]
  • Integration tests: [link / result]
  • Regression tests: [link / result]
  • Fuzz / property-based tests (where applicable): [link / result]
  • Reproducible fixture and expected normalized finding output: [path]
  • Benchmark impact on analysis time and memory: [before → after]
  • CI checks: [link]
  • Independent review of the security-critical detector changes: [reviewer / link]
  • Threat-model or design review (if the trust boundary changed): [link or N/A]

Documentation

Known limitations and false-positive considerations

  • [e.g. callbacks through unresolved external targets are not tracked]
  • [e.g. custom guard implementations not matching known patterns may be flagged]
  • [e.g. try/catch classification depends on recognized token, oracle and bridge interfaces]

Checklist

  • Rule IDs are stable and documented
  • Positive, negative, boundary and regression fixtures pass
  • Malformed or unsupported input fails safely with a diagnostic
  • Output is deterministic and matches the normalized finding schema
  • No untrusted code execution; no sensitive data in logs
  • Benchmarks recorded; CI green without production credentials
  • Docs updated
  • Independent review of security-critical changes linked

@drips-wave

drips-wave Bot commented Nov 22, 2026

Copy link
Copy Markdown

@p3ris0n Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@p3ris0n p3ris0n changed the title feat: detect reentrancy through token hooks and receiver callbacks (#1362) feat: detect reentrancy through token hooks and receiver callbacks Nov 22, 2026
@mijinummi

Copy link
Copy Markdown
Collaborator

Hi @p3ris0n , please kindly resolve the conflict. Thanks

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

Labels

None yet

Projects

None yet

2 participants