Skip to content

[RULE] Rule G014: Flag Storage Array Length Accesses in Storage Operations #689

Description

@mijinummi

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


🧠 Concept

Implement rule G014 to detect storage dynamic array reads where .length is queried directly from storage inside execution loops or repeated conditions.

⚠️ Problem

Reading the length of a storage array (storageArray.length) issues an SLOAD opcode on every query, costing $2,100\text{ gas}$ (cold) or $100\text{ gas}$ (warm).

📁 Implementation Scope

  • rules/g014_storage_array_length.rs
  • test/fixtures/g014_samples.sol

🛠️ Requirements

  1. Identify storage array variable references evaluating .length.
  2. Check if the evaluation occurs inside a loop or conditional block without stack assignment.
  3. Emit actionable warning recommending stack caching.

🎯 Acceptance Criteria

  • Flags un-cached storage array length evaluations.
  • Does not flag memory or calldata array length checks.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions