MegaLimitControl
MegaLimitControl system contract — runtime query for effective remaining compute gas under detention and call-frame limits.
This page specifies the MegaLimitControl system contract. It defines the address, interface, interception semantics, and the remaining-compute-gas query.
Motivation
MegaETH's gas detention and per-call-frame resource budgets both constrain a transaction's effective compute gas below the standard EVM gas limit. The standard GAS opcode returns the remaining total gas, which does not reflect these MegaETH-specific constraints.
Contracts that perform gas-aware logic (e.g., batching operations until a threshold, deciding whether to attempt a costly sub-call) need a way to query their actual effective compute gas budget at runtime.
MegaLimitControl provides a single query that returns the effective remaining compute gas, accounting for both detention and call-frame limits.
Specification
Address
The MegaLimitControl system contract MUST exist at MEGA_LIMIT_CONTROL_ADDRESS.
Bytecode
The contract takes no constructor arguments. A node MUST deploy the bytecode version corresponding to the active spec.
Source: MegaLimitControl.sol
Version 1.0.0
Since: Rex4
Code hash: 0x3927f2a4803c5e18153ff5742d0fa1acd9ad04538e4e6037cb4a9b28694ca87f
Deployed bytecode:
Interface
Interception Scope
The remainingComputeGas function participates in call interception. The node MUST intercept CALL and STATICCALL to MEGA_LIMIT_CONTROL_ADDRESS when the input matches the remainingComputeGas() selector.
DELEGATECALL and CALLCODE to this address MUST NOT be intercepted. They fall through to the on-chain bytecode, which reverts with NotIntercepted().
Unknown selectors MUST NOT be intercepted and MUST fall through to the on-chain bytecode.
Value Transfer Policy
All intercepted functions MUST reject calls with non-zero value transfer. If the call carries a non-zero transferred value, the node MUST revert with NonZeroTransfer().
remainingComputeGas
remainingComputeGasWhen intercepted, the node MUST return the effective remaining compute gas for the caller's call frame at the time of the call.
The returned value MUST equal:
Where:
frame_remaining_compute_gasis the caller's per-call-frame compute gas budget minus the compute gas already consumed in that frame.tx_detained_remaining_compute_gasis the transaction-level effective compute gas limit (after detention, if any) minus the transaction's total compute gas consumed so far.
The returned value is a point-in-time snapshot. It decreases as execution proceeds.
Constants
MEGA_LIMIT_CONTROL_ADDRESS
0x6342000000000000000000000000000000000005
MegaLimitControl contract address
Rationale
Why a system contract instead of an EVM opcode? Effective remaining compute gas is a MegaETH-specific concept that combines detention and call-frame budgets. Using a system contract provides a stable Solidity interface without introducing a non-standard opcode.
Why return a single value instead of separate detention and frame budgets? Contracts that perform gas-aware logic need one number: "how much compute gas can I still use?" Exposing the two components separately would push the min() calculation into every caller, adding complexity without benefit. The combined value is the only operationally meaningful quantity.
Why uint64 instead of uint256? Compute gas is bounded by the transaction compute gas limit (200,000,000), which fits in uint64. Using uint64 avoids unnecessary padding and matches the natural width of gas values in the EVM implementation.
Spec History
Rex4 introduced the MegaLimitControl system contract.
Last updated