Skip to content

[PERF] Implement Gas-Efficient Byte Array Concatenator in Yul #686

Description

@mijinummi

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


🧠 Concept

Build an assembly helper function bytesConcat(bytes calldata a, bytes calldata b) that constructs concatenated byte arrays directly in contiguous free memory.

⚠️ Problem

Solidity's native bytes.concat() allocates temporary intermediate memory buffers and executes repetitive loop boundaries for each byte segment.

📁 Implementation Scope

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

🛠️ Requirements

  1. Read free memory pointer at 0x40.
  2. Copy memory chunks using 32-byte word loops (calldatacopy / mcopy where available).
  3. Update free memory pointer precisely without allocating unused padding space.

🎯 Acceptance Criteria

  • Reduces gas usage when joining dynamic payload segments.
  • Outputs accurately concatenated byte arrays in unit tests.

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