Skip to content

[CORE] Implement Dynamic Programming Storage Packing Optimizer #602

Description

@mijinummi

Labels: high-difficulty, algorithms, solidity, optimization
Difficulty: High
Module: packages/rules/solidity/src/optimizers/


🧠 Concept

Develop a combinatorial storage packing algorithm using dynamic programming (Knapsack Variant) that calculates the optimal field arrangement for complex Solidity contracts.

⚠️ Problem

State variables in contracts with dozens of fields are rarely ordered efficiently, causing teams to spend unnecessary gas on un-packed storage slots.

📁 Implementation Scope

  • packages/rules/solidity/src/optimizers/slot-packer.ts
  • packages/rules/solidity/src/optimizers/slot-packer.spec.ts

🛠️ Requirements

  1. Extract variable declarations, types, and bit-sizes from contract AST.
  2. Solve optimal variable packing into 32-byte (256-bit) slots while honoring inheritance layouts.
  3. Output a refactored contract declaration string minimizing total required storage slots.

🎯 Acceptance Criteria

  • Computes mathematically minimal storage layouts for multi-variable state lists.
  • Respects variable inheritance order constraints.

Metadata

Metadata

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