1use crate::consts::*;
2use evm_core::ExitError;
3
4pub fn memory_gas(a: usize) -> Result<u64, ExitError> {
5 let a = a as u64;
6 G_MEMORY
7 .checked_mul(a)
8 .ok_or(ExitError::OutOfGas)?
9 .checked_add(a.checked_mul(a).ok_or(ExitError::OutOfGas)? / 512)
10 .ok_or(ExitError::OutOfGas)
11}