Skip to content

Add Rust Code Analysis: Infinite Loop Detection#326

Draft
Allen-Cherian wants to merge 9 commits intodevelopmentfrom
allen/contract-analyzer
Draft

Add Rust Code Analysis: Infinite Loop Detection#326
Allen-Cherian wants to merge 9 commits intodevelopmentfrom
allen/contract-analyzer

Conversation

@Allen-Cherian
Copy link
Copy Markdown
Member

This PR introduces Rust code analysis during contract generation and fetching. If the Rust code contains an infinite loop, contract generation will be blocked. The same analysis is also performed when fetching the contract.

Core Logic

  • Analyzes specific loop types (while, for, loop) and recursive function calls for conditions that may lead to infinite loops.

Recursive Traversal

  • Processes nodes recursively to check the entire syntax tree.

Loop Identification and Checks

While Loops

  • Flags loops with conditions always true or unmodified variables.

Rust's loop {} Syntax

  • Flags unless a break statement is present to exit the loop.

For Loops

  • Detects non-terminating iterators (e.g., std::iter::repeat) and checks for break statements.

Recursive Function Calls

  • Flags direct recursion as potential infinite recursion.

Known Limitations

Complex While Conditions

  • Dynamic conditions (dependent on external states or computations) may not be fully analyzed.

External Break Conditions

  • Break conditions dependent on external threads or asynchronous contexts may be missed.

Custom Iterators

  • Does not analyze termination for user-defined iterators.

Indirect Recursion

  • Only detects direct recursion, not circular dependencies between functions.

Unreachable Code

  • Flags loops in unreachable code (e.g., within if false) unnecessarily.

@Allen-Cherian Allen-Cherian self-assigned this May 14, 2025
@Allen-Cherian Allen-Cherian added enhancement New feature or request and removed enhancement New feature or request labels May 14, 2025
Copy link
Copy Markdown
Member

@arnabghose997 arnabghose997 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Allen-Cherian Allen-Cherian marked this pull request as draft February 23, 2026 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants