Skip to content

feat: Rex4 per-frame state growth limits#169

Merged
Troublor merged 10 commits intomainfrom
william/feat/frame_limit
Feb 27, 2026
Merged

feat: Rex4 per-frame state growth limits#169
Troublor merged 10 commits intomainfrom
william/feat/frame_limit

Conversation

@Troublor
Copy link
Collaborator

Summary

  • Introduce per-frame state growth budgets for Rex4: each child call frame receives remaining * 98/100 of the parent's remaining state growth budget
  • When a frame exceeds its budget, it reverts (not halts) with ABI-encoded MegaLimitExceeded(uint8 kind, uint64 limit) revert data, allowing the parent to continue
  • Refactor AdditionalLimit by extracting LimitCheck and introducing FrameLimitTracker to manage per-frame budget allocation, enforcement, and merge-on-return
  • Add comprehensive tests covering budget allocation, progressive reduction, frame-local revert semantics, revert data encoding, nested frames, backward compatibility with REX3, and refund interactions (including eager check behavior)
  • Update resource accounting documentation and add Rex4 spec

Test plan

  • cargo test -p mega-evm — all existing and new tests pass
  • cargo fmt --all --check — formatting verified
  • New test file tests/rex4/frame_state_growth.rs with 30+ tests covering:
    • Basic per-frame budget allocation (98/100 rule, boundary cases)
    • Frame-local absorption semantics (revert not halt, gas returned, state discarded)
    • Revert data encoding (MegaLimitExceeded ABI decoding)
    • Nested frame scenarios (deeply nested, sibling frames, multiple exceeds)
    • Backward compatibility (REX3 has no per-frame limits, halts on TX-level exceed)
    • Refund interactions (net growth, eager check, child refunds reflected in sibling budgets)

…structure

Migrate all four resource limit trackers to use the generic FrameLimitTracker<I>
infrastructure. Per-frame budget enforcement (98/100 forwarding) is enabled for
state growth only in Rex4; compute gas, data size, and KV updates remain
TX-level-only.

- Add FrameLimitTracker<I> and FrameLimitEntry<I> generic frame-aware tracking
- Reimplement ComputeGasLimit2, DataSizeLimit2, KVUpdateLimit2, StateGrowthLimit2
  on top of FrameLimitTracker, replacing old tracker types
- Add frame-local exceed absorption in AdditionalLimit::before_frame_return_result
- Add Rex4 spec, update RESOURCE_ACCOUNTING.md, and add tests
- Rename DataSizeLimit2, KVUpdateLimit2, ComputeGasLimit2, StateGrowthLimit2
  to DataSizeTracker, KVUpdateTracker, ComputeGasTracker, StateGrowthTracker
- Extract shared DataSizeFrameInfo from data_size.rs into frame_limit.rs
  as CallFrameInfo for use by both DataSizeTracker and KVUpdateTracker
- Fix truncated doc comment on FrameLimitTracker::pop_frame
- Fix arithmetic error in specs/Rex4.md example
@Troublor Troublor merged commit e12e054 into main Feb 27, 2026
2 checks passed
@Troublor Troublor deleted the william/feat/frame_limit branch February 27, 2026 07:13
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.

1 participant