Skip to content

feat(security): offline line-level static analysis in the contract scanner [D-25]#443

Open
KayProject wants to merge 1 commit into
Nanle-code:masterfrom
KayProject:feat/offline-contract-security-scanner
Open

feat(security): offline line-level static analysis in the contract scanner [D-25]#443
KayProject wants to merge 1 commit into
Nanle-code:masterfrom
KayProject:feat/offline-contract-security-scanner

Conversation

@KayProject

Copy link
Copy Markdown

Summary

The built-in contract security scanner (security audit) ran the file-level checklist and then delegated real vulnerability detection to Slither and Mythril. When those external tools aren't installed, run_builtin_analysis only produced checklist findings and silently missed line-level issues — so a developer without Slither/Mythril got a weak scan.

This makes the scanner self-sufficient: it now performs line-level static analysis against the existing SecurityPatternLibrary with no external dependencies.

Changes

  • utils/security/audit.rsrun_builtin_analysis now also runs run_pattern_analysis, which walks the contract source through the pattern library (dry-run hardening pass) and emits a VulnerabilityFinding per match with:
    • a file:line location
    • the pattern's severity
    • a remediation derived from the pattern's fix guidance (with a sensible fallback)
  • commands/security.rs — adds --offline to security audit, which forces external tools off and runs the built-in scanner only.

Coverage gained offline

The pattern library detects exactly the classes called out in the issue, now without any external tooling:

Pattern Category Severity
Potential reentrancy (external call before state write) reentrancy high
Unchecked integer arithmetic integer-safety medium
Missing authorization check access-control high
Unwrap/expect on external data error-handling medium
Hardcoded Stellar address configuration warning
Missing upgrade authorization upgrade-safety high

Severity scoring and the report formatter are unchanged — the new findings flow through the existing compute_summary / compute_score / format_report pipeline.

Tests

  • builtin_analysis_detects_line_patterns_without_external_tools — runs the built-in analysis on a deliberately vulnerable contract and asserts reentrancy is caught, every pattern finding carries a line-qualified location and remediation, and is attributed to the built-in scanner.
  • pattern_remediation_falls_back_for_unknown_pattern — guards the remediation fallback.

Closes #362

@drips-wave

drips-wave Bot commented Jun 30, 2026

Copy link
Copy Markdown

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

…anner

The built-in audit only ran file-level checklist heuristics and delegated
real vulnerability detection to Slither/Mythril. When those tools are not
installed the scanner silently missed line-level issues.

This wires the existing SecurityPatternLibrary into the built-in analysis
so the scanner detects reentrancy, unchecked arithmetic, unsafe unwraps,
missing authorization and hardcoded addresses on its own, each reported
with a file:line location, severity and remediation. Adds an --offline
flag to run the scan with built-in analysis only and skip external tools.

Closes Nanle-code#362
@KayProject KayProject force-pushed the feat/offline-contract-security-scanner branch from e378e4e to caba45d Compare June 30, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

D-25: Add Contract Security Scanner

1 participant