Skip to content

🟡 [Medium] Performance EVM: Memory size limited to u24 (16MB) #857

@roninjin10

Description

@roninjin10

Summary

The memory module uses u24 for size parameters, limiting EVM memory to 16MB. While sufficient for most cases, this could be surprising and limiting.

Location

src/memory/memory.zig:100-107

Current Code

pub inline fn ensure_capacity(self: *Self, allocator: std.mem.Allocator, new_size: u24) !void {
    // ...
    if (required_total > MEMORY_LIMIT) {
        @branchHint(.unlikely);
        return MemoryError.MemoryOverflow;
    }

Analysis

  • u24 max value: 16,777,215 bytes (~16MB)
  • EVM has no hard memory limit (only gas-bounded)
  • Some edge cases or tests might require more
  • Performance EVM's FrameConfig uses memory_limit: u32 = 16 * 1024 * 1024 (16MB default)

Impact

  • Contracts requiring >16MB memory will fail unexpectedly
  • May cause issues with certain test cases
  • Inconsistent with EVM specification (no hard limit)

Recommended Fix

Consider using u32 for size parameters:

pub inline fn ensure_capacity(self: *Self, allocator: std.mem.Allocator, new_size: u32) !void {

Or document the limitation clearly if intentional for performance.


Note: This issue was created by Claude AI assistant during code review, not @roninjin10 or @fucory

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions