Skip to content

feat(ir): ArrayT type, array bounds checking, IsPure fix#58

Merged
refcell merged 3 commits into
nox/internal-return-typefrom
brock/array-bounds-check
Mar 9, 2026
Merged

feat(ir): ArrayT type, array bounds checking, IsPure fix#58
refcell merged 3 commits into
nox/internal-return-typefrom
brock/array-bounds-check

Conversation

@brockelmore
Copy link
Copy Markdown
Collaborator

Summary

  • Add ArrayT(EvmBaseType, usize) variant to EvmType across the full pipeline (schema.egg, schema.rs, sexp, pretty-printer, costs, codegen) so array type information is preserved in IR instead of falling back to u256
  • Implement array bounds checking: compile-time errors for constant out-of-bounds indices, runtime If(LT(idx, len), Empty, Revert) guards for dynamic indices — covers both memory and storage arrays
  • Fix pre-existing bug in dead_code.egg where IsPure rule for If nodes only checked 3 of 4 arguments, causing bounds checks (and other If nodes with side-effecting else branches) to be incorrectly eliminated at O1+

Test plan

  • 18 new array tests in crates/evm-tests/tests/suites/arrays.rs covering memory arrays (element access, read-all, write-then-read, iteration, find-max), storage arrays (set/get, multi-slot, sum, overwrite), OOB reverts (storage get/set, large index), boundary indices, and smaller storage arrays
  • All 153 existing tests continue to pass at O0/O1/O2
  • Verified bounds checks survive optimization at all levels via pretty-IR inspection

🤖 Generated with Claude Code

brockelmore and others added 3 commits March 8, 2026 21:11
- Add `ArrayT(EvmBaseType, usize)` variant to EvmType in both Rust and
  egglog schemas. Storage arrays now display as `[u256; 10]` instead of
  `u256` in IR output. Updated pretty-printer, sexp serialization,
  type lowering, codegen type_slot_count, and cost table.

- Add array bounds checking during lowering: constant out-of-bounds
  indices produce compile-time errors with source spans; non-constant
  indices emit runtime LT + REVERT guards for both memory-backed and
  storage-backed arrays.

- Fix pre-existing bug in dead_code.egg IsPure rule for If nodes: the
  rule only checked 3 of 4 arguments (pred, inputs, then) but skipped
  the else branch. This caused If nodes with Revert in the else branch
  to be incorrectly marked pure and eliminated by DCE.

- Add 18 EVM execution tests covering element access, mutation, loop
  iteration, slices, storage round-trips, OOB reverts, and boundary
  indices, all verified at O0/O1/O2.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@refcell refcell merged commit 3b73f58 into nox/internal-return-type Mar 9, 2026
9 checks passed
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.

2 participants