Skip to content

Document memory expansion tracking for MSTORE/MSTORE8#41

Merged
tcrypt25519 merged 4 commits into
masterfrom
copilot/track-memory-length-from-mstore
Feb 8, 2026
Merged

Document memory expansion tracking for MSTORE/MSTORE8#41
tcrypt25519 merged 4 commits into
masterfrom
copilot/track-memory-length-from-mstore

Conversation

Copilot AI commented Feb 8, 2026

Copy link
Copy Markdown

The issue calls for a clear plan to implement correct EVM memory expansion tracking, especially around MSTORE/MSTORE8 so runtime bounds checks can rely on memory_len. This PR adds a focused write-up that ties EVM semantics to Jet’s current runtime design.

  • Write-up: memory expansion semantics
    • Summarizes EVM memory growth rules, word rounding, and MSIZE byte tracking.
  • Write-up: Jet integration plan
    • Details required updates for MSTORE/MSTORE8 and other memory-touching opcodes.
    • Outlines safe expansion, overflow handling, and memory_len updates.
  • Write-up: verification guidance
    • Lists targeted test cases for word-aligned expansion.
new_size = ceil((offset + size) / 32) * 32
Original prompt

This section details on the original issue you should resolve

<issue_title>Memory length tracking from Mstore and Mstore8.</issue_title>
<issue_description>

// TODO: Validate ret_offset + ret_len <= memory_len once memory_len is tracked by MSTORE

// TODO: Validate ret_offset + ret_len <= memory_len once memory_len is tracked by MSTORE

I think it's time that we tackle this issue. Let's first understand exactly what needs to be done to make this work correctly and safely, make a write-up in /docs/tasks explaining everything that will need to be done.</issue_description>

<agent_instructions>Review the documentation that we have about the EVM and opcodes, specifically looking at information about how memory expansion works, and information about the opcodes MSTORE and MSTORE8. Create a writeup explaining how to resolve this issue, how to properly track memory length and memory expansion in a way that's semantically correct with what the EVM does. docs/ext/evm/evm.md and docs/ext/evm/opcodes.json</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@semanticdiff-com

Copy link
Copy Markdown

Review changes with  SemanticDiff

Copilot AI and others added 2 commits February 8, 2026 14:03
Co-authored-by: tcrypt25519 <212655132+tcrypt25519@users.noreply.github.com>
Co-authored-by: tcrypt25519 <212655132+tcrypt25519@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement memory length tracking for Mstore and Mstore8 Document memory expansion tracking for MSTORE/MSTORE8 Feb 8, 2026
Copilot AI requested a review from tcrypt25519 February 8, 2026 14:05
@tcrypt25519
tcrypt25519 marked this pull request as ready for review February 8, 2026 15:44
Copilot AI review requested due to automatic review settings February 8, 2026 15:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a task write-up describing how Jet should correctly track EVM memory expansion (in bytes, word-rounded) so memory_len becomes reliable for runtime bounds checks and future opcode work (especially around MSTORE/MSTORE8).

Changes:

  • Documents EVM memory expansion sizing rules (word rounding, MSIZE byte tracking, and cost formula reference).
  • Describes Jet’s current memory_ptr/memory_len/memory_cap model and the gap (stores don’t update memory_len).
  • Proposes a shared expansion helper + integration points across memory-touching opcodes, with suggested test cases.

Comment thread docs/tasks/memory-length-tracking-mstore.md Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@tcrypt25519
tcrypt25519 merged commit 0c8dd97 into master Feb 8, 2026
1 check failed
tcrypt25519 added a commit that referenced this pull request Feb 9, 2026
Track EVM memory length correctly by expanding memory before writes and
updating memory_len to match EVM semantics (32-byte word-aligned).

Implementation:
- Add jet_mem_expand builtin that:
  * Checks for offset + size overflow
  * Rounds up to 32-byte boundaries
  * Updates memory_len monotonically
  * Reallocates and zeros new memory if needed
- Hook MSTORE (32 bytes) and MSTORE8 (1 byte) to call expansion before write
- Add memory_len field to TestContractRun for validation

Tests (all passing):
- MSTORE at offsets 0, 31, 32 expands to 32, 64, 64 bytes
- MSTORE8 at offsets 0, 31, 32 expands to 32, 32, 64 bytes
- Memory expansion is word-aligned and monotonic

Closes #41

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
tcrypt25519 added a commit that referenced this pull request Feb 10, 2026
* Add EXP.

* style: apply rustfmt formatting 🤖

* fixes

* ci: force LLVM cache invalidation for dynamic linking

The cache was hitting old entries built for static linking, causing
"unable to find library -lLLVM-21" errors after adding the
llvm21-1-prefer-dynamic feature to inkwell. Adding v2 prefix to force
a fresh LLVM installation with dynamic libraries.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix: install libllvm21 for dynamic linking support

The llvm-21-dev package only provides static libraries and headers.
When inkwell uses llvm21-1-prefer-dynamic, the linker needs the shared
library libLLVM-21.so, which comes from the libllvm21 package.

This was causing intermittent "unable to find library -lLLVM-21" errors
because the cached LLVM installations didn't include the shared library.

Changes:
- Add libllvm21 to apt-get install in scripts/install-llvm.sh
- Bump CI cache key to v3 to force fresh installation with shared lib

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* feat: implement memory expansion tracking for MSTORE and MSTORE8

Track EVM memory length correctly by expanding memory before writes and
updating memory_len to match EVM semantics (32-byte word-aligned).

Implementation:
- Add jet_mem_expand builtin that:
  * Checks for offset + size overflow
  * Rounds up to 32-byte boundaries
  * Updates memory_len monotonically
  * Reallocates and zeros new memory if needed
- Hook MSTORE (32 bytes) and MSTORE8 (1 byte) to call expansion before write
- Add memory_len field to TestContractRun for validation

Tests (all passing):
- MSTORE at offsets 0, 31, 32 expands to 32, 64, 64 bytes
- MSTORE8 at offsets 0, 31, 32 expands to 32, 32, 64 bytes
- Memory expansion is word-aligned and monotonic

Closes #41

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* ci: bump LLVM cache to v4

* fix: use div_ceil for memory expansion rounding

* docs: Add process doc for adding opcodes.

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
tcrypt25519 added a commit that referenced this pull request Feb 16, 2026
* Initial plan

* Add memory length tracking writeup

Co-authored-by: tcrypt25519 <212655132+tcrypt25519@users.noreply.github.com>

* Refine opcode naming in writeup

Co-authored-by: tcrypt25519 <212655132+tcrypt25519@users.noreply.github.com>

* Update docs/tasks/memory-length-tracking-mstore.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tcrypt25519 <212655132+tcrypt25519@users.noreply.github.com>
Co-authored-by: Tyler Smith <mail@tcry.pt>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
tcrypt25519 added a commit that referenced this pull request Feb 16, 2026
* Add EXP.

* style: apply rustfmt formatting 🤖

* fixes

* ci: force LLVM cache invalidation for dynamic linking

The cache was hitting old entries built for static linking, causing
"unable to find library -lLLVM-21" errors after adding the
llvm21-1-prefer-dynamic feature to inkwell. Adding v2 prefix to force
a fresh LLVM installation with dynamic libraries.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix: install libllvm21 for dynamic linking support

The llvm-21-dev package only provides static libraries and headers.
When inkwell uses llvm21-1-prefer-dynamic, the linker needs the shared
library libLLVM-21.so, which comes from the libllvm21 package.

This was causing intermittent "unable to find library -lLLVM-21" errors
because the cached LLVM installations didn't include the shared library.

Changes:
- Add libllvm21 to apt-get install in scripts/install-llvm.sh
- Bump CI cache key to v3 to force fresh installation with shared lib

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* feat: implement memory expansion tracking for MSTORE and MSTORE8

Track EVM memory length correctly by expanding memory before writes and
updating memory_len to match EVM semantics (32-byte word-aligned).

Implementation:
- Add jet_mem_expand builtin that:
  * Checks for offset + size overflow
  * Rounds up to 32-byte boundaries
  * Updates memory_len monotonically
  * Reallocates and zeros new memory if needed
- Hook MSTORE (32 bytes) and MSTORE8 (1 byte) to call expansion before write
- Add memory_len field to TestContractRun for validation

Tests (all passing):
- MSTORE at offsets 0, 31, 32 expands to 32, 64, 64 bytes
- MSTORE8 at offsets 0, 31, 32 expands to 32, 32, 64 bytes
- Memory expansion is word-aligned and monotonic

Closes #41

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* ci: bump LLVM cache to v4

* fix: use div_ceil for memory expansion rounding

* docs: Add process doc for adding opcodes.

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
@tcrypt25519
tcrypt25519 deleted the copilot/track-memory-length-from-mstore branch February 16, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory length tracking from Mstore and Mstore8.

3 participants