use super::GasCost;
use crate::Word;
pub fn memory_expansion_gas_cost(curr_memory_word_size: u64, next_memory_word_size: u64) -> u64 {
if next_memory_word_size == curr_memory_word_size {
0
} else {
GasCost::MEMORY_EXPANSION_LINEAR_COEFF * (next_memory_word_size - curr_memory_word_size)
+ next_memory_word_size * next_memory_word_size
/ GasCost::MEMORY_EXPANSION_QUAD_DENOMINATOR
- curr_memory_word_size * curr_memory_word_size
/ GasCost::MEMORY_EXPANSION_QUAD_DENOMINATOR
}
}
pub fn memory_copier_gas_cost(
curr_memory_word_size: u64,
next_memory_word_size: u64,
num_copy_bytes: u64,
) -> u64 {
let num_words = (num_copy_bytes + 31) / 32;
num_words * GasCost::COPY +
if num_words > 0 {
memory_expansion_gas_cost(curr_memory_word_size, next_memory_word_size)
} else {
0
}
}
pub fn eip150_gas(gas_left: u64, gas_specified: Word) -> u64 {
let capped_gas = gas_left - gas_left / 64;
if gas_specified.bits() <= 64 {
let gas_specified = gas_specified.low_u64();
if gas_specified < capped_gas {
return gas_specified;
}
}
capped_gas
}