Skip to content

Commit

Permalink
Add sload gas cost
Browse files Browse the repository at this point in the history
  • Loading branch information
lima-limon-inc committed Feb 11, 2025
1 parent 88d15bf commit f314655
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions crates/vm/levm/src/gas_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,21 +398,26 @@ fn mem_expansion_behavior(
}

pub fn sload(storage_slot_was_cold: bool, fork: Fork) -> Result<u64, VMError> {
// EIP https://eips.ethereum.org/EIPS/eip-2929
if fork < Fork::Berlin {
return Ok(SLOAD_COST_PRE_BERLIN);
}
let static_gas = SLOAD_STATIC;
match fork {
f if f < Fork::Tangerine => Ok(50),
f if f >= Fork::Tangerine && f < Fork::Berlin => {
// EIP https://eips.ethereum.org/EIPS/eip-2929
Ok(SLOAD_COST_PRE_BERLIN)
}
_ => {
let static_gas = SLOAD_STATIC;

let dynamic_cost = if storage_slot_was_cold {
SLOAD_COLD_DYNAMIC
} else {
SLOAD_WARM_DYNAMIC
};
let dynamic_cost = if storage_slot_was_cold {
SLOAD_COLD_DYNAMIC
} else {
SLOAD_WARM_DYNAMIC
};

Ok(static_gas
.checked_add(dynamic_cost)
.ok_or(OutOfGasError::GasCostOverflow)?)
Ok(static_gas
.checked_add(dynamic_cost)
.ok_or(OutOfGasError::GasCostOverflow)?)
}
}
}

pub fn sstore(
Expand Down

0 comments on commit f314655

Please sign in to comment.