diff --git a/src/eei.cpp b/src/eei.cpp index 3877fd1df..bb675a8bc 100644 --- a/src/eei.cpp +++ b/src/eei.cpp @@ -203,8 +203,9 @@ string toHex(evmc_uint256be const& value) { HERA_DEBUG << "useGas " << gas << "\n"; takeGas(gas); - // FIXME: this may overflow - takeGas(gas * memory.size() / GasSchedule::memoryPageSize * GasSchedule::memoryCostPerPage); + + ensureCondition((ffsl(gas) + ffsl(memory.size()) <= 64), OutOfGasException, "Memory gas calculation overflow."); //may need to find alternative to ffsl for cross-libc portability + takeGas(gas * memory.size() / GasSchedule::memoryPageSize * GasSchedule::memoryCostPerPage + 1); //round gas cost up return Literal(); }