Skip to main content

revmc_builtins/
gas.rs

1//! Gas calculation utilities.
2
3use revm_primitives::hardfork::SpecId;
4
5pub use revm_interpreter::gas::*;
6
7/// Calculate SLOAD gas cost (pre-Berlin only).
8#[inline]
9pub const fn sload_cost(spec_id: SpecId, is_cold: bool) -> u64 {
10    if spec_id.is_enabled_in(SpecId::BERLIN) {
11        if is_cold { COLD_SLOAD_COST } else { WARM_STORAGE_READ_COST }
12    } else if spec_id.is_enabled_in(SpecId::ISTANBUL) {
13        ISTANBUL_SLOAD_GAS
14    } else if spec_id.is_enabled_in(SpecId::TANGERINE) {
15        200
16    } else {
17        50
18    }
19}
20
21// These are overridden to only account for the dynamic cost.
22
23/// `LOG` opcode cost calculation.
24#[inline]
25pub const fn dyn_log_cost(len: u64) -> Option<u64> {
26    LOGDATA.checked_mul(len)
27}