Skip to content

[RULE] Rule G025: Flag Post-Decrement Loop Indexing Patterns #750

Description

@mijinummi

Labels: medium-difficulty, gasguard-rules, ast, gasguard
Difficulty: Medium
Module: rules/g025_loop_decrement.rs


🧠 Concept

Implement static rule G025 to detect loop structures that use post-decrement operators (i--) instead of pre-decrement operators (--i).

⚠️ Problem

Post-decrement operations (i--) copy original values to stack locations before applying decrements, creating redundant stack manipulation instructions compared to --i.

📁 Implementation Scope

  • rules/g025_loop_decrement.rs
  • test/fixtures/g025_samples.sol

🛠️ Requirements

  1. Analyze loop step statements in AST loop nodes.
  2. Identify post-decrement expressions on loop counter variables.
  3. Emit recommendation to replace post-decrement (i--) with pre-decrement (--i).

🎯 Acceptance Criteria

  • Flags post-decrement loop counter expressions accurately.
  • Passes without warnings on pre-decrement loop statements.

Activity

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

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third Campaign

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions