Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/mega-evm/src/evm/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,13 @@ pub mod storage_gas_ext {
}
}

/// Compute gas recording implementation. TODO: add more doc
/// Per-opcode compute-gas recording wrappers.
///
/// Each opcode is wrapped so the compute gas it consumes (`gas_before - gas_after`, minus any
/// gas forwarded to a child frame for the call/create family) is recorded into the compute-gas
/// dimension of `AdditionalLimit` after the inner instruction runs. The `wrap_op_compute_gas`
/// macro below defines the `default` and `@frame` variants; `SELFDESTRUCT` uses a dedicated
/// wrapper whose trailing check fans out across all four limit dimensions.
pub mod compute_gas_ext {
use super::*;

Expand Down
9 changes: 5 additions & 4 deletions crates/mega-evm/src/evm/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ impl MegaPrecompiles {
Self { inner: EthPrecompiles { precompiles: inner, spec: spec.into_eth_spec() }, spec }
}

/// Get the precompiles for the current spec.
/// Returns the static base precompile table selected for this provider's spec.
///
/// This method returns precompiles with custom gas cost overrides for `MINI_REX` spec.
/// The MegaETH precompile gas-cost overrides (the fixed-cost KZG point evaluation and the
/// Osaka ModExp schedule) are baked into the table itself by [`mini_rex`] / [`rex`]; the
/// per-spec compute-gas accounting and the REX5 forwarded-gas cap are applied separately in
/// the `run()` method, not here.
#[inline]
pub fn precompiles(&self) -> &'static Precompiles {
// For now, just use the inner precompiles
// Custom gas costs will be applied in the run() method
self.inner.precompiles
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/mega-evm/src/limit/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,12 @@ impl AdditionalLimit {
self.data_size.after_frame_init_on_frame(frame);
self.kv_update.after_frame_init_on_frame(frame);
self.compute_gas.after_frame_init_on_frame(frame);
// Deliberately no `check_limit()` here: this records the child frame's init growth
// (e.g. the CREATE account-info write), but `before_frame_run` runs `check_limit()`
// before the frame's first metered opcode executes. Per the Resource-Limit Check
// Protocol, that latches any exceed ahead of the first `record_compute_gas`, so a
// latch here would be redundant. The deferral is sound only because this fixed
// lifecycle order (after_frame_init → before_frame_run → first opcode) is guaranteed.
} else if let ItemOrResult::Result(result) = init_result {
// Rescue gas if a TX-level limit was exceeded. This covers the
// before_frame_init early-return path and any other Result from frame_init.
Expand Down