Skip to content

Support full u32 memory address range via chunked memory in Brillig VM #11291

@vezenovm

Description

@vezenovm

Problem

The Brillig VM's Memory struct uses a single Vec<MemoryValue> for storage. Due to Rust's allocator limit of isize::MAX bytes per allocation (rust-lang/rust#95295 and https://doc.rust-lang.org/1.81.0/src/core/alloc/layout.rs.html), this limits addressable memory:

  • 32-bit systems: ~44 million slots (i32::MAX / sizeof(MemoryValue))
  • 64-bit systems: Limited by available RAM (~200GB for full u32 range)

Currently, we enforce a deterministic i32::MAX limit across all architectures and panic with an error message when exceeded. However, the full u32 address range remains unusable.

Happy Case

The VM should support the full u32 address range by using chunked memory - multiple smaller Vec allocations that together cover the address space. We could have something like 1-10 million elements per chunk.

Workaround

Yes

Workaround Description

Programs must stay within i32::MAX (~2.1 billion) memory slots. This is sufficient for most practical use cases, as exceeding this would require ~100GB+ of RAM anyway.

Additional Context

Current limit enforced in Memory::resize_to_fit(). Rust allocator limit reference: rust-lang/rust#95295 and https://doc.rust-lang.org/1.81.0/src/core/alloc/layout.rs.html

Project Impact

Nice-to-have

Blocker Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    brilligUnconstrained functions / brillig IR

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions