Skip to content

[PERF] Build Zero-Memory Allocation SHA2-256 Precompile Caller in Yul #749

Description

@mijinummi

Labels: medium-difficulty, yul, cryptography, gasguard
Difficulty: Medium
Module: contracts/crypto/


🧠 Concept

Create an inline Yul assembly helper for invoking the SHA2-256 precompile (address 0x02) directly from calldata without staging payload bytes in memory.

⚠️ Problem

Using high-level sha256(bytes) copies calldata payloads into temporary memory buffers before triggering the precompile call.

📁 Implementation Scope

  • contracts/crypto/YulSHA256.sol
  • test/crypto/YulSHA256.test.ts

🛠️ Requirements

  1. Pass input calldata ranges directly to precompile address 0x02 via Yul staticcall.
  2. Write precompile output directly to scratch space (0x00) and return the resulting digest.

🎯 Acceptance Criteria

  • Computes SHA2-256 hashes without dynamic memory expansion.
  • Matches standard sha256() outputs across all input sizes.

Metadata

Metadata

Assignees

No one assigned

    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