Skip to content

[PERF] Compute Complex Mapping Storage Slots using Inline Yul AssemblyΒ #635

Description

@mijinummi

Labels: medium-difficulty, yul, assembly, gasguard
Difficulty: Medium
Module: contracts/utils/


🧠 Concept

Build an assembly helper function MappingResolver.sol that computes nested mapping storage keys directly in scratch memory (0x00–0x40).

⚠️ Problem

High-level Solidity nested mapping lookups (mapping(address => mapping(uint256 => Struct))) generate repetitive memory allocation and keccak256 hashing instructions.

πŸ“ Implementation Scope

  • contracts/utils/MappingResolver.sol
  • test/utils/MappingResolver.test.ts

πŸ› οΈ Requirements

  1. Use inline assembly mstore to write key and slot index directly to scratch space (0x00).
  2. Compute target storage slot via single keccak256(0x00, 0x40) opcode execution.
  3. Fetch data using low-level sload(slot).

🎯 Acceptance Criteria

  • Reduces gas spent on memory pointer updates during mapping reads.
  • Storage reads return accurate value outputs in unit tests.

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